diff --git a/src/CLOUD/classes.c b/src/CLOUD/classes.cpp similarity index 99% rename from src/CLOUD/classes.c rename to src/CLOUD/classes.cpp index 7b93de86..fef648cf 100644 --- a/src/CLOUD/classes.c +++ b/src/CLOUD/classes.cpp @@ -3,7 +3,7 @@ GitHub/GitLab: korenkonder */ -#include "classes.h" +#include "classes.hpp" bool data_test_shared_lock; diff --git a/src/CLOUD/classes.h b/src/CLOUD/classes.hpp similarity index 98% rename from src/CLOUD/classes.h rename to src/CLOUD/classes.hpp index 9889dd4c..63a58175 100644 --- a/src/CLOUD/classes.h +++ b/src/CLOUD/classes.hpp @@ -6,7 +6,7 @@ #pragma once #include "../KKdLib/default.hpp" -#include "../CRE/lock.h" +#include "../CRE/lock.hpp" #include "../CRE/render_context.hpp" #include "../CRE/task.hpp" diff --git a/src/CLOUD/classes/data_test.c b/src/CLOUD/classes/data_test.cpp similarity index 98% rename from src/CLOUD/classes/data_test.c rename to src/CLOUD/classes/data_test.cpp index e3087809..b52890ca 100644 --- a/src/CLOUD/classes/data_test.c +++ b/src/CLOUD/classes/data_test.cpp @@ -3,7 +3,7 @@ GitHub/GitLab: korenkonder */ -#include "data_test.h" +#include "data_test.hpp" #include "data_test/auth_3d_test.hpp" #include "data_test/glitter_test.hpp" #include "data_test/stage_test.hpp" diff --git a/src/CLOUD/classes/data_test.h b/src/CLOUD/classes/data_test.hpp similarity index 90% rename from src/CLOUD/classes/data_test.h rename to src/CLOUD/classes/data_test.hpp index 62df7586..4cfe89b2 100644 --- a/src/CLOUD/classes/data_test.h +++ b/src/CLOUD/classes/data_test.hpp @@ -5,7 +5,7 @@ #pragma once -#include "../classes.h" +#include "../classes.hpp" enum data_test_classes_enum { DATA_TEST_AUTH_3D_TEST, diff --git a/src/CLOUD/classes/data_test/auth_3d_test.cpp b/src/CLOUD/classes/data_test/auth_3d_test.cpp index e82e0316..4e1bcf99 100644 --- a/src/CLOUD/classes/data_test/auth_3d_test.cpp +++ b/src/CLOUD/classes/data_test/auth_3d_test.cpp @@ -12,8 +12,8 @@ #include "../../../CRE/render_context.hpp" #include "../../../CRE/stage.hpp" #include "../../input.hpp" -#include "../data_test.h" -#include "../imgui_helper.h" +#include "../data_test.hpp" +#include "../imgui_helper.hpp" struct data_test_auth_3d_test_uid { const char* name; @@ -148,7 +148,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { int32_t auth_3d_category_index = auth_3d_test_window->auth_3d_category_index; - imguiGetContentRegionAvailSetNextItemWidth(); + ImGui::GetContentRegionAvailSetNextItemWidth(); if (ImGui::BeginCombo("##Auth 3D Category Index", auth_3d_category_index > -1 ? auth_3d_db_cat[auth_3d_category_index].name : "", 0)) { for (data_test_auth_3d_test_category& i : auth_3d_db_cat) { @@ -156,7 +156,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { ImGui::PushID(&i); if (ImGui::Selectable(i.name, auth_3d_category_index == auth_3d_category_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && auth_3d_category_index != auth_3d_category_idx)) { auth_3d_category_index = auth_3d_category_idx; } @@ -195,7 +195,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { ImGui::Checkbox("OBJ Link", &auth_3d_test_task.window.obj_link); - imguiGetContentRegionAvailSetNextItemWidth(); + ImGui::GetContentRegionAvailSetNextItemWidth(); bool auth_3d_category_found = false; for (data_test_auth_3d_test_category& i : auth_3d_db_cat) { if (auth_3d_category_index != &i - auth_3d_db_cat.data()) @@ -208,7 +208,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { ImGui::PushID(&j); if (ImGui::Selectable(j.name, auth_3d_index == auth_3d_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && auth_3d_index != auth_3d_idx)) { auth_3d_test_window->auth_3d_index = -1; auth_3d_index = auth_3d_idx; @@ -241,8 +241,8 @@ void data_test_auth_3d_test_imgui(class_data* data) { float_t frame = auth_3d_test_window->frame; ImGui::Text("frame[ 0,%4.0f)", auth_3d_test_window->last_frame); - imguiGetContentRegionAvailSetNextItemWidth(); - igSliderFloatButton("##frame slider", &frame, 1.0f, + ImGui::GetContentRegionAvailSetNextItemWidth(); + ImGui::SliderFloatButton("##frame slider", &frame, 1.0f, 0.0f, auth_3d_test_window->last_frame, "%5.0f", 0); if (ImGui::IsItemActivated()) auth_3d_test_window->paused = true; @@ -268,23 +268,21 @@ void data_test_auth_3d_test_imgui(class_data* data) { auth_3d_test_window->frame = frame; } - imguiColumnSliderFloat("transX", &auth_3d_test_task.trans_value.x, 0.1f, -5.0f, 5.0f, "%.2f", 0, true); - imguiColumnSliderFloat("transZ", &auth_3d_test_task.trans_value.z, 0.1f, -5.0f, 5.0f, "%.2f", 0, true); - imguiColumnSliderFloat("rotY", &auth_3d_test_task.rot_y_value, 1.0f, -360.0f, 360.0f, "%.0f", 0, true); + ImGui::ColumnSliderFloat("transX", &auth_3d_test_task.trans_value.x, 0.1f, -5.0f, 5.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("transZ", &auth_3d_test_task.trans_value.z, 0.1f, -5.0f, 5.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("rotY", &auth_3d_test_task.rot_y_value, 1.0f, -360.0f, 360.0f, "%.0f", 0, true); if (ImGui::Button("cam reset", { 72.0f, 0.0f }) && rctx_ptr && rctx_ptr->camera) { camera* cam = rctx_ptr->camera; - camera_set_fov(cam, 32.2673416137695); - camera_set_roll(cam, 0.0); - vec3 view_point = { 0.0f, 1.0f, 6.0f }; - camera_set_view_point(cam, &view_point); - vec3 interest = { 0.0f, 1.0f, 0.0f }; - camera_set_interest(cam, &interest); + cam->set_fov(32.2673416137695); + cam->set_roll(0.0); + cam->set_view_point({ 0.0f, 1.0f, 6.0f }); + cam->set_interest({ 0.0f, 1.0f, 0.0f }); } ImGui::Separator(); - imguiColumnSliderFloat("Frame Speed", &frame_speed, 0.01f, 0.0f, 3.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Frame Speed", &frame_speed, 0.01f, 0.0f, 3.0f, "%.2f", 0, true); data->imgui_focus |= ImGui::IsWindowFocused(); ImGui::End(); @@ -318,7 +316,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { int32_t stage_index = auth_3d_test_task.stage_index; - imguiGetContentRegionAvailSetNextItemWidth(); + ImGui::GetContentRegionAvailSetNextItemWidth(); if (ImGui::BeginCombo("##Stage Index", stage_index > -1 ? auth_3d_test_window->stage[stage_index] : "", 0)) { for (const char*& i : auth_3d_test_window->stage) { @@ -326,7 +324,7 @@ void data_test_auth_3d_test_imgui(class_data* data) { ImGui::PushID(i); if (ImGui::Selectable(i, stage_index == stage_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && stage_index != stage_idx)) stage_index = stage_idx; ImGui::PopID(); diff --git a/src/CLOUD/classes/data_test/auth_3d_test.hpp b/src/CLOUD/classes/data_test/auth_3d_test.hpp index f9bb733b..702e2467 100644 --- a/src/CLOUD/classes/data_test/auth_3d_test.hpp +++ b/src/CLOUD/classes/data_test/auth_3d_test.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_test_auth_3d_test_init(class_data* data, render_context* rctx); extern void data_test_auth_3d_test_ctrl(class_data* data); diff --git a/src/CLOUD/classes/data_test/glitter_test.cpp b/src/CLOUD/classes/data_test/glitter_test.cpp index 922840ba..f5c4b474 100644 --- a/src/CLOUD/classes/data_test/glitter_test.cpp +++ b/src/CLOUD/classes/data_test/glitter_test.cpp @@ -11,8 +11,8 @@ #include "../../../CRE/render_context.hpp" #include "../../../CRE/stage.hpp" #include "../../input.hpp" -#include "../data_test.h" -#include "../imgui_helper.h" +#include "../data_test.hpp" +#include "../imgui_helper.hpp" #include "stage_test.hpp" class TaskDataTestGlitterParticle : public app::TaskWindow { @@ -109,11 +109,9 @@ bool TaskDataTestGlitterParticle::Init() { clear_color = { 0x60, 0x60, 0x60, 0xFF }; camera* cam = rctx_ptr->camera; - camera_reset(cam); - vec3 view_point = { 0.0f, 0.88f, 4.3f }; - camera_set_view_point(cam, &view_point); - vec3 interest = { 0.0f, 1.0f, 0.0f }; - camera_set_interest(cam, &interest); + cam->reset(); + cam->set_view_point({ 0.0f, 0.88f, 4.3f }); + cam->set_interest({ 0.0f, 1.0f, 0.0f }); hash = hash_fnv1a64m_empty; scene_counter = 0; @@ -206,47 +204,47 @@ void TaskDataTestGlitterParticle::Window() { return; } - if (imguiColumnComboBoxConfigFile("File", files.data(), + if (ImGui::ColumnComboBoxConfigFile("File", files.data(), files.size(), &file_index, 0, false, &window_focus)) { load_file = true; input_stop = true; } - if (imguiButton("Reset Camera (R)")) + if (ImGui::ButtonEnterKeyPressed("Reset Camera (R)")) input_reset = true; - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Play (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Play (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) input_play = true; - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Stop (V)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_V)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Stop (V)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_V)) input_stop = true; bool pause = Glitter::glt_particle_manager.GetPause(); - imguiCheckbox("Pause (G)", &pause); + ImGui::CheckboxEnterKeyPressed("Pause (G)", &pause); if (ImGui::IsKeyPressed(GLFW_KEY_G)) pause ^= true; Glitter::glt_particle_manager.SetPause(pause); - imguiCheckbox("Auto (T)", &auto_and_repeat); + ImGui::CheckboxEnterKeyPressed("Auto (T)", &auto_and_repeat); if (ImGui::IsKeyPressed(GLFW_KEY_T)) auto_and_repeat ^= true; - imguiCheckbox("PV Mode (P)", &pv_mode); + ImGui::CheckboxEnterKeyPressed("PV Mode (P)", &pv_mode); if (ImGui::IsKeyPressed(GLFW_KEY_P)) pv_mode ^= true; ImGui::Separator(); - imguiColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); ImGui::Separator(); - imguiCheckbox("Show Grid", &draw_grid_3d); + ImGui::CheckboxEnterKeyPressed("Show Grid", &draw_grid_3d); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Stage", { w, 0.0f })) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Stage", { w, 0.0f })) stage_test = true; window_focus |= ImGui::IsWindowFocused(); diff --git a/src/CLOUD/classes/data_test/glitter_test.hpp b/src/CLOUD/classes/data_test/glitter_test.hpp index 4f636a65..607c2102 100644 --- a/src/CLOUD/classes/data_test/glitter_test.hpp +++ b/src/CLOUD/classes/data_test/glitter_test.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_test_glitter_test_init(class_data* data, render_context* rctx); extern void data_test_glitter_test_ctrl(class_data* data); diff --git a/src/CLOUD/classes/data_test/stage_test.cpp b/src/CLOUD/classes/data_test/stage_test.cpp index 5bd262b2..ebdefaf7 100644 --- a/src/CLOUD/classes/data_test/stage_test.cpp +++ b/src/CLOUD/classes/data_test/stage_test.cpp @@ -11,8 +11,8 @@ #include "../../../CRE/render_context.hpp" #include "../../../CRE/stage.hpp" #include "../../input.hpp" -#include "../data_test.h" -#include "../imgui_helper.h" +#include "../data_test.hpp" +#include "../imgui_helper.hpp" struct data_test_stage_test_stage_pv { int32_t pv_id; @@ -121,7 +121,7 @@ void data_test_stage_test_imgui(class_data* data) { ImGui::PushID(&i); sprintf_s(buf, sizeof(buf), "%03d", i.pv_id); if (ImGui::Selectable(buf, pv_id == i.pv_id) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && pv_id != i.pv_id)) pv_id = i.pv_id; ImGui::PopID(); @@ -155,7 +155,7 @@ void data_test_stage_test_imgui(class_data* data) { ImGui::PushID(j); if (ImGui::Selectable(stg_data[j].name.c_str(), pv_index == pv_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && pv_index != pv_idx)) { dtw_stg->pv_index = -1; pv_index = pv_idx; @@ -195,7 +195,7 @@ void data_test_stage_test_imgui(class_data* data) { ImGui::PushID(i); if (ImGui::Selectable(stg_data[stage_ns[i]].name.c_str(), ns_index == ns_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && ns_index != ns_idx)) { dtw_stg->ns_index = -1; ns_index = ns_idx; @@ -228,7 +228,7 @@ void data_test_stage_test_imgui(class_data* data) { ImGui::PushID(i); if (ImGui::Selectable(stg_data[i].name.c_str(), other_index == other_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && other_index != other_idx)) { dtw_stg->other_index = -1; other_index = other_idx; @@ -251,7 +251,7 @@ void data_test_stage_test_imgui(class_data* data) { int32_t stage_index = dtw_stg->stage_index; - imguiGetContentRegionAvailSetNextItemWidth(); + ImGui::GetContentRegionAvailSetNextItemWidth(); if (ImGui::BeginCombo("##Stage Index", stage_index > -1 ? stg_data[stage_index].name.c_str() : "", 0)) { for (stage_data& i : stg_data) { @@ -259,7 +259,7 @@ void data_test_stage_test_imgui(class_data* data) { ImGui::PushID(&i); if (ImGui::Selectable(i.name.c_str(), stage_index == stage_idx) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && stage_index != stage_idx)) { dtw_stg->stage_index = -1; stage_index = stage_idx; @@ -329,12 +329,10 @@ static bool stage_test_load() { clear_color = { 96, 96, 96, 255 }; camera* cam = rctx_ptr->camera; - camera_reset(cam); - vec3 view_point = { 0.0f, 0.88f, 4.3f }; - camera_set_view_point(cam, &view_point); - vec3 interest = { 0.0f, 1.0f, 0.0f }; - camera_set_interest(cam, &interest); - app::TaskWork::AppendTask(&dtm_stg, "DATA_TEST_STAGE"); + cam->reset(); + cam->set_view_point({ 0.0f, 0.88f, 4.3f }); + cam->set_interest({ 0.0f, 1.0f, 0.0f }); + app::TaskWork::AppendTask(dtm_stg, "DATA_TEST_STAGE"); if (!dtw_stg) dtw_stg = new DtwStg(); @@ -344,7 +342,7 @@ static bool stage_test_load() { } static bool stage_test_unload() { - dtm_stg.SetDest(); + dtm_stg->SetDest(); classes_data* c = &data_test_classes[DATA_TEST_STAGE_TEST]; enum_or(c->data.flags, CLASS_HIDE); diff --git a/src/CLOUD/classes/data_test/stage_test.hpp b/src/CLOUD/classes/data_test/stage_test.hpp index 89687c32..8354ea78 100644 --- a/src/CLOUD/classes/data_test/stage_test.hpp +++ b/src/CLOUD/classes/data_test/stage_test.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_test_stage_test_init(class_data* data, render_context* rctx); extern void data_test_stage_test_ctrl(class_data* data); diff --git a/src/CLOUD/classes/data_view.c b/src/CLOUD/classes/data_view.cpp similarity index 93% rename from src/CLOUD/classes/data_view.c rename to src/CLOUD/classes/data_view.cpp index 9e147c51..8fd02729 100644 --- a/src/CLOUD/classes/data_view.c +++ b/src/CLOUD/classes/data_view.cpp @@ -3,12 +3,12 @@ GitHub/GitLab: korenkonder */ -#include "data_view.h" -#include "data_view/auth_3d.h" -#include "data_view/draw_task.h" -#include "data_view/glitter.h" -#include "data_view/object.h" -#include "data_view/texture.h" +#include "data_view.hpp" +#include "data_view/auth_3d.hpp" +#include "data_view/draw_task.hpp" +#include "data_view/glitter.hpp" +#include "data_view/object.hpp" +#include "data_view/texture.hpp" classes_data data_view_classes[] = { { diff --git a/src/CLOUD/classes/data_view.h b/src/CLOUD/classes/data_view.hpp similarity index 91% rename from src/CLOUD/classes/data_view.h rename to src/CLOUD/classes/data_view.hpp index 59df4322..5cd9a62b 100644 --- a/src/CLOUD/classes/data_view.h +++ b/src/CLOUD/classes/data_view.hpp @@ -5,7 +5,7 @@ #pragma once -#include "../classes.h" +#include "../classes.hpp" enum data_view_classes_enum { DATA_VIEW_AUTH_3D, diff --git a/src/CLOUD/classes/data_view/auth_3d.c b/src/CLOUD/classes/data_view/auth_3d.cpp similarity index 99% rename from src/CLOUD/classes/data_view/auth_3d.c rename to src/CLOUD/classes/data_view/auth_3d.cpp index d19d764d..f45a8ef5 100644 --- a/src/CLOUD/classes/data_view/auth_3d.c +++ b/src/CLOUD/classes/data_view/auth_3d.cpp @@ -3,10 +3,10 @@ GitHub/GitLab: korenkonder */ -#include "auth_3d.h" +#include "auth_3d.hpp" #include "../../../CRE/auth_3d.hpp" #include "../../input.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" static const char* auth_3d_fog_name[] = { "Depth", diff --git a/src/CLOUD/classes/data_view/auth_3d.h b/src/CLOUD/classes/data_view/auth_3d.hpp similarity index 91% rename from src/CLOUD/classes/data_view/auth_3d.h rename to src/CLOUD/classes/data_view/auth_3d.hpp index 6b846c6a..dfee8be8 100644 --- a/src/CLOUD/classes/data_view/auth_3d.h +++ b/src/CLOUD/classes/data_view/auth_3d.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_view_auth_3d_init(class_data* data, render_context* rctx); extern void data_view_auth_3d_imgui(class_data* data); diff --git a/src/CLOUD/classes/data_view/draw_task.c b/src/CLOUD/classes/data_view/draw_task.cpp similarity index 97% rename from src/CLOUD/classes/data_view/draw_task.c rename to src/CLOUD/classes/data_view/draw_task.cpp index c569ca46..fdd99ea0 100644 --- a/src/CLOUD/classes/data_view/draw_task.c +++ b/src/CLOUD/classes/data_view/draw_task.cpp @@ -3,11 +3,11 @@ GitHub/GitLab: korenkonder */ -#include "draw_task.h" +#include "draw_task.hpp" #include "../../../CRE/render_context.hpp" #include "../../../KKdLib/hash.hpp" #include "../../../KKdLib/sort.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" static const char* draw_object_type_name[] = { "Opaque", @@ -124,10 +124,10 @@ void data_view_draw_task_imgui(class_data* data) { std::vector& draw_tasks = draw_task_array[i]; size_t count = draw_tasks.size(); bool enable = count > 0; - imguiDisableElementPush(enable); + ImGui::DisableElementPush(enable); if (!ImGui::TreeNodeEx("", tree_node_flags, "%s; Count: %llu", draw_object_type_name[i], count)) { - imguiDisableElementPop(enable); + ImGui::DisableElementPop(enable); ImGui::PopID(); continue; } @@ -203,7 +203,7 @@ void data_view_draw_task_imgui(class_data* data) { draw_tasks_sort.clear(); ImGui::TreePop(); - imguiDisableElementPop(enable); + ImGui::DisableElementPop(enable); ImGui::PopID(); } diff --git a/src/CLOUD/classes/data_view/draw_task.h b/src/CLOUD/classes/data_view/draw_task.hpp similarity index 91% rename from src/CLOUD/classes/data_view/draw_task.h rename to src/CLOUD/classes/data_view/draw_task.hpp index 4cfaf6c5..08c884a8 100644 --- a/src/CLOUD/classes/data_view/draw_task.h +++ b/src/CLOUD/classes/data_view/draw_task.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_view_draw_task_init(class_data* data, render_context* rctx); extern void data_view_draw_task_imgui(class_data* data); diff --git a/src/CLOUD/classes/data_view/glitter.c b/src/CLOUD/classes/data_view/glitter.cpp similarity index 99% rename from src/CLOUD/classes/data_view/glitter.c rename to src/CLOUD/classes/data_view/glitter.cpp index c2ac474e..d8fba3b9 100644 --- a/src/CLOUD/classes/data_view/glitter.c +++ b/src/CLOUD/classes/data_view/glitter.cpp @@ -3,10 +3,10 @@ GitHub/GitLab: korenkonder */ -#include "glitter.h" +#include "glitter.hpp" #include "../../../CRE/Glitter/glitter.hpp" #include "../../../CRE/render_context.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" struct data_view_glitter { render_context* rctx; diff --git a/src/CLOUD/classes/data_view/glitter.h b/src/CLOUD/classes/data_view/glitter.hpp similarity index 91% rename from src/CLOUD/classes/data_view/glitter.h rename to src/CLOUD/classes/data_view/glitter.hpp index 38497f01..8ff115f6 100644 --- a/src/CLOUD/classes/data_view/glitter.h +++ b/src/CLOUD/classes/data_view/glitter.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_view_glitter_init(class_data* data, render_context* rctx); extern void data_view_glitter_imgui(class_data* data); diff --git a/src/CLOUD/classes/data_view/object.c b/src/CLOUD/classes/data_view/object.cpp similarity index 97% rename from src/CLOUD/classes/data_view/object.c rename to src/CLOUD/classes/data_view/object.cpp index 0427cc90..9b66e50a 100644 --- a/src/CLOUD/classes/data_view/object.c +++ b/src/CLOUD/classes/data_view/object.cpp @@ -3,9 +3,9 @@ GitHub/GitLab: korenkonder */ -#include "object.h" +#include "object.hpp" #include "../../../CRE/render_context.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" struct data_view_object { render_context* rctx; diff --git a/src/CLOUD/classes/data_view/object.h b/src/CLOUD/classes/data_view/object.hpp similarity index 91% rename from src/CLOUD/classes/data_view/object.h rename to src/CLOUD/classes/data_view/object.hpp index 5b309ac4..3a078471 100644 --- a/src/CLOUD/classes/data_view/object.h +++ b/src/CLOUD/classes/data_view/object.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_view_object_init(class_data* data, render_context* rctx); extern void data_view_object_imgui(class_data* data); diff --git a/src/CLOUD/classes/data_view/texture.c b/src/CLOUD/classes/data_view/texture.cpp similarity index 95% rename from src/CLOUD/classes/data_view/texture.c rename to src/CLOUD/classes/data_view/texture.cpp index 5b7b7fd1..1d38257d 100644 --- a/src/CLOUD/classes/data_view/texture.c +++ b/src/CLOUD/classes/data_view/texture.cpp @@ -3,9 +3,9 @@ GitHub/GitLab: korenkonder */ -#include "texture.h" +#include "texture.hpp" #include "../../../CRE/render_context.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" struct data_view_texture { render_context* rctx; @@ -30,7 +30,7 @@ void data_view_texture_imgui(class_data* data) { ImGuiStyle& style = ImGui::GetStyle(); ImFont* font = ImGui::GetFont(); - float_t w = min((float_t)width, 560.0f); + float_t w = min((float_t)width, 580.0f); float_t h = min((float_t)height, 480.0f); ImGui::SetNextWindowPos({ 0, 0 }, ImGuiCond_Appearing); diff --git a/src/CLOUD/classes/data_view/texture.h b/src/CLOUD/classes/data_view/texture.hpp similarity index 91% rename from src/CLOUD/classes/data_view/texture.h rename to src/CLOUD/classes/data_view/texture.hpp index 1824d575..2bb7aecc 100644 --- a/src/CLOUD/classes/data_view/texture.h +++ b/src/CLOUD/classes/data_view/texture.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool data_view_texture_init(class_data* data, render_context* rctx); extern void data_view_texture_imgui(class_data* data); diff --git a/src/CLOUD/classes/glitter_editor.c b/src/CLOUD/classes/glitter_editor.cpp similarity index 93% rename from src/CLOUD/classes/glitter_editor.c rename to src/CLOUD/classes/glitter_editor.cpp index d7510e1d..d2545200 100644 --- a/src/CLOUD/classes/glitter_editor.c +++ b/src/CLOUD/classes/glitter_editor.cpp @@ -6,7 +6,7 @@ */ #if defined(CLOUD_DEV) -#include "glitter_editor.h" +#include "glitter_editor.hpp" #include "../../KKdLib/io/path.hpp" #include "../../KKdLib/io/stream.hpp" #include "../../KKdLib/dds.hpp" @@ -15,19 +15,19 @@ #include "../../KKdLib/txp.hpp" #include "../../KKdLib/vec.hpp" #include "../../CRE/Glitter/glitter.hpp" -#include "../../CRE/camera.h" +#include "../../CRE/camera.hpp" #include "../../CRE/data.hpp" -#include "../../CRE/draw_task.h" -#include "../../CRE/gl_state.h" +#include "../../CRE/draw_task.hpp" +#include "../../CRE/gl_state.hpp" #include "../../CRE/render_context.hpp" #include "../../CRE/shader_glsl.hpp" #include "../../CRE/stage.hpp" -#include "../../CRE/static_var.h" +#include "../../CRE/static_var.hpp" #include "../input.hpp" #include #include #include -#include "imgui_helper.h" +#include "imgui_helper.hpp" #include enum glitter_editor_selected_enum { @@ -83,10 +83,16 @@ struct glitter_curve_editor { typedef struct glitter_editor_gl_wireframe { shader_glsl shader; + + glitter_editor_gl_wireframe(); + virtual ~glitter_editor_gl_wireframe(); } glitter_editor_gl_wireframe; typedef struct glitter_editor_gl { glitter_editor_gl_wireframe wireframe; + + glitter_editor_gl(); + virtual ~glitter_editor_gl(); } glitter_editor_gl; struct glitter_editor_struct { @@ -137,7 +143,7 @@ struct glitter_editor_struct { Glitter::Particle* selected_particle; glitter_curve_editor curve_editor; - glitter_editor_gl gl_data; + glitter_editor_gl* gl_data; }; static const float_t curve_base_values[] = { @@ -1228,6 +1234,22 @@ bool glitter_editor_dispose(class_data* data) { return true; } +glitter_editor_gl_wireframe::glitter_editor_gl_wireframe() { + +} + +glitter_editor_gl_wireframe::~glitter_editor_gl_wireframe() { + +} + +glitter_editor_gl::glitter_editor_gl() { + +} + +glitter_editor_gl::~glitter_editor_gl() { + +} + static void glitter_editor_windows(glitter_editor_struct* glt_edt, class_data* data) { ImGuiIO& io = ImGui::GetIO(); ImGuiStyle& style = ImGui::GetStyle(); @@ -1284,11 +1306,11 @@ static void glitter_editor_windows(glitter_editor_struct* glt_edt, class_data* d } if (ImGui::BeginMenu("View", true)) { - imguiCheckboxFlags("Draw Wireframe", + ImGui::CheckboxFlagsEnterKeyPressed("Draw Wireframe", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_WIREFRAME); - imguiCheckboxFlags("Draw Selected", + ImGui::CheckboxFlagsEnterKeyPressed("Draw Selected", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_SELECTED); - imguiCheckboxFlags("No Draw", + ImGui::CheckboxFlagsEnterKeyPressed("No Draw", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_NO_DRAW); ImGui::EndMenu(); } @@ -1335,14 +1357,14 @@ static void glitter_editor_windows(glitter_editor_struct* glt_edt, class_data* d ImGui::EndTabItem(); } - imguiDisableElementPush(glt_edt->effect_group != 0); + ImGui::DisableElementPush(glt_edt->effect_group != 0); if (ImGui::BeginTabItem("Resources", 0, 0)) { glitter_editor_resources_context_menu(glt_edt, -1, 0, true); if (glt_edt->effect_group) glitter_editor_resources(glt_edt); ImGui::EndTabItem(); } - imguiDisableElementPop(glt_edt->effect_group != 0); + ImGui::DisableElementPop(glt_edt->effect_group != 0); if (ImGui::BeginTabItem("Play Manager", 0, 0)) { glitter_editor_play_manager(glt_edt); @@ -1977,31 +1999,31 @@ static void glitter_editor_test_window(glitter_editor_struct* glt_edt, class_dat return; } - if (imguiButton("Reset Camera (R)")) + if (ImGui::ButtonEnterKeyPressed("Reset Camera (R)")) input_reset = true; - w = imguiGetContentRegionAvailWidth(); + w = ImGui::GetContentRegionAvailWidth(); if (ImGui::BeginTable("buttons", 2)) { ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * 0.5f); ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Play (T)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_T)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Play (T)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_T)) glt_edt->input_play = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Reload (Y)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_Y)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Reload (Y)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_Y)) glt_edt->input_reload = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Pause (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Pause (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) glt_edt->input_pause = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Reset (G)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_G)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Reset (G)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_G)) glt_edt->input_reset = true; ImGui::EndTable(); } @@ -2009,31 +2031,31 @@ static void glitter_editor_test_window(glitter_editor_struct* glt_edt, class_dat ImGui::Separator(); glt_edt->old_frame_counter = glt_edt->frame_counter; - imguiColumnSliderFloat("Frame", &glt_edt->frame_counter, 1.0f, + ImGui::ColumnSliderFloat("Frame", &glt_edt->frame_counter, 1.0f, (float_t)glt_edt->start_frame, (float_t)glt_edt->end_frame, "%.0f", 0, true); - glt_edt->input_pause_temp = imgui_is_item_activated; + glt_edt->input_pause_temp = ImGui::IsItemActivatedAccum; ImGui::Text("Start/End Frame: %d/%d", glt_edt->start_frame, glt_edt->end_frame); - imguiColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); ImGui::Separator(); - imguiCheckbox("Show Grid", &draw_grid_3d); + ImGui::CheckboxEnterKeyPressed("Show Grid", &draw_grid_3d); - imguiCheckbox("Draw All", &Glitter::glt_particle_manager.draw_all); + ImGui::CheckboxEnterKeyPressed("Draw All", &Glitter::glt_particle_manager.draw_all); - imguiDisableElementPush(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); - imguiCheckbox("Draw All Mesh", &Glitter::glt_particle_manager.draw_all_mesh); - imguiDisableElementPop(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); + ImGui::DisableElementPush(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); + ImGui::CheckboxEnterKeyPressed("Draw All Mesh", &Glitter::glt_particle_manager.draw_all_mesh); + ImGui::DisableElementPop(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); ImGui::Separator(); - imguiCheckboxFlags("Draw Wireframe", + ImGui::CheckboxFlagsEnterKeyPressed("Draw Wireframe", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_WIREFRAME); - imguiCheckboxFlags("Draw Selected", + ImGui::CheckboxFlagsEnterKeyPressed("Draw Selected", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_SELECTED); - imguiCheckboxFlags("No Draw", + ImGui::CheckboxFlagsEnterKeyPressed("No Draw", (uint32_t*)&glt_edt->draw_flags, GLITTER_EDITOR_DRAW_NO_DRAW); data->imgui_focus |= ImGui::IsWindowFocused(); @@ -2625,31 +2647,31 @@ End: static void glitter_editor_play_manager(glitter_editor_struct* glt_edt) { Glitter::EffectGroup* eg = glt_edt->effect_group; - if (imguiButton("Reset Camera (R)")) + if (ImGui::ButtonEnterKeyPressed("Reset Camera (R)")) input_reset = true; - float_t w = imguiGetContentRegionAvailWidth(); + float_t w = ImGui::GetContentRegionAvailWidth(); if (ImGui::BeginTable("buttons", 2)) { ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * 0.5f); ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Play (T)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_T)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Play (T)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_T)) glt_edt->input_play = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Reload (Y)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_Y)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Reload (Y)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_Y)) glt_edt->input_reload = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Pause (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Pause (F)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_F)) glt_edt->input_pause = true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Reset (G)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_G)) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Reset (G)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_G)) glt_edt->input_reset = true; ImGui::EndTable(); } @@ -2657,9 +2679,9 @@ static void glitter_editor_play_manager(glitter_editor_struct* glt_edt) { ImGui::Separator(); glt_edt->old_frame_counter = glt_edt->frame_counter; - imguiColumnSliderFloat("Frame", &glt_edt->frame_counter, 1.0f, + ImGui::ColumnSliderFloat("Frame", &glt_edt->frame_counter, 1.0f, (float_t)glt_edt->start_frame, (float_t)glt_edt->end_frame, "%.0f", 0, true); - glt_edt->input_pause_temp = imgui_is_item_activated; + glt_edt->input_pause_temp = ImGui::IsItemActivatedAccum; ImGui::Text("Start/End Frame: %d/%d", glt_edt->start_frame, glt_edt->end_frame); @@ -2692,17 +2714,17 @@ static void glitter_editor_play_manager(glitter_editor_struct* glt_edt) { ImGui::Separator(); - imguiColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Emission", &Glitter::glt_particle_manager.emission, 0.01f, 1.0f, 2.0f, "%.2f", 0, true); ImGui::Separator(); - imguiCheckbox("Grid", &draw_grid_3d); + ImGui::CheckboxEnterKeyPressed("Grid", &draw_grid_3d); - imguiCheckbox("Draw All", &Glitter::glt_particle_manager.draw_all); + ImGui::CheckboxEnterKeyPressed("Draw All", &Glitter::glt_particle_manager.draw_all); - imguiDisableElementPush(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); - imguiCheckbox("Draw All Mesh", &Glitter::glt_particle_manager.draw_all_mesh); - imguiDisableElementPop(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); + ImGui::DisableElementPush(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); + ImGui::CheckboxEnterKeyPressed("Draw All Mesh", &Glitter::glt_particle_manager.draw_all_mesh); + ImGui::DisableElementPop(Glitter::glt_particle_manager.draw_all && eg && eg->type == Glitter::X); } static void glitter_editor_property(glitter_editor_struct* glt_edt, class_data* data) { @@ -2720,7 +2742,7 @@ static void glitter_editor_property(glitter_editor_struct* glt_edt, class_data* } static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class_data* data) { - imguiSetColumnSpace(2.0f / 5.0f); + ImGui::SetColumnSpace(2.0f / 5.0f); uint64_t hash_before = hash_fnv1a64m(glt_edt->selected_effect, sizeof(Glitter::Effect)); @@ -2737,28 +2759,28 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class std::string name; name.reserve(0x200); name.assign(effect->name.c_str()); - if (imguiColumnInputText("Name", (char*)name.c_str(), name.capacity(), 0, 0, 0)) { + if (ImGui::ColumnInputText("Name", (char*)name.c_str(), name.capacity(), 0, 0, 0)) { effect->data.name_hash = eg->type != Glitter::FT ? hash_string_murmurhash(&name) : hash_string_fnv1a64m(&name); effect->name.assign(name.c_str()); changed = true; } - if (imguiColumnDragInt("Appear Time", + if (ImGui::ColumnDragInt("Appear Time", &effect->data.appear_time, 1.0f, 0x0000, 0x7FFF, "%d", 0)) changed = true; - if (imguiColumnDragInt("Life Time", + if (ImGui::ColumnDragInt("Life Time", &effect->data.life_time, 1.0f, 0x0000, 0x7FFF - effect->data.appear_time, "%d", 0)) changed = true; - if (imguiColumnDragInt("Start Time", + if (ImGui::ColumnDragInt("Start Time", &effect->data.start_time, 1.0f, 0x0000, 0x7FFF - effect->data.appear_time, "%d", 0)) changed = true; ImGui::Separator(); - if (imguiColumnDragVec3Flag("Translation", + if (ImGui::ColumnDragVec3("Translation", &effect->translation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, flags & Glitter::CURVE_TYPE_TRANSLATION_XYZ)) @@ -2766,7 +2788,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class vec3 rotation; vec3_mult_scalar(effect->rotation, RAD_TO_DEG_FLOAT, rotation); - if (imguiColumnDragVec3Flag("Rotation", + if (ImGui::ColumnDragVec3("Rotation", &rotation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -2774,7 +2796,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class changed = true; } - if (imguiColumnDragVec3Flag("Scale", + if (ImGui::ColumnDragVec3("Scale", &effect->scale, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_SCALE_XYZ) >> 6)) @@ -2782,33 +2804,33 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class ImGui::Separator(); - if (imguiCheckboxFlags("Loop", + if (ImGui::CheckboxFlagsEnterKeyPressed("Loop", (uint32_t*)&effect->data.flags, Glitter::EFFECT_LOOP)) changed = true; - if (imguiCheckboxFlags("Draw as Transparent", + if (ImGui::CheckboxFlagsEnterKeyPressed("Draw as Transparent", (uint32_t*)&effect->data.flags, Glitter::EFFECT_ALPHA)) changed = true; - if (imguiCheckboxFlags("Fog", + if (ImGui::CheckboxFlagsEnterKeyPressed("Fog", (uint32_t*)&effect->data.flags, Glitter::EFFECT_FOG)) changed = true; - if (imguiCheckboxFlags("Fog Height", + if (ImGui::CheckboxFlagsEnterKeyPressed("Fog Height", (uint32_t*)&effect->data.flags, Glitter::EFFECT_FOG_HEIGHT)) changed = true; - if (imguiCheckboxFlags("Use External Emission", + if (ImGui::CheckboxFlagsEnterKeyPressed("Use External Emission", (uint32_t*)&effect->data.flags, Glitter::EFFECT_EMISSION)) changed = true; if (eg->type == Glitter::X) - if (imguiCheckboxFlags("Use Seed", + if (ImGui::CheckboxFlagsEnterKeyPressed("Use Seed", (uint32_t*)&effect->data.flags, Glitter::EFFECT_USE_SEED)) changed = true; @@ -2825,24 +2847,24 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class if (eg->type != Glitter::X) { bool set_emission = effect->version == 7; - if (imguiCheckbox("Set Emission", + if (ImGui::CheckboxEnterKeyPressed("Set Emission", &set_emission)) { effect->version = set_emission ? 7 : 6; changed = true; } - if (effect->version == 7 && imguiColumnDragFloat("Emission", + if (effect->version == 7 && ImGui::ColumnDragFloat("Emission", &effect->data.emission, 0.0001f, 0.0f, HALF_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; } else { if (effect->data.flags & Glitter::EFFECT_USE_SEED - && imguiColumnInputScalar("Seed", ImGuiDataType_U32, &effect->data.seed, + && ImGui::ColumnInputScalar("Seed", ImGuiDataType_U32, &effect->data.seed, 0, 0, "%08X", ImGuiInputTextFlags_CharsHexadecimal)) changed = true; - if (imguiColumnDragFloat("Emission", + if (ImGui::ColumnDragFloat("Emission", &effect->data.emission, 0.0001f, 0.0f, HALF_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -2856,7 +2878,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class else type = 0; - if (imguiColumnComboBox("Type", Glitter::effect_type_name, + if (ImGui::ColumnComboBox("Type", Glitter::effect_type_name, 4, &type, 0, false, &data->imgui_focus)) { if (type == 1) { enum_or(effect->data.flags, Glitter::EFFECT_LOCAL); @@ -2889,7 +2911,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class Glitter::Effect::ExtAnimX* ext_anim = effect->data.ext_anim_x; if (ext_anim->flags & Glitter::EFFECT_EXT_ANIM_CHARA_ANIM) { const int32_t max_chara = 4; - if (imguiColumnComboBox("Chara Index", Glitter::effect_ext_anim_index_name, + if (ImGui::ColumnComboBox("Chara Index", Glitter::effect_ext_anim_index_name, max_chara, &ext_anim->chara_index, 0, false, &data->imgui_focus)) changed = true; @@ -2899,7 +2921,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class node_index = Glitter::EFFECT_EXT_ANIM_CHARA_NONE; node_index++; - if (imguiColumnComboBox("Parent Bone", Glitter::effect_ext_anim_node_index_name, + if (ImGui::ColumnComboBox("Parent Bone", Glitter::effect_ext_anim_node_index_name, Glitter::EFFECT_EXT_ANIM_CHARA_MAX, &node_index, 0, true, &data->imgui_focus)) { node_index--; @@ -2920,7 +2942,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class changed = true; } - imguiColumnInputScalar("Instance ID", ImGuiDataType_U32, &ext_anim->instance_id, + ImGui::ColumnInputScalar("Instance ID", ImGuiDataType_U32, &ext_anim->instance_id, 0, 0, "%d", ImGuiInputTextFlags_CharsDecimal); uint64_t file_name_hash = ext_anim->file_name_hash; @@ -2932,38 +2954,38 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class const size_t mesh_name_size = sizeof(ext_anim->mesh_name); char mesh_name[sizeof(ext_anim->mesh_name)]; memcpy(mesh_name, ext_anim->mesh_name, mesh_name_size); - if (imguiColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { + if (ImGui::ColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { memcpy(ext_anim->mesh_name, mesh_name, mesh_name_size); changed = true; } } - if (imguiCheckboxFlags("Trans Only", + if (ImGui::CheckboxFlagsEnterKeyPressed("Trans Only", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_TRANS_ONLY)) changed = true; - if (imguiCheckboxFlags("No Trans X", + if (ImGui::CheckboxFlagsEnterKeyPressed("No Trans X", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_NO_TRANS_X)) changed = true; - if (imguiCheckboxFlags("No Trans Y", + if (ImGui::CheckboxFlagsEnterKeyPressed("No Trans Y", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_NO_TRANS_Y)) changed = true; - if (imguiCheckboxFlags("No Trans Z", + if (ImGui::CheckboxFlagsEnterKeyPressed("No Trans Z", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_NO_TRANS_Z)) changed = true; - if (imguiCheckboxFlags("Draw Only when Chara Visible", + if (ImGui::CheckboxFlagsEnterKeyPressed("Draw Only when Chara Visible", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_NO_DRAW_IF_NO_DATA)) changed = true; - if (imguiCheckboxFlags("Get Then Update", + if (ImGui::CheckboxFlagsEnterKeyPressed("Get Then Update", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_GET_THEN_UPDATE)) changed = true; @@ -2980,7 +3002,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class Glitter::Effect::ExtAnim* ext_anim = effect->data.ext_anim; if (ext_anim->flags & Glitter::EFFECT_EXT_ANIM_CHARA_ANIM) { const int32_t max_chara = eg->type == Glitter::FT ? 6 : 3; - if (imguiColumnComboBox("Chara Index", Glitter::effect_ext_anim_index_name, + if (ImGui::ColumnComboBox("Chara Index", Glitter::effect_ext_anim_index_name, max_chara, &ext_anim->chara_index, 0, false, &data->imgui_focus)) changed = true; @@ -2990,7 +3012,7 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class node_index = Glitter::EFFECT_EXT_ANIM_CHARA_NONE; node_index++; - if (imguiColumnComboBox("Parent Bone", Glitter::effect_ext_anim_node_index_name, + if (ImGui::ColumnComboBox("Parent Bone", Glitter::effect_ext_anim_node_index_name, Glitter::EFFECT_EXT_ANIM_CHARA_MAX, &node_index, 0, true, &data->imgui_focus)) { node_index--; @@ -3014,13 +3036,13 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class const size_t mesh_name_size = sizeof(ext_anim->mesh_name); char mesh_name[sizeof(ext_anim->mesh_name)]; memcpy(mesh_name, ext_anim->mesh_name, mesh_name_size); - if (imguiColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { + if (ImGui::ColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { memcpy(ext_anim->mesh_name, mesh_name, mesh_name_size); changed = true; } } - if (imguiCheckboxFlags("Trans Only", + if (ImGui::CheckboxFlagsEnterKeyPressed("Trans Only", (uint32_t*)&ext_anim->flags, Glitter::EFFECT_EXT_ANIM_TRANS_ONLY)) changed = true; @@ -3060,14 +3082,14 @@ static void glitter_editor_property_effect(glitter_editor_struct* glt_edt, class glt_edt->input_reload = true; } - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); } static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, class_data* data) { Glitter::Effect* sel_efct = glt_edt->selected_effect; Glitter::Emitter* sel_emit = glt_edt->selected_emitter; - imguiSetColumnSpace(2.0f / 5.0f); + ImGui::SetColumnSpace(2.0f / 5.0f); uint64_t hash_before = hash_fnv1a64m(glt_edt->selected_emitter, sizeof(Glitter::Emitter)); @@ -3088,22 +3110,22 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas ImGui::Separator(); - if (imguiColumnDragInt("Start Time", + if (ImGui::ColumnDragInt("Start Time", &emitter->data.start_time, 1.0f, 0x0000, 0x7FFF, "%d", 0)) changed = true; - if (imguiColumnDragInt("Life Time", + if (ImGui::ColumnDragInt("Life Time", &emitter->data.life_time, 1.0f, 0x0000, 0x7FFF, "%d", 0)) changed = true; - if (imguiColumnDragInt("Loop Start Time", &emitter->data.loop_start_time, + if (ImGui::ColumnDragInt("Loop Start Time", &emitter->data.loop_start_time, 1.0f, -0x0001, emitter->data.start_time + emitter->data.life_time, "%d", 0)) { if (emitter->data.loop_start_time < emitter->data.start_time) emitter->data.loop_start_time = 0; changed = emitter->data.loop_start_time != sel_emit->data.loop_start_time; } - if (imguiColumnDragInt("Loop End Time", &emitter->data.loop_end_time, + if (ImGui::ColumnDragInt("Loop End Time", &emitter->data.loop_end_time, 1.0f, -0x0001, emitter->data.start_time + emitter->data.life_time, "%d", 0)) { if (emitter->data.loop_end_time < 0) emitter->data.loop_end_time = -1; @@ -3112,7 +3134,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas ImGui::Separator(); - if (imguiColumnDragVec3Flag("Translation", + if (ImGui::ColumnDragVec3("Translation", &emitter->translation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, flags & Glitter::CURVE_TYPE_TRANSLATION_XYZ)) @@ -3125,7 +3147,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas if (draw_z_axis) rotation.z -= (float_t)M_PI_2; vec3_mult_scalar(rotation, RAD_TO_DEG_FLOAT, rotation); - if (imguiColumnDragVec3Flag("Rotation", + if (ImGui::ColumnDragVec3("Rotation", &rotation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3139,7 +3161,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas else { vec3 rotation; vec3_mult_scalar(emitter->rotation, RAD_TO_DEG_FLOAT, rotation); - if (imguiColumnDragVec3Flag("Rotation", + if (ImGui::ColumnDragVec3("Rotation", &rotation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3150,7 +3172,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas vec3 rotation_add; vec3_mult_scalar(emitter->data.rotation_add, RAD_TO_DEG_FLOAT, rotation_add); - if (imguiColumnDragVec3Flag("Rotation Add", + if (ImGui::ColumnDragVec3("Rotation Add", &rotation_add, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3158,7 +3180,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas changed = true; } - if (imguiColumnDragVec3Flag("Scale", + if (ImGui::ColumnDragVec3("Scale", &emitter->scale, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_SCALE_XYZ) >> 6)) @@ -3166,18 +3188,18 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas ImGui::Separator(); - if (imguiCheckboxFlags("Loop", + if (ImGui::CheckboxFlagsEnterKeyPressed("Loop", (uint32_t*)&emitter->data.flags, Glitter::EMITTER_LOOP)) changed = true; - if (imguiCheckboxFlags("Kill On End", + if (ImGui::CheckboxFlagsEnterKeyPressed("Kill On End", (uint32_t*)&emitter->data.flags, Glitter::EMITTER_KILL_ON_END)) changed = true; if (eg->type == Glitter::X - && imguiCheckboxFlags("Use Seed", + && ImGui::CheckboxFlagsEnterKeyPressed("Use Seed", (uint32_t*)&emitter->data.flags, Glitter::EMITTER_USE_SEED)) changed = true; @@ -3186,11 +3208,11 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas if (eg->type == Glitter::X) { if (emitter->data.flags & Glitter::EMITTER_USE_SEED - && imguiColumnInputScalar("Seed", ImGuiDataType_U32, &emitter->data.seed, + && ImGui::ColumnInputScalar("Seed", ImGuiDataType_U32, &emitter->data.seed, 0, 0, "%08X", ImGuiInputTextFlags_CharsHexadecimal)) changed = true; - if (imguiColumnComboBox("Timer Type", Glitter::emitter_timer_name, + if (ImGui::ColumnComboBox("Timer Type", Glitter::emitter_timer_name, Glitter::EMITTER_TIMER_BY_DISTANCE, (int32_t*)&emitter->data.timer, 0, true, &data->imgui_focus)) { float_t emission_interval = emitter->data.emission_interval; @@ -3205,7 +3227,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas if (eg->type == Glitter::X && emitter->data.timer == Glitter::EMITTER_TIMER_BY_DISTANCE) { - if (imguiColumnDragFloatFlag("Emit Interval", + if (ImGui::ColumnDragFloat("Emit Interval", &emitter->data.emission_interval, 0.0001f, -1.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_EMISSION_INTERVAL) >> 20)) @@ -3219,7 +3241,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas else emission = Glitter::EMITTER_EMISSION_ON_END; - if (imguiColumnComboBox("Emission Type", Glitter::emitter_emission_name, + if (ImGui::ColumnComboBox("Emission Type", Glitter::emitter_emission_name, Glitter::EMITTER_EMISSION_ON_END, (int32_t*)&emission, 0, true, &data->imgui_focus)) { float_t emission_interval; @@ -3243,14 +3265,14 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas } if (emission == Glitter::EMITTER_EMISSION_ON_TIMER - && imguiColumnDragFloatFlag("Emit Interval", + && ImGui::ColumnDragFloat("Emit Interval", &emitter->data.emission_interval, 1.0f, 1.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_EMISSION_INTERVAL) >> 20)) changed = true; } - if (imguiColumnDragFloatFlag("PTC Per Emit", + if (ImGui::ColumnDragFloat("PTC Per Emit", &emitter->data.particles_per_emission, 1.0f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_PARTICLES_PER_EMISSION) >> 21)) @@ -3265,7 +3287,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas } prev_direction = direction; - if (imguiColumnComboBox("Direction", Glitter::emitter_direction_name, + if (ImGui::ColumnComboBox("Direction", Glitter::emitter_direction_name, Glitter::EMITTER_DIRECTION_EFFECT_ROTATION, (int32_t*)&direction, 0, true, &data->imgui_focus)) if (Glitter::emitter_direction_types[direction] != emitter->data.direction) { @@ -3292,7 +3314,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas changed = true; } - if (imguiColumnComboBox("Type", Glitter::emitter_name, + if (ImGui::ColumnComboBox("Type", Glitter::emitter_name, Glitter::EMITTER_POLYGON, (int32_t*)&emitter->data.type, 0, true, &data->imgui_focus)) changed = true; @@ -3302,7 +3324,7 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas switch (emitter->data.type) { case Glitter::EMITTER_BOX: { ImGui::PushID("Box"); - if (imguiColumnDragVec3("Size", + if (ImGui::ColumnDragVec3("Size", &emitter->data.box.size, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -3312,18 +3334,18 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas float_t start_angle, end_angle; ImGui::PushID("Cylinder"); - if (imguiColumnDragFloat("Radius", + if (ImGui::ColumnDragFloat("Radius", &emitter->data.cylinder.radius, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragFloat("Height", + if (ImGui::ColumnDragFloat("Height", &emitter->data.cylinder.height, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; start_angle = emitter->data.cylinder.start_angle * RAD_TO_DEG_FLOAT; - if (imguiColumnDragFloat("Start Angle", + if (ImGui::ColumnDragFloat("Start Angle", &start_angle, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { emitter->data.cylinder.start_angle = start_angle * DEG_TO_RAD_FLOAT; @@ -3331,18 +3353,18 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas } end_angle = emitter->data.cylinder.end_angle * RAD_TO_DEG_FLOAT; - if (imguiColumnDragFloat("End Angle", + if (ImGui::ColumnDragFloat("End Angle", &end_angle, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { emitter->data.cylinder.end_angle = end_angle * DEG_TO_RAD_FLOAT; changed = true; } - if (imguiCheckbox("On Edge", + if (ImGui::CheckboxEnterKeyPressed("On Edge", &emitter->data.cylinder.on_edge)) changed = true; - if (imguiColumnComboBox("Direction", + if (ImGui::ColumnComboBox("Direction", Glitter::emitter_emission_direction_name, Glitter::EMITTER_EMISSION_DIRECTION_INWARD, (int32_t*)&emitter->data.cylinder.direction, 0, true, &data->imgui_focus)) @@ -3353,13 +3375,13 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas float_t latitude, longitude; ImGui::PushID("Sphere"); - if (imguiColumnDragFloat("Radius", + if (ImGui::ColumnDragFloat("Radius", &emitter->data.sphere.radius, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; latitude = emitter->data.sphere.latitude * RAD_TO_DEG_FLOAT; - if (imguiColumnDragFloat("Latitude", + if (ImGui::ColumnDragFloat("Latitude", &latitude, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { emitter->data.sphere.latitude = latitude * DEG_TO_RAD_FLOAT; @@ -3367,18 +3389,18 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas } longitude = emitter->data.sphere.longitude * RAD_TO_DEG_FLOAT; - if (imguiColumnDragFloat("Longitude", + if (ImGui::ColumnDragFloat("Longitude", &longitude, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { emitter->data.sphere.longitude = longitude * DEG_TO_RAD_FLOAT; changed = true; } - if (imguiCheckbox("On Edge", + if (ImGui::CheckboxEnterKeyPressed("On Edge", &emitter->data.sphere.on_edge)) changed = true; - if (imguiColumnComboBox("Direction", + if (ImGui::ColumnComboBox("Direction", Glitter::emitter_emission_direction_name, Glitter::EMITTER_EMISSION_DIRECTION_INWARD, (int32_t*)&emitter->data.sphere.direction, 0, true, &data->imgui_focus)) @@ -3387,17 +3409,17 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas } break; case Glitter::EMITTER_POLYGON: { ImGui::PushID("Polygon"); - if (imguiColumnDragFloat("Scale", + if (ImGui::ColumnDragFloat("Scale", &emitter->data.polygon.size, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragInt("Count", + if (ImGui::ColumnDragInt("Count", &emitter->data.polygon.count, 1.0f, 0, 0x7FFFFF, "%d", 0)) changed = true; if (eg->type == Glitter::X) - if (imguiColumnComboBox("Direction", + if (ImGui::ColumnComboBox("Direction", Glitter::emitter_emission_direction_name, Glitter::EMITTER_EMISSION_DIRECTION_INWARD, (int32_t*)&emitter->data.cylinder.direction, 0, true, &data->imgui_focus)) @@ -3410,14 +3432,14 @@ static void glitter_editor_property_emitter(glitter_editor_struct* glt_edt, clas if (hash_before != hash_after && changed) glt_edt->input_reload = true; - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); } static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, class_data* data) { Glitter::Effect* sel_efct = glt_edt->selected_effect; Glitter::Emitter* sel_emit = glt_edt->selected_emitter; - imguiSetColumnSpace(2.0f / 5.0f); + ImGui::SetColumnSpace(2.0f / 5.0f); uint64_t hash_before = hash_fnv1a64m(glt_edt->selected_particle, sizeof(Glitter::Particle)); @@ -3457,49 +3479,49 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::Separator(); bool flags_changed = false; - if (imguiCheckboxFlags("Loop", + if (ImGui::CheckboxFlagsEnterKeyPressed("Loop", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_LOOP)) flags_changed = true; - if (imguiCheckboxFlags("Emitter Local", + if (ImGui::CheckboxFlagsEnterKeyPressed("Emitter Local", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_EMITTER_LOCAL)) flags_changed = true; - if (imguiCheckboxFlags("Scale Y by X", + if (ImGui::CheckboxFlagsEnterKeyPressed("Scale Y by X", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_SCALE_Y_BY_X)) flags_changed = true; - if (imguiCheckboxFlags("Rebound Plane", + if (ImGui::CheckboxFlagsEnterKeyPressed("Rebound Plane", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_REBOUND_PLANE)) flags_changed = true; - if (imguiCheckboxFlags("Rotate by Emitter", + if (ImGui::CheckboxFlagsEnterKeyPressed("Rotate by Emitter", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_ROTATE_BY_EMITTER)) flags_changed = true; - if (imguiCheckboxFlags("Scale by Emitter", + if (ImGui::CheckboxFlagsEnterKeyPressed("Scale by Emitter", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_SCALE)) flags_changed = true; - if (imguiCheckboxFlags("Texture Mask##Flag", + if (ImGui::CheckboxFlagsEnterKeyPressed("Texture Mask##Flag", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_TEXTURE_MASK)) flags_changed = true; if (eg->type == Glitter::X) { - if (imguiCheckboxFlags("Disable Depth Test", + if (ImGui::CheckboxFlagsEnterKeyPressed("Disable Depth Test", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_DEPTH_TEST)) flags_changed = true; if (particle->data.type == Glitter::PARTICLE_LOCUS - && imguiCheckboxFlags("Rotate Locus", + && ImGui::CheckboxFlagsEnterKeyPressed("Rotate Locus", (uint32_t*)&particle->data.flags, Glitter::PARTICLE_ROTATE_LOCUS)) flags_changed = true; @@ -3514,7 +3536,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2i life_time; life_time.x = particle->data.life_time; life_time.y = particle->data.life_time_random; - if (imguiColumnDragVec2I("Life Time [R]", + if (ImGui::ColumnDragVec2I("Life Time [R]", &life_time, 1.0f, 0x0000, 0x7FFF, "%d", 0)) { particle->data.life_time = life_time.x; particle->data.life_time_random = life_time.y; @@ -3524,7 +3546,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2i fade_in; fade_in.x = particle->data.fade_in; fade_in.y = particle->data.fade_in_random; - if (imguiColumnDragVec2I("Fade In [R]", + if (ImGui::ColumnDragVec2I("Fade In [R]", &fade_in, 1.0f, 0x0000, 0x7FFF, "%d", 0)) { particle->data.fade_in = fade_in.x; particle->data.fade_in_random = fade_in.y; @@ -3534,31 +3556,31 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2i fade_out; fade_out.x = particle->data.fade_out; fade_out.y = particle->data.fade_out_random; - if (imguiColumnDragVec2I("Fade Out [R]", + if (ImGui::ColumnDragVec2I("Fade Out [R]", &fade_out, 1.0f, 0x0000, 0x7FFF, "%d", 0)) { particle->data.fade_out = fade_out.x; particle->data.fade_out_random = fade_out.y; changed = true; } - if (imguiColumnComboBox("Type", Glitter::particle_name, + if (ImGui::ColumnComboBox("Type", Glitter::particle_name, Glitter::PARTICLE_MESH, (int32_t*)&particle->data.type, 0, true, &data->imgui_focus)) changed = true; } else { - if (imguiColumnDragInt("Life Time", + if (ImGui::ColumnDragInt("Life Time", &particle->data.life_time, 1.0f, 0x0000, 0x7FFF, "%d", 0)) changed = true; - if (imguiColumnComboBox("Type", Glitter::particle_name, + if (ImGui::ColumnComboBox("Type", Glitter::particle_name, Glitter::PARTICLE_LOCUS, (int32_t*)&particle->data.type, 0, true, &data->imgui_focus)) changed = true; } if (particle->data.type != Glitter::PARTICLE_MESH - && imguiColumnComboBox("Pivot", Glitter::pivot_name, + && ImGui::ColumnComboBox("Pivot", Glitter::pivot_name, Glitter::PIVOT_BOTTOM_RIGHT, (int32_t*)&particle->data.pivot, 0, true, &data->imgui_focus)) changed = true; @@ -3573,7 +3595,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla } prev_draw_type = draw_type; - if (imguiColumnComboBox("Draw Type", Glitter::particle_draw_type_name, + if (ImGui::ColumnComboBox("Draw Type", Glitter::particle_draw_type_name, Glitter::PARTICLE_DRAW_TYPE_EMIT_POSITION, (int32_t*)&draw_type, 0, true, &data->imgui_focus)) if (Glitter::particle_draw_types[draw_type] != particle->data.draw_type) { @@ -3611,7 +3633,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla } if (particle->data.type == Glitter::PARTICLE_QUAD) - if (imguiColumnDragFloat("Z Offset", + if (ImGui::ColumnDragFloat("Z Offset", &particle->data.z_offset, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -3631,7 +3653,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla else if (draw_z_axis) rotation.z -= (float_t)M_PI_2; vec3_mult_scalar(rotation, RAD_TO_DEG_FLOAT, rotation); - if (imguiColumnDragVec3Flag("Rotation", + if (ImGui::ColumnDragVec3("Rotation", &rotation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3647,7 +3669,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla else { vec3 rotation; vec3_mult_scalar(particle->data.rotation, RAD_TO_DEG_FLOAT, rotation); - if (imguiColumnDragVec3Flag("Rotation", + if (ImGui::ColumnDragVec3("Rotation", &rotation, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3658,7 +3680,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec3 rotation_random; vec3_mult_scalar(particle->data.rotation_random, RAD_TO_DEG_FLOAT, rotation_random); - if (imguiColumnDragVec3Flag("Rotation Random", + if (ImGui::ColumnDragVec3("Rotation Random", &rotation_random, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3668,7 +3690,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec3 rotation_add; vec3_mult_scalar(particle->data.rotation_add, RAD_TO_DEG_FLOAT, rotation_add); - if (imguiColumnDragVec3Flag("Rotation Add", + if (ImGui::ColumnDragVec3("Rotation Add", &rotation_add, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3678,7 +3700,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec3 rotation_add_random; vec3_mult_scalar(particle->data.rotation_add_random, RAD_TO_DEG_FLOAT, rotation_add_random); - if (imguiColumnDragVec3Flag("Rotation Add Random", + if (ImGui::ColumnDragVec3("Rotation Add Random", &rotation_add_random, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, (flags & Glitter::CURVE_TYPE_ROTATION_XYZ) >> 3)) { @@ -3686,28 +3708,28 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla changed = true; } - imguiDisableElementPush(particle->data.type != Glitter::PARTICLE_MESH); - if (imguiColumnDragVec2Flag("Scale", + ImGui::DisableElementPush(particle->data.type != Glitter::PARTICLE_MESH); + if (ImGui::ColumnDragVec2("Scale", (vec2*)&particle->data.scale, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, particle->data.flags & Glitter::PARTICLE_SCALE_Y_BY_X ? 0x01 : 0x03)) changed = true; - if (imguiColumnDragVec2Flag("Scale Random", + if (ImGui::ColumnDragVec2("Scale Random", (vec2*)&particle->data.scale_random, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat, particle->data.flags & Glitter::PARTICLE_SCALE_Y_BY_X ? 0x01 : 0x03)) changed = true; - imguiDisableElementPop(particle->data.type != Glitter::PARTICLE_MESH); + ImGui::DisableElementPop(particle->data.type != Glitter::PARTICLE_MESH); ImGui::Separator(); - if (imguiColumnDragVec3("Direction", + if (ImGui::ColumnDragVec3("Direction", &particle->data.direction, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragVec3("Direction Random", + if (ImGui::ColumnDragVec3("Direction Random", &particle->data.direction_random, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -3715,7 +3737,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2 speed; speed.x = particle->data.speed; speed.y = particle->data.speed_random; - if (imguiColumnDragVec2("Speed [R]", + if (ImGui::ColumnDragVec2("Speed [R]", &speed, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { particle->data.speed = speed.x; @@ -3726,7 +3748,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2 deceleration; deceleration.x = particle->data.deceleration; deceleration.y = particle->data.deceleration_random; - if (imguiColumnDragVec2("Deceleration [R]", + if (ImGui::ColumnDragVec2("Deceleration [R]", &deceleration, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { particle->data.deceleration = deceleration.x; @@ -3734,17 +3756,17 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla changed = true; } - if (imguiColumnDragVec3("Gravity", + if (ImGui::ColumnDragVec3("Gravity", &particle->data.gravity, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragVec3("Acceleration", + if (ImGui::ColumnDragVec3("Acceleration", &particle->data.acceleration, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragVec3("Acceleration Random", + if (ImGui::ColumnDragVec3("Acceleration Random", &particle->data.acceleration_random, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -3752,7 +3774,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2 reflection_coeff; reflection_coeff.x = particle->data.reflection_coeff; reflection_coeff.y = particle->data.reflection_coeff_random; - if (imguiColumnDragVec2("Refl Coeff [R]", + if (ImGui::ColumnDragVec2("Refl Coeff [R]", &reflection_coeff, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { particle->data.reflection_coeff = reflection_coeff.x; @@ -3760,7 +3782,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla changed = true; } - if (imguiColumnDragFloat("Rebound Plane Y", + if (ImGui::ColumnDragFloat("Rebound Plane Y", &particle->data.rebound_plane_y, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; @@ -3768,12 +3790,12 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::Separator(); vec4 color = particle->data.color; - if (imguiColumnColorEdit4("Color", &color, + if (ImGui::ColumnColorEdit4("Color", &color, ImGuiColorEditFlags_NoLabel | ImGuiColorEditFlags_AlphaBar)) changed = true; particle->data.color = color; - if (imguiColumnComboBox("UV Index Type", Glitter::uv_index_type_name, + if (ImGui::ColumnComboBox("UV Index Type", Glitter::uv_index_type_name, Glitter::UV_INDEX_USER, (int32_t*)&particle->data.uv_index_type, 0, true, &data->imgui_focus)) changed = true; @@ -3781,7 +3803,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla vec2i split; split.x = particle->data.split_u; split.y = particle->data.split_v; - if (imguiColumnSliderLogVec2I("UV Split", + if (ImGui::ColumnSliderLogVec2I("UV Split", &split, 1, 128, "%d", 0)) { particle->data.split_u = (uint8_t)split.x; particle->data.split_v = (uint8_t)split.y; @@ -3795,46 +3817,46 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla if (uv_max_count) uv_max_count--; - if (imguiColumnDragInt("Frame Step UV", + if (ImGui::ColumnDragInt("Frame Step UV", &particle->data.frame_step_uv, 1.0f, 0x0000, 0x7FFF, "%d", 0)) changed = true; - if (imguiColumnDragInt("UV Index Start", + if (ImGui::ColumnDragInt("UV Index Start", &particle->data.uv_index_start, 1.0f, 0, uv_max_count, "%d", 0)) changed = true; - if (imguiColumnDragInt("UV Index End", + if (ImGui::ColumnDragInt("UV Index End", &particle->data.uv_index_end, 1.0f, particle->data.uv_index_start + 1, uv_max_count + 1, "%d", 0)) changed = true; - if (imguiColumnDragInt("UV Index", + if (ImGui::ColumnDragInt("UV Index", &particle->data.uv_index, 1.0f, particle->data.uv_index_start, particle->data.uv_index_end - 1, "%d", 0)) changed = true; - if (imguiColumnDragVec2("UV Scroll Add", + if (ImGui::ColumnDragVec2("UV Scroll Add", &particle->data.uv_scroll_add, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragFloat("UV Scroll Add Scale", + if (ImGui::ColumnDragFloat("UV Scroll Add Scale", &particle->data.uv_scroll_add_scale, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; if (particle->data.type == Glitter::PARTICLE_MESH) { bool uv_2nd_add = particle->data.sub_flags & Glitter::PARTICLE_SUB_UV_2ND_ADD ? true : false; - imguiDisableElementPush(uv_2nd_add); - if (imguiColumnDragVec2("UV Scroll 2nd Add", + ImGui::DisableElementPush(uv_2nd_add); + if (ImGui::ColumnDragVec2("UV Scroll 2nd Add", &particle->data.uv_scroll_2nd_add, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - if (imguiColumnDragFloat("UV Scroll 2nd Add Scale", + if (ImGui::ColumnDragFloat("UV Scroll 2nd Add Scale", &particle->data.uv_scroll_2nd_add_scale, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) changed = true; - imguiDisableElementPop(uv_2nd_add); + ImGui::DisableElementPop(uv_2nd_add); } if (particle->data.type != Glitter::PARTICLE_MESH) { @@ -3889,7 +3911,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla break; } - if (imguiColumnComboBox("Blend Mode", Glitter::particle_blend_draw_name, + if (ImGui::ColumnComboBox("Blend Mode", Glitter::particle_blend_draw_name, Glitter::PARTICLE_BLEND_DRAW_MULTIPLY, (int32_t*)&blend_draw, 0, true, &data->imgui_focus)) if (Glitter::particle_blend_draw_types[blend_draw] != particle->data.blend_mode) { @@ -3905,7 +3927,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla break; } - if (imguiColumnComboBox("Mask Blend Mode", Glitter::particle_blend_mask_name, + if (ImGui::ColumnComboBox("Mask Blend Mode", Glitter::particle_blend_mask_name, Glitter::PARTICLE_BLEND_MASK_MULTIPLY, (int32_t*)&blend_mask, 0, true, &data->imgui_focus)) if (Glitter::particle_blend_mask_types[blend_mask] != particle->data.mask_blend_mode) { @@ -3943,13 +3965,13 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla if (particle->data.uv_index_count < 0) particle->data.uv_index_count = 0; - if (imguiCheckboxFlags("Use Animation Curve", + if (ImGui::CheckboxFlagsEnterKeyPressed("Use Animation Curve", (uint32_t*)&particle->data.sub_flags, Glitter::PARTICLE_SUB_USE_CURVE)) changed = true; if (eg->type == Glitter::X && particle->data.type == Glitter::PARTICLE_MESH) - if (imguiCheckboxFlags("UV Add", + if (ImGui::CheckboxFlagsEnterKeyPressed("UV Add", (uint32_t*)&particle->data.sub_flags, Glitter::PARTICLE_SUB_UV_2ND_ADD)) changed = true; @@ -3957,11 +3979,11 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::Separator(); if (eg->type != Glitter::X || particle->data.type == Glitter::PARTICLE_QUAD) - if (imguiColumnDragInt("Count", + if (ImGui::ColumnDragInt("Count", &particle->data.count, 1.0f, 0x0000, 0x7FFFFF, "%d", 0)) changed = true; - if (imguiColumnDragFloat("Emission", + if (ImGui::ColumnDragFloat("Emission", &particle->data.emission, 0.0001f, 0.0f, HALF_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { if (sel_efct->data.flags & Glitter::EFFECT_EMISSION @@ -3972,20 +3994,20 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla changed = true; } - if (imguiColumnDragInt("Unk 0", + if (ImGui::ColumnDragInt("Unk 0", &particle->data.unk0, 1.0f, INT_MIN, INT_MAX, "%d", 0)) changed = true; - if (eg->version >= 7 && imguiColumnDragInt("Unk 1", + if (eg->version >= 7 && ImGui::ColumnDragInt("Unk 1", &particle->data.unk1, 1.0f, INT_MIN, INT_MAX, "%d", 0)) changed = true; if (particle->data.type == Glitter::PARTICLE_LOCUS) { - if (imguiColumnDragInt("Locus Hist Size", + if (ImGui::ColumnDragInt("Locus Hist Size", &particle->data.locus_history_size, 1.0f, 0x0000, 0x7FFFFF, "%d", 0)) changed = true; - if (imguiColumnDragInt("Locus Hist Size Rand", + if (ImGui::ColumnDragInt("Locus Hist Size Rand", &particle->data.locus_history_size_random, 1.0f, 0x0000, 0x7FFFFF, "%d", 0)) changed = true; } @@ -3999,13 +4021,13 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla obj_set_handler* handler = object_storage_get_obj_set_handler(set_id); ssize_t object_set_count = object_storage_get_obj_set_count(); - imguiStartPropertyColumn("Object Set"); + ImGui::StartPropertyColumn("Object Set"); if (ImGui::BeginCombo("##Object Set", handler ? handler->name.c_str() : "None", 0)) { ssize_t set_index = handler ? object_storage_get_obj_set_index(set_id) : -1; ImGui::PushID(-1); if (ImGui::Selectable("None", !handler) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true)) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true)) set_index = -1; ImGui::PopID(); @@ -4016,7 +4038,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::PushID((int32_t)i); if (ImGui::Selectable(handler->name.c_str(), handler->set_id == set_id) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && handler->set_id != set_id)) set_index = i; ImGui::PopID(); @@ -4036,9 +4058,9 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla data->imgui_focus |= true; ImGui::EndCombo(); } - imguiEndPropertyColumn(); + ImGui::EndPropertyColumn(); - imguiDisableElementPush(set_id != -1); + ImGui::DisableElementPush(set_id != -1); obj* obj = 0; if (handler && handler->obj_set) { obj_set* set = handler->obj_set; @@ -4049,7 +4071,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla } } - imguiStartPropertyColumn("Object"); + ImGui::StartPropertyColumn("Object"); if (ImGui::BeginCombo("##Object", obj ? obj->name : "None", 0)) { if (set_id != -1 && handler && handler->set_id == set_id && handler->obj_set) { obj_set* set = handler->obj_set; @@ -4062,7 +4084,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::PushID(-1); if (ImGui::Selectable("None", !obj) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && obj)) obj_index = -1; ImGui::PopID(); @@ -4071,7 +4093,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla ImGui::PushID(i); ::obj* obj = &set->obj_data[i]; if (ImGui::Selectable(obj->name, obj->id == obj_id) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && obj->id != obj_id)) obj_index = i; ImGui::PopID(); @@ -4091,8 +4113,8 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla data->imgui_focus |= true; ImGui::EndCombo(); } - imguiEndPropertyColumn(); - imguiDisableElementPop(set_id != -1); + ImGui::EndPropertyColumn(); + ImGui::DisableElementPop(set_id != -1); /*if (glitter_editor_hash_input("Object Set Name Hash", &mesh->object_set_name_hash)) changed = true; @@ -4103,7 +4125,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla const size_t mesh_name_size = sizeof(mesh->mesh_name); char mesh_name[sizeof(mesh->mesh_name)]; memcpy(mesh_name, mesh->mesh_name, mesh_name_size); - if (imguiColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { + if (ImGui::ColumnInputText("Mesh Name", mesh_name, mesh_name_size, 0, 0, 0)) { memcpy(mesh->mesh_name, mesh_name, mesh_name_size); changed = true; } @@ -4116,7 +4138,7 @@ static void glitter_editor_property_particle(glitter_editor_struct* glt_edt, cla if (hash_before != hash_after && changed) glt_edt->input_reload = true; - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); } static bool glitter_editor_property_particle_texture(glitter_editor_struct* glt_edt, @@ -4135,7 +4157,7 @@ static bool glitter_editor_property_particle_texture(glitter_editor_struct* glt_ ImVec2 uv_min; ImVec2 uv_max; - imguiStartPropertyColumn(label); + ImGui::StartPropertyColumn(label); int32_t prev_tex_idx = tex_idx; if (ImGui::BeginCombo("", items[tex_idx], 0)) { int32_t uv_index = *tex_index; @@ -4204,7 +4226,7 @@ static bool glitter_editor_property_particle_texture(glitter_editor_struct* glt_ for (int32_t n = 0; n <= rc; n++) { ImGui::PushID(n); if (ImGui::Selectable(items[n], tex_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) + || ImGui::ItemKeyPressed(GLFW_KEY_ENTER, true) || (ImGui::IsItemFocused() && tex_idx != n)) tex_idx = n; @@ -4291,7 +4313,7 @@ static bool glitter_editor_property_particle_texture(glitter_editor_struct* glt_ *tex_tex = 0; } bool res = prev_tex_idx != tex_idx; - imguiEndPropertyColumn(); + ImGui::EndPropertyColumn(); if (res) if (tex_idx) { @@ -4379,19 +4401,19 @@ static void glitter_editor_file_create_popup(glitter_editor_struct* glt_edt, cla bool close = false; ImGui::TableNextColumn(); - if (imguiButton("F2", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::F2; close = true; } ImGui::TableNextColumn(); - if (imguiButton("FT", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("FT", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::FT; close = true; } /*ImGui::TableNextColumn(); - if (imguiButton("X", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("X", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::X; close = true; }*/ @@ -4453,19 +4475,19 @@ static void glitter_editor_file_load_popup(glitter_editor_struct* glt_edt, class bool close = false; ImGui::TableNextColumn(); - if (imguiButton("F2", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::F2; close = true; } ImGui::TableNextColumn(); - if (imguiButton("FT", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("FT", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::FT; close = true; } ImGui::TableNextColumn(); - if (imguiButton("X", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("X", ImGui::GetContentRegionAvail())) { glt_edt->load_glt_type = Glitter::X; close = true; } @@ -4583,7 +4605,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, case Glitter::F2: if (data_f2le_enable) { ImGui::TableNextColumn(); - if (imguiButton("F2LE", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2LE", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_F2LE; close = true; } @@ -4591,7 +4613,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, if (data_f2be_enable) { ImGui::TableNextColumn(); - if (imguiButton("F2BE", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2BE", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_F2BE; close = true; } @@ -4600,7 +4622,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, case Glitter::FT: if (data_aft_enable) { ImGui::TableNextColumn(); - if (imguiButton("AFT", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("AFT", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_AFT; close = true; } @@ -4608,7 +4630,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, if (data_ft_enable) { ImGui::TableNextColumn(); - if (imguiButton("FT", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("FT", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_FT; close = true; } @@ -4616,7 +4638,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, if (data_m39_enable) { ImGui::TableNextColumn(); - if (imguiButton("M39", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("M39", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_M39; close = true; } @@ -4625,7 +4647,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, case Glitter::X: if (data_x_enable) { ImGui::TableNextColumn(); - if (imguiButton("X", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("X", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_X; close = true; } @@ -4633,7 +4655,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, if (data_xhd_enable) { ImGui::TableNextColumn(); - if (imguiButton("XHD", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("XHD", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_XHD; close = true; } @@ -4641,7 +4663,7 @@ static void glitter_editor_file_load_model_popup(glitter_editor_struct* glt_edt, if (data_vrfl_enable) { ImGui::TableNextColumn(); - if (imguiButton("VRFL", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("VRFL", ImGui::GetContentRegionAvail())) { glt_edt->load_data_type = DATA_VRFL; close = true; } @@ -4704,7 +4726,7 @@ static void glitter_editor_file_load_error_list_popup(glitter_editor_struct* glt x = 40.0f; y = font->FontSize + style.FramePadding.y * 2.0f; - if (imguiButton("OK", { x, y })) + if (ImGui::ButtonEnterKeyPressed("OK", { x, y })) ImGui::CloseCurrentPopup(); data->imgui_focus |= ImGui::IsWindowFocused(); ImGui::EndPopup(); @@ -4761,7 +4783,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class bool close = false; ImGui::TableNextColumn(); - if (imguiButton("X", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("X", ImGui::GetContentRegionAvail())) { glt_edt->save = true; glt_edt->save_compress = false; glt_edt->save_glt_type = Glitter::X; @@ -4769,7 +4791,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class } ImGui::TableNextColumn(); - if (imguiButton("X HD", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("X HD", ImGui::GetContentRegionAvail())) { glt_edt->save = true; glt_edt->save_compress = true; glt_edt->save_glt_type = Glitter::X; @@ -4777,7 +4799,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class } ImGui::TableNextColumn(); - if (imguiButton("None", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("None", ImGui::GetContentRegionAvail())) { glt_edt->save = false; glt_edt->save_compress = false; close = true; @@ -4793,7 +4815,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class bool close = false; ImGui::TableNextColumn(); - if (imguiButton("F2 PSV", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2 PSV", ImGui::GetContentRegionAvail())) { glt_edt->save = true; glt_edt->save_compress = false; glt_edt->save_glt_type = Glitter::F2; @@ -4801,7 +4823,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class } ImGui::TableNextColumn(); - if (imguiButton("F2 PS3", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("F2 PS3", ImGui::GetContentRegionAvail())) { glt_edt->save = true; glt_edt->save_compress = true; glt_edt->save_glt_type = Glitter::F2; @@ -4809,7 +4831,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class } ImGui::TableNextColumn(); - if (imguiButton("FT", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("FT", ImGui::GetContentRegionAvail())) { glt_edt->save = true; glt_edt->save_compress = false; glt_edt->save_glt_type = Glitter::FT; @@ -4817,7 +4839,7 @@ static void glitter_editor_file_save_popup(glitter_editor_struct* glt_edt, class } ImGui::TableNextColumn(); - if (imguiButton("None", ImGui::GetContentRegionAvail())) { + if (ImGui::ButtonEnterKeyPressed("None", ImGui::GetContentRegionAvail())) { glt_edt->save = false; glt_edt->save_compress = false; close = true; @@ -6004,7 +6026,7 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g Glitter::Curve::Key* c = crv_edt->key; Glitter::Curve::Key* n = curve->keys_rev.data() + curve->keys_rev.size() - crv_edt->key > 1 ? &crv_edt->key[1] : 0; - if (imguiColumnComboBox("Type", Glitter::key_name, + if (ImGui::ColumnComboBox("Type", Glitter::key_name, Glitter::KEY_HERMITE, (int32_t*)&c->type, 0, true, &data->imgui_focus)) changed = true; @@ -6014,7 +6036,7 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g if (fix_rot_z) value -= (float_t)M_PI_2; value *= scale; - if (imguiColumnDragFloat("Value", + if (ImGui::ColumnDragFloat("Value", &value, 0.0001f, min, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { value *= inv_scale; @@ -6025,9 +6047,9 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g } key_edit |= ImGui::IsItemFocused(); - imguiDisableElementPush(key_random_range); + ImGui::DisableElementPush(key_random_range); float_t random = c->random_range * scale; - if (imguiColumnDragFloat("Random Range", + if (ImGui::ColumnDragFloat("Random Range", &random, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { random *= inv_scale; @@ -6037,11 +6059,11 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g } } key_edit |= ImGui::IsItemFocused(); - imguiDisableElementPop(key_random_range); + ImGui::DisableElementPop(key_random_range); if (n && c->type == Glitter::KEY_HERMITE) { float_t tangent2 = c->tangent2 * scale; - if (imguiColumnDragFloat("Tangent 1", + if (ImGui::ColumnDragFloat("Tangent 1", &tangent2, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { c->tangent2 = tangent2 * inv_scale; @@ -6050,7 +6072,7 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g key_edit |= ImGui::IsItemFocused(); float_t tangent1 = n->tangent1 * scale; - if (imguiColumnDragFloat("Tangent 2", + if (ImGui::ColumnDragFloat("Tangent 2", &tangent1, 0.0001f, -FLT_MAX, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { n->tangent1 = tangent1 * inv_scale; @@ -6063,11 +6085,11 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g crv_edt->key_edit = key_edit; if (ImGui::TreeNodeEx("Curve", ImGuiTreeNodeFlags_DefaultOpen)) { - if (imguiCheckbox("Repeat", &curve->repeat)) + if (ImGui::CheckboxEnterKeyPressed("Repeat", &curve->repeat)) changed = true; int32_t start_time = curve->start_time; - if (imguiColumnDragInt("Start Time", + if (ImGui::ColumnDragInt("Start Time", &start_time, 1, 0, 0x7FFF, "%d", 0)) { if (curve->end_time < start_time) { curve->end_time = start_time; @@ -6081,7 +6103,7 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g } int32_t end_time = curve->end_time; - if (imguiColumnDragInt("End Time", + if (ImGui::ColumnDragInt("End Time", &end_time, 1, 0, 0x7FFF, "%d", 0)) { if (curve->start_time > end_time) end_time = curve->start_time; @@ -6092,9 +6114,9 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g } } - imguiDisableElementPush(random_range); + ImGui::DisableElementPush(random_range); float_t random = curve->random_range * scale; - if (imguiColumnDragFloat("Random Range", + if (ImGui::ColumnDragFloat("Random Range", &random, 0.0001f, 0.0f, FLT_MAX, "%g", ImGuiSliderFlags_NoRoundToFormat)) { random *= inv_scale; @@ -6103,7 +6125,7 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g changed = true; } } - imguiDisableElementPop(random_range); + ImGui::DisableElementPop(random_range); int32_t c_type = curve->version; ImGui::Text("C Type:"); @@ -6139,48 +6161,48 @@ static void glitter_editor_curve_editor_property_window(glitter_editor_struct* g ImGui::Separator(); ImGui::PushID("Flags"); - if (imguiCheckboxFlags("Baked", + if (ImGui::CheckboxFlagsEnterKeyPressed("Baked", (uint32_t*)&curve->flags, Glitter::CURVE_BAKED)) changed = true; if (eg->type == Glitter::X) { - imguiDisableElementPush(curve->flags & Glitter::CURVE_BAKED ? true : false); - if (imguiCheckboxFlags("Baked Full", + ImGui::DisableElementPush(curve->flags & Glitter::CURVE_BAKED ? true : false); + if (ImGui::CheckboxFlagsEnterKeyPressed("Baked Full", (uint32_t*)&curve->flags, Glitter::CURVE_BAKED_FULL)) changed = true; - imguiDisableElementPop(curve->flags & Glitter::CURVE_BAKED ? true : false); + ImGui::DisableElementPop(curve->flags & Glitter::CURVE_BAKED ? true : false); } ImGui::Separator(); - if (imguiCheckboxFlags("Random Range", + if (ImGui::CheckboxFlagsEnterKeyPressed("Random Range", (uint32_t*)&curve->flags, Glitter::CURVE_RANDOM_RANGE)) changed = true; - if (imguiCheckboxFlags("Key Random Range", + if (ImGui::CheckboxFlagsEnterKeyPressed("Key Random Range", (uint32_t*)&curve->flags, Glitter::CURVE_KEY_RANDOM_RANGE)) changed = true; - if (imguiCheckboxFlags("Random Range Negate", + if (ImGui::CheckboxFlagsEnterKeyPressed("Random Range Negate", (uint32_t*)&curve->flags, Glitter::CURVE_RANDOM_RANGE_NEGATE)) changed = true; - if (imguiCheckboxFlags("Step Random", + if (ImGui::CheckboxFlagsEnterKeyPressed("Step Random", (uint32_t*)&curve->flags, Glitter::CURVE_STEP)) changed = true; - if (imguiCheckboxFlags("Random Negate", + if (ImGui::CheckboxFlagsEnterKeyPressed("Random Negate", (uint32_t*)&curve->flags, Glitter::CURVE_NEGATE)) changed = true; - if (imguiCheckboxFlags(eg->type == Glitter::FT + if (ImGui::CheckboxFlagsEnterKeyPressed(eg->type == Glitter::FT ? "Scale Random by Value" : "Scale Random by Value * 0.01", (uint32_t*)&curve->flags, Glitter::CURVE_RANDOM_RANGE_MULT)) @@ -6436,18 +6458,18 @@ if (flags & Glitter::CURVE_TYPE_##curve_type){ \ ImGui::SameLine(); ImGui::BeginGroup(); - imguiSetColumnSpace(3.0f / 7.0f); + ImGui::SetColumnSpace(3.0f / 7.0f); float_t zoom_time = crv_edt->zoom_time * 100.0f; - imguiColumnSliderFloat("Zoom Time", &zoom_time, 1.0f, 5.0f, 500.0f, "%.1f%%", 0, true); + ImGui::ColumnSliderFloat("Zoom Time", &zoom_time, 1.0f, 5.0f, 500.0f, "%.1f%%", 0, true); crv_edt->zoom_time = zoom_time * 0.01f; int32_t zoom_value = (int32_t)roundf(crv_edt->zoom_value * 100.0f); - imguiColumnSliderInt("Zoom Value", &zoom_value, 10, 1000, "%d%%", 0, true); + ImGui::ColumnSliderInt("Zoom Value", &zoom_value, 10, 1000, "%d%%", 0, true); crv_edt->zoom_value = (float_t)zoom_value * 0.01f; - imguiColumnDragFloat("Range", + ImGui::ColumnDragFloat("Range", &crv_edt->range, 0.0001f, 0.0f, FLT_MAX, "%g", 0); - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); bool add_key = false; bool del_key = false; @@ -6455,39 +6477,39 @@ if (flags & Glitter::CURVE_TYPE_##curve_type){ \ glitter_editor_curve_editor_key_manager(glt_edt, &curve->keys_rev, &add_key, &del_key); ImGui::Separator(); - float_t w = imguiGetContentRegionAvailWidth(); - imguiDisableElementPush(add_key); - if (imguiButton("Add Key", { w, 0.0f })) + float_t w = ImGui::GetContentRegionAvailWidth(); + ImGui::DisableElementPush(add_key); + if (ImGui::ButtonEnterKeyPressed("Add Key", { w, 0.0f })) crv_edt->add_key = true; - imguiDisableElementPop(add_key); + ImGui::DisableElementPop(add_key); - imguiDisableElementPush(del_key); - if (imguiButton("Delete Key", { w, 0.0f })) + ImGui::DisableElementPush(del_key); + if (ImGui::ButtonEnterKeyPressed("Delete Key", { w, 0.0f })) crv_edt->del_key = true; - imguiDisableElementPop(del_key); + ImGui::DisableElementPop(del_key); bool has_curve_in_list = curve ? true : false; - imguiDisableElementPush(!has_curve_in_list); - if (imguiButton("Add Curve", { w, 0.0f })) + ImGui::DisableElementPush(!has_curve_in_list); + if (ImGui::ButtonEnterKeyPressed("Add Curve", { w, 0.0f })) crv_edt->add_curve = true; - imguiDisableElementPop(!has_curve_in_list); + ImGui::DisableElementPop(!has_curve_in_list); - imguiDisableElementPush(has_curve_in_list); - if (imguiButton("Delete Curve", { w, 0.0f })) + ImGui::DisableElementPush(has_curve_in_list); + if (ImGui::ButtonEnterKeyPressed("Delete Curve", { w, 0.0f })) crv_edt->del_curve = true; - imguiDisableElementPop(has_curve_in_list); + ImGui::DisableElementPop(has_curve_in_list); ImGui::EndGroup(); } static bool glitter_editor_hash_input(glitter_editor_struct* glt_edt, const char* label, uint64_t* hash) { uint64_t h = *hash; if (glt_edt->effect_group->type == Glitter::FT) { - if (imguiColumnInputScalar(label, ImGuiDataType_U64, &h, + if (ImGui::ColumnInputScalar(label, ImGuiDataType_U64, &h, 0, 0, "%016llX", ImGuiInputTextFlags_CharsHexadecimal) && h == 0) h = hash_fnv1a64m_empty; } else { - if (imguiColumnInputScalar(label, ImGuiDataType_U32, &h, + if (ImGui::ColumnInputScalar(label, ImGuiDataType_U32, &h, 0, 0, "%08X", ImGuiInputTextFlags_CharsHexadecimal) && (uint32_t)h == 0) h = hash_murmurhash_empty; } @@ -6500,7 +6522,7 @@ static bool glitter_editor_hash_input(glitter_editor_struct* glt_edt, const char } static void glitter_editor_gl_load(glitter_editor_struct* glt_edt) { - const char* glitter_editor_wireframe_vert = + static const char* glitter_editor_wireframe_vert = "#version 430 core\n" "layout (location = 0) in vec3 a_position;\n" "\n" @@ -6513,7 +6535,7 @@ static void glitter_editor_gl_load(glitter_editor_struct* glt_edt) { " gl_Position = COMMON_DATA_VP * pos;\n" "}\n"; - const char* glitter_editor_wireframe_frag = + static const char* glitter_editor_wireframe_frag = "#version 430 core\n" "layout(location = 0) out vec4 result;\n" "\n" @@ -6525,9 +6547,11 @@ static void glitter_editor_gl_load(glitter_editor_struct* glt_edt) { " result = color;\n" "}\n"; + glt_edt->gl_data = new glitter_editor_gl; + shader_glsl_param param = {}; param.name = "Glitter Editor Wireframe"; - glt_edt->gl_data.wireframe.shader.load(glitter_editor_wireframe_vert, + glt_edt->gl_data->wireframe.shader.load(glitter_editor_wireframe_vert, glitter_editor_wireframe_frag, 0, ¶m); } @@ -6549,7 +6573,10 @@ static void glitter_editor_gl_process(glitter_editor_struct* glt_edt) { } static void glitter_editor_gl_free(glitter_editor_struct* glt_edt) { - glt_edt->gl_data.wireframe.shader.unload(); + if (glt_edt->gl_data) { + delete glt_edt->gl_data; + glt_edt->gl_data = 0; + } } static void glitter_editor_gl_draw_wireframe(glitter_editor_struct* glt_edt) { @@ -6710,8 +6737,8 @@ static void glitter_editor_gl_draw_wireframe_draw(glitter_editor_struct* glt_edt gl_state_set_polygon_mode(GL_FRONT_AND_BACK, GL_LINE); gl_state_bind_vertex_array(glt_edt->vao); - glt_edt->gl_data.wireframe.shader.use(); - glt_edt->gl_data.wireframe.shader.set("color", 1.0f, 1.0f, 0.0f, 1.0f); + glt_edt->gl_data->wireframe.shader.use(); + glt_edt->gl_data->wireframe.shader.set("color", 1.0f, 1.0f, 0.0f, 1.0f); for (Glitter::F2RenderGroup*& i : eff->render_scene.groups) { if (!i) continue; @@ -6722,7 +6749,7 @@ static void glitter_editor_gl_draw_wireframe_draw(glitter_editor_struct* glt_edt else if (rg->disp < 1) continue; - glt_edt->gl_data.wireframe.shader.set("model", false, rg->mat_draw); + glt_edt->gl_data->wireframe.shader.set("model", false, rg->mat_draw); switch (rg->type) { case Glitter::PARTICLE_QUAD: { @@ -6772,8 +6799,8 @@ static void glitter_editor_gl_draw_wireframe_draw(glitter_editor_struct* glt_edt gl_state_set_polygon_mode(GL_FRONT_AND_BACK, GL_LINE); gl_state_bind_vertex_array(glt_edt->vao); - glt_edt->gl_data.wireframe.shader.use(); - glt_edt->gl_data.wireframe.shader.set("color", 1.0f, 1.0f, 0.0f, 1.0f); + glt_edt->gl_data->wireframe.shader.use(); + glt_edt->gl_data->wireframe.shader.set("color", 1.0f, 1.0f, 0.0f, 1.0f); for (Glitter::XRenderGroup*& i : eff->render_scene.groups) { if (!i) continue; @@ -6784,7 +6811,7 @@ static void glitter_editor_gl_draw_wireframe_draw(glitter_editor_struct* glt_edt else if (rg->disp < 1) continue; - glt_edt->gl_data.wireframe.shader.set("model", false, rg->mat_draw); + glt_edt->gl_data->wireframe.shader.set("model", false, rg->mat_draw); switch (rg->type) { case Glitter::PARTICLE_QUAD: { @@ -6860,7 +6887,7 @@ static void glitter_editor_gl_draw_wireframe_draw_mesh(glitter_editor_struct* gl object_data, rctx->camera, &mat))) continue; - glt_edt->gl_data.wireframe.shader.set("model", false, mat); + glt_edt->gl_data->wireframe.shader.set("model", false, mat); int32_t ttc = 0; texture_transform_struct* tt = object_data->texture_transform_array; @@ -6874,7 +6901,7 @@ static void glitter_editor_gl_draw_wireframe_draw_mesh(glitter_editor_struct* gl for (uint32_t j = 0; j < mesh->num_submesh; j++) { obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; - if (sub_mesh->attrib.m.flag_3) + if (sub_mesh->attrib.m.cloth) continue; if (object_data->object_culling) { @@ -6913,7 +6940,7 @@ static void glitter_editor_gl_draw_wireframe_draw_mesh(glitter_editor_struct* gl GL_UNSIGNED_INT, }; - GLuint array_buffer = obj_mesh_vertex_buffer_get_buffer(&obj_vertex_buffer[i]); + GLuint array_buffer = obj_vertex_buffer[i].get_buffer(); gl_state_bind_array_buffer(array_buffer); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, mesh->size_vertex, (void*)0); diff --git a/src/CLOUD/classes/glitter_editor.h b/src/CLOUD/classes/glitter_editor.hpp similarity index 95% rename from src/CLOUD/classes/glitter_editor.h rename to src/CLOUD/classes/glitter_editor.hpp index 313d4e8a..465aba0b 100644 --- a/src/CLOUD/classes/glitter_editor.h +++ b/src/CLOUD/classes/glitter_editor.hpp @@ -7,7 +7,7 @@ #if defined(CLOUD_DEV) #include "../../KKdLib/default.hpp" -#include "../classes.h" +#include "../classes.hpp" extern bool glitter_editor_init(class_data* data, render_context* rctx); extern void glitter_editor_ctrl(class_data* data); diff --git a/src/CLOUD/classes/graphics.c b/src/CLOUD/classes/graphics.cpp similarity index 93% rename from src/CLOUD/classes/graphics.c rename to src/CLOUD/classes/graphics.cpp index 06a8c2e5..aad43d0c 100644 --- a/src/CLOUD/classes/graphics.c +++ b/src/CLOUD/classes/graphics.cpp @@ -3,7 +3,11 @@ GitHub/GitLab: korenkonder */ -#include "graphics.h" +#include "graphics.hpp" +#include "graphics/background_color.hpp" +#include "graphics/glitter.hpp" +#include "graphics/post_process.hpp" +#include "graphics/render_settings.hpp" classes_data graphics_classes[] = { { diff --git a/src/CLOUD/classes/graphics.h b/src/CLOUD/classes/graphics.h deleted file mode 100644 index 85e7ed3f..00000000 --- a/src/CLOUD/classes/graphics.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include "../classes.h" -#include "graphics/background_color.h" -#include "graphics/glitter.h" -#include "graphics/post_process.h" -#include "graphics/render_settings.h" - -extern classes_data graphics_classes[]; diff --git a/src/CLOUD/classes/graphics.hpp b/src/CLOUD/classes/graphics.hpp new file mode 100644 index 00000000..7847446c --- /dev/null +++ b/src/CLOUD/classes/graphics.hpp @@ -0,0 +1,10 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "../classes.hpp" + +extern classes_data graphics_classes[]; diff --git a/src/CLOUD/classes/graphics/background_color.c b/src/CLOUD/classes/graphics/background_color.cpp similarity index 92% rename from src/CLOUD/classes/graphics/background_color.c rename to src/CLOUD/classes/graphics/background_color.cpp index 39109a99..fa03014b 100644 --- a/src/CLOUD/classes/graphics/background_color.c +++ b/src/CLOUD/classes/graphics/background_color.cpp @@ -3,9 +3,9 @@ GitHub/GitLab: korenkonder */ -#include "background_color.h" +#include "background_color.hpp" #include "../../../KKdLib/vec.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; @@ -51,7 +51,7 @@ void graphics_background_color_imgui(class_data* data) { color_edit_flags |= ImGuiColorEditFlags_NoSidePreview; color_edit_flags |= ImGuiColorEditFlags_NoDragDrop; - imguiGetContentRegionAvailSetNextItemWidth(); + ImGui::GetContentRegionAvailSetNextItemWidth(); vec4 _clear_color; vec4u8_to_vec4(clear_color, _clear_color); vec4_mult_scalar(_clear_color, (float_t)(1.0 / 255.0), _clear_color); @@ -62,7 +62,7 @@ void graphics_background_color_imgui(class_data* data) { } ImGui::Checkbox("Set Clear Color", &set_clear_color); - if (imguiButton("Reset Color")) { + if (ImGui::ButtonEnterKeyPressed("Reset Color")) { clear_color = { 0x60, 0x60, 0x60, 0xFF }; set_clear_color = true; } diff --git a/src/CLOUD/classes/graphics/background_color.h b/src/CLOUD/classes/graphics/background_color.hpp similarity index 91% rename from src/CLOUD/classes/graphics/background_color.h rename to src/CLOUD/classes/graphics/background_color.hpp index 2bbf369f..96e6483f 100644 --- a/src/CLOUD/classes/graphics/background_color.h +++ b/src/CLOUD/classes/graphics/background_color.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool graphics_background_color_init(class_data* data, render_context* rctx); extern void graphics_background_color_imgui(class_data* data); diff --git a/src/CLOUD/classes/graphics/glitter.c b/src/CLOUD/classes/graphics/glitter.cpp similarity index 98% rename from src/CLOUD/classes/graphics/glitter.c rename to src/CLOUD/classes/graphics/glitter.cpp index 4708e7ef..f98adb52 100644 --- a/src/CLOUD/classes/graphics/glitter.c +++ b/src/CLOUD/classes/graphics/glitter.cpp @@ -3,10 +3,10 @@ GitHub/GitLab: korenkonder */ -#include "glitter.h" +#include "glitter.hpp" #include "../../../CRE/Glitter/glitter.hpp" #include "../../../CRE/render_context.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; diff --git a/src/CLOUD/classes/graphics/glitter.h b/src/CLOUD/classes/graphics/glitter.hpp similarity index 91% rename from src/CLOUD/classes/graphics/glitter.h rename to src/CLOUD/classes/graphics/glitter.hpp index eca04685..f4c96869 100644 --- a/src/CLOUD/classes/graphics/glitter.h +++ b/src/CLOUD/classes/graphics/glitter.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool graphics_glitter_init(class_data* data, render_context* rctx); extern void graphics_glitter_imgui(class_data* data); diff --git a/src/CLOUD/classes/graphics/post_process.c b/src/CLOUD/classes/graphics/post_process.cpp similarity index 71% rename from src/CLOUD/classes/graphics/post_process.c rename to src/CLOUD/classes/graphics/post_process.cpp index 14d3ee80..8507bfea 100644 --- a/src/CLOUD/classes/graphics/post_process.c +++ b/src/CLOUD/classes/graphics/post_process.cpp @@ -4,9 +4,9 @@ GitHub/GitLab: korenkonder */ -#include "post_process.h" +#include "post_process.hpp" #include "../../../CRE/stage.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; @@ -62,30 +62,30 @@ void graphics_post_process_imgui(class_data* data) { "cone(2tap)", }; - imguiColumnComboBox("MAG Filter", mag_filter_labels, POST_PROCESS_MAG_FILTER_MAX, + ImGui::ColumnComboBox("MAG Filter", mag_filter_labels, POST_PROCESS_MAG_FILTER_MAX, (int32_t*)&pp->mag_filter, 0, false, &data->imgui_focus); - imguiCheckbox("Morphological AA", &pp->mlaa); + ImGui::CheckboxEnterKeyPressed("Morphological AA", &pp->mlaa); - imguiSetColumnSpace(1.0f / 4.0f); + ImGui::SetColumnSpace(1.0f / 4.0f); if (ImGui::TreeNode("Tone Trans")) { vec3 tone_trans_start = tone_map->get_tone_trans_start(); - imguiColumnSliderVec3("Start", &tone_trans_start, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); + ImGui::ColumnSliderVec3("Start", &tone_trans_start, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); tone_map->set_tone_trans_start(tone_trans_start); vec3 tone_trans_end = tone_map->get_tone_trans_end(); - imguiColumnSliderVec3("End", &tone_trans_end, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); + ImGui::ColumnSliderVec3("End", &tone_trans_end, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); tone_map->set_tone_trans_end(tone_trans_end); ImGui::TreePop(); } if (ImGui::TreeNode("Scene Fade")) { float_t scene_fade_alpha = tone_map->get_scene_fade_alpha(); - imguiColumnSliderFloat("Alpha", &scene_fade_alpha, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Alpha", &scene_fade_alpha, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); tone_map->set_scene_fade_alpha(scene_fade_alpha); vec3 scene_fade_color = tone_map->get_scene_fade_color(); - imguiColumnSliderVec3("Color", &scene_fade_color, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); + ImGui::ColumnSliderVec3("Color", &scene_fade_color, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); tone_map->set_scene_fade_color(scene_fade_color); const char* scene_fade_blend_func_labels[] = { @@ -95,7 +95,7 @@ void graphics_post_process_imgui(class_data* data) { }; int32_t scene_fade_blend_func = tone_map->get_scene_fade_blend_func(); - imguiColumnComboBox("Blend Func", scene_fade_blend_func_labels, 3, + ImGui::ColumnComboBox("Blend Func", scene_fade_blend_func_labels, 3, &scene_fade_blend_func, 0, false, &data->imgui_focus); tone_map->set_scene_fade_blend_func(scene_fade_blend_func); ImGui::TreePop(); @@ -109,66 +109,66 @@ void graphics_post_process_imgui(class_data* data) { }; int32_t _tone_map_method = tone_map->get_tone_map_method(); - imguiColumnComboBox("Tone Map", tone_map_method_labels, 3, + ImGui::ColumnComboBox("Tone Map", tone_map_method_labels, 3, &_tone_map_method, 0, false, &data->imgui_focus); tone_map->set_tone_map_method((tone_map_method)_tone_map_method); float_t exposure = tone_map->get_exposure(); - imguiColumnSliderFloat("Exposure", &exposure, 0.02f, 0.0f, 4.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Exposure", &exposure, 0.02f, 0.0f, 4.0f, "%.2f", 0, true); exposure = roundf(exposure / 0.02f) * 0.02f; tone_map->set_exposure(exposure); bool auto_exposure = tone_map->get_auto_exposure(); - imguiCheckbox("Auto Exposure", &auto_exposure); + ImGui::CheckboxEnterKeyPressed("Auto Exposure", &auto_exposure); tone_map->set_auto_exposure(auto_exposure); float_t gamma = tone_map->get_gamma(); - imguiColumnSliderFloat("Gamma", &gamma, 0.01f, 0.2f, 2.2f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Gamma", &gamma, 0.01f, 0.2f, 2.2f, "%.2f", 0, true); tone_map->set_gamma(gamma); int32_t saturate1 = tone_map->get_saturate_power(); - imguiColumnSliderInt("Saturate 1", &saturate1, 1, 6, "%d", 0, true); + ImGui::ColumnSliderInt("Saturate 1", &saturate1, 1, 6, "%d", 0, true); tone_map->set_saturate_power(saturate1); float_t saturate2 = tone_map->get_saturate_coeff(); - imguiColumnSliderFloat("Saturate 2", &saturate2, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Saturate 2", &saturate2, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); tone_map->set_saturate_coeff(saturate2); ImGui::TreePop(); } if (ImGui::TreeNodeEx("Glare", ImGuiTreeNodeFlags_DefaultOpen)) { vec3 radius = blur->get_radius(); - imguiColumnSliderFloat("Radius R", &radius.x, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); - imguiColumnSliderFloat("Radius G", &radius.y, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); - imguiColumnSliderFloat("Radius B", &radius.z, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Radius R", &radius.x, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Radius G", &radius.y, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Radius B", &radius.z, 0.1f, 1.0f, 3.0f, "%.2f", 0, true); blur->set_radius(radius); vec3 intensity = blur->get_intensity(); - imguiColumnSliderFloat("Inten R", &intensity.x, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); - imguiColumnSliderFloat("Inten G", &intensity.y, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); - imguiColumnSliderFloat("Inten B", &intensity.z, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Inten R", &intensity.x, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Inten G", &intensity.y, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); + ImGui::ColumnSliderFloat("Inten B", &intensity.z, 0.05f, 0.0f, 2.0f, "%.2f", 0, true); blur->set_intensity(intensity); ImGui::TreePop(); } - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); if (ImGui::TreeNodeEx("DOF", ImGuiTreeNodeFlags_DefaultOpen)) { bool use_ui_params = dof->data.debug.flags & DOF_DEBUG_USE_UI_PARAMS; bool phys = use_ui_params && dof->data.debug.flags & DOF_DEBUG_ENABLE_PHYS_DOF; bool f2 = use_ui_params && ~dof->data.debug.flags & DOF_DEBUG_ENABLE_PHYS_DOF; - float_t alpha = style.Alpha * imgui_alpha_disabled_scale; + float_t alpha = style.Alpha * ImGui::AlphaDisabledScale; - imguiCheckboxFlags("use UI params", + ImGui::CheckboxFlagsEnterKeyPressed("use UI params", (uint32_t*)&dof->data.debug.flags, DOF_DEBUG_USE_UI_PARAMS); if (!use_ui_params) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha); } - imguiCheckboxFlags("enable DOF", + ImGui::CheckboxFlagsEnterKeyPressed("enable DOF", (uint32_t*)&dof->data.debug.flags, DOF_DEBUG_ENABLE_DOF); - imguiCheckboxFlags("enable physical DOF", + ImGui::CheckboxFlagsEnterKeyPressed("enable physical DOF", (uint32_t*)&dof->data.debug.flags, DOF_DEBUG_ENABLE_PHYS_DOF); if (!use_ui_params) { ImGui::PopItemFlag(); @@ -179,27 +179,27 @@ void graphics_post_process_imgui(class_data* data) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha); } - imguiCheckboxFlags("auto focus", + ImGui::CheckboxFlagsEnterKeyPressed("auto focus", (uint32_t*)&dof->data.debug.flags, DOF_DEBUG_AUTO_FOCUS); if (!phys) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); } - imguiSetColumnSpace(16.0f / 31.0f); + ImGui::SetColumnSpace(16.0f / 31.0f); if (!phys) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha); } - imguiColumnSliderFloat("distance to focus[m]", + ImGui::ColumnSliderFloat("distance to focus[m]", &dof->data.debug.focus, 0.01f, 0.01f, 30.0f, "%.2f", 0, true); float_t focal_length = dof->data.debug.focal_length * 1000.0f; - imguiColumnSliderFloat("focal length[mm]", + ImGui::ColumnSliderFloat("focal length[mm]", &focal_length, 0.01f, 0.1f, 100.0f, "%.2f", 0, true); dof->data.debug.focal_length = focal_length / 1000.0f; - imguiColumnSliderFloat("F-Number", + ImGui::ColumnSliderFloat("F-Number", &dof->data.debug.f_number, 0.01f, 0.1f, 40.0f, "%.2f", 0, true); if (!phys) { ImGui::PopItemFlag(); @@ -210,23 +210,23 @@ void graphics_post_process_imgui(class_data* data) { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, alpha); } - imguiColumnSliderFloat("f2 distance to focus[m]", + ImGui::ColumnSliderFloat("f2 distance to focus[m]", &dof->data.debug.f2.focus, 0.01f, 0.01f, 30.0f, "%.2f", 0, true); - imguiColumnSliderFloat("f2 focus range[m]", + ImGui::ColumnSliderFloat("f2 focus range[m]", &dof->data.debug.f2.focus_range, 0.01f, 0.0f, 10.0f, "%.2f", 0, true); - imguiColumnSliderFloat("f2 fuzzing range[m]", + ImGui::ColumnSliderFloat("f2 fuzzing range[m]", &dof->data.debug.f2.fuzzing_range, 0.01f, 0.0f, 10.0f, "%.2f", 0, true); - imguiColumnSliderFloat("f2 ratio", + ImGui::ColumnSliderFloat("f2 ratio", &dof->data.debug.f2.ratio, 0.01f, 0.0f, 1.0f, "%.2f", 0, true); if (!f2) { ImGui::PopItemFlag(); ImGui::PopStyleVar(); } - imguiSetDefaultColumnSpace(); + ImGui::SetDefaultColumnSpace(); ImGui::TreePop(); } - if (imguiButton("Reset Post Process", { 0, 0 })) { + if (ImGui::ButtonEnterKeyPressed("Reset Post Process", { 0, 0 })) { stage* stg = task_stage_get_current_stage(); light_param_storage_data_set_stage(stg->index); } diff --git a/src/CLOUD/classes/graphics/post_process.h b/src/CLOUD/classes/graphics/post_process.hpp similarity index 91% rename from src/CLOUD/classes/graphics/post_process.h rename to src/CLOUD/classes/graphics/post_process.hpp index 8cef71ec..3a1b513c 100644 --- a/src/CLOUD/classes/graphics/post_process.h +++ b/src/CLOUD/classes/graphics/post_process.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool graphics_post_process_init(class_data* data, render_context* rctx); extern void graphics_post_process_imgui(class_data* data); diff --git a/src/CLOUD/classes/graphics/render_settings.c b/src/CLOUD/classes/graphics/render_settings.cpp similarity index 86% rename from src/CLOUD/classes/graphics/render_settings.c rename to src/CLOUD/classes/graphics/render_settings.cpp index 0aa61f94..4613b6ef 100644 --- a/src/CLOUD/classes/graphics/render_settings.c +++ b/src/CLOUD/classes/graphics/render_settings.cpp @@ -3,17 +3,17 @@ GitHub/GitLab: korenkonder */ -#include "render_settings.h" -#include "../../../CRE/lock.h" -#include "../../../CRE/static_var.h" -#include "../../../CRE/timer.h" -#include "../imgui_helper.h" +#include "render_settings.hpp" +#include "../../../CRE/lock.hpp" +#include "../../../CRE/static_var.hpp" +#include "../../../CRE/timer.hpp" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; -extern timer render_timer; -extern timer sound_timer; +extern timer* render_timer; +extern timer* sound_timer; extern size_t render_scale_table_count; extern double_t render_get_scale(); @@ -74,17 +74,17 @@ void graphics_render_settings_imgui(class_data* data) { int32_t scale_index = render_get_scale_index(); char buf[0x80]; sprintf_s(buf, sizeof(buf), "%g%%%%", scale); - if (imguiColumnSliderInt("Scale", &scale_index, 0, + if (ImGui::ColumnSliderInt("Scale", &scale_index, 0, (int32_t)render_scale_table_count, buf, ImGuiSliderFlags_NoInput, true)) render_set_scale_index(scale_index); #if defined(CLOUD_DEV) ImGui::Separator(); - double_t render_freq = timer_get_freq(&render_timer); - double_t sound_freq = timer_get_freq(&sound_timer); - double_t render_freq_hist = timer_get_freq_hist(&render_timer); - double_t sound_freq_hist = timer_get_freq_hist(&sound_timer); + double_t render_freq = render_timer->get_freq(); + double_t sound_freq = sound_timer->get_freq(); + double_t render_freq_hist = render_timer->get_freq_hist(); + double_t sound_freq_hist = sound_timer->get_freq_hist(); char render_freq_str[0x20]; char sound_freq_str[0x20]; @@ -117,7 +117,7 @@ void graphics_render_settings_imgui(class_data* data) { ImGui::Separator(); - if (imguiButton("Reset Render Settings")) + if (ImGui::ButtonEnterKeyPressed("Reset Render Settings")) render_set_scale(1.0); data->imgui_focus |= ImGui::IsWindowFocused(); diff --git a/src/CLOUD/classes/graphics/render_settings.h b/src/CLOUD/classes/graphics/render_settings.hpp similarity index 91% rename from src/CLOUD/classes/graphics/render_settings.h rename to src/CLOUD/classes/graphics/render_settings.hpp index 04c68694..c22de4e1 100644 --- a/src/CLOUD/classes/graphics/render_settings.h +++ b/src/CLOUD/classes/graphics/render_settings.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool graphics_render_settings_init(class_data* data, render_context* rctx); extern void graphics_render_settings_imgui(class_data* data); diff --git a/src/CLOUD/classes/imgui_helper.c b/src/CLOUD/classes/imgui_helper.c deleted file mode 100644 index 87d64abc..00000000 --- a/src/CLOUD/classes/imgui_helper.c +++ /dev/null @@ -1,1787 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#include "imgui_helper.h" -#include "../../KKdLib/str_utils.hpp" -#include "../../CRE/data.hpp" - -const float_t imgui_alpha_disabled_scale = 0.5f; - -bool imgui_is_item_active; -bool imgui_is_item_focused; -bool imgui_is_item_visible; -bool imgui_is_item_edited; -bool imgui_is_item_activated; -bool imgui_is_item_deactivated; -bool imgui_is_item_deactivated_after_edit; -bool imgui_is_item_toggled_open; - -static float_t column_space = (float_t)(1.0 / 3.0); -static float_t cell_padding; - -#undef min -#undef max - -static void imgui_reset_is_item() { - imgui_is_item_active = false; - imgui_is_item_focused = false; - imgui_is_item_visible = false; - imgui_is_item_edited = false; - imgui_is_item_activated = false; - imgui_is_item_deactivated = false; - imgui_is_item_deactivated_after_edit = false; - imgui_is_item_toggled_open = false; -} - -static void imgui_get_is_item() { - imgui_is_item_active |= ImGui::IsItemActive(); - imgui_is_item_focused |= ImGui::IsItemFocused(); - imgui_is_item_visible |= ImGui::IsItemVisible(); - imgui_is_item_edited |= ImGui::IsItemEdited(); - imgui_is_item_activated |= ImGui::IsItemActivated(); - imgui_is_item_deactivated |= ImGui::IsItemDeactivated(); - imgui_is_item_deactivated_after_edit |= ImGui::IsItemDeactivatedAfterEdit(); - imgui_is_item_toggled_open |= ImGui::IsItemToggledOpen(); -} - -inline bool imguiItemKeyDown(int32_t key) { - return ImGui::IsItemFocused() && ImGui::IsKeyDown(key); -} - -inline bool imguiItemKeyPressed(int32_t key, bool repeat) { - return ImGui::IsItemFocused() && ImGui::IsKeyPressed(key, repeat); -} - -inline bool imguiItemKeyReleased(int32_t key) { - return ImGui::IsItemFocused() && ImGui::IsKeyReleased(key); -} - -inline float_t imguiGetColumnSpace() { - return column_space; -} - -inline void imguiSetColumnSpace(float_t val) { - column_space = val; -} - -inline void imguiSetDefaultColumnSpace() { - column_space = (float_t)(1.0 / 3.0); -} - -inline void imguiDisableElementPush(bool enable) { - if (!enable) { - ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * imgui_alpha_disabled_scale); - } -} - -inline void imguiDisableElementPop(bool enable) { - if (!enable) { - ImGui::PopItemFlag(); - ImGui::PopStyleVar(1); - } -} - -inline float_t imguiGetContentRegionAvailWidth() { - return ImGui::GetContentRegionAvail().x; -} - -inline float_t imguiGetContentRegionAvailHeight() { - return ImGui::GetContentRegionAvail().y; -} - -inline void imguiGetContentRegionAvailSetNextItemWidth() { - ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x); -} - -void imguiStartPropertyColumn(const char* label) { - ImGui::PushID(label); - - float_t w = imguiGetContentRegionAvailWidth(); - ImGui::BeginTable("table", 2); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * column_space, 0); - - char* label_temp = str_utils_copy(label); - char* temp; - if (temp = strstr(label_temp, "##")) - *temp = 0; - ImGui::TableNextColumn(); - imguiGetContentRegionAvailSetNextItemWidth(); - ImGui::Text(label_temp); - free(label_temp); - - ImGui::TableNextColumn(); - imguiGetContentRegionAvailSetNextItemWidth(); -} - -void imguiEndPropertyColumn() { - ImGui::EndTable(); - ImGui::PopID(); -} - -bool igSliderFloatButton(const char* label, float_t* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { - float_t button_size = ImGui::GetFont()->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f; - ImGuiIO& io = ImGui::GetIO(); - - float_t key_repeat_delay = io.KeyRepeatDelay; - float_t key_repeat_rate = io.KeyRepeatRate; - io.KeyRepeatDelay = (float_t)(30.0 / 60.0); - io.KeyRepeatRate = (float_t)(10.0 / 60.0); - - ImGuiButtonFlags button_flags = ImGuiButtonFlags_Repeat; - if (flags & ImGuiSliderFlags_NoInput) - ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); - - float_t v = *val; - float_t w = ImGui::CalcItemWidth(); - ImGui::PushID(label); - ImGui::BeginGroup(); - ImGui::PushButtonRepeat(true); - imgui_reset_is_item(); - ImGui::ButtonEx("<", { button_size, button_size }, ImGuiButtonFlags_Repeat); - imgui_get_is_item(); - bool l = ImGui::IsItemActive() && (ImGui::IsKeyPressed(VK_RETURN, true) - || ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)); - ImGui::SameLine(0.0f, 0.0f); - ImGui::SetNextItemWidth(w - button_size * 2.0f); - ImGui::SliderScalar(label, ImGuiDataType_Float, &v, &min, &max, format, flags); - imgui_get_is_item(); - ImGui::SameLine(0.0f, 0.0f); - ImGui::ButtonEx(">", { button_size, button_size }, ImGuiButtonFlags_Repeat); - imgui_get_is_item(); - bool r = ImGui::IsItemActive() && (ImGui::IsKeyPressed(VK_RETURN, true) - || ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)); - ImGui::PopButtonRepeat(); - ImGui::EndGroup(); - ImGui::PopID(); - if (flags & ImGuiSliderFlags_NoInput) - ImGui::PopItemFlag(); - - io.KeyRepeatDelay = key_repeat_delay; - io.KeyRepeatRate = key_repeat_rate; - - if (l) { - v -= step; - if (v < min) - v = min; - } - else if (r) { - v += step; - if (v > max) - v = max; - } - - bool res = *val != v ? true : false; - *val = v; - return res; -} - -bool igSliderIntButton(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - float_t button_size = ImGui::GetFont()->FontSize + ImGui::GetStyle().FramePadding.y * 2.0f; - ImGuiIO& io = ImGui::GetIO(); - - float_t key_repeat_delay = io.KeyRepeatDelay; - float_t key_repeat_rate = io.KeyRepeatRate; - io.KeyRepeatDelay = (float_t)(30.0 / 60.0); - io.KeyRepeatRate = (float_t)(10.0 / 60.0); - - int32_t v = *val; - float_t w = ImGui::CalcItemWidth(); - ImGui::PushID(label); - ImGui::BeginGroup(); - ImGui::PushButtonRepeat(true); - imgui_reset_is_item(); - ImGui::ButtonEx("<", { button_size, button_size }, ImGuiButtonFlags_Repeat); - imgui_get_is_item(); - bool l = ImGui::IsItemActive() && (ImGui::IsKeyPressed(VK_RETURN, true) - || ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)); - ImGui::SameLine(0.0f, 0.0f); - ImGui::SetNextItemWidth(w - button_size * 2.0f); - ImGui::SliderScalar(label, ImGuiDataType_S32, &v, &min, &max, format, flags); - imgui_get_is_item(); - ImGui::SameLine(0.0f, 0.0f); - ImGui::ButtonEx(">", { button_size, button_size }, ImGuiButtonFlags_Repeat); - imgui_get_is_item(); - bool r = ImGui::IsItemActive() && (ImGui::IsKeyPressed(VK_RETURN, true) - || ImGui::IsMouseClicked(ImGuiMouseButton_Left, true)); - ImGui::PopButtonRepeat(); - ImGui::EndGroup(); - ImGui::PopID(); - - io.KeyRepeatDelay = key_repeat_delay; - io.KeyRepeatRate = key_repeat_rate; - - if (l) { - v--; - if (v < min) - v = min; - } - else if (r) { - v++; - if (v > max) - v = max; - } - - bool res = *val != v ? true : false; - *val = v; - return res; -} - -bool imguiButton(const char* label, const ImVec2& size) { - imgui_reset_is_item(); - bool res = ImGui::Button(label, size); - imgui_get_is_item(); - return res || imguiItemKeyPressed(GLFW_KEY_ENTER, true); -} - -bool imguiButtonEx(const char* label, const ImVec2& size, ImGuiButtonFlags flags) { - imgui_reset_is_item(); - bool res = ImGui::ButtonEx(label, size, flags); - imgui_get_is_item(); - return res || imguiItemKeyPressed(GLFW_KEY_ENTER, true); -} - -bool imguiCheckbox(const char* label, bool* v) { - if (ImGui::Checkbox(label, v)) - return true; - else if (imguiItemKeyPressed(GLFW_KEY_ENTER, true)) { - v[0] ^= true; - return true; - } - else - return false; -} - -bool imguiCheckboxFlags(const char* label, int* flags, int flags_value) { - if (ImGui::CheckboxFlags(label, flags, flags_value)) - return true; - else if (imguiItemKeyPressed(GLFW_KEY_ENTER, true)) { - *flags ^= flags_value; - return true; - } - else - return false; -} - -bool imguiCheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value) { - if (ImGui::CheckboxFlags(label, flags, flags_value)) - return true; - else if (imguiItemKeyPressed(GLFW_KEY_ENTER, true)) { - *flags ^= flags_value; - return true; - } - else - return false; -} - -static bool igDragFloatDisable(const char* label, float_t* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = ImGui::DragFloat("", val, speed, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static bool igDragIntDisable(const char* label, int32_t* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = ImGui::DragInt("", val, speed, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static bool igSliderFloatDisable(const char* label, float_t* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = ImGui::SliderFloat("", val, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static bool igSliderFloatButtonDisable(const char* label, float_t* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = igSliderFloatButton("", val, step, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static bool igSliderIntDisable(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = ImGui::SliderInt("", val, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static bool igSliderIntButtonDisable(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { - ImGui::PushID(label); - imguiDisableElementPush(enable); - bool res = igSliderIntButton("", val, min, max, enable ? format : "...", flags); - imguiDisableElementPop(enable); - ImGui::PopID(); - ImGui::PopItemWidth(); - return res; -} - -static const char* imguiStartPropertyColumnDisable(const char* label, bool enable) { - ImGui::PushID(label); - - float_t w = imguiGetContentRegionAvailWidth(); - ImGui::BeginTable("table", 2); - ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * column_space, 0); - - char* label_temp = str_utils_copy(label); - char* temp; - if (temp = strstr(label_temp, "##")) - *temp = 0; - ImGui::TableNextColumn(); - imguiGetContentRegionAvailSetNextItemWidth(); - imguiDisableElementPush(enable); - ImGui::Text(label_temp); - imguiDisableElementPop(enable); - free(label_temp); - - ImGui::TableNextColumn(); - imguiGetContentRegionAvailSetNextItemWidth(); - return 0; -} - -bool imguiComboBox(const char* label, const char** items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - int32_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items[*selected_idx] : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items[n], *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items[n], *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiComboBox(const char* label, const char** items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - size_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items[*selected_idx] : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items[n], *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items[n], *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiComboBoxString(const char* label, std::string* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - int32_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items[*selected_idx].c_str() : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items[n].c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items[n].c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiComboBoxString(const char* label, std::string* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - size_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items[*selected_idx].c_str() : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items[n].c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items[n].c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiComboBoxConfigFile(const char* label, void* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - int32_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - data_struct_file* items_ds = (data_struct_file*)items; - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items_ds[*selected_idx].name.c_str() : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items_ds[n].name.c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((int32_t)n); - if (ImGui::Selectable(items_ds[n].name.c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = (int32_t)n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiComboBoxConfigFile(const char* label, void* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - size_t prev_selected_idx = *selected_idx; - - if (!include_last && size < 1) { - imguiDisableElementPush(false); - if (ImGui::BeginCombo(label, "None", flags)) { - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - imguiDisableElementPop(false); - return false; - } - - data_struct_file* items_ds = (data_struct_file*)items; - if (ImGui::BeginCombo(label, *selected_idx != -1 ? items_ds[*selected_idx].name.c_str() : 0, flags)) { - if (include_last) - for (size_t n = 0; n <= size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items_ds[n].name.c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - else - for (size_t n = 0; n < size; n++) { - ImGui::PushID((void*)n); - if (ImGui::Selectable(items_ds[n].name.c_str(), *selected_idx == n) - || imguiItemKeyPressed(GLFW_KEY_ENTER, true) - || (ImGui::IsItemFocused() && *selected_idx != n)) - *selected_idx = n; - ImGui::PopID(); - - if (*selected_idx == n) - ImGui::SetItemDefaultFocus(); - } - - if (focus) - *focus |= true; - ImGui::EndCombo(); - } - return prev_selected_idx != *selected_idx; -} - -bool imguiColumnColorEdit3(const char* label, vec3* val, ImGuiColorEditFlags flags) { - float_t v[3]; - *(vec3*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::ColorEdit3("", v, flags); - imguiEndPropertyColumn(); - if (res) - *val = *(vec3*)v; - return res; -} - -bool imguiColumnColorEdit4(const char* label, vec4* val, ImGuiColorEditFlags flags) { - float_t v[4]; - *(vec4*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::ColorEdit4("", v, flags); - imguiEndPropertyColumn(); - if (res) - *val = *(vec4*)v; - return res; -} - -bool imguiColumnComboBox(const char* label, const char** items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBox("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnComboBox(const char* label, const char** items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBox("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnComboBoxString(const char* label, std::string* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBoxString("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnComboBoxString(const char* label, std::string* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBoxString("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnComboBoxConfigFile(const char* label, void* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBoxConfigFile("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnComboBoxConfigFile(const char* label, void* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { - imguiStartPropertyColumn(label); - bool res = imguiComboBoxConfigFile("", items, size, selected_idx, flags, include_last, focus); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnDragFloat(const char* label, float_t* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { - float_t v[1]; - v[0] = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragFloat("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnDragVec2(const char* label, vec2* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { - float_t v[2]; - *(vec2*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragFloat2("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2*)v; - return true; -} - -bool imguiColumnDragVec3(const char* label, vec3* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { - float_t v[3]; - *(vec3*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragFloat3("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3*)v; - return true; -} - -bool imguiColumnDragVec4(const char* label, vec4* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { - float_t v[4]; - *(vec4*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragFloat4("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4*)v; - return true; -} - -bool imguiColumnDragInt(const char* label, int32_t* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - int32_t v[1]; - v[0] = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragInt("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnDragVec2I(const char* label, vec2i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - int32_t v[2]; - *(vec2i*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragInt2("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2i*)v; - return true; -} - -bool imguiColumnDragVec3I(const char* label, vec3i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - int32_t v[3]; - *(vec3i*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragInt3("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3i*)v; - return true; -} - -bool imguiColumnDragVec4I(const char* label, vec4i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - int32_t v[4]; - *(vec4i*)v = *val; - imguiStartPropertyColumn(label); - bool res = ImGui::DragInt4("", v, speed, min, max, format, flags); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4i*)v; - return true; -} - -bool imguiColumnInputText(const char* label, char* buf, size_t buf_size, - ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) { - imguiStartPropertyColumn(label); - bool res = ImGui::InputText("", buf, buf_size, flags, callback, user_data); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnSliderFloat(const char* label, float_t* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { - float_t v[1]; - v[0] = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) - res = igSliderFloatButton("", v, step, min, max, format, flags); - else { - res = ImGui::SliderFloat("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnSliderVec2(const char* label, vec2* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { - float_t v[2]; - *(vec2*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - res |= igSliderFloatButton("##X", &v[0], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##Y", &v[1], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::EndGroup(); - } - else { - res = ImGui::SliderFloat2("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2*)v; - return true; -} - -bool imguiColumnSliderVec3(const char* label, vec3* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { - float_t v[3]; - *(vec3*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - res |= igSliderFloatButton("##X", &v[0], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##Y", &v[1], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##Z", &v[2], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::EndGroup(); - } - else { - res = ImGui::SliderFloat3("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3*)v; - return true; -} - -bool imguiColumnSliderVec4(const char* label, vec4* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { - float_t v[4]; - *(vec4*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderFloatButton("##X", &v[0], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##Y", &v[1], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##Z", &v[2], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatButton("##W", &v[3], step, min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::EndGroup(); - } - else { - res = ImGui::SliderFloat4("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4*)v; - return true; -} - -bool imguiColumnSliderInt(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { - int32_t v[1]; - v[0] = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) - res = igSliderIntButton("", v, min, max, format, flags); - else { - res = ImGui::SliderInt("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnSliderVec2I(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { - int32_t v[2]; - *(vec2i*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderIntButton("##X", &v[0], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##Y", &v[1], min, max, format, flags); - ImGui::PopItemWidth(); - - ImGui::EndGroup(); - } - else { - res = ImGui::SliderInt2("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2i*)v; - return true; -} - -bool imguiColumnSliderVec3I(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { - int32_t v[3]; - *(vec3i*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderIntButton("##X", &v[0], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##Y", &v[1], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##Z", &v[2], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::EndGroup(); - } - else { - res = ImGui::SliderInt3("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3i*)v; - return true; -} - -bool imguiColumnSliderVec4I(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { - int32_t v[4]; - *(vec4i*)v = *val; - imguiStartPropertyColumn(label); - bool res = false; - imgui_reset_is_item(); - if (button) { - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderIntButton("##X", &v[0], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##Y", &v[1], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##Z", &v[2], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntButton("##W", &v[3], min, max, format, flags); - ImGui::PopItemWidth(); - ImGui::EndGroup(); - } - else { - res = ImGui::SliderInt4("", v, min, max, format, flags); - imgui_get_is_item(); - } - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4i*)v; - return true; -} - -bool imguiColumnSliderLogInt(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - char buf[0x1000]; - int32_t v[1]; - if (min < 1) - min = 1; - if (min > max) - max = min; - flags |= ImGuiSliderFlags_NoInput; - - v[0] = (int32_t)roundf(log2f((float_t)*val)); - imguiStartPropertyColumn(label); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth()); - min = (int32_t)roundf(log2f((float_t)min)); - max = (int32_t)roundf(log2f((float_t)max)); - sprintf_s(buf, sizeof(buf), format, 1 << v[0]); - res |= igSliderIntDisable("##X", &v[0], min, max, buf, flags, true); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = 1 << clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnSliderLogVec2I(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - char buf[0x1000]; - int32_t v[2]; - if (min < 1) - min = 1; - if (min > max) - max = min; - flags |= ImGuiSliderFlags_NoInput; - - v[0] = (int32_t)roundf(log2f((float_t)val->x)); - v[1] = (int32_t)roundf(log2f((float_t)val->y)); - imguiStartPropertyColumn(label); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - min = (int32_t)roundf(log2f((float_t)min)); - max = (int32_t)roundf(log2f((float_t)max)); - sprintf_s(buf, sizeof(buf), format, 1 << v[0]); - res |= igSliderIntDisable("##X", &v[0], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[1]); - res |= igSliderIntDisable("##Y", &v[1], min, max, buf, flags, true); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = 1 << clamp(v[0], min, max); - v[1] = 1 << clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2i*)v; - return true; -} - -bool imguiColumnSliderLogVec3I(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - char buf[0x1000]; - int32_t v[3]; - if (min < 1) - min = 1; - if (min > max) - max = min; - flags |= ImGuiSliderFlags_NoInput; - - v[0] = (int32_t)roundf(log2f((float_t)val->x)); - v[1] = (int32_t)roundf(log2f((float_t)val->y)); - v[2] = (int32_t)roundf(log2f((float_t)val->z)); - imguiStartPropertyColumn(label); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - min = (int32_t)roundf(log2f((float_t)min)); - max = (int32_t)roundf(log2f((float_t)max)); - sprintf_s(buf, sizeof(buf), format, 1 << v[0]); - res |= igSliderIntDisable("##X", &v[0], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[1]); - res |= igSliderIntDisable("##Y", &v[1], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[2]); - res |= igSliderIntDisable("##Z", &v[2], min, max, buf, flags, true); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = 1 << clamp(v[0], min, max); - v[1] = 1 << clamp(v[1], min, max); - v[2] = 1 << clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3i*)v; - return true; -} - -bool imguiColumnSliderLogVec4I(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { - char buf[0x1000]; - int32_t v[4]; - if (min < 1) - min = 1; - if (min > max) - max = min; - flags |= ImGuiSliderFlags_NoInput; - - v[0] = (int32_t)roundf(log2f((float_t)val->x)); - v[1] = (int32_t)roundf(log2f((float_t)val->y)); - v[2] = (int32_t)roundf(log2f((float_t)val->z)); - v[3] = (int32_t)roundf(log2f((float_t)val->w)); - imguiStartPropertyColumn(label); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - min = (int32_t)roundf(log2f((float_t)min)); - max = (int32_t)roundf(log2f((float_t)max)); - sprintf_s(buf, sizeof(buf), format, 1 << v[0]); - res |= igSliderIntDisable("##X", &v[0], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[1]); - res |= igSliderIntDisable("##Y", &v[1], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[2]); - res |= igSliderIntDisable("##Z", &v[2], min, max, buf, flags, true); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - sprintf_s(buf, sizeof(buf), format, 1 << v[3]); - res |= igSliderIntDisable("##W", &v[3], min, max, buf, flags, true); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = 1 << clamp(v[0], min, max); - v[1] = 1 << clamp(v[1], min, max); - v[2] = 1 << clamp(v[2], min, max); - v[3] = 1 << clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4i*)v; - return true; -} - -bool imguiColumnInputScalar(const char* label, ImGuiDataType data_type, void* p_data, - const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags) { - imguiStartPropertyColumn(label); - bool res = ImGui::InputScalar("", data_type, p_data, p_step, p_step_fast, format, flags); - imguiEndPropertyColumn(); - return res; -} - -bool imguiColumnDragFloatFlag(const char* label, float_t* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[1]; - v[0] = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth()); - res |= igDragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnDragVec2Flag(const char* label, vec2* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[2]; - *(vec2*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - res |= igDragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2*)v; - return true; -} - -bool imguiColumnDragVec3Flag(const char* label, vec3* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[3]; - *(vec3*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - res |= igDragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3*)v; - return true; -} - -bool imguiColumnDragVec4Flag(const char* label, vec4* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[4]; - *(vec4*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igDragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragFloatDisable("##W", &v[3], speed, min, max, format, flags, bit_flag & 0x08 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4*)v; - return true; -} - -bool imguiColumnDragIntFlag(const char* label, int32_t* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[1]; - v[0] = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth()); - res |= igDragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnDragVec2IFlag(const char* label, vec2i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[2]; - *(vec2i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - res |= igDragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2i*)v; - return true; -} - -bool imguiColumnDragVec3IFlag(const char* label, vec3i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[3]; - *(vec3i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - res |= igDragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3i*)v; - return true; -} - -bool imguiColumnDragVec4IFlag(const char* label, vec4i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[4]; - *(vec4i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igDragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igDragIntDisable("##W", &v[3], speed, min, max, format, flags, bit_flag & 0x08 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4i*)v; - return true; -} - -bool imguiColumnSliderFloatFlag(const char* label, float_t* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[1]; - v[0] = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth()); - res |= igSliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnSliderVec2Flag(const char* label, vec2* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[2]; - *(vec2*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - res |= igSliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2*)v; - return true; -} - -bool imguiColumnSliderVec3Flag(const char* label, vec3* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[3]; - *(vec3*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - res |= igSliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3*)v; - return true; -} - -bool imguiColumnSliderVec4Flag(const char* label, vec4* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - float_t v[4]; - *(vec4*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderFloatDisable("##W", &v[3], min, max, format, flags, bit_flag & 0x08 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4*)v; - return true; -} - -bool imguiColumnSliderIntFlag(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[1]; - v[0] = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(1, ImGui::CalcItemWidth()); - res |= igSliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - if (v[0] == *val) - return false; - - *val = v[0]; - return true; -} - -bool imguiColumnSliderVec2IFlag(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[2]; - *(vec2i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(2, ImGui::CalcItemWidth()); - res |= igSliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - if (v[0] == val->x && v[1] == val->y) - return false; - - *val = *(vec2i*)v; - return true; -} - -bool imguiColumnSliderVec3IFlag(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[3]; - *(vec3i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); - res |= igSliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z) - return false; - - *val = *(vec3i*)v; - return true; -} - -bool imguiColumnSliderVec4IFlag(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { - int32_t v[4]; - *(vec4i*)v = *val; - imguiStartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); - bool res = false; - ImGuiStyle& style = ImGui::GetStyle(); - ImGui::BeginGroup(); - ImGui::PushMultiItemsWidths(4, ImGui::CalcItemWidth()); - res |= igSliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); - ImGui::SameLine(0.0f, style.ItemInnerSpacing.x); - res |= igSliderIntDisable("##W", &v[3], min, max, format, flags, bit_flag & 0x08 ? true : false); - ImGui::EndGroup(); - imguiEndPropertyColumn(); - if (!res) - return false; - - v[0] = clamp(v[0], min, max); - v[1] = clamp(v[1], min, max); - v[2] = clamp(v[2], min, max); - v[3] = clamp(v[3], min, max); - if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) - return false; - - *val = *(vec4i*)v; - return true; -} diff --git a/src/CLOUD/classes/imgui_helper.cpp b/src/CLOUD/classes/imgui_helper.cpp new file mode 100644 index 00000000..60565f36 --- /dev/null +++ b/src/CLOUD/classes/imgui_helper.cpp @@ -0,0 +1,1789 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "imgui_helper.hpp" +#include "../../KKdLib/str_utils.hpp" +#include "../../CRE/data.hpp" + +namespace ImGui { + const float_t AlphaDisabledScale = 0.5f; + + bool IsItemActiveAccum; + bool IsItemFocusedAccum; + bool IsItemVisibleAccum; + bool IsItemEditedAccum; + bool IsItemActivatedAccum; + bool IsItemDeactivatedAccum; + bool IsItemDeactivatedAfterEditAccum; + bool IsItemToggledOpenAccum; + + static float_t column_space = (float_t)(1.0 / 3.0); + static float_t cell_padding; + + #undef min + #undef max + + static void ResetIsItemAccum() { + IsItemActiveAccum = false; + IsItemFocusedAccum = false; + IsItemVisibleAccum = false; + IsItemEditedAccum = false; + IsItemActivatedAccum = false; + IsItemDeactivatedAccum = false; + IsItemDeactivatedAfterEditAccum = false; + IsItemToggledOpenAccum = false; + } + + static void GetIsItemAccum() { + IsItemActiveAccum |= IsItemActive(); + IsItemFocusedAccum |= IsItemFocused(); + IsItemVisibleAccum |= IsItemVisible(); + IsItemEditedAccum |= IsItemEdited(); + IsItemActivatedAccum |= IsItemActivated(); + IsItemDeactivatedAccum |= IsItemDeactivated(); + IsItemDeactivatedAfterEditAccum |= IsItemDeactivatedAfterEdit(); + IsItemToggledOpenAccum |= IsItemToggledOpen(); + } + + inline bool ItemKeyDown(int32_t key) { + return IsItemFocused() && IsKeyDown(key); + } + + inline bool ItemKeyPressed(int32_t key, bool repeat) { + return IsItemFocused() && IsKeyPressed(key, repeat); + } + + inline bool ItemKeyReleased(int32_t key) { + return IsItemFocused() && IsKeyReleased(key); + } + + inline float_t GetColumnSpace() { + return column_space; + } + + inline void SetColumnSpace(float_t val) { + column_space = val; + } + + inline void SetDefaultColumnSpace() { + column_space = (float_t)(1.0 / 3.0); + } + + inline void DisableElementPush(bool enable) { + if (!enable) { + PushItemFlag(ImGuiItemFlags_Disabled, true); + PushStyleVar(ImGuiStyleVar_Alpha, GetStyle().Alpha * AlphaDisabledScale); + } + } + + inline void DisableElementPop(bool enable) { + if (!enable) { + PopItemFlag(); + PopStyleVar(1); + } + } + + inline float_t GetContentRegionAvailWidth() { + return GetContentRegionAvail().x; + } + + inline float_t GetContentRegionAvailHeight() { + return GetContentRegionAvail().y; + } + + inline void GetContentRegionAvailSetNextItemWidth() { + SetNextItemWidth(GetContentRegionAvail().x); + } + + void StartPropertyColumn(const char* label) { + PushID(label); + + float_t w = GetContentRegionAvailWidth(); + BeginTable("table", 2); + TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * column_space, 0); + + char* label_temp = str_utils_copy(label); + char* temp; + if (temp = strstr(label_temp, "##")) + *temp = 0; + TableNextColumn(); + GetContentRegionAvailSetNextItemWidth(); + Text(label_temp); + free(label_temp); + + TableNextColumn(); + GetContentRegionAvailSetNextItemWidth(); + } + + void EndPropertyColumn() { + EndTable(); + PopID(); + } + + bool SliderFloatButton(const char* label, float_t* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { + float_t button_size = GetFont()->FontSize + GetStyle().FramePadding.y * 2.0f; + ImGuiIO& io = GetIO(); + + float_t key_repeat_delay = io.KeyRepeatDelay; + float_t key_repeat_rate = io.KeyRepeatRate; + io.KeyRepeatDelay = (float_t)(30.0 / 60.0); + io.KeyRepeatRate = (float_t)(10.0 / 60.0); + + ImGuiButtonFlags button_flags = ImGuiButtonFlags_Repeat; + if (flags & ImGuiSliderFlags_NoInput) + PushItemFlag(ImGuiItemFlags_Disabled, true); + + float_t v = *val; + float_t w = CalcItemWidth(); + PushID(label); + BeginGroup(); + PushButtonRepeat(true); + ResetIsItemAccum(); + ButtonEx("<", { button_size, button_size }, ImGuiButtonFlags_Repeat); + GetIsItemAccum(); + bool l = IsItemActive() && (IsKeyPressed(VK_RETURN, true) + || IsMouseClicked(ImGuiMouseButton_Left, true)); + SameLine(0.0f, 0.0f); + SetNextItemWidth(w - button_size * 2.0f); + SliderScalar(label, ImGuiDataType_Float, &v, &min, &max, format, flags); + GetIsItemAccum(); + SameLine(0.0f, 0.0f); + ButtonEx(">", { button_size, button_size }, ImGuiButtonFlags_Repeat); + GetIsItemAccum(); + bool r = IsItemActive() && (IsKeyPressed(VK_RETURN, true) + || IsMouseClicked(ImGuiMouseButton_Left, true)); + PopButtonRepeat(); + EndGroup(); + PopID(); + if (flags & ImGuiSliderFlags_NoInput) + PopItemFlag(); + + io.KeyRepeatDelay = key_repeat_delay; + io.KeyRepeatRate = key_repeat_rate; + + if (l) { + v -= step; + if (v < min) + v = min; + } + else if (r) { + v += step; + if (v > max) + v = max; + } + + bool res = *val != v ? true : false; + *val = v; + return res; + } + + bool SliderIntButton(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + float_t button_size = GetFont()->FontSize + GetStyle().FramePadding.y * 2.0f; + ImGuiIO& io = GetIO(); + + float_t key_repeat_delay = io.KeyRepeatDelay; + float_t key_repeat_rate = io.KeyRepeatRate; + io.KeyRepeatDelay = (float_t)(30.0 / 60.0); + io.KeyRepeatRate = (float_t)(10.0 / 60.0); + + int32_t v = *val; + float_t w = CalcItemWidth(); + PushID(label); + BeginGroup(); + PushButtonRepeat(true); + ResetIsItemAccum(); + ButtonEx("<", { button_size, button_size }, ImGuiButtonFlags_Repeat); + GetIsItemAccum(); + bool l = IsItemActive() && (IsKeyPressed(VK_RETURN, true) + || IsMouseClicked(ImGuiMouseButton_Left, true)); + SameLine(0.0f, 0.0f); + SetNextItemWidth(w - button_size * 2.0f); + SliderScalar(label, ImGuiDataType_S32, &v, &min, &max, format, flags); + GetIsItemAccum(); + SameLine(0.0f, 0.0f); + ButtonEx(">", { button_size, button_size }, ImGuiButtonFlags_Repeat); + GetIsItemAccum(); + bool r = IsItemActive() && (IsKeyPressed(VK_RETURN, true) + || IsMouseClicked(ImGuiMouseButton_Left, true)); + PopButtonRepeat(); + EndGroup(); + PopID(); + + io.KeyRepeatDelay = key_repeat_delay; + io.KeyRepeatRate = key_repeat_rate; + + if (l) { + v--; + if (v < min) + v = min; + } + else if (r) { + v++; + if (v > max) + v = max; + } + + bool res = *val != v ? true : false; + *val = v; + return res; + } + + bool ButtonEnterKeyPressed(const char* label, const ImVec2& size) { + ResetIsItemAccum(); + bool res = Button(label, size); + GetIsItemAccum(); + return res || ItemKeyPressed(GLFW_KEY_ENTER, true); + } + + bool ButtonExEnterKeyPressed(const char* label, const ImVec2& size, ImGuiButtonFlags flags) { + ResetIsItemAccum(); + bool res = ButtonEx(label, size, flags); + GetIsItemAccum(); + return res || ItemKeyPressed(GLFW_KEY_ENTER, true); + } + + bool CheckboxEnterKeyPressed(const char* label, bool* v) { + if (Checkbox(label, v)) + return true; + else if (ItemKeyPressed(GLFW_KEY_ENTER, true)) { + v[0] ^= true; + return true; + } + else + return false; + } + + bool CheckboxFlagsEnterKeyPressed(const char* label, int* flags, int flags_value) { + if (CheckboxFlags(label, flags, flags_value)) + return true; + else if (ItemKeyPressed(GLFW_KEY_ENTER, true)) { + *flags ^= flags_value; + return true; + } + else + return false; + } + + bool CheckboxFlagsEnterKeyPressed(const char* label, unsigned int* flags, unsigned int flags_value) { + if (CheckboxFlags(label, flags, flags_value)) + return true; + else if (ItemKeyPressed(GLFW_KEY_ENTER, true)) { + *flags ^= flags_value; + return true; + } + else + return false; + } + + static bool DragFloatDisable(const char* label, float_t* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = DragFloat("", val, speed, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static bool DragIntDisable(const char* label, int32_t* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = DragInt("", val, speed, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static bool SliderFloatDisable(const char* label, float_t* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = SliderFloat("", val, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static bool SliderFloatButtonDisable(const char* label, float_t* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = SliderFloatButton("", val, step, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static bool SliderIntDisable(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = SliderInt("", val, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static bool SliderIntButtonDisable(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool enable) { + PushID(label); + DisableElementPush(enable); + bool res = SliderIntButton("", val, min, max, enable ? format : "...", flags); + DisableElementPop(enable); + PopID(); + PopItemWidth(); + return res; + } + + static const char* StartPropertyColumnDisable(const char* label, bool enable) { + PushID(label); + + float_t w = GetContentRegionAvailWidth(); + BeginTable("table", 2); + TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * column_space, 0); + + char* label_temp = str_utils_copy(label); + char* temp; + if (temp = strstr(label_temp, "##")) + *temp = 0; + TableNextColumn(); + GetContentRegionAvailSetNextItemWidth(); + DisableElementPush(enable); + Text(label_temp); + DisableElementPop(enable); + free(label_temp); + + TableNextColumn(); + GetContentRegionAvailSetNextItemWidth(); + return 0; + } + + bool ComboBox(const char* label, const char** items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + int32_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + if (BeginCombo(label, *selected_idx != -1 ? items[*selected_idx] : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((int32_t)n); + if (Selectable(items[n], *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((int32_t)n); + if (Selectable(items[n], *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ComboBox(const char* label, const char** items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + size_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + if (BeginCombo(label, *selected_idx != -1 ? items[*selected_idx] : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((void*)n); + if (Selectable(items[n], *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((void*)n); + if (Selectable(items[n], *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ComboBoxString(const char* label, std::string* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + int32_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + if (BeginCombo(label, *selected_idx != -1 ? items[*selected_idx].c_str() : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((int32_t)n); + if (Selectable(items[n].c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((int32_t)n); + if (Selectable(items[n].c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ComboBoxString(const char* label, std::string* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + size_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + if (BeginCombo(label, *selected_idx != -1 ? items[*selected_idx].c_str() : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((void*)n); + if (Selectable(items[n].c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((void*)n); + if (Selectable(items[n].c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ComboBoxConfigFile(const char* label, void* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + int32_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + data_struct_file* items_ds = (data_struct_file*)items; + if (BeginCombo(label, *selected_idx != -1 ? items_ds[*selected_idx].name.c_str() : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((int32_t)n); + if (Selectable(items_ds[n].name.c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((int32_t)n); + if (Selectable(items_ds[n].name.c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = (int32_t)n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ComboBoxConfigFile(const char* label, void* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + size_t prev_selected_idx = *selected_idx; + + if (!include_last && size < 1) { + DisableElementPush(false); + if (BeginCombo(label, "None", flags)) { + if (focus) + *focus |= true; + EndCombo(); + } + DisableElementPop(false); + return false; + } + + data_struct_file* items_ds = (data_struct_file*)items; + if (BeginCombo(label, *selected_idx != -1 ? items_ds[*selected_idx].name.c_str() : 0, flags)) { + if (include_last) + for (size_t n = 0; n <= size; n++) { + PushID((void*)n); + if (Selectable(items_ds[n].name.c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + else + for (size_t n = 0; n < size; n++) { + PushID((void*)n); + if (Selectable(items_ds[n].name.c_str(), *selected_idx == n) + || ItemKeyPressed(GLFW_KEY_ENTER, true) + || (IsItemFocused() && *selected_idx != n)) + *selected_idx = n; + PopID(); + + if (*selected_idx == n) + SetItemDefaultFocus(); + } + + if (focus) + *focus |= true; + EndCombo(); + } + return prev_selected_idx != *selected_idx; + } + + bool ColumnColorEdit3(const char* label, vec3* val, ImGuiColorEditFlags flags) { + float_t v[3]; + *(vec3*)v = *val; + StartPropertyColumn(label); + bool res = ColorEdit3("", v, flags); + EndPropertyColumn(); + if (res) + *val = *(vec3*)v; + return res; + } + + bool ColumnColorEdit4(const char* label, vec4* val, ImGuiColorEditFlags flags) { + float_t v[4]; + *(vec4*)v = *val; + StartPropertyColumn(label); + bool res = ColorEdit4("", v, flags); + EndPropertyColumn(); + if (res) + *val = *(vec4*)v; + return res; + } + + bool ColumnComboBox(const char* label, const char** items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBox("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnComboBox(const char* label, const char** items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBox("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnComboBoxString(const char* label, std::string* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBoxString("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnComboBoxString(const char* label, std::string* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBoxString("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnComboBoxConfigFile(const char* label, void* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBoxConfigFile("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnComboBoxConfigFile(const char* label, void* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus) { + StartPropertyColumn(label); + bool res = ComboBoxConfigFile("", items, size, selected_idx, flags, include_last, focus); + EndPropertyColumn(); + return res; + } + + bool ColumnDragFloat(const char* label, float_t* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { + float_t v[1]; + v[0] = *val; + StartPropertyColumn(label); + bool res = DragFloat("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnDragVec2(const char* label, vec2* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { + float_t v[2]; + *(vec2*)v = *val; + StartPropertyColumn(label); + bool res = DragFloat2("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2*)v; + return true; + } + + bool ColumnDragVec3(const char* label, vec3* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { + float_t v[3]; + *(vec3*)v = *val; + StartPropertyColumn(label); + bool res = DragFloat3("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3*)v; + return true; + } + + bool ColumnDragVec4(const char* label, vec4* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags) { + float_t v[4]; + *(vec4*)v = *val; + StartPropertyColumn(label); + bool res = DragFloat4("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4*)v; + return true; + } + + bool ColumnDragInt(const char* label, int32_t* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + int32_t v[1]; + v[0] = *val; + StartPropertyColumn(label); + bool res = DragInt("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnDragVec2I(const char* label, vec2i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + int32_t v[2]; + *(vec2i*)v = *val; + StartPropertyColumn(label); + bool res = DragInt2("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2i*)v; + return true; + } + + bool ColumnDragVec3I(const char* label, vec3i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + int32_t v[3]; + *(vec3i*)v = *val; + StartPropertyColumn(label); + bool res = DragInt3("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3i*)v; + return true; + } + + bool ColumnDragVec4I(const char* label, vec4i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + int32_t v[4]; + *(vec4i*)v = *val; + StartPropertyColumn(label); + bool res = DragInt4("", v, speed, min, max, format, flags); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4i*)v; + return true; + } + + bool ColumnInputText(const char* label, char* buf, size_t buf_size, + ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) { + StartPropertyColumn(label); + bool res = InputText("", buf, buf_size, flags, callback, user_data); + EndPropertyColumn(); + return res; + } + + bool ColumnSliderFloat(const char* label, float_t* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { + float_t v[1]; + v[0] = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) + res = SliderFloatButton("", v, step, min, max, format, flags); + else { + res = SliderFloat("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnSliderVec2(const char* label, vec2* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { + float_t v[2]; + *(vec2*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + res |= SliderFloatButton("##X", &v[0], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##Y", &v[1], step, min, max, format, flags); + PopItemWidth(); + EndGroup(); + } + else { + res = SliderFloat2("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2*)v; + return true; + } + + bool ColumnSliderVec3(const char* label, vec3* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { + float_t v[3]; + *(vec3*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + res |= SliderFloatButton("##X", &v[0], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##Y", &v[1], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##Z", &v[2], step, min, max, format, flags); + PopItemWidth(); + EndGroup(); + } + else { + res = SliderFloat3("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3*)v; + return true; + } + + bool ColumnSliderVec4(const char* label, vec4* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button) { + float_t v[4]; + *(vec4*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderFloatButton("##X", &v[0], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##Y", &v[1], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##Z", &v[2], step, min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatButton("##W", &v[3], step, min, max, format, flags); + PopItemWidth(); + EndGroup(); + } + else { + res = SliderFloat4("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4*)v; + return true; + } + + bool ColumnSliderInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { + int32_t v[1]; + v[0] = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) + res = SliderIntButton("", v, min, max, format, flags); + else { + res = SliderInt("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnSliderVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { + int32_t v[2]; + *(vec2i*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderIntButton("##X", &v[0], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##Y", &v[1], min, max, format, flags); + PopItemWidth(); + + EndGroup(); + } + else { + res = SliderInt2("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2i*)v; + return true; + } + + bool ColumnSliderVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { + int32_t v[3]; + *(vec3i*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderIntButton("##X", &v[0], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##Y", &v[1], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##Z", &v[2], min, max, format, flags); + PopItemWidth(); + EndGroup(); + } + else { + res = SliderInt3("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3i*)v; + return true; + } + + bool ColumnSliderVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button) { + int32_t v[4]; + *(vec4i*)v = *val; + StartPropertyColumn(label); + bool res = false; + ResetIsItemAccum(); + if (button) { + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderIntButton("##X", &v[0], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##Y", &v[1], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##Z", &v[2], min, max, format, flags); + PopItemWidth(); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntButton("##W", &v[3], min, max, format, flags); + PopItemWidth(); + EndGroup(); + } + else { + res = SliderInt4("", v, min, max, format, flags); + GetIsItemAccum(); + } + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4i*)v; + return true; + } + + bool ColumnSliderLogInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + char buf[0x1000]; + int32_t v[1]; + if (min < 1) + min = 1; + if (min > max) + max = min; + flags |= ImGuiSliderFlags_NoInput; + + v[0] = (int32_t)roundf(log2f((float_t)*val)); + StartPropertyColumn(label); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(1, CalcItemWidth()); + min = (int32_t)roundf(log2f((float_t)min)); + max = (int32_t)roundf(log2f((float_t)max)); + sprintf_s(buf, sizeof(buf), format, 1 << v[0]); + res |= SliderIntDisable("##X", &v[0], min, max, buf, flags, true); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = 1 << clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnSliderLogVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + char buf[0x1000]; + int32_t v[2]; + if (min < 1) + min = 1; + if (min > max) + max = min; + flags |= ImGuiSliderFlags_NoInput; + + v[0] = (int32_t)roundf(log2f((float_t)val->x)); + v[1] = (int32_t)roundf(log2f((float_t)val->y)); + StartPropertyColumn(label); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + min = (int32_t)roundf(log2f((float_t)min)); + max = (int32_t)roundf(log2f((float_t)max)); + sprintf_s(buf, sizeof(buf), format, 1 << v[0]); + res |= SliderIntDisable("##X", &v[0], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[1]); + res |= SliderIntDisable("##Y", &v[1], min, max, buf, flags, true); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = 1 << clamp(v[0], min, max); + v[1] = 1 << clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2i*)v; + return true; + } + + bool ColumnSliderLogVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + char buf[0x1000]; + int32_t v[3]; + if (min < 1) + min = 1; + if (min > max) + max = min; + flags |= ImGuiSliderFlags_NoInput; + + v[0] = (int32_t)roundf(log2f((float_t)val->x)); + v[1] = (int32_t)roundf(log2f((float_t)val->y)); + v[2] = (int32_t)roundf(log2f((float_t)val->z)); + StartPropertyColumn(label); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + min = (int32_t)roundf(log2f((float_t)min)); + max = (int32_t)roundf(log2f((float_t)max)); + sprintf_s(buf, sizeof(buf), format, 1 << v[0]); + res |= SliderIntDisable("##X", &v[0], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[1]); + res |= SliderIntDisable("##Y", &v[1], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[2]); + res |= SliderIntDisable("##Z", &v[2], min, max, buf, flags, true); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = 1 << clamp(v[0], min, max); + v[1] = 1 << clamp(v[1], min, max); + v[2] = 1 << clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3i*)v; + return true; + } + + bool ColumnSliderLogVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags) { + char buf[0x1000]; + int32_t v[4]; + if (min < 1) + min = 1; + if (min > max) + max = min; + flags |= ImGuiSliderFlags_NoInput; + + v[0] = (int32_t)roundf(log2f((float_t)val->x)); + v[1] = (int32_t)roundf(log2f((float_t)val->y)); + v[2] = (int32_t)roundf(log2f((float_t)val->z)); + v[3] = (int32_t)roundf(log2f((float_t)val->w)); + StartPropertyColumn(label); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + min = (int32_t)roundf(log2f((float_t)min)); + max = (int32_t)roundf(log2f((float_t)max)); + sprintf_s(buf, sizeof(buf), format, 1 << v[0]); + res |= SliderIntDisable("##X", &v[0], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[1]); + res |= SliderIntDisable("##Y", &v[1], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[2]); + res |= SliderIntDisable("##Z", &v[2], min, max, buf, flags, true); + SameLine(0.0f, style.ItemInnerSpacing.x); + sprintf_s(buf, sizeof(buf), format, 1 << v[3]); + res |= SliderIntDisable("##W", &v[3], min, max, buf, flags, true); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = 1 << clamp(v[0], min, max); + v[1] = 1 << clamp(v[1], min, max); + v[2] = 1 << clamp(v[2], min, max); + v[3] = 1 << clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4i*)v; + return true; + } + + bool ColumnInputScalar(const char* label, ImGuiDataType data_type, void* p_data, + const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags) { + StartPropertyColumn(label); + bool res = InputScalar("", data_type, p_data, p_step, p_step_fast, format, flags); + EndPropertyColumn(); + return res; + } + + bool ColumnDragFloat(const char* label, float_t* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[1]; + v[0] = *val; + StartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(1, CalcItemWidth()); + res |= DragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnDragVec2(const char* label, vec2* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[2]; + *(vec2*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + res |= DragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2*)v; + return true; + } + + bool ColumnDragVec3(const char* label, vec3* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[3]; + *(vec3*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + res |= DragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3*)v; + return true; + } + + bool ColumnDragVec4(const char* label, vec4* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[4]; + *(vec4*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= DragFloatDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragFloatDisable("##W", &v[3], speed, min, max, format, flags, bit_flag & 0x08 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4*)v; + return true; + } + + bool ColumnDragInt(const char* label, int32_t* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[1]; + v[0] = *val; + StartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(1, CalcItemWidth()); + res |= DragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnDragVec2I(const char* label, vec2i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[2]; + *(vec2i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + res |= DragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2i*)v; + return true; + } + + bool ColumnDragVec3I(const char* label, vec3i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[3]; + *(vec3i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + res |= DragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3i*)v; + return true; + } + + bool ColumnDragVec4I(const char* label, vec4i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[4]; + *(vec4i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= DragIntDisable("##X", &v[0], speed, min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##Y", &v[1], speed, min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##Z", &v[2], speed, min, max, format, flags, bit_flag & 0x04 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= DragIntDisable("##W", &v[3], speed, min, max, format, flags, bit_flag & 0x08 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4i*)v; + return true; + } + + bool ColumnSliderFloat(const char* label, float_t* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[1]; + v[0] = *val; + StartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(1, CalcItemWidth()); + res |= SliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnSliderVec2(const char* label, vec2* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[2]; + *(vec2*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + res |= SliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2*)v; + return true; + } + + bool ColumnSliderVec3(const char* label, vec3* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[3]; + *(vec3*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + res |= SliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3*)v; + return true; + } + + bool ColumnSliderVec4(const char* label, vec4* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + float_t v[4]; + *(vec4*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderFloatDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderFloatDisable("##W", &v[3], min, max, format, flags, bit_flag & 0x08 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4*)v; + return true; + } + + bool ColumnSliderInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[1]; + v[0] = *val; + StartPropertyColumnDisable(label, bit_flag & 0x01 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(1, CalcItemWidth()); + res |= SliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + if (v[0] == *val) + return false; + + *val = v[0]; + return true; + } + + bool ColumnSliderVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[2]; + *(vec2i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x03 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(2, CalcItemWidth()); + res |= SliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + if (v[0] == val->x && v[1] == val->y) + return false; + + *val = *(vec2i*)v; + return true; + } + + bool ColumnSliderVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[3]; + *(vec3i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x07 ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(3, CalcItemWidth()); + res |= SliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z) + return false; + + *val = *(vec3i*)v; + return true; + } + + bool ColumnSliderVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag) { + int32_t v[4]; + *(vec4i*)v = *val; + StartPropertyColumnDisable(label, bit_flag & 0x0F ? true : false); + bool res = false; + ImGuiStyle& style = GetStyle(); + BeginGroup(); + PushMultiItemsWidths(4, CalcItemWidth()); + res |= SliderIntDisable("##X", &v[0], min, max, format, flags, bit_flag & 0x01 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##Y", &v[1], min, max, format, flags, bit_flag & 0x02 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##Z", &v[2], min, max, format, flags, bit_flag & 0x04 ? true : false); + SameLine(0.0f, style.ItemInnerSpacing.x); + res |= SliderIntDisable("##W", &v[3], min, max, format, flags, bit_flag & 0x08 ? true : false); + EndGroup(); + EndPropertyColumn(); + if (!res) + return false; + + v[0] = clamp(v[0], min, max); + v[1] = clamp(v[1], min, max); + v[2] = clamp(v[2], min, max); + v[3] = clamp(v[3], min, max); + if (v[0] == val->x && v[1] == val->y && v[2] == val->z && v[3] == val->w) + return false; + + *val = *(vec4i*)v; + return true; + } +} \ No newline at end of file diff --git a/src/CLOUD/classes/imgui_helper.h b/src/CLOUD/classes/imgui_helper.h deleted file mode 100644 index 1f8ab612..00000000 --- a/src/CLOUD/classes/imgui_helper.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include -#include "../../KKdLib/default.hpp" -#include "../../KKdLib/vec.hpp" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include -#include -#include -#include - -extern const float_t imgui_alpha_disabled_scale; - -extern bool imgui_is_item_active; -extern bool imgui_is_item_focused; -extern bool imgui_is_item_visible; -extern bool imgui_is_item_edited; -extern bool imgui_is_item_activated; -extern bool imgui_is_item_deactivated; -extern bool imgui_is_item_deactivated_after_edit; -extern bool imgui_is_item_toggled_open; - -extern bool imguiItemKeyDown(int32_t key); -extern bool imguiItemKeyPressed(int32_t key, bool repeat); -extern bool imguiItemKeyReleased(int32_t key); -extern float_t imguiGetColumnSpace(); -extern void imguiSetColumnSpace(float_t val); -extern void imguiSetDefaultColumnSpace(); -extern void imguiDisableElementPush(bool enable); -extern void imguiDisableElementPop(bool enable); -extern float_t imguiGetContentRegionAvailWidth(); -extern float_t imguiGetContentRegionAvailHeight(); -extern void imguiGetContentRegionAvailSetNextItemWidth(); - -extern void imguiStartPropertyColumn(const char* label); -extern void imguiEndPropertyColumn(); - -bool igSliderFloatButton(const char* label, float_t* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags); -bool igSliderIntButton(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); - -extern bool imguiButton(const char* label, const ImVec2& size = ImVec2(0, 0)); -extern bool imguiButtonEx(const char* label, const ImVec2& size = ImVec2(0, 0), ImGuiButtonFlags flags = 0); -extern bool imguiCheckbox(const char* label, bool* v); -extern bool imguiCheckboxFlags(const char* label, int* flags, int flags_value); -extern bool imguiCheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); -extern bool imguiComboBox(const char* label, const char** items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiComboBox(const char* label, const char** items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiComboBoxString(const char* label, std::string* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiComboBoxString(const char* label, std::string* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiComboBoxConfigFile(const char* label, void* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiComboBoxConfigFile(const char* label, void* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnColorEdit3(const char* label, vec3* val, ImGuiColorEditFlags flags); -extern bool imguiColumnColorEdit4(const char* label, vec4* val, ImGuiColorEditFlags flags); -extern bool imguiColumnComboBox(const char* label, const char** items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnComboBox(const char* label, const char** items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnComboBoxString(const char* label, std::string* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnComboBoxString(const char* label, std::string* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnComboBoxConfigFile(const char* label, void* items, const size_t size, - int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnComboBoxConfigFile(const char* label, void* items, const size_t size, - size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); -extern bool imguiColumnDragFloat(const char* label, float_t* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec2(const char* label, vec2* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec3(const char* label, vec3* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec4(const char* label, vec4* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragInt(const char* label, int32_t* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec2I(const char* label, vec2i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec3I(const char* label, vec3i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnDragVec4I(const char* label, vec4i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnInputText(const char* label, char* buf, size_t buf_size, - ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data); -extern bool imguiColumnSliderFloat(const char* label, float_t* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec2(const char* label, vec2* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec3(const char* label, vec3* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec4(const char* label, vec4* val, float_t step, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderInt(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec2I(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec3I(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderVec4I(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button); -extern bool imguiColumnSliderLogInt(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnSliderLogVec2I(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnSliderLogVec3I(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnSliderLogVec4I(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); -extern bool imguiColumnInputScalar(const char* label, ImGuiDataType data_type, void* p_data, - const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags); -extern bool imguiColumnDragFloatFlag(const char* label, float_t* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec2Flag(const char* label, vec2* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec3Flag(const char* label, vec3* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec4Flag(const char* label, vec4* val, float_t speed, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragIntFlag(const char* label, int32_t* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec2IFlag(const char* label, vec2i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec3IFlag(const char* label, vec3i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnDragVec4IFlag(const char* label, vec4i* val, float_t speed, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderFloatFlag(const char* label, float_t* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec2Flag(const char* label, vec2* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec3Flag(const char* label, vec3* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec4Flag(const char* label, vec4* val, - float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderIntFlag(const char* label, int32_t* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec2IFlag(const char* label, vec2i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec3IFlag(const char* label, vec3i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); -extern bool imguiColumnSliderVec4IFlag(const char* label, vec4i* val, - int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); diff --git a/src/CLOUD/classes/imgui_helper.hpp b/src/CLOUD/classes/imgui_helper.hpp new file mode 100644 index 00000000..a71c3a09 --- /dev/null +++ b/src/CLOUD/classes/imgui_helper.hpp @@ -0,0 +1,156 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include +#include "../../KKdLib/default.hpp" +#include "../../KKdLib/vec.hpp" +#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS +#include +#include +#include +#include + +namespace ImGui { + extern const float_t AlphaDisabledScale; + + extern bool IsItemActiveAccum; + extern bool IsItemFocusedAccum; + extern bool IsItemVisibleAccum; + extern bool IsItemEditedAccum; + extern bool IsItemActivatedAccum; + extern bool IsItemDeactivatedAccum; + extern bool IsItemDeactivatedAfterEditAccum; + extern bool IsItemToggledOpenAccum; + + extern bool ItemKeyDown(int32_t key); + extern bool ItemKeyPressed(int32_t key, bool repeat); + extern bool ItemKeyReleased(int32_t key); + extern float_t GetColumnSpace(); + extern void SetColumnSpace(float_t val); + extern void SetDefaultColumnSpace(); + extern void DisableElementPush(bool enable); + extern void DisableElementPop(bool enable); + extern float_t GetContentRegionAvailWidth(); + extern float_t GetContentRegionAvailHeight(); + extern void GetContentRegionAvailSetNextItemWidth(); + + extern void StartPropertyColumn(const char* label); + extern void EndPropertyColumn(); + + bool SliderFloatButton(const char* label, float_t* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags); + bool SliderIntButton(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + + extern bool ButtonEnterKeyPressed(const char* label, const ImVec2& size = ImVec2(0, 0)); + extern bool ButtonExEnterKeyPressed(const char* label, const ImVec2& size = ImVec2(0, 0), ImGuiButtonFlags flags = 0); + extern bool CheckboxEnterKeyPressed(const char* label, bool* v); + extern bool CheckboxFlagsEnterKeyPressed(const char* label, int* flags, int flags_value); + extern bool CheckboxFlagsEnterKeyPressed(const char* label, unsigned int* flags, unsigned int flags_value); + extern bool ComboBox(const char* label, const char** items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ComboBox(const char* label, const char** items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ComboBoxString(const char* label, std::string* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ComboBoxString(const char* label, std::string* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ComboBoxConfigFile(const char* label, void* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ComboBoxConfigFile(const char* label, void* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnColorEdit3(const char* label, vec3* val, ImGuiColorEditFlags flags); + extern bool ColumnColorEdit4(const char* label, vec4* val, ImGuiColorEditFlags flags); + extern bool ColumnComboBox(const char* label, const char** items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnComboBox(const char* label, const char** items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnComboBoxString(const char* label, std::string* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnComboBoxString(const char* label, std::string* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnComboBoxConfigFile(const char* label, void* items, const size_t size, + int32_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnComboBoxConfigFile(const char* label, void* items, const size_t size, + size_t* selected_idx, ImGuiComboFlags flags, bool include_last, bool* focus); + extern bool ColumnDragFloat(const char* label, float_t* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec2(const char* label, vec2* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec3(const char* label, vec3* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec4(const char* label, vec4* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragInt(const char* label, int32_t* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec2I(const char* label, vec2i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec3I(const char* label, vec3i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnDragVec4I(const char* label, vec4i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnInputText(const char* label, char* buf, size_t buf_size, + ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data); + extern bool ColumnSliderFloat(const char* label, float_t* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec2(const char* label, vec2* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec3(const char* label, vec3* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec4(const char* label, vec4* val, float_t step, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, bool button = true); + extern bool ColumnSliderLogInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnSliderLogVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnSliderLogVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnSliderLogVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags); + extern bool ColumnInputScalar(const char* label, ImGuiDataType data_type, void* p_data, + const void* p_step, const void* p_step_fast, const char* format, ImGuiInputTextFlags flags); + extern bool ColumnDragFloat(const char* label, float_t* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec2(const char* label, vec2* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec3(const char* label, vec3* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec4(const char* label, vec4* val, float_t speed, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragInt(const char* label, int32_t* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec2I(const char* label, vec2i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec3I(const char* label, vec3i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnDragVec4I(const char* label, vec4i* val, float_t speed, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderFloat(const char* label, float_t* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec2(const char* label, vec2* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec3(const char* label, vec3* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec4(const char* label, vec4* val, + float_t min, float_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderInt(const char* label, int32_t* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec2I(const char* label, vec2i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec3I(const char* label, vec3i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); + extern bool ColumnSliderVec4I(const char* label, vec4i* val, + int32_t min, int32_t max, const char* format, ImGuiSliderFlags flags, int32_t bit_flag); +} \ No newline at end of file diff --git a/src/CLOUD/classes/information.c b/src/CLOUD/classes/information.cpp similarity index 92% rename from src/CLOUD/classes/information.c rename to src/CLOUD/classes/information.cpp index cf984970..11175305 100644 --- a/src/CLOUD/classes/information.c +++ b/src/CLOUD/classes/information.cpp @@ -3,9 +3,9 @@ GitHub/GitLab: korenkonder */ -#include "information.h" -#include "information/frame_speed.h" -#include "information/task.h" +#include "information.hpp" +#include "information/frame_speed.hpp" +#include "information/task.hpp" classes_data information_classes[] = { { diff --git a/src/CLOUD/classes/information.h b/src/CLOUD/classes/information.hpp similarity index 88% rename from src/CLOUD/classes/information.h rename to src/CLOUD/classes/information.hpp index 8b2ca80b..2952a86c 100644 --- a/src/CLOUD/classes/information.h +++ b/src/CLOUD/classes/information.hpp @@ -5,7 +5,7 @@ #pragma once -#include "../classes.h" +#include "../classes.hpp" enum information_classes_enum { INFORMATION_FRAME_SPEED, diff --git a/src/CLOUD/classes/information/frame_speed.c b/src/CLOUD/classes/information/frame_speed.cpp similarity index 86% rename from src/CLOUD/classes/information/frame_speed.c rename to src/CLOUD/classes/information/frame_speed.cpp index dcb1c3dd..3f78878b 100644 --- a/src/CLOUD/classes/information/frame_speed.c +++ b/src/CLOUD/classes/information/frame_speed.cpp @@ -3,8 +3,8 @@ GitHub/GitLab: korenkonder */ -#include "frame_speed.h" -#include "../imgui_helper.h" +#include "frame_speed.hpp" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; @@ -44,8 +44,8 @@ void information_frame_speed_imgui(class_data* data) { return; } - imguiGetContentRegionAvailSetNextItemWidth(); - imguiColumnSliderFloat("frame speed", &frame_speed, 0.01f, 0.0f, 3.0f, "%.2f", 0, true); + ImGui::GetContentRegionAvailSetNextItemWidth(); + ImGui::ColumnSliderFloat("frame speed", &frame_speed, 0.01f, 0.0f, 3.0f, "%.2f", 0, true); data->imgui_focus |= ImGui::IsWindowFocused(); ImGui::End(); diff --git a/src/CLOUD/classes/information/frame_speed.h b/src/CLOUD/classes/information/frame_speed.hpp similarity index 91% rename from src/CLOUD/classes/information/frame_speed.h rename to src/CLOUD/classes/information/frame_speed.hpp index 51b98c76..c2728ea1 100644 --- a/src/CLOUD/classes/information/frame_speed.h +++ b/src/CLOUD/classes/information/frame_speed.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool information_frame_speed_init(class_data* data, render_context* rctx); extern void information_frame_speed_imgui(class_data* data); diff --git a/src/CLOUD/classes/information/task.c b/src/CLOUD/classes/information/task.cpp similarity index 98% rename from src/CLOUD/classes/information/task.c rename to src/CLOUD/classes/information/task.cpp index 1b40c4ba..cf96ed4b 100644 --- a/src/CLOUD/classes/information/task.c +++ b/src/CLOUD/classes/information/task.cpp @@ -3,11 +3,11 @@ GitHub/GitLab: korenkonder */ -#include "task.h" +#include "task.hpp" #include "../../../KKdLib/sort.hpp" #include "../../../KKdLib/str_utils.hpp" #include "../../../CRE/task.hpp" -#include "../imgui_helper.h" +#include "../imgui_helper.hpp" extern int32_t width; extern int32_t height; diff --git a/src/CLOUD/classes/information/task.h b/src/CLOUD/classes/information/task.hpp similarity index 91% rename from src/CLOUD/classes/information/task.h rename to src/CLOUD/classes/information/task.hpp index 3063ddf4..b11c343a 100644 --- a/src/CLOUD/classes/information/task.h +++ b/src/CLOUD/classes/information/task.hpp @@ -6,7 +6,7 @@ #pragma once #include "../../../KKdLib/default.hpp" -#include "../../classes.h" +#include "../../classes.hpp" extern bool information_task_init(class_data* data, render_context* rctx); extern void information_task_imgui(class_data* data); diff --git a/src/CLOUD/elf.h b/src/CLOUD/elf.h deleted file mode 100644 index 79d3b974..00000000 --- a/src/CLOUD/elf.h +++ /dev/null @@ -1,3147 +0,0 @@ -/* -From musl include/elf.h - -Copyright © 2005-2014 Rich Felker, et al. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef _ELF_H -#define _ELF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef uint16_t Elf32_Half; -typedef uint16_t Elf64_Half; - -typedef uint32_t Elf32_Word; -typedef int32_t Elf32_Sword; -typedef uint32_t Elf64_Word; -typedef int32_t Elf64_Sword; - -typedef uint64_t Elf32_Xword; -typedef int64_t Elf32_Sxword; -typedef uint64_t Elf64_Xword; -typedef int64_t Elf64_Sxword; - -typedef uint32_t Elf32_Addr; -typedef uint64_t Elf64_Addr; - -typedef uint32_t Elf32_Off; -typedef uint64_t Elf64_Off; - -typedef uint16_t Elf32_Section; -typedef uint16_t Elf64_Section; - -typedef Elf32_Half Elf32_Versym; -typedef Elf64_Half Elf64_Versym; - -#define EI_NIDENT (16) - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; -} Elf32_Ehdr; - -typedef struct { - unsigned char e_ident[EI_NIDENT]; - Elf64_Half e_type; - Elf64_Half e_machine; - Elf64_Word e_version; - Elf64_Addr e_entry; - Elf64_Off e_phoff; - Elf64_Off e_shoff; - Elf64_Word e_flags; - Elf64_Half e_ehsize; - Elf64_Half e_phentsize; - Elf64_Half e_phnum; - Elf64_Half e_shentsize; - Elf64_Half e_shnum; - Elf64_Half e_shstrndx; -} Elf64_Ehdr; - -#define EI_MAG0 0 -#define ELFMAG0 0x7f - -#define EI_MAG1 1 -#define ELFMAG1 'E' - -#define EI_MAG2 2 -#define ELFMAG2 'L' - -#define EI_MAG3 3 -#define ELFMAG3 'F' - - -#define ELFMAG "\177ELF" -#define SELFMAG 4 - -#define EI_CLASS 4 -#define ELFCLASSNONE 0 -#define ELFCLASS32 1 -#define ELFCLASS64 2 -#define ELFCLASSNUM 3 - -#define EI_DATA 5 -#define ELFDATANONE 0 -#define ELFDATA2LSB 1 -#define ELFDATA2MSB 2 -#define ELFDATANUM 3 - -#define EI_VERSION 6 - - -#define EI_OSABI 7 -#define ELFOSABI_NONE 0 -#define ELFOSABI_SYSV 0 -#define ELFOSABI_HPUX 1 -#define ELFOSABI_NETBSD 2 -#define ELFOSABI_LINUX 3 -#define ELFOSABI_GNU 3 -#define ELFOSABI_SOLARIS 6 -#define ELFOSABI_AIX 7 -#define ELFOSABI_IRIX 8 -#define ELFOSABI_FREEBSD 9 -#define ELFOSABI_TRU64 10 -#define ELFOSABI_MODESTO 11 -#define ELFOSABI_OPENBSD 12 -#define ELFOSABI_ARM 97 -#define ELFOSABI_STANDALONE 255 - -#define EI_ABIVERSION 8 - -#define EI_PAD 9 - - - -#define ET_NONE 0 -#define ET_REL 1 -#define ET_EXEC 2 -#define ET_DYN 3 -#define ET_CORE 4 -#define ET_NUM 5 -#define ET_LOOS 0xfe00 -#define ET_HIOS 0xfeff -#define ET_LOPROC 0xff00 -#define ET_HIPROC 0xffff - - - -#define EM_NONE 0 -#define EM_M32 1 -#define EM_SPARC 2 -#define EM_386 3 -#define EM_68K 4 -#define EM_88K 5 -#define EM_860 7 -#define EM_MIPS 8 -#define EM_S370 9 -#define EM_MIPS_RS3_LE 10 - -#define EM_PARISC 15 -#define EM_VPP500 17 -#define EM_SPARC32PLUS 18 -#define EM_960 19 -#define EM_PPC 20 -#define EM_PPC64 21 -#define EM_S390 22 - -#define EM_V800 36 -#define EM_FR20 37 -#define EM_RH32 38 -#define EM_RCE 39 -#define EM_ARM 40 -#define EM_FAKE_ALPHA 41 -#define EM_SH 42 -#define EM_SPARCV9 43 -#define EM_TRICORE 44 -#define EM_ARC 45 -#define EM_H8_300 46 -#define EM_H8_300H 47 -#define EM_H8S 48 -#define EM_H8_500 49 -#define EM_IA_64 50 -#define EM_MIPS_X 51 -#define EM_COLDFIRE 52 -#define EM_68HC12 53 -#define EM_MMA 54 -#define EM_PCP 55 -#define EM_NCPU 56 -#define EM_NDR1 57 -#define EM_STARCORE 58 -#define EM_ME16 59 -#define EM_ST100 60 -#define EM_TINYJ 61 -#define EM_X86_64 62 -#define EM_PDSP 63 - -#define EM_FX66 66 -#define EM_ST9PLUS 67 -#define EM_ST7 68 -#define EM_68HC16 69 -#define EM_68HC11 70 -#define EM_68HC08 71 -#define EM_68HC05 72 -#define EM_SVX 73 -#define EM_ST19 74 -#define EM_VAX 75 -#define EM_CRIS 76 -#define EM_JAVELIN 77 -#define EM_FIREPATH 78 -#define EM_ZSP 79 -#define EM_MMIX 80 -#define EM_HUANY 81 -#define EM_PRISM 82 -#define EM_AVR 83 -#define EM_FR30 84 -#define EM_D10V 85 -#define EM_D30V 86 -#define EM_V850 87 -#define EM_M32R 88 -#define EM_MN10300 89 -#define EM_MN10200 90 -#define EM_PJ 91 -#define EM_OR1K 92 -#define EM_OPENRISC 92 -#define EM_ARC_A5 93 -#define EM_ARC_COMPACT 93 -#define EM_XTENSA 94 -#define EM_VIDEOCORE 95 -#define EM_TMM_GPP 96 -#define EM_NS32K 97 -#define EM_TPC 98 -#define EM_SNP1K 99 -#define EM_ST200 100 -#define EM_IP2K 101 -#define EM_MAX 102 -#define EM_CR 103 -#define EM_F2MC16 104 -#define EM_MSP430 105 -#define EM_BLACKFIN 106 -#define EM_SE_C33 107 -#define EM_SEP 108 -#define EM_ARCA 109 -#define EM_UNICORE 110 -#define EM_EXCESS 111 -#define EM_DXP 112 -#define EM_ALTERA_NIOS2 113 -#define EM_CRX 114 -#define EM_XGATE 115 -#define EM_C166 116 -#define EM_M16C 117 -#define EM_DSPIC30F 118 -#define EM_CE 119 -#define EM_M32C 120 -#define EM_TSK3000 131 -#define EM_RS08 132 -#define EM_SHARC 133 -#define EM_ECOG2 134 -#define EM_SCORE7 135 -#define EM_DSP24 136 -#define EM_VIDEOCORE3 137 -#define EM_LATTICEMICO32 138 -#define EM_SE_C17 139 -#define EM_TI_C6000 140 -#define EM_TI_C2000 141 -#define EM_TI_C5500 142 -#define EM_TI_ARP32 143 -#define EM_TI_PRU 144 -#define EM_MMDSP_PLUS 160 -#define EM_CYPRESS_M8C 161 -#define EM_R32C 162 -#define EM_TRIMEDIA 163 -#define EM_QDSP6 164 -#define EM_8051 165 -#define EM_STXP7X 166 -#define EM_NDS32 167 -#define EM_ECOG1X 168 -#define EM_MAXQ30 169 -#define EM_XIMO16 170 -#define EM_MANIK 171 -#define EM_CRAYNV2 172 -#define EM_RX 173 -#define EM_METAG 174 -#define EM_MCST_ELBRUS 175 -#define EM_ECOG16 176 -#define EM_CR16 177 -#define EM_ETPU 178 -#define EM_SLE9X 179 -#define EM_L10M 180 -#define EM_K10M 181 -#define EM_AARCH64 183 -#define EM_AVR32 185 -#define EM_STM8 186 -#define EM_TILE64 187 -#define EM_TILEPRO 188 -#define EM_MICROBLAZE 189 -#define EM_CUDA 190 -#define EM_TILEGX 191 -#define EM_CLOUDSHIELD 192 -#define EM_COREA_1ST 193 -#define EM_COREA_2ND 194 -#define EM_ARC_COMPACT2 195 -#define EM_OPEN8 196 -#define EM_RL78 197 -#define EM_VIDEOCORE5 198 -#define EM_78KOR 199 -#define EM_56800EX 200 -#define EM_BA1 201 -#define EM_BA2 202 -#define EM_XCORE 203 -#define EM_MCHP_PIC 204 -#define EM_KM32 210 -#define EM_KMX32 211 -#define EM_EMX16 212 -#define EM_EMX8 213 -#define EM_KVARC 214 -#define EM_CDP 215 -#define EM_COGE 216 -#define EM_COOL 217 -#define EM_NORC 218 -#define EM_CSR_KALIMBA 219 -#define EM_Z80 220 -#define EM_VISIUM 221 -#define EM_FT32 222 -#define EM_MOXIE 223 -#define EM_AMDGPU 224 -#define EM_RISCV 243 -#define EM_BPF 247 -#define EM_NUM 248 - -#define EM_ALPHA 0x9026 - -#define EV_NONE 0 -#define EV_CURRENT 1 -#define EV_NUM 2 - -typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; -} Elf32_Shdr; - -typedef struct { - Elf64_Word sh_name; - Elf64_Word sh_type; - Elf64_Xword sh_flags; - Elf64_Addr sh_addr; - Elf64_Off sh_offset; - Elf64_Xword sh_size; - Elf64_Word sh_link; - Elf64_Word sh_info; - Elf64_Xword sh_addralign; - Elf64_Xword sh_entsize; -} Elf64_Shdr; - - - -#define SHN_UNDEF 0 -#define SHN_LORESERVE 0xff00 -#define SHN_LOPROC 0xff00 -#define SHN_BEFORE 0xff00 - -#define SHN_AFTER 0xff01 - -#define SHN_HIPROC 0xff1f -#define SHN_LOOS 0xff20 -#define SHN_HIOS 0xff3f -#define SHN_ABS 0xfff1 -#define SHN_COMMON 0xfff2 -#define SHN_XINDEX 0xffff -#define SHN_HIRESERVE 0xffff - - - -#define SHT_NULL 0 -#define SHT_PROGBITS 1 -#define SHT_SYMTAB 2 -#define SHT_STRTAB 3 -#define SHT_RELA 4 -#define SHT_HASH 5 -#define SHT_DYNAMIC 6 -#define SHT_NOTE 7 -#define SHT_NOBITS 8 -#define SHT_REL 9 -#define SHT_SHLIB 10 -#define SHT_DYNSYM 11 -#define SHT_INIT_ARRAY 14 -#define SHT_FINI_ARRAY 15 -#define SHT_PREINIT_ARRAY 16 -#define SHT_GROUP 17 -#define SHT_SYMTAB_SHNDX 18 -#define SHT_NUM 19 -#define SHT_LOOS 0x60000000 -#define SHT_GNU_ATTRIBUTES 0x6ffffff5 -#define SHT_GNU_HASH 0x6ffffff6 -#define SHT_GNU_LIBLIST 0x6ffffff7 -#define SHT_CHECKSUM 0x6ffffff8 -#define SHT_LOSUNW 0x6ffffffa -#define SHT_SUNW_move 0x6ffffffa -#define SHT_SUNW_COMDAT 0x6ffffffb -#define SHT_SUNW_syminfo 0x6ffffffc -#define SHT_GNU_verdef 0x6ffffffd -#define SHT_GNU_verneed 0x6ffffffe -#define SHT_GNU_versym 0x6fffffff -#define SHT_HISUNW 0x6fffffff -#define SHT_HIOS 0x6fffffff -#define SHT_LOPROC 0x70000000 -#define SHT_HIPROC 0x7fffffff -#define SHT_LOUSER 0x80000000 -#define SHT_HIUSER 0x8fffffff - -#define SHF_WRITE (1 << 0) -#define SHF_ALLOC (1 << 1) -#define SHF_EXECINSTR (1 << 2) -#define SHF_MERGE (1 << 4) -#define SHF_STRINGS (1 << 5) -#define SHF_INFO_LINK (1 << 6) -#define SHF_LINK_ORDER (1 << 7) -#define SHF_OS_NONCONFORMING (1 << 8) - -#define SHF_GROUP (1 << 9) -#define SHF_TLS (1 << 10) -#define SHF_COMPRESSED (1 << 11) -#define SHF_MASKOS 0x0ff00000 -#define SHF_MASKPROC 0xf0000000 -#define SHF_ORDERED (1 << 30) -#define SHF_EXCLUDE (1U << 31) - -typedef struct { - Elf32_Word ch_type; - Elf32_Word ch_size; - Elf32_Word ch_addralign; -} Elf32_Chdr; - -typedef struct { - Elf64_Word ch_type; - Elf64_Word ch_reserved; - Elf64_Xword ch_size; - Elf64_Xword ch_addralign; -} Elf64_Chdr; - -#define ELFCOMPRESS_ZLIB 1 -#define ELFCOMPRESS_LOOS 0x60000000 -#define ELFCOMPRESS_HIOS 0x6fffffff -#define ELFCOMPRESS_LOPROC 0x70000000 -#define ELFCOMPRESS_HIPROC 0x7fffffff - - -#define GRP_COMDAT 0x1 - -typedef struct { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; - unsigned char st_info; - unsigned char st_other; - Elf32_Section st_shndx; -} Elf32_Sym; - -typedef struct { - Elf64_Word st_name; - unsigned char st_info; - unsigned char st_other; - Elf64_Section st_shndx; - Elf64_Addr st_value; - Elf64_Xword st_size; -} Elf64_Sym; - -typedef struct { - Elf32_Half si_boundto; - Elf32_Half si_flags; -} Elf32_Syminfo; - -typedef struct { - Elf64_Half si_boundto; - Elf64_Half si_flags; -} Elf64_Syminfo; - -#define SYMINFO_BT_SELF 0xffff -#define SYMINFO_BT_PARENT 0xfffe -#define SYMINFO_BT_LOWRESERVE 0xff00 - -#define SYMINFO_FLG_DIRECT 0x0001 -#define SYMINFO_FLG_PASSTHRU 0x0002 -#define SYMINFO_FLG_COPY 0x0004 -#define SYMINFO_FLG_LAZYLOAD 0x0008 - -#define SYMINFO_NONE 0 -#define SYMINFO_CURRENT 1 -#define SYMINFO_NUM 2 - -#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) -#define ELF32_ST_TYPE(val) ((val) & 0xf) -#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) - -#define ELF64_ST_BIND(val) ELF32_ST_BIND (val) -#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) -#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) - -#define STB_LOCAL 0 -#define STB_GLOBAL 1 -#define STB_WEAK 2 -#define STB_NUM 3 -#define STB_LOOS 10 -#define STB_GNU_UNIQUE 10 -#define STB_HIOS 12 -#define STB_LOPROC 13 -#define STB_HIPROC 15 - -#define STT_NOTYPE 0 -#define STT_OBJECT 1 -#define STT_FUNC 2 -#define STT_SECTION 3 -#define STT_FILE 4 -#define STT_COMMON 5 -#define STT_TLS 6 -#define STT_NUM 7 -#define STT_LOOS 10 -#define STT_GNU_IFUNC 10 -#define STT_HIOS 12 -#define STT_LOPROC 13 -#define STT_HIPROC 15 - -#define STN_UNDEF 0 - -#define ELF32_ST_VISIBILITY(o) ((o) & 0x03) -#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) - -#define STV_DEFAULT 0 -#define STV_INTERNAL 1 -#define STV_HIDDEN 2 -#define STV_PROTECTED 3 - - - - -typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; -} Elf32_Rel; - -typedef struct { - Elf64_Addr r_offset; - Elf64_Xword r_info; -} Elf64_Rel; - - - -typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; -} Elf32_Rela; - -typedef struct { - Elf64_Addr r_offset; - Elf64_Xword r_info; - Elf64_Sxword r_addend; -} Elf64_Rela; - - - -#define ELF32_R_SYM(val) ((val) >> 8) -#define ELF32_R_TYPE(val) ((val) & 0xff) -#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) - -#define ELF64_R_SYM(i) ((i) >> 32) -#define ELF64_R_TYPE(i) ((i) & 0xffffffff) -#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) - - - -typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; -} Elf32_Phdr; - -typedef struct { - Elf64_Word p_type; - Elf64_Word p_flags; - Elf64_Off p_offset; - Elf64_Addr p_vaddr; - Elf64_Addr p_paddr; - Elf64_Xword p_filesz; - Elf64_Xword p_memsz; - Elf64_Xword p_align; -} Elf64_Phdr; - - - -#define PT_NULL 0 -#define PT_LOAD 1 -#define PT_DYNAMIC 2 -#define PT_INTERP 3 -#define PT_NOTE 4 -#define PT_SHLIB 5 -#define PT_PHDR 6 -#define PT_TLS 7 -#define PT_NUM 8 -#define PT_LOOS 0x60000000 -#define PT_GNU_EH_FRAME 0x6474e550 -#define PT_GNU_STACK 0x6474e551 -#define PT_GNU_RELRO 0x6474e552 -#define PT_LOSUNW 0x6ffffffa -#define PT_SUNWBSS 0x6ffffffa -#define PT_SUNWSTACK 0x6ffffffb -#define PT_HISUNW 0x6fffffff -#define PT_HIOS 0x6fffffff -#define PT_LOPROC 0x70000000 -#define PT_HIPROC 0x7fffffff - - -#define PN_XNUM 0xffff - - -#define PF_X (1 << 0) -#define PF_W (1 << 1) -#define PF_R (1 << 2) -#define PF_MASKOS 0x0ff00000 -#define PF_MASKPROC 0xf0000000 - - - -#define NT_PRSTATUS 1 -#define NT_FPREGSET 2 -#define NT_PRPSINFO 3 -#define NT_PRXREG 4 -#define NT_TASKSTRUCT 4 -#define NT_PLATFORM 5 -#define NT_AUXV 6 -#define NT_GWINDOWS 7 -#define NT_ASRS 8 -#define NT_PSTATUS 10 -#define NT_PSINFO 13 -#define NT_PRCRED 14 -#define NT_UTSNAME 15 -#define NT_LWPSTATUS 16 -#define NT_LWPSINFO 17 -#define NT_PRFPXREG 20 -#define NT_SIGINFO 0x53494749 -#define NT_FILE 0x46494c45 -#define NT_PRXFPREG 0x46e62b7f -#define NT_PPC_VMX 0x100 -#define NT_PPC_SPE 0x101 -#define NT_PPC_VSX 0x102 -#define NT_386_TLS 0x200 -#define NT_386_IOPERM 0x201 -#define NT_X86_XSTATE 0x202 -#define NT_S390_HIGH_GPRS 0x300 -#define NT_S390_TIMER 0x301 -#define NT_S390_TODCMP 0x302 -#define NT_S390_TODPREG 0x303 -#define NT_S390_CTRS 0x304 -#define NT_S390_PREFIX 0x305 -#define NT_S390_LAST_BREAK 0x306 -#define NT_S390_SYSTEM_CALL 0x307 -#define NT_S390_TDB 0x308 -#define NT_ARM_VFP 0x400 -#define NT_ARM_TLS 0x401 -#define NT_ARM_HW_BREAK 0x402 -#define NT_ARM_HW_WATCH 0x403 -#define NT_ARM_SYSTEM_CALL 0x404 -#define NT_ARM_SVE 0x405 -#define NT_METAG_CBUF 0x500 -#define NT_METAG_RPIPE 0x501 -#define NT_METAG_TLS 0x502 -#define NT_VERSION 1 - - - - -typedef struct { - Elf32_Sword d_tag; - union { - Elf32_Word d_val; - Elf32_Addr d_ptr; - } d_un; -} Elf32_Dyn; - -typedef struct { - Elf64_Sxword d_tag; - union { - Elf64_Xword d_val; - Elf64_Addr d_ptr; - } d_un; -} Elf64_Dyn; - - - -#define DT_NULL 0 -#define DT_NEEDED 1 -#define DT_PLTRELSZ 2 -#define DT_PLTGOT 3 -#define DT_HASH 4 -#define DT_STRTAB 5 -#define DT_SYMTAB 6 -#define DT_RELA 7 -#define DT_RELASZ 8 -#define DT_RELAENT 9 -#define DT_STRSZ 10 -#define DT_SYMENT 11 -#define DT_INIT 12 -#define DT_FINI 13 -#define DT_SONAME 14 -#define DT_RPATH 15 -#define DT_SYMBOLIC 16 -#define DT_REL 17 -#define DT_RELSZ 18 -#define DT_RELENT 19 -#define DT_PLTREL 20 -#define DT_DEBUG 21 -#define DT_TEXTREL 22 -#define DT_JMPREL 23 -#define DT_BIND_NOW 24 -#define DT_INIT_ARRAY 25 -#define DT_FINI_ARRAY 26 -#define DT_INIT_ARRAYSZ 27 -#define DT_FINI_ARRAYSZ 28 -#define DT_RUNPATH 29 -#define DT_FLAGS 30 -#define DT_ENCODING 32 -#define DT_PREINIT_ARRAY 32 -#define DT_PREINIT_ARRAYSZ 33 -#define DT_NUM 34 -#define DT_LOOS 0x6000000d -#define DT_HIOS 0x6ffff000 -#define DT_LOPROC 0x70000000 -#define DT_HIPROC 0x7fffffff -#define DT_PROCNUM DT_MIPS_NUM - -#define DT_VALRNGLO 0x6ffffd00 -#define DT_GNU_PRELINKED 0x6ffffdf5 -#define DT_GNU_CONFLICTSZ 0x6ffffdf6 -#define DT_GNU_LIBLISTSZ 0x6ffffdf7 -#define DT_CHECKSUM 0x6ffffdf8 -#define DT_PLTPADSZ 0x6ffffdf9 -#define DT_MOVEENT 0x6ffffdfa -#define DT_MOVESZ 0x6ffffdfb -#define DT_FEATURE_1 0x6ffffdfc -#define DT_POSFLAG_1 0x6ffffdfd - -#define DT_SYMINSZ 0x6ffffdfe -#define DT_SYMINENT 0x6ffffdff -#define DT_VALRNGHI 0x6ffffdff -#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) -#define DT_VALNUM 12 - -#define DT_ADDRRNGLO 0x6ffffe00 -#define DT_GNU_HASH 0x6ffffef5 -#define DT_TLSDESC_PLT 0x6ffffef6 -#define DT_TLSDESC_GOT 0x6ffffef7 -#define DT_GNU_CONFLICT 0x6ffffef8 -#define DT_GNU_LIBLIST 0x6ffffef9 -#define DT_CONFIG 0x6ffffefa -#define DT_DEPAUDIT 0x6ffffefb -#define DT_AUDIT 0x6ffffefc -#define DT_PLTPAD 0x6ffffefd -#define DT_MOVETAB 0x6ffffefe -#define DT_SYMINFO 0x6ffffeff -#define DT_ADDRRNGHI 0x6ffffeff -#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) -#define DT_ADDRNUM 11 - - - -#define DT_VERSYM 0x6ffffff0 - -#define DT_RELACOUNT 0x6ffffff9 -#define DT_RELCOUNT 0x6ffffffa - - -#define DT_FLAGS_1 0x6ffffffb -#define DT_VERDEF 0x6ffffffc - -#define DT_VERDEFNUM 0x6ffffffd -#define DT_VERNEED 0x6ffffffe - -#define DT_VERNEEDNUM 0x6fffffff -#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) -#define DT_VERSIONTAGNUM 16 - - - -#define DT_AUXILIARY 0x7ffffffd -#define DT_FILTER 0x7fffffff -#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) -#define DT_EXTRANUM 3 - - -#define DF_ORIGIN 0x00000001 -#define DF_SYMBOLIC 0x00000002 -#define DF_TEXTREL 0x00000004 -#define DF_BIND_NOW 0x00000008 -#define DF_STATIC_TLS 0x00000010 - - - -#define DF_1_NOW 0x00000001 -#define DF_1_GLOBAL 0x00000002 -#define DF_1_GROUP 0x00000004 -#define DF_1_NODELETE 0x00000008 -#define DF_1_LOADFLTR 0x00000010 -#define DF_1_INITFIRST 0x00000020 -#define DF_1_NOOPEN 0x00000040 -#define DF_1_ORIGIN 0x00000080 -#define DF_1_DIRECT 0x00000100 -#define DF_1_TRANS 0x00000200 -#define DF_1_INTERPOSE 0x00000400 -#define DF_1_NODEFLIB 0x00000800 -#define DF_1_NODUMP 0x00001000 -#define DF_1_CONFALT 0x00002000 -#define DF_1_ENDFILTEE 0x00004000 -#define DF_1_DISPRELDNE 0x00008000 -#define DF_1_DISPRELPND 0x00010000 -#define DF_1_NODIRECT 0x00020000 -#define DF_1_IGNMULDEF 0x00040000 -#define DF_1_NOKSYMS 0x00080000 -#define DF_1_NOHDR 0x00100000 -#define DF_1_EDITED 0x00200000 -#define DF_1_NORELOC 0x00400000 -#define DF_1_SYMINTPOSE 0x00800000 -#define DF_1_GLOBAUDIT 0x01000000 -#define DF_1_SINGLETON 0x02000000 - -#define DTF_1_PARINIT 0x00000001 -#define DTF_1_CONFEXP 0x00000002 - - -#define DF_P1_LAZYLOAD 0x00000001 -#define DF_P1_GROUPPERM 0x00000002 - - - - -typedef struct { - Elf32_Half vd_version; - Elf32_Half vd_flags; - Elf32_Half vd_ndx; - Elf32_Half vd_cnt; - Elf32_Word vd_hash; - Elf32_Word vd_aux; - Elf32_Word vd_next; -} Elf32_Verdef; - -typedef struct { - Elf64_Half vd_version; - Elf64_Half vd_flags; - Elf64_Half vd_ndx; - Elf64_Half vd_cnt; - Elf64_Word vd_hash; - Elf64_Word vd_aux; - Elf64_Word vd_next; -} Elf64_Verdef; - - - -#define VER_DEF_NONE 0 -#define VER_DEF_CURRENT 1 -#define VER_DEF_NUM 2 - - -#define VER_FLG_BASE 0x1 -#define VER_FLG_WEAK 0x2 - - -#define VER_NDX_LOCAL 0 -#define VER_NDX_GLOBAL 1 -#define VER_NDX_LORESERVE 0xff00 -#define VER_NDX_ELIMINATE 0xff01 - - - -typedef struct { - Elf32_Word vda_name; - Elf32_Word vda_next; -} Elf32_Verdaux; - -typedef struct { - Elf64_Word vda_name; - Elf64_Word vda_next; -} Elf64_Verdaux; - - - - -typedef struct { - Elf32_Half vn_version; - Elf32_Half vn_cnt; - Elf32_Word vn_file; - Elf32_Word vn_aux; - Elf32_Word vn_next; -} Elf32_Verneed; - -typedef struct { - Elf64_Half vn_version; - Elf64_Half vn_cnt; - Elf64_Word vn_file; - Elf64_Word vn_aux; - Elf64_Word vn_next; -} Elf64_Verneed; - - - -#define VER_NEED_NONE 0 -#define VER_NEED_CURRENT 1 -#define VER_NEED_NUM 2 - - - -typedef struct { - Elf32_Word vna_hash; - Elf32_Half vna_flags; - Elf32_Half vna_other; - Elf32_Word vna_name; - Elf32_Word vna_next; -} Elf32_Vernaux; - -typedef struct { - Elf64_Word vna_hash; - Elf64_Half vna_flags; - Elf64_Half vna_other; - Elf64_Word vna_name; - Elf64_Word vna_next; -} Elf64_Vernaux; - - - -#define VER_FLG_WEAK 0x2 - - - -typedef struct { - uint32_t a_type; - union { - uint32_t a_val; - } a_un; -} Elf32_auxv_t; - -typedef struct { - uint64_t a_type; - union { - uint64_t a_val; - } a_un; -} Elf64_auxv_t; - - - -#define AT_NULL 0 -#define AT_IGNORE 1 -#define AT_EXECFD 2 -#define AT_PHDR 3 -#define AT_PHENT 4 -#define AT_PHNUM 5 -#define AT_PAGESZ 6 -#define AT_BASE 7 -#define AT_FLAGS 8 -#define AT_ENTRY 9 -#define AT_NOTELF 10 -#define AT_UID 11 -#define AT_EUID 12 -#define AT_GID 13 -#define AT_EGID 14 -#define AT_CLKTCK 17 - - -#define AT_PLATFORM 15 -#define AT_HWCAP 16 - - - - -#define AT_FPUCW 18 - - -#define AT_DCACHEBSIZE 19 -#define AT_ICACHEBSIZE 20 -#define AT_UCACHEBSIZE 21 - - - -#define AT_IGNOREPPC 22 - -#define AT_SECURE 23 - -#define AT_BASE_PLATFORM 24 - -#define AT_RANDOM 25 - -#define AT_HWCAP2 26 - -#define AT_EXECFN 31 - - - -#define AT_SYSINFO 32 -#define AT_SYSINFO_EHDR 33 - - - -#define AT_L1I_CACHESHAPE 34 -#define AT_L1D_CACHESHAPE 35 -#define AT_L2_CACHESHAPE 36 -#define AT_L3_CACHESHAPE 37 - - - - -typedef struct { - Elf32_Word n_namesz; - Elf32_Word n_descsz; - Elf32_Word n_type; -} Elf32_Nhdr; - -typedef struct { - Elf64_Word n_namesz; - Elf64_Word n_descsz; - Elf64_Word n_type; -} Elf64_Nhdr; - - - - -#define ELF_NOTE_SOLARIS "SUNW Solaris" - - -#define ELF_NOTE_GNU "GNU" - - - - - -#define ELF_NOTE_PAGESIZE_HINT 1 - - -#define NT_GNU_ABI_TAG 1 -#define ELF_NOTE_ABI NT_GNU_ABI_TAG - - - -#define ELF_NOTE_OS_LINUX 0 -#define ELF_NOTE_OS_GNU 1 -#define ELF_NOTE_OS_SOLARIS2 2 -#define ELF_NOTE_OS_FREEBSD 3 - -#define NT_GNU_BUILD_ID 3 -#define NT_GNU_GOLD_VERSION 4 - - - -typedef struct { - Elf32_Xword m_value; - Elf32_Word m_info; - Elf32_Word m_poffset; - Elf32_Half m_repeat; - Elf32_Half m_stride; -} Elf32_Move; - -typedef struct { - Elf64_Xword m_value; - Elf64_Xword m_info; - Elf64_Xword m_poffset; - Elf64_Half m_repeat; - Elf64_Half m_stride; -} Elf64_Move; - - -#define ELF32_M_SYM(info) ((info) >> 8) -#define ELF32_M_SIZE(info) ((unsigned char) (info)) -#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) - -#define ELF64_M_SYM(info) ELF32_M_SYM (info) -#define ELF64_M_SIZE(info) ELF32_M_SIZE (info) -#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) - -#define EF_CPU32 0x00810000 - -#define R_68K_NONE 0 -#define R_68K_32 1 -#define R_68K_16 2 -#define R_68K_8 3 -#define R_68K_PC32 4 -#define R_68K_PC16 5 -#define R_68K_PC8 6 -#define R_68K_GOT32 7 -#define R_68K_GOT16 8 -#define R_68K_GOT8 9 -#define R_68K_GOT32O 10 -#define R_68K_GOT16O 11 -#define R_68K_GOT8O 12 -#define R_68K_PLT32 13 -#define R_68K_PLT16 14 -#define R_68K_PLT8 15 -#define R_68K_PLT32O 16 -#define R_68K_PLT16O 17 -#define R_68K_PLT8O 18 -#define R_68K_COPY 19 -#define R_68K_GLOB_DAT 20 -#define R_68K_JMP_SLOT 21 -#define R_68K_RELATIVE 22 -#define R_68K_NUM 23 - -#define R_386_NONE 0 -#define R_386_32 1 -#define R_386_PC32 2 -#define R_386_GOT32 3 -#define R_386_PLT32 4 -#define R_386_COPY 5 -#define R_386_GLOB_DAT 6 -#define R_386_JMP_SLOT 7 -#define R_386_RELATIVE 8 -#define R_386_GOTOFF 9 -#define R_386_GOTPC 10 -#define R_386_32PLT 11 -#define R_386_TLS_TPOFF 14 -#define R_386_TLS_IE 15 -#define R_386_TLS_GOTIE 16 -#define R_386_TLS_LE 17 -#define R_386_TLS_GD 18 -#define R_386_TLS_LDM 19 -#define R_386_16 20 -#define R_386_PC16 21 -#define R_386_8 22 -#define R_386_PC8 23 -#define R_386_TLS_GD_32 24 -#define R_386_TLS_GD_PUSH 25 -#define R_386_TLS_GD_CALL 26 -#define R_386_TLS_GD_POP 27 -#define R_386_TLS_LDM_32 28 -#define R_386_TLS_LDM_PUSH 29 -#define R_386_TLS_LDM_CALL 30 -#define R_386_TLS_LDM_POP 31 -#define R_386_TLS_LDO_32 32 -#define R_386_TLS_IE_32 33 -#define R_386_TLS_LE_32 34 -#define R_386_TLS_DTPMOD32 35 -#define R_386_TLS_DTPOFF32 36 -#define R_386_TLS_TPOFF32 37 -#define R_386_SIZE32 38 -#define R_386_TLS_GOTDESC 39 -#define R_386_TLS_DESC_CALL 40 -#define R_386_TLS_DESC 41 -#define R_386_IRELATIVE 42 -#define R_386_GOT32X 43 -#define R_386_NUM 44 - - - - - -#define STT_SPARC_REGISTER 13 - - - -#define EF_SPARCV9_MM 3 -#define EF_SPARCV9_TSO 0 -#define EF_SPARCV9_PSO 1 -#define EF_SPARCV9_RMO 2 -#define EF_SPARC_LEDATA 0x800000 -#define EF_SPARC_EXT_MASK 0xFFFF00 -#define EF_SPARC_32PLUS 0x000100 -#define EF_SPARC_SUN_US1 0x000200 -#define EF_SPARC_HAL_R1 0x000400 -#define EF_SPARC_SUN_US3 0x000800 - - - -#define R_SPARC_NONE 0 -#define R_SPARC_8 1 -#define R_SPARC_16 2 -#define R_SPARC_32 3 -#define R_SPARC_DISP8 4 -#define R_SPARC_DISP16 5 -#define R_SPARC_DISP32 6 -#define R_SPARC_WDISP30 7 -#define R_SPARC_WDISP22 8 -#define R_SPARC_HI22 9 -#define R_SPARC_22 10 -#define R_SPARC_13 11 -#define R_SPARC_LO10 12 -#define R_SPARC_GOT10 13 -#define R_SPARC_GOT13 14 -#define R_SPARC_GOT22 15 -#define R_SPARC_PC10 16 -#define R_SPARC_PC22 17 -#define R_SPARC_WPLT30 18 -#define R_SPARC_COPY 19 -#define R_SPARC_GLOB_DAT 20 -#define R_SPARC_JMP_SLOT 21 -#define R_SPARC_RELATIVE 22 -#define R_SPARC_UA32 23 - - - -#define R_SPARC_PLT32 24 -#define R_SPARC_HIPLT22 25 -#define R_SPARC_LOPLT10 26 -#define R_SPARC_PCPLT32 27 -#define R_SPARC_PCPLT22 28 -#define R_SPARC_PCPLT10 29 -#define R_SPARC_10 30 -#define R_SPARC_11 31 -#define R_SPARC_64 32 -#define R_SPARC_OLO10 33 -#define R_SPARC_HH22 34 -#define R_SPARC_HM10 35 -#define R_SPARC_LM22 36 -#define R_SPARC_PC_HH22 37 -#define R_SPARC_PC_HM10 38 -#define R_SPARC_PC_LM22 39 -#define R_SPARC_WDISP16 40 -#define R_SPARC_WDISP19 41 -#define R_SPARC_GLOB_JMP 42 -#define R_SPARC_7 43 -#define R_SPARC_5 44 -#define R_SPARC_6 45 -#define R_SPARC_DISP64 46 -#define R_SPARC_PLT64 47 -#define R_SPARC_HIX22 48 -#define R_SPARC_LOX10 49 -#define R_SPARC_H44 50 -#define R_SPARC_M44 51 -#define R_SPARC_L44 52 -#define R_SPARC_REGISTER 53 -#define R_SPARC_UA64 54 -#define R_SPARC_UA16 55 -#define R_SPARC_TLS_GD_HI22 56 -#define R_SPARC_TLS_GD_LO10 57 -#define R_SPARC_TLS_GD_ADD 58 -#define R_SPARC_TLS_GD_CALL 59 -#define R_SPARC_TLS_LDM_HI22 60 -#define R_SPARC_TLS_LDM_LO10 61 -#define R_SPARC_TLS_LDM_ADD 62 -#define R_SPARC_TLS_LDM_CALL 63 -#define R_SPARC_TLS_LDO_HIX22 64 -#define R_SPARC_TLS_LDO_LOX10 65 -#define R_SPARC_TLS_LDO_ADD 66 -#define R_SPARC_TLS_IE_HI22 67 -#define R_SPARC_TLS_IE_LO10 68 -#define R_SPARC_TLS_IE_LD 69 -#define R_SPARC_TLS_IE_LDX 70 -#define R_SPARC_TLS_IE_ADD 71 -#define R_SPARC_TLS_LE_HIX22 72 -#define R_SPARC_TLS_LE_LOX10 73 -#define R_SPARC_TLS_DTPMOD32 74 -#define R_SPARC_TLS_DTPMOD64 75 -#define R_SPARC_TLS_DTPOFF32 76 -#define R_SPARC_TLS_DTPOFF64 77 -#define R_SPARC_TLS_TPOFF32 78 -#define R_SPARC_TLS_TPOFF64 79 -#define R_SPARC_GOTDATA_HIX22 80 -#define R_SPARC_GOTDATA_LOX10 81 -#define R_SPARC_GOTDATA_OP_HIX22 82 -#define R_SPARC_GOTDATA_OP_LOX10 83 -#define R_SPARC_GOTDATA_OP 84 -#define R_SPARC_H34 85 -#define R_SPARC_SIZE32 86 -#define R_SPARC_SIZE64 87 -#define R_SPARC_GNU_VTINHERIT 250 -#define R_SPARC_GNU_VTENTRY 251 -#define R_SPARC_REV32 252 - -#define R_SPARC_NUM 253 - - - -#define DT_SPARC_REGISTER 0x70000001 -#define DT_SPARC_NUM 2 - - -#define EF_MIPS_NOREORDER 1 -#define EF_MIPS_PIC 2 -#define EF_MIPS_CPIC 4 -#define EF_MIPS_XGOT 8 -#define EF_MIPS_64BIT_WHIRL 16 -#define EF_MIPS_ABI2 32 -#define EF_MIPS_ABI_ON32 64 -#define EF_MIPS_FP64 512 -#define EF_MIPS_NAN2008 1024 -#define EF_MIPS_ARCH 0xf0000000 - - - -#define EF_MIPS_ARCH_1 0x00000000 -#define EF_MIPS_ARCH_2 0x10000000 -#define EF_MIPS_ARCH_3 0x20000000 -#define EF_MIPS_ARCH_4 0x30000000 -#define EF_MIPS_ARCH_5 0x40000000 -#define EF_MIPS_ARCH_32 0x50000000 -#define EF_MIPS_ARCH_64 0x60000000 -#define EF_MIPS_ARCH_32R2 0x70000000 -#define EF_MIPS_ARCH_64R2 0x80000000 - - -#define E_MIPS_ARCH_1 0x00000000 -#define E_MIPS_ARCH_2 0x10000000 -#define E_MIPS_ARCH_3 0x20000000 -#define E_MIPS_ARCH_4 0x30000000 -#define E_MIPS_ARCH_5 0x40000000 -#define E_MIPS_ARCH_32 0x50000000 -#define E_MIPS_ARCH_64 0x60000000 - - - -#define SHN_MIPS_ACOMMON 0xff00 -#define SHN_MIPS_TEXT 0xff01 -#define SHN_MIPS_DATA 0xff02 -#define SHN_MIPS_SCOMMON 0xff03 -#define SHN_MIPS_SUNDEFINED 0xff04 - - - -#define SHT_MIPS_LIBLIST 0x70000000 -#define SHT_MIPS_MSYM 0x70000001 -#define SHT_MIPS_CONFLICT 0x70000002 -#define SHT_MIPS_GPTAB 0x70000003 -#define SHT_MIPS_UCODE 0x70000004 -#define SHT_MIPS_DEBUG 0x70000005 -#define SHT_MIPS_REGINFO 0x70000006 -#define SHT_MIPS_PACKAGE 0x70000007 -#define SHT_MIPS_PACKSYM 0x70000008 -#define SHT_MIPS_RELD 0x70000009 -#define SHT_MIPS_IFACE 0x7000000b -#define SHT_MIPS_CONTENT 0x7000000c -#define SHT_MIPS_OPTIONS 0x7000000d -#define SHT_MIPS_SHDR 0x70000010 -#define SHT_MIPS_FDESC 0x70000011 -#define SHT_MIPS_EXTSYM 0x70000012 -#define SHT_MIPS_DENSE 0x70000013 -#define SHT_MIPS_PDESC 0x70000014 -#define SHT_MIPS_LOCSYM 0x70000015 -#define SHT_MIPS_AUXSYM 0x70000016 -#define SHT_MIPS_OPTSYM 0x70000017 -#define SHT_MIPS_LOCSTR 0x70000018 -#define SHT_MIPS_LINE 0x70000019 -#define SHT_MIPS_RFDESC 0x7000001a -#define SHT_MIPS_DELTASYM 0x7000001b -#define SHT_MIPS_DELTAINST 0x7000001c -#define SHT_MIPS_DELTACLASS 0x7000001d -#define SHT_MIPS_DWARF 0x7000001e -#define SHT_MIPS_DELTADECL 0x7000001f -#define SHT_MIPS_SYMBOL_LIB 0x70000020 -#define SHT_MIPS_EVENTS 0x70000021 -#define SHT_MIPS_TRANSLATE 0x70000022 -#define SHT_MIPS_PIXIE 0x70000023 -#define SHT_MIPS_XLATE 0x70000024 -#define SHT_MIPS_XLATE_DEBUG 0x70000025 -#define SHT_MIPS_WHIRL 0x70000026 -#define SHT_MIPS_EH_REGION 0x70000027 -#define SHT_MIPS_XLATE_OLD 0x70000028 -#define SHT_MIPS_PDR_EXCEPTION 0x70000029 - - - -#define SHF_MIPS_GPREL 0x10000000 -#define SHF_MIPS_MERGE 0x20000000 -#define SHF_MIPS_ADDR 0x40000000 -#define SHF_MIPS_STRINGS 0x80000000 -#define SHF_MIPS_NOSTRIP 0x08000000 -#define SHF_MIPS_LOCAL 0x04000000 -#define SHF_MIPS_NAMES 0x02000000 -#define SHF_MIPS_NODUPE 0x01000000 - - - - - -#define STO_MIPS_DEFAULT 0x0 -#define STO_MIPS_INTERNAL 0x1 -#define STO_MIPS_HIDDEN 0x2 -#define STO_MIPS_PROTECTED 0x3 -#define STO_MIPS_PLT 0x8 -#define STO_MIPS_SC_ALIGN_UNUSED 0xff - - -#define STB_MIPS_SPLIT_COMMON 13 - - - -typedef union { - struct { - Elf32_Word gt_current_g_value; - Elf32_Word gt_unused; - } gt_header; - struct { - Elf32_Word gt_g_value; - Elf32_Word gt_bytes; - } gt_entry; -} Elf32_gptab; - - - -typedef struct { - Elf32_Word ri_gprmask; - Elf32_Word ri_cprmask[4]; - Elf32_Sword ri_gp_value; -} Elf32_RegInfo; - - - -typedef struct { - unsigned char kind; - - unsigned char size; - Elf32_Section section; - - Elf32_Word info; -} Elf_Options; - - - -#define ODK_NULL 0 -#define ODK_REGINFO 1 -#define ODK_EXCEPTIONS 2 -#define ODK_PAD 3 -#define ODK_HWPATCH 4 -#define ODK_FILL 5 -#define ODK_TAGS 6 -#define ODK_HWAND 7 -#define ODK_HWOR 8 - - - -#define OEX_FPU_MIN 0x1f -#define OEX_FPU_MAX 0x1f00 -#define OEX_PAGE0 0x10000 -#define OEX_SMM 0x20000 -#define OEX_FPDBUG 0x40000 -#define OEX_PRECISEFP OEX_FPDBUG -#define OEX_DISMISS 0x80000 - -#define OEX_FPU_INVAL 0x10 -#define OEX_FPU_DIV0 0x08 -#define OEX_FPU_OFLO 0x04 -#define OEX_FPU_UFLO 0x02 -#define OEX_FPU_INEX 0x01 - - - -#define OHW_R4KEOP 0x1 -#define OHW_R8KPFETCH 0x2 -#define OHW_R5KEOP 0x4 -#define OHW_R5KCVTL 0x8 - -#define OPAD_PREFIX 0x1 -#define OPAD_POSTFIX 0x2 -#define OPAD_SYMBOL 0x4 - - - -typedef struct { - Elf32_Word hwp_flags1; - Elf32_Word hwp_flags2; -} Elf_Options_Hw; - - - -#define OHWA0_R4KEOP_CHECKED 0x00000001 -#define OHWA1_R4KEOP_CLEAN 0x00000002 - - - -#define R_MIPS_NONE 0 -#define R_MIPS_16 1 -#define R_MIPS_32 2 -#define R_MIPS_REL32 3 -#define R_MIPS_26 4 -#define R_MIPS_HI16 5 -#define R_MIPS_LO16 6 -#define R_MIPS_GPREL16 7 -#define R_MIPS_LITERAL 8 -#define R_MIPS_GOT16 9 -#define R_MIPS_PC16 10 -#define R_MIPS_CALL16 11 -#define R_MIPS_GPREL32 12 - -#define R_MIPS_SHIFT5 16 -#define R_MIPS_SHIFT6 17 -#define R_MIPS_64 18 -#define R_MIPS_GOT_DISP 19 -#define R_MIPS_GOT_PAGE 20 -#define R_MIPS_GOT_OFST 21 -#define R_MIPS_GOT_HI16 22 -#define R_MIPS_GOT_LO16 23 -#define R_MIPS_SUB 24 -#define R_MIPS_INSERT_A 25 -#define R_MIPS_INSERT_B 26 -#define R_MIPS_DELETE 27 -#define R_MIPS_HIGHER 28 -#define R_MIPS_HIGHEST 29 -#define R_MIPS_CALL_HI16 30 -#define R_MIPS_CALL_LO16 31 -#define R_MIPS_SCN_DISP 32 -#define R_MIPS_REL16 33 -#define R_MIPS_ADD_IMMEDIATE 34 -#define R_MIPS_PJUMP 35 -#define R_MIPS_RELGOT 36 -#define R_MIPS_JALR 37 -#define R_MIPS_TLS_DTPMOD32 38 -#define R_MIPS_TLS_DTPREL32 39 -#define R_MIPS_TLS_DTPMOD64 40 -#define R_MIPS_TLS_DTPREL64 41 -#define R_MIPS_TLS_GD 42 -#define R_MIPS_TLS_LDM 43 -#define R_MIPS_TLS_DTPREL_HI16 44 -#define R_MIPS_TLS_DTPREL_LO16 45 -#define R_MIPS_TLS_GOTTPREL 46 -#define R_MIPS_TLS_TPREL32 47 -#define R_MIPS_TLS_TPREL64 48 -#define R_MIPS_TLS_TPREL_HI16 49 -#define R_MIPS_TLS_TPREL_LO16 50 -#define R_MIPS_GLOB_DAT 51 -#define R_MIPS_COPY 126 -#define R_MIPS_JUMP_SLOT 127 - -#define R_MIPS_NUM 128 - - - -#define PT_MIPS_REGINFO 0x70000000 -#define PT_MIPS_RTPROC 0x70000001 -#define PT_MIPS_OPTIONS 0x70000002 -#define PT_MIPS_ABIFLAGS 0x70000003 - - - -#define PF_MIPS_LOCAL 0x10000000 - - - -#define DT_MIPS_RLD_VERSION 0x70000001 -#define DT_MIPS_TIME_STAMP 0x70000002 -#define DT_MIPS_ICHECKSUM 0x70000003 -#define DT_MIPS_IVERSION 0x70000004 -#define DT_MIPS_FLAGS 0x70000005 -#define DT_MIPS_BASE_ADDRESS 0x70000006 -#define DT_MIPS_MSYM 0x70000007 -#define DT_MIPS_CONFLICT 0x70000008 -#define DT_MIPS_LIBLIST 0x70000009 -#define DT_MIPS_LOCAL_GOTNO 0x7000000a -#define DT_MIPS_CONFLICTNO 0x7000000b -#define DT_MIPS_LIBLISTNO 0x70000010 -#define DT_MIPS_SYMTABNO 0x70000011 -#define DT_MIPS_UNREFEXTNO 0x70000012 -#define DT_MIPS_GOTSYM 0x70000013 -#define DT_MIPS_HIPAGENO 0x70000014 -#define DT_MIPS_RLD_MAP 0x70000016 -#define DT_MIPS_DELTA_CLASS 0x70000017 -#define DT_MIPS_DELTA_CLASS_NO 0x70000018 - -#define DT_MIPS_DELTA_INSTANCE 0x70000019 -#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a - -#define DT_MIPS_DELTA_RELOC 0x7000001b -#define DT_MIPS_DELTA_RELOC_NO 0x7000001c - -#define DT_MIPS_DELTA_SYM 0x7000001d - -#define DT_MIPS_DELTA_SYM_NO 0x7000001e - -#define DT_MIPS_DELTA_CLASSSYM 0x70000020 - -#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 - -#define DT_MIPS_CXX_FLAGS 0x70000022 -#define DT_MIPS_PIXIE_INIT 0x70000023 -#define DT_MIPS_SYMBOL_LIB 0x70000024 -#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 -#define DT_MIPS_LOCAL_GOTIDX 0x70000026 -#define DT_MIPS_HIDDEN_GOTIDX 0x70000027 -#define DT_MIPS_PROTECTED_GOTIDX 0x70000028 -#define DT_MIPS_OPTIONS 0x70000029 -#define DT_MIPS_INTERFACE 0x7000002a -#define DT_MIPS_DYNSTR_ALIGN 0x7000002b -#define DT_MIPS_INTERFACE_SIZE 0x7000002c -#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d - -#define DT_MIPS_PERF_SUFFIX 0x7000002e - -#define DT_MIPS_COMPACT_SIZE 0x7000002f -#define DT_MIPS_GP_VALUE 0x70000030 -#define DT_MIPS_AUX_DYNAMIC 0x70000031 - -#define DT_MIPS_PLTGOT 0x70000032 - -#define DT_MIPS_RWPLT 0x70000034 -#define DT_MIPS_RLD_MAP_REL 0x70000035 -#define DT_MIPS_NUM 0x36 - - - -#define RHF_NONE 0 -#define RHF_QUICKSTART (1 << 0) -#define RHF_NOTPOT (1 << 1) -#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) -#define RHF_NO_MOVE (1 << 3) -#define RHF_SGI_ONLY (1 << 4) -#define RHF_GUARANTEE_INIT (1 << 5) -#define RHF_DELTA_C_PLUS_PLUS (1 << 6) -#define RHF_GUARANTEE_START_INIT (1 << 7) -#define RHF_PIXIE (1 << 8) -#define RHF_DEFAULT_DELAY_LOAD (1 << 9) -#define RHF_REQUICKSTART (1 << 10) -#define RHF_REQUICKSTARTED (1 << 11) -#define RHF_CORD (1 << 12) -#define RHF_NO_UNRES_UNDEF (1 << 13) -#define RHF_RLD_ORDER_SAFE (1 << 14) - - - -typedef struct { - Elf32_Word l_name; - Elf32_Word l_time_stamp; - Elf32_Word l_checksum; - Elf32_Word l_version; - Elf32_Word l_flags; -} Elf32_Lib; - -typedef struct { - Elf64_Word l_name; - Elf64_Word l_time_stamp; - Elf64_Word l_checksum; - Elf64_Word l_version; - Elf64_Word l_flags; -} Elf64_Lib; - - - - -#define LL_NONE 0 -#define LL_EXACT_MATCH (1 << 0) -#define LL_IGNORE_INT_VER (1 << 1) -#define LL_REQUIRE_MINOR (1 << 2) -#define LL_EXPORTS (1 << 3) -#define LL_DELAY_LOAD (1 << 4) -#define LL_DELTA (1 << 5) - - - -typedef Elf32_Addr Elf32_Conflict; - -typedef struct { - Elf32_Half version; - unsigned char isa_level; - unsigned char isa_rev; - unsigned char gpr_size; - unsigned char cpr1_size; - unsigned char cpr2_size; - unsigned char fp_abi; - Elf32_Word isa_ext; - Elf32_Word ases; - Elf32_Word flags1; - Elf32_Word flags2; -} Elf_MIPS_ABIFlags_v0; - -#define MIPS_AFL_REG_NONE 0x00 -#define MIPS_AFL_REG_32 0x01 -#define MIPS_AFL_REG_64 0x02 -#define MIPS_AFL_REG_128 0x03 - -#define MIPS_AFL_ASE_DSP 0x00000001 -#define MIPS_AFL_ASE_DSPR2 0x00000002 -#define MIPS_AFL_ASE_EVA 0x00000004 -#define MIPS_AFL_ASE_MCU 0x00000008 -#define MIPS_AFL_ASE_MDMX 0x00000010 -#define MIPS_AFL_ASE_MIPS3D 0x00000020 -#define MIPS_AFL_ASE_MT 0x00000040 -#define MIPS_AFL_ASE_SMARTMIPS 0x00000080 -#define MIPS_AFL_ASE_VIRT 0x00000100 -#define MIPS_AFL_ASE_MSA 0x00000200 -#define MIPS_AFL_ASE_MIPS16 0x00000400 -#define MIPS_AFL_ASE_MICROMIPS 0x00000800 -#define MIPS_AFL_ASE_XPA 0x00001000 -#define MIPS_AFL_ASE_MASK 0x00001fff - -#define MIPS_AFL_EXT_XLR 1 -#define MIPS_AFL_EXT_OCTEON2 2 -#define MIPS_AFL_EXT_OCTEONP 3 -#define MIPS_AFL_EXT_LOONGSON_3A 4 -#define MIPS_AFL_EXT_OCTEON 5 -#define MIPS_AFL_EXT_5900 6 -#define MIPS_AFL_EXT_4650 7 -#define MIPS_AFL_EXT_4010 8 -#define MIPS_AFL_EXT_4100 9 -#define MIPS_AFL_EXT_3900 10 -#define MIPS_AFL_EXT_10000 11 -#define MIPS_AFL_EXT_SB1 12 -#define MIPS_AFL_EXT_4111 13 -#define MIPS_AFL_EXT_4120 14 -#define MIPS_AFL_EXT_5400 15 -#define MIPS_AFL_EXT_5500 16 -#define MIPS_AFL_EXT_LOONGSON_2E 17 -#define MIPS_AFL_EXT_LOONGSON_2F 18 - -#define MIPS_AFL_FLAGS1_ODDSPREG 1 - -enum -{ - Val_GNU_MIPS_ABI_FP_ANY = 0, - Val_GNU_MIPS_ABI_FP_DOUBLE = 1, - Val_GNU_MIPS_ABI_FP_SINGLE = 2, - Val_GNU_MIPS_ABI_FP_SOFT = 3, - Val_GNU_MIPS_ABI_FP_OLD_64 = 4, - Val_GNU_MIPS_ABI_FP_XX = 5, - Val_GNU_MIPS_ABI_FP_64 = 6, - Val_GNU_MIPS_ABI_FP_64A = 7, - Val_GNU_MIPS_ABI_FP_MAX = 7 -}; - - - - -#define EF_PARISC_TRAPNIL 0x00010000 -#define EF_PARISC_EXT 0x00020000 -#define EF_PARISC_LSB 0x00040000 -#define EF_PARISC_WIDE 0x00080000 -#define EF_PARISC_NO_KABP 0x00100000 - -#define EF_PARISC_LAZYSWAP 0x00400000 -#define EF_PARISC_ARCH 0x0000ffff - - - -#define EFA_PARISC_1_0 0x020b -#define EFA_PARISC_1_1 0x0210 -#define EFA_PARISC_2_0 0x0214 - - - -#define SHN_PARISC_ANSI_COMMON 0xff00 - -#define SHN_PARISC_HUGE_COMMON 0xff01 - - - -#define SHT_PARISC_EXT 0x70000000 -#define SHT_PARISC_UNWIND 0x70000001 -#define SHT_PARISC_DOC 0x70000002 - - - -#define SHF_PARISC_SHORT 0x20000000 -#define SHF_PARISC_HUGE 0x40000000 -#define SHF_PARISC_SBP 0x80000000 - - - -#define STT_PARISC_MILLICODE 13 - -#define STT_HP_OPAQUE (STT_LOOS + 0x1) -#define STT_HP_STUB (STT_LOOS + 0x2) - - - -#define R_PARISC_NONE 0 -#define R_PARISC_DIR32 1 -#define R_PARISC_DIR21L 2 -#define R_PARISC_DIR17R 3 -#define R_PARISC_DIR17F 4 -#define R_PARISC_DIR14R 6 -#define R_PARISC_PCREL32 9 -#define R_PARISC_PCREL21L 10 -#define R_PARISC_PCREL17R 11 -#define R_PARISC_PCREL17F 12 -#define R_PARISC_PCREL14R 14 -#define R_PARISC_DPREL21L 18 -#define R_PARISC_DPREL14R 22 -#define R_PARISC_GPREL21L 26 -#define R_PARISC_GPREL14R 30 -#define R_PARISC_LTOFF21L 34 -#define R_PARISC_LTOFF14R 38 -#define R_PARISC_SECREL32 41 -#define R_PARISC_SEGBASE 48 -#define R_PARISC_SEGREL32 49 -#define R_PARISC_PLTOFF21L 50 -#define R_PARISC_PLTOFF14R 54 -#define R_PARISC_LTOFF_FPTR32 57 -#define R_PARISC_LTOFF_FPTR21L 58 -#define R_PARISC_LTOFF_FPTR14R 62 -#define R_PARISC_FPTR64 64 -#define R_PARISC_PLABEL32 65 -#define R_PARISC_PLABEL21L 66 -#define R_PARISC_PLABEL14R 70 -#define R_PARISC_PCREL64 72 -#define R_PARISC_PCREL22F 74 -#define R_PARISC_PCREL14WR 75 -#define R_PARISC_PCREL14DR 76 -#define R_PARISC_PCREL16F 77 -#define R_PARISC_PCREL16WF 78 -#define R_PARISC_PCREL16DF 79 -#define R_PARISC_DIR64 80 -#define R_PARISC_DIR14WR 83 -#define R_PARISC_DIR14DR 84 -#define R_PARISC_DIR16F 85 -#define R_PARISC_DIR16WF 86 -#define R_PARISC_DIR16DF 87 -#define R_PARISC_GPREL64 88 -#define R_PARISC_GPREL14WR 91 -#define R_PARISC_GPREL14DR 92 -#define R_PARISC_GPREL16F 93 -#define R_PARISC_GPREL16WF 94 -#define R_PARISC_GPREL16DF 95 -#define R_PARISC_LTOFF64 96 -#define R_PARISC_LTOFF14WR 99 -#define R_PARISC_LTOFF14DR 100 -#define R_PARISC_LTOFF16F 101 -#define R_PARISC_LTOFF16WF 102 -#define R_PARISC_LTOFF16DF 103 -#define R_PARISC_SECREL64 104 -#define R_PARISC_SEGREL64 112 -#define R_PARISC_PLTOFF14WR 115 -#define R_PARISC_PLTOFF14DR 116 -#define R_PARISC_PLTOFF16F 117 -#define R_PARISC_PLTOFF16WF 118 -#define R_PARISC_PLTOFF16DF 119 -#define R_PARISC_LTOFF_FPTR64 120 -#define R_PARISC_LTOFF_FPTR14WR 123 -#define R_PARISC_LTOFF_FPTR14DR 124 -#define R_PARISC_LTOFF_FPTR16F 125 -#define R_PARISC_LTOFF_FPTR16WF 126 -#define R_PARISC_LTOFF_FPTR16DF 127 -#define R_PARISC_LORESERVE 128 -#define R_PARISC_COPY 128 -#define R_PARISC_IPLT 129 -#define R_PARISC_EPLT 130 -#define R_PARISC_TPREL32 153 -#define R_PARISC_TPREL21L 154 -#define R_PARISC_TPREL14R 158 -#define R_PARISC_LTOFF_TP21L 162 -#define R_PARISC_LTOFF_TP14R 166 -#define R_PARISC_LTOFF_TP14F 167 -#define R_PARISC_TPREL64 216 -#define R_PARISC_TPREL14WR 219 -#define R_PARISC_TPREL14DR 220 -#define R_PARISC_TPREL16F 221 -#define R_PARISC_TPREL16WF 222 -#define R_PARISC_TPREL16DF 223 -#define R_PARISC_LTOFF_TP64 224 -#define R_PARISC_LTOFF_TP14WR 227 -#define R_PARISC_LTOFF_TP14DR 228 -#define R_PARISC_LTOFF_TP16F 229 -#define R_PARISC_LTOFF_TP16WF 230 -#define R_PARISC_LTOFF_TP16DF 231 -#define R_PARISC_GNU_VTENTRY 232 -#define R_PARISC_GNU_VTINHERIT 233 -#define R_PARISC_TLS_GD21L 234 -#define R_PARISC_TLS_GD14R 235 -#define R_PARISC_TLS_GDCALL 236 -#define R_PARISC_TLS_LDM21L 237 -#define R_PARISC_TLS_LDM14R 238 -#define R_PARISC_TLS_LDMCALL 239 -#define R_PARISC_TLS_LDO21L 240 -#define R_PARISC_TLS_LDO14R 241 -#define R_PARISC_TLS_DTPMOD32 242 -#define R_PARISC_TLS_DTPMOD64 243 -#define R_PARISC_TLS_DTPOFF32 244 -#define R_PARISC_TLS_DTPOFF64 245 -#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L -#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R -#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L -#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R -#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32 -#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64 -#define R_PARISC_HIRESERVE 255 - - - -#define PT_HP_TLS (PT_LOOS + 0x0) -#define PT_HP_CORE_NONE (PT_LOOS + 0x1) -#define PT_HP_CORE_VERSION (PT_LOOS + 0x2) -#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) -#define PT_HP_CORE_COMM (PT_LOOS + 0x4) -#define PT_HP_CORE_PROC (PT_LOOS + 0x5) -#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) -#define PT_HP_CORE_STACK (PT_LOOS + 0x7) -#define PT_HP_CORE_SHM (PT_LOOS + 0x8) -#define PT_HP_CORE_MMF (PT_LOOS + 0x9) -#define PT_HP_PARALLEL (PT_LOOS + 0x10) -#define PT_HP_FASTBIND (PT_LOOS + 0x11) -#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) -#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) -#define PT_HP_STACK (PT_LOOS + 0x14) - -#define PT_PARISC_ARCHEXT 0x70000000 -#define PT_PARISC_UNWIND 0x70000001 - - - -#define PF_PARISC_SBP 0x08000000 - -#define PF_HP_PAGE_SIZE 0x00100000 -#define PF_HP_FAR_SHARED 0x00200000 -#define PF_HP_NEAR_SHARED 0x00400000 -#define PF_HP_CODE 0x01000000 -#define PF_HP_MODIFY 0x02000000 -#define PF_HP_LAZYSWAP 0x04000000 -#define PF_HP_SBP 0x08000000 - - - - - - -#define EF_ALPHA_32BIT 1 -#define EF_ALPHA_CANRELAX 2 - - - - -#define SHT_ALPHA_DEBUG 0x70000001 -#define SHT_ALPHA_REGINFO 0x70000002 - - - -#define SHF_ALPHA_GPREL 0x10000000 - - -#define STO_ALPHA_NOPV 0x80 -#define STO_ALPHA_STD_GPLOAD 0x88 - - - -#define R_ALPHA_NONE 0 -#define R_ALPHA_REFLONG 1 -#define R_ALPHA_REFQUAD 2 -#define R_ALPHA_GPREL32 3 -#define R_ALPHA_LITERAL 4 -#define R_ALPHA_LITUSE 5 -#define R_ALPHA_GPDISP 6 -#define R_ALPHA_BRADDR 7 -#define R_ALPHA_HINT 8 -#define R_ALPHA_SREL16 9 -#define R_ALPHA_SREL32 10 -#define R_ALPHA_SREL64 11 -#define R_ALPHA_GPRELHIGH 17 -#define R_ALPHA_GPRELLOW 18 -#define R_ALPHA_GPREL16 19 -#define R_ALPHA_COPY 24 -#define R_ALPHA_GLOB_DAT 25 -#define R_ALPHA_JMP_SLOT 26 -#define R_ALPHA_RELATIVE 27 -#define R_ALPHA_TLS_GD_HI 28 -#define R_ALPHA_TLSGD 29 -#define R_ALPHA_TLS_LDM 30 -#define R_ALPHA_DTPMOD64 31 -#define R_ALPHA_GOTDTPREL 32 -#define R_ALPHA_DTPREL64 33 -#define R_ALPHA_DTPRELHI 34 -#define R_ALPHA_DTPRELLO 35 -#define R_ALPHA_DTPREL16 36 -#define R_ALPHA_GOTTPREL 37 -#define R_ALPHA_TPREL64 38 -#define R_ALPHA_TPRELHI 39 -#define R_ALPHA_TPRELLO 40 -#define R_ALPHA_TPREL16 41 - -#define R_ALPHA_NUM 46 - - -#define LITUSE_ALPHA_ADDR 0 -#define LITUSE_ALPHA_BASE 1 -#define LITUSE_ALPHA_BYTOFF 2 -#define LITUSE_ALPHA_JSR 3 -#define LITUSE_ALPHA_TLS_GD 4 -#define LITUSE_ALPHA_TLS_LDM 5 - - -#define DT_ALPHA_PLTRO (DT_LOPROC + 0) -#define DT_ALPHA_NUM 1 - - - - -#define EF_PPC_EMB 0x80000000 - - -#define EF_PPC_RELOCATABLE 0x00010000 -#define EF_PPC_RELOCATABLE_LIB 0x00008000 - - - -#define R_PPC_NONE 0 -#define R_PPC_ADDR32 1 -#define R_PPC_ADDR24 2 -#define R_PPC_ADDR16 3 -#define R_PPC_ADDR16_LO 4 -#define R_PPC_ADDR16_HI 5 -#define R_PPC_ADDR16_HA 6 -#define R_PPC_ADDR14 7 -#define R_PPC_ADDR14_BRTAKEN 8 -#define R_PPC_ADDR14_BRNTAKEN 9 -#define R_PPC_REL24 10 -#define R_PPC_REL14 11 -#define R_PPC_REL14_BRTAKEN 12 -#define R_PPC_REL14_BRNTAKEN 13 -#define R_PPC_GOT16 14 -#define R_PPC_GOT16_LO 15 -#define R_PPC_GOT16_HI 16 -#define R_PPC_GOT16_HA 17 -#define R_PPC_PLTREL24 18 -#define R_PPC_COPY 19 -#define R_PPC_GLOB_DAT 20 -#define R_PPC_JMP_SLOT 21 -#define R_PPC_RELATIVE 22 -#define R_PPC_LOCAL24PC 23 -#define R_PPC_UADDR32 24 -#define R_PPC_UADDR16 25 -#define R_PPC_REL32 26 -#define R_PPC_PLT32 27 -#define R_PPC_PLTREL32 28 -#define R_PPC_PLT16_LO 29 -#define R_PPC_PLT16_HI 30 -#define R_PPC_PLT16_HA 31 -#define R_PPC_SDAREL16 32 -#define R_PPC_SECTOFF 33 -#define R_PPC_SECTOFF_LO 34 -#define R_PPC_SECTOFF_HI 35 -#define R_PPC_SECTOFF_HA 36 - - -#define R_PPC_TLS 67 -#define R_PPC_DTPMOD32 68 -#define R_PPC_TPREL16 69 -#define R_PPC_TPREL16_LO 70 -#define R_PPC_TPREL16_HI 71 -#define R_PPC_TPREL16_HA 72 -#define R_PPC_TPREL32 73 -#define R_PPC_DTPREL16 74 -#define R_PPC_DTPREL16_LO 75 -#define R_PPC_DTPREL16_HI 76 -#define R_PPC_DTPREL16_HA 77 -#define R_PPC_DTPREL32 78 -#define R_PPC_GOT_TLSGD16 79 -#define R_PPC_GOT_TLSGD16_LO 80 -#define R_PPC_GOT_TLSGD16_HI 81 -#define R_PPC_GOT_TLSGD16_HA 82 -#define R_PPC_GOT_TLSLD16 83 -#define R_PPC_GOT_TLSLD16_LO 84 -#define R_PPC_GOT_TLSLD16_HI 85 -#define R_PPC_GOT_TLSLD16_HA 86 -#define R_PPC_GOT_TPREL16 87 -#define R_PPC_GOT_TPREL16_LO 88 -#define R_PPC_GOT_TPREL16_HI 89 -#define R_PPC_GOT_TPREL16_HA 90 -#define R_PPC_GOT_DTPREL16 91 -#define R_PPC_GOT_DTPREL16_LO 92 -#define R_PPC_GOT_DTPREL16_HI 93 -#define R_PPC_GOT_DTPREL16_HA 94 -#define R_PPC_TLSGD 95 -#define R_PPC_TLSLD 96 - - -#define R_PPC_EMB_NADDR32 101 -#define R_PPC_EMB_NADDR16 102 -#define R_PPC_EMB_NADDR16_LO 103 -#define R_PPC_EMB_NADDR16_HI 104 -#define R_PPC_EMB_NADDR16_HA 105 -#define R_PPC_EMB_SDAI16 106 -#define R_PPC_EMB_SDA2I16 107 -#define R_PPC_EMB_SDA2REL 108 -#define R_PPC_EMB_SDA21 109 -#define R_PPC_EMB_MRKREF 110 -#define R_PPC_EMB_RELSEC16 111 -#define R_PPC_EMB_RELST_LO 112 -#define R_PPC_EMB_RELST_HI 113 -#define R_PPC_EMB_RELST_HA 114 -#define R_PPC_EMB_BIT_FLD 115 -#define R_PPC_EMB_RELSDA 116 - - -#define R_PPC_DIAB_SDA21_LO 180 -#define R_PPC_DIAB_SDA21_HI 181 -#define R_PPC_DIAB_SDA21_HA 182 -#define R_PPC_DIAB_RELSDA_LO 183 -#define R_PPC_DIAB_RELSDA_HI 184 -#define R_PPC_DIAB_RELSDA_HA 185 - - -#define R_PPC_IRELATIVE 248 - - -#define R_PPC_REL16 249 -#define R_PPC_REL16_LO 250 -#define R_PPC_REL16_HI 251 -#define R_PPC_REL16_HA 252 - - - -#define R_PPC_TOC16 255 - - -#define DT_PPC_GOT (DT_LOPROC + 0) -#define DT_PPC_OPT (DT_LOPROC + 1) -#define DT_PPC_NUM 2 - -#define PPC_OPT_TLS 1 - - -#define R_PPC64_NONE R_PPC_NONE -#define R_PPC64_ADDR32 R_PPC_ADDR32 -#define R_PPC64_ADDR24 R_PPC_ADDR24 -#define R_PPC64_ADDR16 R_PPC_ADDR16 -#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO -#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI -#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA -#define R_PPC64_ADDR14 R_PPC_ADDR14 -#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN -#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN -#define R_PPC64_REL24 R_PPC_REL24 -#define R_PPC64_REL14 R_PPC_REL14 -#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN -#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN -#define R_PPC64_GOT16 R_PPC_GOT16 -#define R_PPC64_GOT16_LO R_PPC_GOT16_LO -#define R_PPC64_GOT16_HI R_PPC_GOT16_HI -#define R_PPC64_GOT16_HA R_PPC_GOT16_HA - -#define R_PPC64_COPY R_PPC_COPY -#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT -#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT -#define R_PPC64_RELATIVE R_PPC_RELATIVE - -#define R_PPC64_UADDR32 R_PPC_UADDR32 -#define R_PPC64_UADDR16 R_PPC_UADDR16 -#define R_PPC64_REL32 R_PPC_REL32 -#define R_PPC64_PLT32 R_PPC_PLT32 -#define R_PPC64_PLTREL32 R_PPC_PLTREL32 -#define R_PPC64_PLT16_LO R_PPC_PLT16_LO -#define R_PPC64_PLT16_HI R_PPC_PLT16_HI -#define R_PPC64_PLT16_HA R_PPC_PLT16_HA - -#define R_PPC64_SECTOFF R_PPC_SECTOFF -#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO -#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI -#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA -#define R_PPC64_ADDR30 37 -#define R_PPC64_ADDR64 38 -#define R_PPC64_ADDR16_HIGHER 39 -#define R_PPC64_ADDR16_HIGHERA 40 -#define R_PPC64_ADDR16_HIGHEST 41 -#define R_PPC64_ADDR16_HIGHESTA 42 -#define R_PPC64_UADDR64 43 -#define R_PPC64_REL64 44 -#define R_PPC64_PLT64 45 -#define R_PPC64_PLTREL64 46 -#define R_PPC64_TOC16 47 -#define R_PPC64_TOC16_LO 48 -#define R_PPC64_TOC16_HI 49 -#define R_PPC64_TOC16_HA 50 -#define R_PPC64_TOC 51 -#define R_PPC64_PLTGOT16 52 -#define R_PPC64_PLTGOT16_LO 53 -#define R_PPC64_PLTGOT16_HI 54 -#define R_PPC64_PLTGOT16_HA 55 - -#define R_PPC64_ADDR16_DS 56 -#define R_PPC64_ADDR16_LO_DS 57 -#define R_PPC64_GOT16_DS 58 -#define R_PPC64_GOT16_LO_DS 59 -#define R_PPC64_PLT16_LO_DS 60 -#define R_PPC64_SECTOFF_DS 61 -#define R_PPC64_SECTOFF_LO_DS 62 -#define R_PPC64_TOC16_DS 63 -#define R_PPC64_TOC16_LO_DS 64 -#define R_PPC64_PLTGOT16_DS 65 -#define R_PPC64_PLTGOT16_LO_DS 66 - - -#define R_PPC64_TLS 67 -#define R_PPC64_DTPMOD64 68 -#define R_PPC64_TPREL16 69 -#define R_PPC64_TPREL16_LO 70 -#define R_PPC64_TPREL16_HI 71 -#define R_PPC64_TPREL16_HA 72 -#define R_PPC64_TPREL64 73 -#define R_PPC64_DTPREL16 74 -#define R_PPC64_DTPREL16_LO 75 -#define R_PPC64_DTPREL16_HI 76 -#define R_PPC64_DTPREL16_HA 77 -#define R_PPC64_DTPREL64 78 -#define R_PPC64_GOT_TLSGD16 79 -#define R_PPC64_GOT_TLSGD16_LO 80 -#define R_PPC64_GOT_TLSGD16_HI 81 -#define R_PPC64_GOT_TLSGD16_HA 82 -#define R_PPC64_GOT_TLSLD16 83 -#define R_PPC64_GOT_TLSLD16_LO 84 -#define R_PPC64_GOT_TLSLD16_HI 85 -#define R_PPC64_GOT_TLSLD16_HA 86 -#define R_PPC64_GOT_TPREL16_DS 87 -#define R_PPC64_GOT_TPREL16_LO_DS 88 -#define R_PPC64_GOT_TPREL16_HI 89 -#define R_PPC64_GOT_TPREL16_HA 90 -#define R_PPC64_GOT_DTPREL16_DS 91 -#define R_PPC64_GOT_DTPREL16_LO_DS 92 -#define R_PPC64_GOT_DTPREL16_HI 93 -#define R_PPC64_GOT_DTPREL16_HA 94 -#define R_PPC64_TPREL16_DS 95 -#define R_PPC64_TPREL16_LO_DS 96 -#define R_PPC64_TPREL16_HIGHER 97 -#define R_PPC64_TPREL16_HIGHERA 98 -#define R_PPC64_TPREL16_HIGHEST 99 -#define R_PPC64_TPREL16_HIGHESTA 100 -#define R_PPC64_DTPREL16_DS 101 -#define R_PPC64_DTPREL16_LO_DS 102 -#define R_PPC64_DTPREL16_HIGHER 103 -#define R_PPC64_DTPREL16_HIGHERA 104 -#define R_PPC64_DTPREL16_HIGHEST 105 -#define R_PPC64_DTPREL16_HIGHESTA 106 -#define R_PPC64_TLSGD 107 -#define R_PPC64_TLSLD 108 -#define R_PPC64_TOCSAVE 109 -#define R_PPC64_ADDR16_HIGH 110 -#define R_PPC64_ADDR16_HIGHA 111 -#define R_PPC64_TPREL16_HIGH 112 -#define R_PPC64_TPREL16_HIGHA 113 -#define R_PPC64_DTPREL16_HIGH 114 -#define R_PPC64_DTPREL16_HIGHA 115 - - -#define R_PPC64_JMP_IREL 247 -#define R_PPC64_IRELATIVE 248 -#define R_PPC64_REL16 249 -#define R_PPC64_REL16_LO 250 -#define R_PPC64_REL16_HI 251 -#define R_PPC64_REL16_HA 252 - -#define EF_PPC64_ABI 3 - -#define DT_PPC64_GLINK (DT_LOPROC + 0) -#define DT_PPC64_OPD (DT_LOPROC + 1) -#define DT_PPC64_OPDSZ (DT_LOPROC + 2) -#define DT_PPC64_OPT (DT_LOPROC + 3) -#define DT_PPC64_NUM 4 - -#define PPC64_OPT_TLS 1 -#define PPC64_OPT_MULTI_TOC 2 - -#define STO_PPC64_LOCAL_BIT 5 -#define STO_PPC64_LOCAL_MASK 0xe0 -#define PPC64_LOCAL_ENTRY_OFFSET(x) (1 << (((x)&0xe0)>>5) & 0xfc) - - -#define EF_ARM_RELEXEC 0x01 -#define EF_ARM_HASENTRY 0x02 -#define EF_ARM_INTERWORK 0x04 -#define EF_ARM_APCS_26 0x08 -#define EF_ARM_APCS_FLOAT 0x10 -#define EF_ARM_PIC 0x20 -#define EF_ARM_ALIGN8 0x40 -#define EF_ARM_NEW_ABI 0x80 -#define EF_ARM_OLD_ABI 0x100 -#define EF_ARM_SOFT_FLOAT 0x200 -#define EF_ARM_VFP_FLOAT 0x400 -#define EF_ARM_MAVERICK_FLOAT 0x800 - -#define EF_ARM_ABI_FLOAT_SOFT 0x200 -#define EF_ARM_ABI_FLOAT_HARD 0x400 - - -#define EF_ARM_SYMSARESORTED 0x04 -#define EF_ARM_DYNSYMSUSESEGIDX 0x08 -#define EF_ARM_MAPSYMSFIRST 0x10 -#define EF_ARM_EABIMASK 0XFF000000 - - -#define EF_ARM_BE8 0x00800000 -#define EF_ARM_LE8 0x00400000 - -#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) -#define EF_ARM_EABI_UNKNOWN 0x00000000 -#define EF_ARM_EABI_VER1 0x01000000 -#define EF_ARM_EABI_VER2 0x02000000 -#define EF_ARM_EABI_VER3 0x03000000 -#define EF_ARM_EABI_VER4 0x04000000 -#define EF_ARM_EABI_VER5 0x05000000 - - -#define STT_ARM_TFUNC STT_LOPROC -#define STT_ARM_16BIT STT_HIPROC - - -#define SHF_ARM_ENTRYSECT 0x10000000 -#define SHF_ARM_COMDEF 0x80000000 - - - -#define PF_ARM_SB 0x10000000 - -#define PF_ARM_PI 0x20000000 -#define PF_ARM_ABS 0x40000000 - - -#define PT_ARM_EXIDX (PT_LOPROC + 1) - - -#define SHT_ARM_EXIDX (SHT_LOPROC + 1) -#define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) -#define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) - -#define R_AARCH64_NONE 0 -#define R_AARCH64_P32_ABS32 1 -#define R_AARCH64_P32_COPY 180 -#define R_AARCH64_P32_GLOB_DAT 181 -#define R_AARCH64_P32_JUMP_SLOT 182 -#define R_AARCH64_P32_RELATIVE 183 -#define R_AARCH64_P32_TLS_DTPMOD 184 -#define R_AARCH64_P32_TLS_DTPREL 185 -#define R_AARCH64_P32_TLS_TPREL 186 -#define R_AARCH64_P32_TLSDESC 187 -#define R_AARCH64_P32_IRELATIVE 188 -#define R_AARCH64_ABS64 257 -#define R_AARCH64_ABS32 258 -#define R_AARCH64_ABS16 259 -#define R_AARCH64_PREL64 260 -#define R_AARCH64_PREL32 261 -#define R_AARCH64_PREL16 262 -#define R_AARCH64_MOVW_UABS_G0 263 -#define R_AARCH64_MOVW_UABS_G0_NC 264 -#define R_AARCH64_MOVW_UABS_G1 265 -#define R_AARCH64_MOVW_UABS_G1_NC 266 -#define R_AARCH64_MOVW_UABS_G2 267 -#define R_AARCH64_MOVW_UABS_G2_NC 268 -#define R_AARCH64_MOVW_UABS_G3 269 -#define R_AARCH64_MOVW_SABS_G0 270 -#define R_AARCH64_MOVW_SABS_G1 271 -#define R_AARCH64_MOVW_SABS_G2 272 -#define R_AARCH64_LD_PREL_LO19 273 -#define R_AARCH64_ADR_PREL_LO21 274 -#define R_AARCH64_ADR_PREL_PG_HI21 275 -#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 -#define R_AARCH64_ADD_ABS_LO12_NC 277 -#define R_AARCH64_LDST8_ABS_LO12_NC 278 -#define R_AARCH64_TSTBR14 279 -#define R_AARCH64_CONDBR19 280 -#define R_AARCH64_JUMP26 282 -#define R_AARCH64_CALL26 283 -#define R_AARCH64_LDST16_ABS_LO12_NC 284 -#define R_AARCH64_LDST32_ABS_LO12_NC 285 -#define R_AARCH64_LDST64_ABS_LO12_NC 286 -#define R_AARCH64_MOVW_PREL_G0 287 -#define R_AARCH64_MOVW_PREL_G0_NC 288 -#define R_AARCH64_MOVW_PREL_G1 289 -#define R_AARCH64_MOVW_PREL_G1_NC 290 -#define R_AARCH64_MOVW_PREL_G2 291 -#define R_AARCH64_MOVW_PREL_G2_NC 292 -#define R_AARCH64_MOVW_PREL_G3 293 -#define R_AARCH64_LDST128_ABS_LO12_NC 299 -#define R_AARCH64_MOVW_GOTOFF_G0 300 -#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 -#define R_AARCH64_MOVW_GOTOFF_G1 302 -#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 -#define R_AARCH64_MOVW_GOTOFF_G2 304 -#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 -#define R_AARCH64_MOVW_GOTOFF_G3 306 -#define R_AARCH64_GOTREL64 307 -#define R_AARCH64_GOTREL32 308 -#define R_AARCH64_GOT_LD_PREL19 309 -#define R_AARCH64_LD64_GOTOFF_LO15 310 -#define R_AARCH64_ADR_GOT_PAGE 311 -#define R_AARCH64_LD64_GOT_LO12_NC 312 -#define R_AARCH64_LD64_GOTPAGE_LO15 313 -#define R_AARCH64_TLSGD_ADR_PREL21 512 -#define R_AARCH64_TLSGD_ADR_PAGE21 513 -#define R_AARCH64_TLSGD_ADD_LO12_NC 514 -#define R_AARCH64_TLSGD_MOVW_G1 515 -#define R_AARCH64_TLSGD_MOVW_G0_NC 516 -#define R_AARCH64_TLSLD_ADR_PREL21 517 -#define R_AARCH64_TLSLD_ADR_PAGE21 518 -#define R_AARCH64_TLSLD_ADD_LO12_NC 519 -#define R_AARCH64_TLSLD_MOVW_G1 520 -#define R_AARCH64_TLSLD_MOVW_G0_NC 521 -#define R_AARCH64_TLSLD_LD_PREL19 522 -#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 -#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 -#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 -#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 -#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 -#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 -#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 -#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 -#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 -#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 -#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 -#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 -#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 -#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 -#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 -#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 -#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 -#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 -#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 -#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 -#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 -#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 -#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 -#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 -#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 -#define R_AARCH64_TLSDESC_LD_PREL19 560 -#define R_AARCH64_TLSDESC_ADR_PREL21 561 -#define R_AARCH64_TLSDESC_ADR_PAGE21 562 -#define R_AARCH64_TLSDESC_LD64_LO12 563 -#define R_AARCH64_TLSDESC_ADD_LO12 564 -#define R_AARCH64_TLSDESC_OFF_G1 565 -#define R_AARCH64_TLSDESC_OFF_G0_NC 566 -#define R_AARCH64_TLSDESC_LDR 567 -#define R_AARCH64_TLSDESC_ADD 568 -#define R_AARCH64_TLSDESC_CALL 569 -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 -#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 -#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 -#define R_AARCH64_COPY 1024 -#define R_AARCH64_GLOB_DAT 1025 -#define R_AARCH64_JUMP_SLOT 1026 -#define R_AARCH64_RELATIVE 1027 -#define R_AARCH64_TLS_DTPMOD 1028 -#define R_AARCH64_TLS_DTPMOD64 1028 -#define R_AARCH64_TLS_DTPREL 1029 -#define R_AARCH64_TLS_DTPREL64 1029 -#define R_AARCH64_TLS_TPREL 1030 -#define R_AARCH64_TLS_TPREL64 1030 -#define R_AARCH64_TLSDESC 1031 - - -#define R_ARM_NONE 0 -#define R_ARM_PC24 1 -#define R_ARM_ABS32 2 -#define R_ARM_REL32 3 -#define R_ARM_PC13 4 -#define R_ARM_ABS16 5 -#define R_ARM_ABS12 6 -#define R_ARM_THM_ABS5 7 -#define R_ARM_ABS8 8 -#define R_ARM_SBREL32 9 -#define R_ARM_THM_PC22 10 -#define R_ARM_THM_PC8 11 -#define R_ARM_AMP_VCALL9 12 -#define R_ARM_TLS_DESC 13 -#define R_ARM_THM_SWI8 14 -#define R_ARM_XPC25 15 -#define R_ARM_THM_XPC22 16 -#define R_ARM_TLS_DTPMOD32 17 -#define R_ARM_TLS_DTPOFF32 18 -#define R_ARM_TLS_TPOFF32 19 -#define R_ARM_COPY 20 -#define R_ARM_GLOB_DAT 21 -#define R_ARM_JUMP_SLOT 22 -#define R_ARM_RELATIVE 23 -#define R_ARM_GOTOFF 24 -#define R_ARM_GOTPC 25 -#define R_ARM_GOT32 26 -#define R_ARM_PLT32 27 -#define R_ARM_CALL 28 -#define R_ARM_JUMP24 29 -#define R_ARM_THM_JUMP24 30 -#define R_ARM_BASE_ABS 31 -#define R_ARM_ALU_PCREL_7_0 32 -#define R_ARM_ALU_PCREL_15_8 33 -#define R_ARM_ALU_PCREL_23_15 34 -#define R_ARM_LDR_SBREL_11_0 35 -#define R_ARM_ALU_SBREL_19_12 36 -#define R_ARM_ALU_SBREL_27_20 37 -#define R_ARM_TARGET1 38 -#define R_ARM_SBREL31 39 -#define R_ARM_V4BX 40 -#define R_ARM_TARGET2 41 -#define R_ARM_PREL31 42 -#define R_ARM_MOVW_ABS_NC 43 -#define R_ARM_MOVT_ABS 44 -#define R_ARM_MOVW_PREL_NC 45 -#define R_ARM_MOVT_PREL 46 -#define R_ARM_THM_MOVW_ABS_NC 47 -#define R_ARM_THM_MOVT_ABS 48 -#define R_ARM_THM_MOVW_PREL_NC 49 -#define R_ARM_THM_MOVT_PREL 50 -#define R_ARM_THM_JUMP19 51 -#define R_ARM_THM_JUMP6 52 -#define R_ARM_THM_ALU_PREL_11_0 53 -#define R_ARM_THM_PC12 54 -#define R_ARM_ABS32_NOI 55 -#define R_ARM_REL32_NOI 56 -#define R_ARM_ALU_PC_G0_NC 57 -#define R_ARM_ALU_PC_G0 58 -#define R_ARM_ALU_PC_G1_NC 59 -#define R_ARM_ALU_PC_G1 60 -#define R_ARM_ALU_PC_G2 61 -#define R_ARM_LDR_PC_G1 62 -#define R_ARM_LDR_PC_G2 63 -#define R_ARM_LDRS_PC_G0 64 -#define R_ARM_LDRS_PC_G1 65 -#define R_ARM_LDRS_PC_G2 66 -#define R_ARM_LDC_PC_G0 67 -#define R_ARM_LDC_PC_G1 68 -#define R_ARM_LDC_PC_G2 69 -#define R_ARM_ALU_SB_G0_NC 70 -#define R_ARM_ALU_SB_G0 71 -#define R_ARM_ALU_SB_G1_NC 72 -#define R_ARM_ALU_SB_G1 73 -#define R_ARM_ALU_SB_G2 74 -#define R_ARM_LDR_SB_G0 75 -#define R_ARM_LDR_SB_G1 76 -#define R_ARM_LDR_SB_G2 77 -#define R_ARM_LDRS_SB_G0 78 -#define R_ARM_LDRS_SB_G1 79 -#define R_ARM_LDRS_SB_G2 80 -#define R_ARM_LDC_SB_G0 81 -#define R_ARM_LDC_SB_G1 82 -#define R_ARM_LDC_SB_G2 83 -#define R_ARM_MOVW_BREL_NC 84 -#define R_ARM_MOVT_BREL 85 -#define R_ARM_MOVW_BREL 86 -#define R_ARM_THM_MOVW_BREL_NC 87 -#define R_ARM_THM_MOVT_BREL 88 -#define R_ARM_THM_MOVW_BREL 89 -#define R_ARM_TLS_GOTDESC 90 -#define R_ARM_TLS_CALL 91 -#define R_ARM_TLS_DESCSEQ 92 -#define R_ARM_THM_TLS_CALL 93 -#define R_ARM_PLT32_ABS 94 -#define R_ARM_GOT_ABS 95 -#define R_ARM_GOT_PREL 96 -#define R_ARM_GOT_BREL12 97 -#define R_ARM_GOTOFF12 98 -#define R_ARM_GOTRELAX 99 -#define R_ARM_GNU_VTENTRY 100 -#define R_ARM_GNU_VTINHERIT 101 -#define R_ARM_THM_PC11 102 -#define R_ARM_THM_PC9 103 -#define R_ARM_TLS_GD32 104 - -#define R_ARM_TLS_LDM32 105 - -#define R_ARM_TLS_LDO32 106 - -#define R_ARM_TLS_IE32 107 - -#define R_ARM_TLS_LE32 108 -#define R_ARM_TLS_LDO12 109 -#define R_ARM_TLS_LE12 110 -#define R_ARM_TLS_IE12GP 111 -#define R_ARM_ME_TOO 128 -#define R_ARM_THM_TLS_DESCSEQ 129 -#define R_ARM_THM_TLS_DESCSEQ16 129 -#define R_ARM_THM_TLS_DESCSEQ32 130 -#define R_ARM_THM_GOT_BREL12 131 -#define R_ARM_IRELATIVE 160 -#define R_ARM_RXPC25 249 -#define R_ARM_RSBREL32 250 -#define R_ARM_THM_RPC22 251 -#define R_ARM_RREL32 252 -#define R_ARM_RABS22 253 -#define R_ARM_RPC24 254 -#define R_ARM_RBASE 255 - -#define R_ARM_NUM 256 - - - - -#define EF_IA_64_MASKOS 0x0000000f -#define EF_IA_64_ABI64 0x00000010 -#define EF_IA_64_ARCH 0xff000000 - - -#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) -#define PT_IA_64_UNWIND (PT_LOPROC + 1) -#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12) -#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13) -#define PT_IA_64_HP_STACK (PT_LOOS + 0x14) - - -#define PF_IA_64_NORECOV 0x80000000 - - -#define SHT_IA_64_EXT (SHT_LOPROC + 0) -#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) - - -#define SHF_IA_64_SHORT 0x10000000 -#define SHF_IA_64_NORECOV 0x20000000 - - -#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) -#define DT_IA_64_NUM 1 - - -#define R_IA64_NONE 0x00 -#define R_IA64_IMM14 0x21 -#define R_IA64_IMM22 0x22 -#define R_IA64_IMM64 0x23 -#define R_IA64_DIR32MSB 0x24 -#define R_IA64_DIR32LSB 0x25 -#define R_IA64_DIR64MSB 0x26 -#define R_IA64_DIR64LSB 0x27 -#define R_IA64_GPREL22 0x2a -#define R_IA64_GPREL64I 0x2b -#define R_IA64_GPREL32MSB 0x2c -#define R_IA64_GPREL32LSB 0x2d -#define R_IA64_GPREL64MSB 0x2e -#define R_IA64_GPREL64LSB 0x2f -#define R_IA64_LTOFF22 0x32 -#define R_IA64_LTOFF64I 0x33 -#define R_IA64_PLTOFF22 0x3a -#define R_IA64_PLTOFF64I 0x3b -#define R_IA64_PLTOFF64MSB 0x3e -#define R_IA64_PLTOFF64LSB 0x3f -#define R_IA64_FPTR64I 0x43 -#define R_IA64_FPTR32MSB 0x44 -#define R_IA64_FPTR32LSB 0x45 -#define R_IA64_FPTR64MSB 0x46 -#define R_IA64_FPTR64LSB 0x47 -#define R_IA64_PCREL60B 0x48 -#define R_IA64_PCREL21B 0x49 -#define R_IA64_PCREL21M 0x4a -#define R_IA64_PCREL21F 0x4b -#define R_IA64_PCREL32MSB 0x4c -#define R_IA64_PCREL32LSB 0x4d -#define R_IA64_PCREL64MSB 0x4e -#define R_IA64_PCREL64LSB 0x4f -#define R_IA64_LTOFF_FPTR22 0x52 -#define R_IA64_LTOFF_FPTR64I 0x53 -#define R_IA64_LTOFF_FPTR32MSB 0x54 -#define R_IA64_LTOFF_FPTR32LSB 0x55 -#define R_IA64_LTOFF_FPTR64MSB 0x56 -#define R_IA64_LTOFF_FPTR64LSB 0x57 -#define R_IA64_SEGREL32MSB 0x5c -#define R_IA64_SEGREL32LSB 0x5d -#define R_IA64_SEGREL64MSB 0x5e -#define R_IA64_SEGREL64LSB 0x5f -#define R_IA64_SECREL32MSB 0x64 -#define R_IA64_SECREL32LSB 0x65 -#define R_IA64_SECREL64MSB 0x66 -#define R_IA64_SECREL64LSB 0x67 -#define R_IA64_REL32MSB 0x6c -#define R_IA64_REL32LSB 0x6d -#define R_IA64_REL64MSB 0x6e -#define R_IA64_REL64LSB 0x6f -#define R_IA64_LTV32MSB 0x74 -#define R_IA64_LTV32LSB 0x75 -#define R_IA64_LTV64MSB 0x76 -#define R_IA64_LTV64LSB 0x77 -#define R_IA64_PCREL21BI 0x79 -#define R_IA64_PCREL22 0x7a -#define R_IA64_PCREL64I 0x7b -#define R_IA64_IPLTMSB 0x80 -#define R_IA64_IPLTLSB 0x81 -#define R_IA64_COPY 0x84 -#define R_IA64_SUB 0x85 -#define R_IA64_LTOFF22X 0x86 -#define R_IA64_LDXMOV 0x87 -#define R_IA64_TPREL14 0x91 -#define R_IA64_TPREL22 0x92 -#define R_IA64_TPREL64I 0x93 -#define R_IA64_TPREL64MSB 0x96 -#define R_IA64_TPREL64LSB 0x97 -#define R_IA64_LTOFF_TPREL22 0x9a -#define R_IA64_DTPMOD64MSB 0xa6 -#define R_IA64_DTPMOD64LSB 0xa7 -#define R_IA64_LTOFF_DTPMOD22 0xaa -#define R_IA64_DTPREL14 0xb1 -#define R_IA64_DTPREL22 0xb2 -#define R_IA64_DTPREL64I 0xb3 -#define R_IA64_DTPREL32MSB 0xb4 -#define R_IA64_DTPREL32LSB 0xb5 -#define R_IA64_DTPREL64MSB 0xb6 -#define R_IA64_DTPREL64LSB 0xb7 -#define R_IA64_LTOFF_DTPREL22 0xba - - -#define EF_SH_MACH_MASK 0x1f -#define EF_SH_UNKNOWN 0x0 -#define EF_SH1 0x1 -#define EF_SH2 0x2 -#define EF_SH3 0x3 -#define EF_SH_DSP 0x4 -#define EF_SH3_DSP 0x5 -#define EF_SH4AL_DSP 0x6 -#define EF_SH3E 0x8 -#define EF_SH4 0x9 -#define EF_SH2E 0xb -#define EF_SH4A 0xc -#define EF_SH2A 0xd -#define EF_SH4_NOFPU 0x10 -#define EF_SH4A_NOFPU 0x11 -#define EF_SH4_NOMMU_NOFPU 0x12 -#define EF_SH2A_NOFPU 0x13 -#define EF_SH3_NOMMU 0x14 -#define EF_SH2A_SH4_NOFPU 0x15 -#define EF_SH2A_SH3_NOFPU 0x16 -#define EF_SH2A_SH4 0x17 -#define EF_SH2A_SH3E 0x18 - -#define R_SH_NONE 0 -#define R_SH_DIR32 1 -#define R_SH_REL32 2 -#define R_SH_DIR8WPN 3 -#define R_SH_IND12W 4 -#define R_SH_DIR8WPL 5 -#define R_SH_DIR8WPZ 6 -#define R_SH_DIR8BP 7 -#define R_SH_DIR8W 8 -#define R_SH_DIR8L 9 -#define R_SH_SWITCH16 25 -#define R_SH_SWITCH32 26 -#define R_SH_USES 27 -#define R_SH_COUNT 28 -#define R_SH_ALIGN 29 -#define R_SH_CODE 30 -#define R_SH_DATA 31 -#define R_SH_LABEL 32 -#define R_SH_SWITCH8 33 -#define R_SH_GNU_VTINHERIT 34 -#define R_SH_GNU_VTENTRY 35 -#define R_SH_TLS_GD_32 144 -#define R_SH_TLS_LD_32 145 -#define R_SH_TLS_LDO_32 146 -#define R_SH_TLS_IE_32 147 -#define R_SH_TLS_LE_32 148 -#define R_SH_TLS_DTPMOD32 149 -#define R_SH_TLS_DTPOFF32 150 -#define R_SH_TLS_TPOFF32 151 -#define R_SH_GOT32 160 -#define R_SH_PLT32 161 -#define R_SH_COPY 162 -#define R_SH_GLOB_DAT 163 -#define R_SH_JMP_SLOT 164 -#define R_SH_RELATIVE 165 -#define R_SH_GOTOFF 166 -#define R_SH_GOTPC 167 -#define R_SH_GOT20 201 -#define R_SH_GOTOFF20 202 -#define R_SH_GOTFUNCDESC 203 -#define R_SH_GOTFUNCDEST20 204 -#define R_SH_GOTOFFFUNCDESC 205 -#define R_SH_GOTOFFFUNCDEST20 206 -#define R_SH_FUNCDESC 207 -#define R_SH_FUNCDESC_VALUE 208 - -#define R_SH_NUM 256 - - - -#define R_390_NONE 0 -#define R_390_8 1 -#define R_390_12 2 -#define R_390_16 3 -#define R_390_32 4 -#define R_390_PC32 5 -#define R_390_GOT12 6 -#define R_390_GOT32 7 -#define R_390_PLT32 8 -#define R_390_COPY 9 -#define R_390_GLOB_DAT 10 -#define R_390_JMP_SLOT 11 -#define R_390_RELATIVE 12 -#define R_390_GOTOFF32 13 -#define R_390_GOTPC 14 -#define R_390_GOT16 15 -#define R_390_PC16 16 -#define R_390_PC16DBL 17 -#define R_390_PLT16DBL 18 -#define R_390_PC32DBL 19 -#define R_390_PLT32DBL 20 -#define R_390_GOTPCDBL 21 -#define R_390_64 22 -#define R_390_PC64 23 -#define R_390_GOT64 24 -#define R_390_PLT64 25 -#define R_390_GOTENT 26 -#define R_390_GOTOFF16 27 -#define R_390_GOTOFF64 28 -#define R_390_GOTPLT12 29 -#define R_390_GOTPLT16 30 -#define R_390_GOTPLT32 31 -#define R_390_GOTPLT64 32 -#define R_390_GOTPLTENT 33 -#define R_390_PLTOFF16 34 -#define R_390_PLTOFF32 35 -#define R_390_PLTOFF64 36 -#define R_390_TLS_LOAD 37 -#define R_390_TLS_GDCALL 38 - -#define R_390_TLS_LDCALL 39 - -#define R_390_TLS_GD32 40 - -#define R_390_TLS_GD64 41 - -#define R_390_TLS_GOTIE12 42 - -#define R_390_TLS_GOTIE32 43 - -#define R_390_TLS_GOTIE64 44 - -#define R_390_TLS_LDM32 45 - -#define R_390_TLS_LDM64 46 - -#define R_390_TLS_IE32 47 - -#define R_390_TLS_IE64 48 - -#define R_390_TLS_IEENT 49 - -#define R_390_TLS_LE32 50 - -#define R_390_TLS_LE64 51 - -#define R_390_TLS_LDO32 52 - -#define R_390_TLS_LDO64 53 - -#define R_390_TLS_DTPMOD 54 -#define R_390_TLS_DTPOFF 55 -#define R_390_TLS_TPOFF 56 - -#define R_390_20 57 -#define R_390_GOT20 58 -#define R_390_GOTPLT20 59 -#define R_390_TLS_GOTIE20 60 - - -#define R_390_NUM 61 - - - -#define R_CRIS_NONE 0 -#define R_CRIS_8 1 -#define R_CRIS_16 2 -#define R_CRIS_32 3 -#define R_CRIS_8_PCREL 4 -#define R_CRIS_16_PCREL 5 -#define R_CRIS_32_PCREL 6 -#define R_CRIS_GNU_VTINHERIT 7 -#define R_CRIS_GNU_VTENTRY 8 -#define R_CRIS_COPY 9 -#define R_CRIS_GLOB_DAT 10 -#define R_CRIS_JUMP_SLOT 11 -#define R_CRIS_RELATIVE 12 -#define R_CRIS_16_GOT 13 -#define R_CRIS_32_GOT 14 -#define R_CRIS_16_GOTPLT 15 -#define R_CRIS_32_GOTPLT 16 -#define R_CRIS_32_GOTREL 17 -#define R_CRIS_32_PLT_GOTREL 18 -#define R_CRIS_32_PLT_PCREL 19 - -#define R_CRIS_NUM 20 - - - -#define R_X86_64_NONE 0 -#define R_X86_64_64 1 -#define R_X86_64_PC32 2 -#define R_X86_64_GOT32 3 -#define R_X86_64_PLT32 4 -#define R_X86_64_COPY 5 -#define R_X86_64_GLOB_DAT 6 -#define R_X86_64_JUMP_SLOT 7 -#define R_X86_64_RELATIVE 8 -#define R_X86_64_GOTPCREL 9 - -#define R_X86_64_32 10 -#define R_X86_64_32S 11 -#define R_X86_64_16 12 -#define R_X86_64_PC16 13 -#define R_X86_64_8 14 -#define R_X86_64_PC8 15 -#define R_X86_64_DTPMOD64 16 -#define R_X86_64_DTPOFF64 17 -#define R_X86_64_TPOFF64 18 -#define R_X86_64_TLSGD 19 - -#define R_X86_64_TLSLD 20 - -#define R_X86_64_DTPOFF32 21 -#define R_X86_64_GOTTPOFF 22 - -#define R_X86_64_TPOFF32 23 -#define R_X86_64_PC64 24 -#define R_X86_64_GOTOFF64 25 -#define R_X86_64_GOTPC32 26 -#define R_X86_64_GOT64 27 -#define R_X86_64_GOTPCREL64 28 -#define R_X86_64_GOTPC64 29 -#define R_X86_64_GOTPLT64 30 -#define R_X86_64_PLTOFF64 31 -#define R_X86_64_SIZE32 32 -#define R_X86_64_SIZE64 33 - -#define R_X86_64_GOTPC32_TLSDESC 34 -#define R_X86_64_TLSDESC_CALL 35 - -#define R_X86_64_TLSDESC 36 -#define R_X86_64_IRELATIVE 37 -#define R_X86_64_RELATIVE64 38 -#define R_X86_64_GOTPCRELX 41 -#define R_X86_64_REX_GOTPCRELX 42 -#define R_X86_64_NUM 43 - - - -#define R_MN10300_NONE 0 -#define R_MN10300_32 1 -#define R_MN10300_16 2 -#define R_MN10300_8 3 -#define R_MN10300_PCREL32 4 -#define R_MN10300_PCREL16 5 -#define R_MN10300_PCREL8 6 -#define R_MN10300_GNU_VTINHERIT 7 -#define R_MN10300_GNU_VTENTRY 8 -#define R_MN10300_24 9 -#define R_MN10300_GOTPC32 10 -#define R_MN10300_GOTPC16 11 -#define R_MN10300_GOTOFF32 12 -#define R_MN10300_GOTOFF24 13 -#define R_MN10300_GOTOFF16 14 -#define R_MN10300_PLT32 15 -#define R_MN10300_PLT16 16 -#define R_MN10300_GOT32 17 -#define R_MN10300_GOT24 18 -#define R_MN10300_GOT16 19 -#define R_MN10300_COPY 20 -#define R_MN10300_GLOB_DAT 21 -#define R_MN10300_JMP_SLOT 22 -#define R_MN10300_RELATIVE 23 - -#define R_MN10300_NUM 24 - - - -#define R_M32R_NONE 0 -#define R_M32R_16 1 -#define R_M32R_32 2 -#define R_M32R_24 3 -#define R_M32R_10_PCREL 4 -#define R_M32R_18_PCREL 5 -#define R_M32R_26_PCREL 6 -#define R_M32R_HI16_ULO 7 -#define R_M32R_HI16_SLO 8 -#define R_M32R_LO16 9 -#define R_M32R_SDA16 10 -#define R_M32R_GNU_VTINHERIT 11 -#define R_M32R_GNU_VTENTRY 12 - -#define R_M32R_16_RELA 33 -#define R_M32R_32_RELA 34 -#define R_M32R_24_RELA 35 -#define R_M32R_10_PCREL_RELA 36 -#define R_M32R_18_PCREL_RELA 37 -#define R_M32R_26_PCREL_RELA 38 -#define R_M32R_HI16_ULO_RELA 39 -#define R_M32R_HI16_SLO_RELA 40 -#define R_M32R_LO16_RELA 41 -#define R_M32R_SDA16_RELA 42 -#define R_M32R_RELA_GNU_VTINHERIT 43 -#define R_M32R_RELA_GNU_VTENTRY 44 -#define R_M32R_REL32 45 - -#define R_M32R_GOT24 48 -#define R_M32R_26_PLTREL 49 -#define R_M32R_COPY 50 -#define R_M32R_GLOB_DAT 51 -#define R_M32R_JMP_SLOT 52 -#define R_M32R_RELATIVE 53 -#define R_M32R_GOTOFF 54 -#define R_M32R_GOTPC24 55 -#define R_M32R_GOT16_HI_ULO 56 - -#define R_M32R_GOT16_HI_SLO 57 - -#define R_M32R_GOT16_LO 58 -#define R_M32R_GOTPC_HI_ULO 59 - -#define R_M32R_GOTPC_HI_SLO 60 - -#define R_M32R_GOTPC_LO 61 - -#define R_M32R_GOTOFF_HI_ULO 62 - -#define R_M32R_GOTOFF_HI_SLO 63 - -#define R_M32R_GOTOFF_LO 64 -#define R_M32R_NUM 256 - -#define R_MICROBLAZE_NONE 0 -#define R_MICROBLAZE_32 1 -#define R_MICROBLAZE_32_PCREL 2 -#define R_MICROBLAZE_64_PCREL 3 -#define R_MICROBLAZE_32_PCREL_LO 4 -#define R_MICROBLAZE_64 5 -#define R_MICROBLAZE_32_LO 6 -#define R_MICROBLAZE_SRO32 7 -#define R_MICROBLAZE_SRW32 8 -#define R_MICROBLAZE_64_NONE 9 -#define R_MICROBLAZE_32_SYM_OP_SYM 10 -#define R_MICROBLAZE_GNU_VTINHERIT 11 -#define R_MICROBLAZE_GNU_VTENTRY 12 -#define R_MICROBLAZE_GOTPC_64 13 -#define R_MICROBLAZE_GOT_64 14 -#define R_MICROBLAZE_PLT_64 15 -#define R_MICROBLAZE_REL 16 -#define R_MICROBLAZE_JUMP_SLOT 17 -#define R_MICROBLAZE_GLOB_DAT 18 -#define R_MICROBLAZE_GOTOFF_64 19 -#define R_MICROBLAZE_GOTOFF_32 20 -#define R_MICROBLAZE_COPY 21 -#define R_MICROBLAZE_TLS 22 -#define R_MICROBLAZE_TLSGD 23 -#define R_MICROBLAZE_TLSLD 24 -#define R_MICROBLAZE_TLSDTPMOD32 25 -#define R_MICROBLAZE_TLSDTPREL32 26 -#define R_MICROBLAZE_TLSDTPREL64 27 -#define R_MICROBLAZE_TLSGOTTPREL32 28 -#define R_MICROBLAZE_TLSTPREL32 29 - -#define DT_NIOS2_GP 0x70000002 - -#define R_NIOS2_NONE 0 -#define R_NIOS2_S16 1 -#define R_NIOS2_U16 2 -#define R_NIOS2_PCREL16 3 -#define R_NIOS2_CALL26 4 -#define R_NIOS2_IMM5 5 -#define R_NIOS2_CACHE_OPX 6 -#define R_NIOS2_IMM6 7 -#define R_NIOS2_IMM8 8 -#define R_NIOS2_HI16 9 -#define R_NIOS2_LO16 10 -#define R_NIOS2_HIADJ16 11 -#define R_NIOS2_BFD_RELOC_32 12 -#define R_NIOS2_BFD_RELOC_16 13 -#define R_NIOS2_BFD_RELOC_8 14 -#define R_NIOS2_GPREL 15 -#define R_NIOS2_GNU_VTINHERIT 16 -#define R_NIOS2_GNU_VTENTRY 17 -#define R_NIOS2_UJMP 18 -#define R_NIOS2_CJMP 19 -#define R_NIOS2_CALLR 20 -#define R_NIOS2_ALIGN 21 -#define R_NIOS2_GOT16 22 -#define R_NIOS2_CALL16 23 -#define R_NIOS2_GOTOFF_LO 24 -#define R_NIOS2_GOTOFF_HA 25 -#define R_NIOS2_PCREL_LO 26 -#define R_NIOS2_PCREL_HA 27 -#define R_NIOS2_TLS_GD16 28 -#define R_NIOS2_TLS_LDM16 29 -#define R_NIOS2_TLS_LDO16 30 -#define R_NIOS2_TLS_IE16 31 -#define R_NIOS2_TLS_LE16 32 -#define R_NIOS2_TLS_DTPMOD 33 -#define R_NIOS2_TLS_DTPREL 34 -#define R_NIOS2_TLS_TPREL 35 -#define R_NIOS2_COPY 36 -#define R_NIOS2_GLOB_DAT 37 -#define R_NIOS2_JUMP_SLOT 38 -#define R_NIOS2_RELATIVE 39 -#define R_NIOS2_GOTOFF 40 -#define R_NIOS2_CALL26_NOAT 41 -#define R_NIOS2_GOT_LO 42 -#define R_NIOS2_GOT_HA 43 -#define R_NIOS2_CALL_LO 44 -#define R_NIOS2_CALL_HA 45 - -#define R_OR1K_NONE 0 -#define R_OR1K_32 1 -#define R_OR1K_16 2 -#define R_OR1K_8 3 -#define R_OR1K_LO_16_IN_INSN 4 -#define R_OR1K_HI_16_IN_INSN 5 -#define R_OR1K_INSN_REL_26 6 -#define R_OR1K_GNU_VTENTRY 7 -#define R_OR1K_GNU_VTINHERIT 8 -#define R_OR1K_32_PCREL 9 -#define R_OR1K_16_PCREL 10 -#define R_OR1K_8_PCREL 11 -#define R_OR1K_GOTPC_HI16 12 -#define R_OR1K_GOTPC_LO16 13 -#define R_OR1K_GOT16 14 -#define R_OR1K_PLT26 15 -#define R_OR1K_GOTOFF_HI16 16 -#define R_OR1K_GOTOFF_LO16 17 -#define R_OR1K_COPY 18 -#define R_OR1K_GLOB_DAT 19 -#define R_OR1K_JMP_SLOT 20 -#define R_OR1K_RELATIVE 21 -#define R_OR1K_TLS_GD_HI16 22 -#define R_OR1K_TLS_GD_LO16 23 -#define R_OR1K_TLS_LDM_HI16 24 -#define R_OR1K_TLS_LDM_LO16 25 -#define R_OR1K_TLS_LDO_HI16 26 -#define R_OR1K_TLS_LDO_LO16 27 -#define R_OR1K_TLS_IE_HI16 28 -#define R_OR1K_TLS_IE_LO16 29 -#define R_OR1K_TLS_LE_HI16 30 -#define R_OR1K_TLS_LE_LO16 31 -#define R_OR1K_TLS_TPOFF 32 -#define R_OR1K_TLS_DTPOFF 33 -#define R_OR1K_TLS_DTPMOD 34 - -#define R_BPF_NONE 0 -#define R_BPF_MAP_FD 1 - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/src/CLOUD/input.cpp b/src/CLOUD/input.cpp index 6d4d0a22..d0c50f0d 100644 --- a/src/CLOUD/input.cpp +++ b/src/CLOUD/input.cpp @@ -8,7 +8,7 @@ #include "input.hpp" #include #include "../KKdLib/vec.hpp" -#include "../CRE/timer.h" +#include "../CRE/timer.hpp" #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS #include @@ -19,12 +19,11 @@ vec2d input_rotate; double_t input_roll; bool input_reset; bool input_reset_mouse_position; -bool input_shaders_reload; bool input_locked; extern bool close; extern lock render_lock; -extern timer render_timer; +extern timer* render_timer; extern HWND window_handle; extern ImGuiContext* imgui_context; extern lock imgui_context_lock; @@ -43,148 +42,143 @@ namespace Input { int32_t mods; }; - std::map keys; - std::map mouse_buttons; + std::vector keys; + std::vector mouse_buttons; POINT pos; - std::map keys_prev; - std::map mouse_buttons_prev; + std::vector keys_prev; + std::vector mouse_buttons_prev; POINT pos_prev; + static bool is_key_mod(int32_t key); + static bool is_key_numpad(int32_t key); static void KeyboardCallback(GLFWwindow* window, int32_t key, int32_t scancode, int32_t action, int32_t mods); static void MouseButtonCallback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods); + static Key* vector_Key_find(std::vector& keys, int32_t key); + static MouseButton* vector_MouseButton_find( + std::vector& mouse_buttons, int32_t button); bool IsKeyDown(int32_t key, int32_t mods) { - auto elem = keys.find(key); - if (elem != keys.end()) - if (elem->second.mods == mods) - return elem->second.action != GLFW_RELEASE; + Key* k = vector_Key_find(keys, key); + if (k && (mods == -1 || k->mods == mods)) + return k->action != GLFW_RELEASE; return false; } bool IsKeyUp(int32_t key, int32_t mods) { - auto elem = keys.find(key); - if (elem != keys.end()) - if (elem->second.mods == mods) - return elem->second.action == GLFW_RELEASE; + Key* k = vector_Key_find(keys, key); + if (k && (mods == -1 || k->mods == mods)) + return k->action == GLFW_RELEASE; return false; } bool IsKeyTapped(int32_t key, int32_t mods) { - auto elem = keys.find(key); - auto elem_prev = keys_prev.find(key); - if (elem != keys.end()) - if (elem_prev != keys_prev.end()) { - if (elem->second.mods == mods && elem_prev->second.mods == mods) - return elem->second.action != GLFW_RELEASE && elem_prev->second.action == GLFW_RELEASE; + Key* k = vector_Key_find(keys, key); + Key* k_prev = vector_Key_find(keys_prev, key); + if (k) + if (k_prev) { + if (mods == -1 || (k->mods == mods && k_prev->mods == mods)) + return k->action != GLFW_RELEASE && k_prev->action == GLFW_RELEASE; } else { - if (elem->second.mods == mods) - return elem->second.action != GLFW_RELEASE; + if (mods == -1 || k->mods == mods) + return k->action != GLFW_RELEASE; } return false; } bool IsKeyReleased(int32_t key, int32_t mods) { - auto elem = keys.find(key); - auto elem_prev = keys_prev.find(key); - if (elem != keys.end()) - if (elem_prev != keys_prev.end()) { - if (elem->second.mods == mods && elem_prev->second.mods == mods) - return elem->second.action == GLFW_RELEASE && elem_prev->second.action != GLFW_RELEASE; + Key* k = vector_Key_find(keys, key); + Key* k_prev = vector_Key_find(keys_prev, key); + if (k) + if (k_prev) { + if ((k->mods == mods && k_prev->mods == mods)) + return k->action == GLFW_RELEASE && k_prev->action != GLFW_RELEASE; } else { - if (elem->second.mods == mods) - return elem->second.action == GLFW_RELEASE; + if (mods == -1 || k->mods == mods) + return k->action == GLFW_RELEASE; } return false; } bool IsMouseButtonDown(int32_t button, int32_t mods) { - auto elem = mouse_buttons.find(button); - if (elem != mouse_buttons.end()) - if (elem->second.mods == mods) - return elem->second.action != GLFW_RELEASE; + MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); + if (mb && (mods == -1 || mb->mods == mods)) + return mb->action != GLFW_RELEASE; return false; } bool IsMouseButtonUp(int32_t button, int32_t mods) { - auto elem = mouse_buttons.find(button); - if (elem != mouse_buttons.end()) - if (elem->second.mods == mods) - return elem->second.action == GLFW_RELEASE; + MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); + if (mb && (mods == -1 || mb->mods == mods)) + return mb->action == GLFW_RELEASE; return false; } bool IsMouseButtonTapped(int32_t button, int32_t mods) { - auto elem = mouse_buttons.find(button); - auto elem_prev = mouse_buttons_prev.find(button); - if (elem != mouse_buttons.end()) - if (elem_prev != mouse_buttons_prev.end()) { - if (elem->second.mods == mods && elem_prev->second.mods == mods) - return elem->second.action != GLFW_RELEASE && elem_prev->second.action == GLFW_RELEASE; + MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); + MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); + if (mb) + if (mb_prev) { + if ((mods == -1 || mb->mods == mods && mb_prev->mods == mods)) + return mb->action != GLFW_RELEASE && mb_prev->action == GLFW_RELEASE; } else { - if (elem->second.mods == mods) - return elem->second.action != GLFW_RELEASE; + if (mods == -1 || mb->mods == mods) + return mb->action != GLFW_RELEASE; } return false; } bool IsMouseButtonReleased(int32_t button, int32_t mods) { - auto elem = mouse_buttons.find(button); - auto elem_prev = mouse_buttons_prev.find(button); - if (elem != mouse_buttons.end()) - if (elem_prev != mouse_buttons_prev.end()) { - if (elem->second.mods == mods && elem_prev->second.mods == mods) - return elem->second.action == GLFW_RELEASE && elem_prev->second.action != GLFW_RELEASE; + MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); + MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); + if (mb) + if (mb_prev) { + if ((mods == -1 || mb->mods == mods && mb_prev->mods == mods)) + return mb->action == GLFW_RELEASE && mb_prev->action != GLFW_RELEASE; } else { - if (elem->second.mods == mods) - return elem->second.action == GLFW_RELEASE; + if (mods == -1 || mb->mods == mods) + return mb->action == GLFW_RELEASE; } return true; } bool WasKeyDown(int32_t key, int32_t mods) { - auto elem_prev = keys_prev.find(key); - if (elem_prev != keys_prev.end()) - if (elem_prev->second.mods == mods) - return elem_prev->second.action != GLFW_RELEASE; + Key* k_prev = vector_Key_find(keys_prev, key); + if (k_prev && (mods == -1 || k_prev->mods == mods)) + return k_prev->action != GLFW_RELEASE; return false; } bool WasKeyUp(int32_t key, int32_t mods) { - auto elem_prev = keys_prev.find(key); - if (elem_prev != keys_prev.end()) - if (elem_prev->second.mods == mods) - return elem_prev->second.action == GLFW_RELEASE; + Key* k_prev = vector_Key_find(keys_prev, key); + if (k_prev && (mods == -1 || k_prev->mods == mods)) + return k_prev->action == GLFW_RELEASE; return true; } bool WasMouseButtonDown(int32_t button, int32_t mods) { - auto elem_prev = mouse_buttons_prev.find(button); - if (elem_prev != mouse_buttons_prev.end()) - if (elem_prev->second.mods == mods) - return elem_prev->second.action != GLFW_RELEASE; + MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); + if (mb_prev && (mods == -1 || mb_prev->mods == mods)) + return mb_prev->action != GLFW_RELEASE; return true; } bool WasMouseButtonUp(int32_t button, int32_t mods) { - auto elem_prev = mouse_buttons_prev.find(button); - if (elem_prev != mouse_buttons_prev.end()) - if (elem_prev->second.mods == mods) - return elem_prev->second.action == GLFW_RELEASE; + MouseButton* mb_prev = vector_MouseButton_find(mouse_buttons_prev, button); + if (mb_prev && (mods == -1 || mb_prev->mods == mods)) + return mb_prev->action == GLFW_RELEASE; return true; } void EndFrame() { - for (auto& i : keys) - keys_prev.insert_or_assign(i.first, i.second); - for (auto& i : mouse_buttons) - mouse_buttons_prev.insert_or_assign(i.first, i.second); + keys_prev = keys; + mouse_buttons_prev = mouse_buttons; } void NewFrame() { @@ -204,113 +198,132 @@ namespace Input { if (!window_handle || window_handle != GetForegroundWindow()) return; - double_t freq = timer_get_freq(&render_timer); - double_t freq_hist = timer_get_freq_hist(&render_timer); + double_t freq = render_timer->get_freq(); + double_t freq_hist = render_timer->get_freq_hist(); double_t frame_speed = freq / freq_hist; input_locked = false; classes_process_input(classes, classes_count); - if (!input_locked) { - double_t speed = input_movement_speed; - double_t speed_fast = input_movement_speed * 10.0; - double_t speed_slow = input_movement_speed / 10.0; - speed *= frame_speed; - speed_fast *= frame_speed; - speed_slow *= frame_speed; - - if (IsKeyDown(GLFW_KEY_W) || IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move.x += speed; - else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_SHIFT)) - input_move.x += speed_fast; - else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL)) - input_move.x += speed_slow; - - if (IsKeyDown(GLFW_KEY_S) || IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move.x -= speed; - else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_SHIFT)) - input_move.x -= speed_fast; - else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL)) - input_move.x -= speed_slow; - - if (IsKeyDown(GLFW_KEY_A) || IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move.y -= speed; - else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_SHIFT)) - input_move.y -= speed_fast; - else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL)) - input_move.y -= speed_slow; - - if (IsKeyDown(GLFW_KEY_D) || IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_move.y += speed; - else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_SHIFT)) - input_move.y += speed_fast; - else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL)) - input_move.y += speed_slow; - - speed = input_movement_speed; - speed_fast = input_movement_speed * 2.0; - speed_slow = input_movement_speed / 2.0; - speed *= frame_speed; - speed_fast *= frame_speed; - speed_slow *= frame_speed; - speed *= freq / freq_hist; - speed_fast *= freq / freq_hist; - speed_slow *= freq / freq_hist; - speed *= 10.0; - speed_fast *= 10.0; - speed_slow *= 10.0; - - if (IsKeyDown(GLFW_KEY_UP) || IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate.y += speed; - else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_SHIFT)) - input_rotate.y += speed_fast; - else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL)) - input_rotate.y += speed_slow; - - if (IsKeyDown(GLFW_KEY_DOWN) || IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate.y -= speed; - else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_SHIFT)) - input_rotate.y -= speed_fast; - else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL)) - input_rotate.y -= speed_slow; - - if (IsKeyDown(GLFW_KEY_LEFT) || IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate.x -= speed; - else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_SHIFT)) - input_rotate.x -= speed_fast; - else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL)) - input_rotate.x -= speed_slow; - - if (IsKeyDown(GLFW_KEY_RIGHT) || IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_rotate.x += speed; - else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_SHIFT)) - input_rotate.x += speed_fast; - else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL)) - input_rotate.x += speed_slow; - - if (IsKeyDown(GLFW_KEY_Q) || IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_roll += speed; - else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_SHIFT)) - input_roll += speed_fast; - else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL)) - input_roll += speed_slow; - - if (IsKeyDown(GLFW_KEY_E) || IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) - input_roll += speed; - else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_SHIFT)) - input_roll += speed_fast; - else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL)) - input_roll += speed_slow; - - if (IsKeyDown(GLFW_KEY_R, GLFW_MOD_CONTROL)) - input_shaders_reload = true; - else if (IsKeyDown(GLFW_KEY_R)) - input_reset = true; + if (input_locked) { + input_reset_mouse_position = true; + return; } - lock_lock(&imgui_context_lock); - ImGui::SetCurrentContext(imgui_context); - if (!ImGui::GetIO().WantCaptureMouse && Input::IsMouseButtonDown(GLFW_MOUSE_BUTTON_MIDDLE)) { + double_t speed = input_movement_speed; + double_t speed_fast = input_movement_speed * 10.0; + double_t speed_slow = input_movement_speed / 10.0; + speed *= frame_speed; + speed_fast *= frame_speed; + speed_slow *= frame_speed; + + if (IsKeyDown(GLFW_KEY_W) || IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_move.x += speed; + else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_SHIFT)) + input_move.x += speed_fast; + else if (IsKeyDown(GLFW_KEY_W, GLFW_MOD_CONTROL)) + input_move.x += speed_slow; + else if (IsKeyDown(GLFW_KEY_W, -1)) + input_move.x += speed; + + if (IsKeyDown(GLFW_KEY_S) || IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_move.x -= speed; + else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_SHIFT)) + input_move.x -= speed_fast; + else if (IsKeyDown(GLFW_KEY_S, GLFW_MOD_CONTROL)) + input_move.x -= speed_slow; + else if (IsKeyDown(GLFW_KEY_S, -1)) + input_move.x -= speed; + + if (IsKeyDown(GLFW_KEY_A) || IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_move.y -= speed; + else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_SHIFT)) + input_move.y -= speed_fast; + else if (IsKeyDown(GLFW_KEY_A, GLFW_MOD_CONTROL)) + input_move.y -= speed_slow; + else if (IsKeyDown(GLFW_KEY_A, -1)) + input_move.y -= speed; + + if (IsKeyDown(GLFW_KEY_D) || IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_move.y += speed; + else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_SHIFT)) + input_move.y += speed_fast; + else if (IsKeyDown(GLFW_KEY_D, GLFW_MOD_CONTROL)) + input_move.y += speed_slow; + else if (IsKeyDown(GLFW_KEY_D, -1)) + input_move.y += speed; + + speed = input_movement_speed; + speed_fast = input_movement_speed * 2.0; + speed_slow = input_movement_speed / 2.0; + speed *= frame_speed; + speed_fast *= frame_speed; + speed_slow *= frame_speed; + speed *= freq / freq_hist; + speed_fast *= freq / freq_hist; + speed_slow *= freq / freq_hist; + speed *= 10.0; + speed_fast *= 10.0; + speed_slow *= 10.0; + + if (IsKeyDown(GLFW_KEY_UP) || IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_rotate.y += speed; + else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_SHIFT)) + input_rotate.y += speed_fast; + else if (IsKeyDown(GLFW_KEY_UP, GLFW_MOD_CONTROL)) + input_rotate.y += speed_slow; + else if (IsKeyDown(GLFW_KEY_UP, -1)) + input_rotate.y += speed; + + if (IsKeyDown(GLFW_KEY_DOWN) || IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_rotate.y -= speed; + else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_SHIFT)) + input_rotate.y -= speed_fast; + else if (IsKeyDown(GLFW_KEY_DOWN, GLFW_MOD_CONTROL)) + input_rotate.y -= speed_slow; + else if (IsKeyDown(GLFW_KEY_DOWN, -1)) + input_rotate.y -= speed; + + if (IsKeyDown(GLFW_KEY_LEFT) || IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_rotate.x -= speed; + else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_SHIFT)) + input_rotate.x -= speed_fast; + else if (IsKeyDown(GLFW_KEY_LEFT, GLFW_MOD_CONTROL)) + input_rotate.x -= speed_slow; + else if (IsKeyDown(GLFW_KEY_LEFT, -1)) + input_rotate.x -= speed; + + if (IsKeyDown(GLFW_KEY_RIGHT) || IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_rotate.x += speed; + else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_SHIFT)) + input_rotate.x += speed_fast; + else if (IsKeyDown(GLFW_KEY_RIGHT, GLFW_MOD_CONTROL)) + input_rotate.x += speed_slow; + else if (IsKeyDown(GLFW_KEY_RIGHT, -1)) + input_rotate.x += speed; + + if (IsKeyDown(GLFW_KEY_Q) || IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_roll += speed; + else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_SHIFT)) + input_roll += speed_fast; + else if (IsKeyDown(GLFW_KEY_Q, GLFW_MOD_CONTROL)) + input_roll += speed_slow; + else if (IsKeyDown(GLFW_KEY_Q, -1)) + input_roll += speed; + + if (IsKeyDown(GLFW_KEY_E) || IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) + input_roll -= speed; + else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_SHIFT)) + input_roll -= speed_fast; + else if (IsKeyDown(GLFW_KEY_E, GLFW_MOD_CONTROL)) + input_roll -= speed_slow; + else if (IsKeyDown(GLFW_KEY_E, -1)) + input_roll -= speed; + + if (IsKeyDown(GLFW_KEY_R)) + input_reset = true; + + if (IsMouseButtonDown(GLFW_MOUSE_BUTTON_MIDDLE, -1)) { if (!input_reset_mouse_position) { input_rotate.y += ((double_t)pos_prev.y - (double_t)pos.y) * input_rotation_sensitivity; input_rotate.x += ((double_t)pos.x - (double_t)pos_prev.x) * input_rotation_sensitivity; @@ -319,7 +332,6 @@ namespace Input { } else input_reset_mouse_position = true; - lock_unlock(&imgui_context_lock); } void SetInputs(GLFWwindow* window) { @@ -327,21 +339,127 @@ namespace Input { glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)MouseButtonCallback); } + static bool is_key_mod(int32_t key) { + switch (key) { + case GLFW_KEY_LEFT_SHIFT: + case GLFW_KEY_LEFT_CONTROL: + case GLFW_KEY_LEFT_ALT: + case GLFW_KEY_LEFT_SUPER: + case GLFW_KEY_RIGHT_SHIFT: + case GLFW_KEY_RIGHT_CONTROL: + case GLFW_KEY_RIGHT_ALT: + case GLFW_KEY_RIGHT_SUPER: + return true; + default: + return false; + } + } + + static bool is_key_numpad(int32_t key) { + switch (key) { + case GLFW_KEY_KP_0: + case GLFW_KEY_KP_1: + case GLFW_KEY_KP_2: + case GLFW_KEY_KP_3: + case GLFW_KEY_KP_4: + case GLFW_KEY_KP_5: + case GLFW_KEY_KP_6: + case GLFW_KEY_KP_7: + case GLFW_KEY_KP_8: + case GLFW_KEY_KP_9: + return true; + default: + return false; + } + } + static void KeyboardCallback(GLFWwindow* window, int32_t key, int32_t scancode, int32_t action, int32_t mods) { - auto elem = keys.find(key); - if (elem != keys.end()) - elem->second = { key, scancode, action, mods }; + if (mods & GLFW_MOD_CAPS_LOCK) + mods &= ~GLFW_MOD_CAPS_LOCK; + + if (mods & GLFW_MOD_NUM_LOCK) + mods &= ~GLFW_MOD_NUM_LOCK; + + bool is_mod = false; + switch (key) { + case GLFW_KEY_LEFT_SHIFT: + case GLFW_KEY_RIGHT_SHIFT: + mods = GLFW_MOD_SHIFT; + is_mod = true; + break; + case GLFW_KEY_LEFT_CONTROL: + case GLFW_KEY_RIGHT_CONTROL: + mods = GLFW_MOD_CONTROL; + is_mod = true; + break; + case GLFW_KEY_LEFT_ALT: + case GLFW_KEY_RIGHT_ALT: + mods = GLFW_MOD_ALT; + is_mod = true; + break; + case GLFW_KEY_LEFT_SUPER: + case GLFW_KEY_RIGHT_SUPER: + mods = GLFW_MOD_SUPER; + is_mod = true; + break; + case GLFW_MOD_CAPS_LOCK: + mods = 0; + break; + case GLFW_KEY_NUM_LOCK: + mods = 0; + break; + } + + if (is_mod) { + if (action != GLFW_RELEASE) { + for (Key& i : keys) + if (!is_key_mod(i.key)) + i.mods |= mods; + + for (MouseButton& i : mouse_buttons) + i.mods |= mods; + } + else { + mods = ~mods; + for (Key& i : keys) + if (!is_key_mod(i.key)) + i.mods &= mods; + + for (MouseButton& i : mouse_buttons) + i.mods &= mods; + } + mods = 0; + } + + Key* k = vector_Key_find(keys, key); + if (k) + *k = { key, scancode, action, mods }; else - keys.insert({ key, { key, scancode, action, mods } }); + keys.push_back({ key, scancode, action, mods }); } static void MouseButtonCallback(GLFWwindow* window, int32_t button, int32_t action, int32_t mods) { - auto elem = mouse_buttons.find(button); - if (elem != mouse_buttons.end()) - elem->second = { button, action, mods }; + MouseButton* mb = vector_MouseButton_find(mouse_buttons, button); + if (mb) + *mb = { button, action, mods }; else - mouse_buttons.insert({ button, { button, action, mods } }); + mouse_buttons.push_back({ button, action, mods }); + } + + static Key* vector_Key_find(std::vector& keys, int32_t key) { + for (Key& i : keys) + if (i.key == key) + return &i; + return 0; + } + + static MouseButton* vector_MouseButton_find( + std::vector& mouse_buttons, int32_t button) { + for (MouseButton& i : mouse_buttons) + if (i.button == button) + return &i; + return 0; } }; diff --git a/src/CLOUD/input.hpp b/src/CLOUD/input.hpp index 9b0c352e..15e57dd1 100644 --- a/src/CLOUD/input.hpp +++ b/src/CLOUD/input.hpp @@ -5,7 +5,7 @@ #pragma once -#include "shared.h" +#include "shared.hpp" #include namespace Input { diff --git a/src/CLOUD/lz.c b/src/CLOUD/lz.c deleted file mode 100644 index f245fd96..00000000 --- a/src/CLOUD/lz.c +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright (C) 2014 Hykem -// Licensed under the terms of the GNU GPL, version 3 -// http://www.gnu.org/licenses/gpl-3.0.txt - -#include "lz.h" - -void decode_range(unsigned int *range, unsigned int *code, unsigned char **src) -{ - if (!((*range) >> 24)) - { - (*range) <<= 8; - *code = ((*code) << 8) + (*src)++[5]; - } -} - -int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c) -{ - decode_range(range, code, src); - - unsigned int val = ((*range) >> 8) * (*c); - - *c -= ((*c) >> 3); - if (index) (*index) <<= 1; - - if (*code < val) - { - *range = val; - *c += 31; - if (index) (*index)++; - return 1; - } - else - { - *code -= val; - *range -= val; - return 0; - } -} - -int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src) -{ - int i = 1; - - if (index >= 3) - { - decode_bit(range, code, &i, src, ptr + 0x18); - if (index >= 4) - { - decode_bit(range, code, &i, src, ptr + 0x18); - if (index >= 5) - { - decode_range(range, code, src); - for (; index >= 5; index--) - { - i <<= 1; - (*range) >>= 1; - if (*code < *range) - i++; - else - (*code) -= *range; - } - } - } - } - - *bit_flag = decode_bit(range, code, &i, src, ptr); - - if (index >= 1) - { - decode_bit(range, code, &i, src, ptr + 0x8); - if (index >= 2) - { - decode_bit(range, code, &i, src, ptr + 0x10); - } - } - - return i; -} - -int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src) -{ - int i = 1; - index /= 8; - - if (index >= 3) - { - decode_bit(range, code, &i, src, ptr + 4); - if (index >= 4) - { - decode_bit(range, code, &i, src, ptr + 4); - if (index >= 5) - { - decode_range(range, code, src); - for (; index >= 5; index--) - { - i <<= 1; - (*range) >>= 1; - if (*code < *range) - i++; - else - (*code) -= *range; - } - } - } - } - - *bit_flag = decode_bit(range, code, &i, src, ptr); - - if (index >= 1) - { - decode_bit(range, code, &i, src, ptr + 1); - if (index >= 2) - { - decode_bit(range, code, &i, src, ptr + 2); - } - } - - return i; -} - -int decompress(unsigned char* out, unsigned char* in, unsigned int size) -{ - int result; - - unsigned char tmp[0xCC8]; - - int offset = 0; - int bit_flag = 0; - int data_length = 0; - int data_offset = 0; - - unsigned char* tmp_sect1, * tmp_sect2, * tmp_sect3; - unsigned char* buf_start, * buf_end; - unsigned char prev = 0; - - unsigned char* start = out; - unsigned char* end = (out + size); - unsigned char head = in[0]; - - unsigned int range = 0xFFFFFFFF; - unsigned int code = (in[1] << 24) | (in[2] << 16) | (in[3] << 8) | in[4]; - - if (head > 0x80) { // Check if we have a valid starting byte. - // The dictionary header is invalid, the data is not compressed. - result = -1; - if (code <= size) { - memcpy(out, in + 5, code); - result = (int)(start - out); - } - return result; - } - - // Set up a temporary buffer (sliding window). - memset(tmp, 0x80, 0xCA8); - while (1) { - // Start reading at 0xB68. - tmp_sect1 = tmp + offset + 0xB68; - if (!decode_bit(&range, &code, 0, &in, tmp_sect1)) { // Raw char. - // Adjust offset and check for stream end. - if (offset > 0) offset--; - if (start == end) return (int)(start - out); - - // Locate first section. - int sect = (((((((int)(start - out)) & 7) << 8) + prev) >> head) & 7) * 0xFF - 1; - tmp_sect1 = tmp + sect; - int index = 1; - - // Read, decode and write back. - do { - decode_bit(&range, &code, &index, &in, tmp_sect1 + index); - } while ((index >> 8) == 0); - - // Save index. - *start++ = index; - } - else { // Compressed char stream. - int index = -1; - - // Identify the data length bit field. - do { - tmp_sect1 += 8; - bit_flag = decode_bit(&range, &code, 0, &in, tmp_sect1); - index += bit_flag; - } while ((bit_flag != 0) && (index < 6)); - - // Default block size is 0x160. - int b_size = 0x160; - tmp_sect2 = tmp + index + 0x7F1; - - // If the data length was found, parse it as a number. - if ((index >= 0) || (bit_flag != 0)) { - // Locate next section. - int sect = (index << 5) | (((((int)(start - out)) << index) & 3) << 3) | (offset & 7); - tmp_sect1 = tmp + 0xBA8 + sect; - - // Decode the data length (8 bit fields). - data_length = decode_number(tmp_sect1, index, &bit_flag, &range, &code, &in); - if (data_length == 0xFF) return (int)(start - out); // End of stream. - } - else - // Assume one byte of advance. - data_length = 1; - - // If we got valid parameters, seek to find data offset. - if ((data_length <= 2)) { - tmp_sect2 += 0xF8; - b_size = 0x40; // Block size is now 0x40. - } - - int diff = 0; - int shift = 1; - - // Identify the data offset bit field. - do { - diff = (shift << 4) - b_size; - bit_flag = decode_bit(&range, &code, &shift, &in, tmp_sect2 + ((size_t)shift << 3)); - } while (diff < 0); - - // If the data offset was found, parse it as a number. - if ((diff > 0) || (bit_flag != 0)) { - // Adjust diff if needed. - if (bit_flag == 0) - diff -= 8; - - // Locate section. - tmp_sect3 = tmp + 0x928 + diff; - - // Decode the data offset (1 bit fields). - data_offset = decode_word(tmp_sect3, diff, &bit_flag, &range, &code, &in); - } - else - // Assume one byte of advance. - data_offset = 1; - - // Set buffer start/end. - buf_start = start - data_offset; - buf_end = start + data_length + 1; - - // Underflow. - if (buf_start < out) - return -1; - - // Overflow. - if (buf_end > end) - return -1; - - // Update offset. - offset = ((((int)(buf_end - out)) + 1) & 1) + 6; - - // Copy data. - do { - *start++ = *buf_start++; - } while (start < buf_end); - - } - prev = *(start - 1); - } - result = (int)(start - out); - return result; -} diff --git a/src/CLOUD/lz.h b/src/CLOUD/lz.h deleted file mode 100644 index 94918446..00000000 --- a/src/CLOUD/lz.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -// Copyright (C) 2014 Hykem -// Licensed under the terms of the GNU GPL, version 3 -// http://www.gnu.org/licenses/gpl-3.0.txt - -// Reverse-engineered custom Lempel–Ziv–Markov based compression. - -#include - -extern void decode_range(unsigned int *range, unsigned int *code, unsigned char **src); -extern int decode_bit(unsigned int *range, unsigned int *code, int *index, unsigned char **src, unsigned char *c); -extern int decode_number(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src); -extern int decode_word(unsigned char *ptr, int index, int *bit_flag, unsigned int *range, unsigned int *code, unsigned char **src); -extern int decompress(unsigned char *out, unsigned char *in, unsigned int size); diff --git a/src/CLOUD/main.c b/src/CLOUD/main.cpp similarity index 95% rename from src/CLOUD/main.c rename to src/CLOUD/main.cpp index c3400919..e5ed9169 100644 --- a/src/CLOUD/main.c +++ b/src/CLOUD/main.cpp @@ -7,10 +7,8 @@ #include "../KKdLib/dsc.hpp" #include "../KKdLib/f2/struct.hpp" #include "../CRE/auth_3d.hpp" -#include "elf.h" -#include "main.h" -#include "shared.h" -#include "unedat.h" +#include "main.hpp" +#include "shared.hpp" #include #include #include @@ -31,18 +29,6 @@ inline static void next_rand_uint8_t_pointer(uint8_t* arr, size_t length, uint32 } } -static void decrypt_edat() { - uint8_t klic[16] = { 0xe2, 0x2d, 0x52, 0x46, 0x10, 0xa4, 0x4b, 0xb1, - 0xb5, 0x00, 0xf0, 0x66, 0xe7, 0xa0, 0xed, 0x49 }; - - stream f0; - stream f1; - f0.open("misc\\shader_ps3.edat", "rb"); - f1.open("misc\\shader_ps3.dat", "wb"); - if (f0.io.stream && f1.io.stream) - DecryptEDAT(f0, f1, 8, "misc\\EP0177-NPEB02013_00-PJDF2MOMJTNSDAYO.rap", klic); -} - struct dof_data { int32_t flags; float_t focus; diff --git a/src/CLOUD/main.h b/src/CLOUD/main.hpp similarity index 74% rename from src/CLOUD/main.h rename to src/CLOUD/main.hpp index 3adde270..e8543c47 100644 --- a/src/CLOUD/main.h +++ b/src/CLOUD/main.hpp @@ -7,5 +7,5 @@ #include "../KKdLib/default.hpp" #include "input.hpp" -#include "render.h" -#include "sound.h" +#include "render.hpp" +#include "sound.hpp" diff --git a/src/CLOUD/pv_game.cpp b/src/CLOUD/pv_game.cpp index 27b0a9af..9741cb71 100644 --- a/src/CLOUD/pv_game.cpp +++ b/src/CLOUD/pv_game.cpp @@ -17,7 +17,7 @@ #include "../KKdLib/farc.hpp" #include "../KKdLib/sort.hpp" #include "input.hpp" -#include "classes/imgui_helper.h" +#include "classes/imgui_helper.hpp" enum dsc_ft_func { DSC_FT_END, @@ -129,7 +129,7 @@ enum dsc_ft_func { DSC_FT_MAX, }; -pv_game pv_game_data; +pv_game_old pv_game_old_data; extern render_context* rctx_ptr; @@ -138,16 +138,176 @@ static int32_t expression_id_to_mottbl_index(int32_t expression_id); static int32_t hand_anim_id_to_mottbl_index(int32_t hand_anim_id); static int32_t look_anim_id_to_mottbl_index(int32_t look_anim_id); static int32_t mouth_anim_id_to_mottbl_index(int32_t mouth_anim_id); -static void pv_game_change_field(pv_game* pvgm, int32_t field, int64_t dsc_time, int64_t curr_time); -static bool pv_game_dsc_process(pv_game* pvgm, int64_t curr_time); -static void pv_game_reset_field(pv_game* pvgm); +static void pv_game_change_field(pv_game_old* pvgm, int32_t field, int64_t dsc_time, int64_t curr_time); +static bool pv_game_dsc_process(pv_game_old* pvgm, int64_t curr_time); +static void pv_game_reset_field(pv_game_old* pvgm); -static dsc_data* sub_1401216D0(pv_game* a1, dsc_ft_func func_name, +static dsc_data* sub_1401216D0(pv_game_old* a1, dsc_ft_func func_name, int32_t* time, int32_t* pv_branch_mode, dsc_data* start, dsc_data* end); -static void sub_140121A80(pv_game* a1, int32_t chara_id); -static void sub_140122770(pv_game* a1, int32_t chara_id); +static void sub_140121A80(pv_game_old* a1, int32_t chara_id); +static void sub_140122770(pv_game_old* a1, int32_t chara_id); -pv_game::pv_game() : state(), frame(), frame_float(), time(), rob_chara_ids(), +pv_play_data_motion_data::pv_play_data_motion_data() : rob_chr(), current_time(), +duration(), start_pos(), end_pos(), start_rot(), end_rot() { + mot_smooth_len = 12.0f; +} + +pv_play_data_motion_data::~pv_play_data_motion_data() { + +} + +void pv_play_data_motion_data::reset() { + rob_chr = 0; + current_time = 0.0f; + duration = 0.0f; + start_pos = vec3_null; + end_pos = vec3_null; + start_rot = 0.0f; + end_rot = 0.0f; + mot_smooth_len = 12.0f; + set_motion.clear(); + set_motion.shrink_to_fit(); + set_item.clear(); + set_item.shrink_to_fit(); +} + +pv_play_data::pv_play_data() : rob_chr(), disp() { + +} + +pv_play_data::~pv_play_data() { + +} + +void pv_play_data::reset() { + motion.clear(); + motion.shrink_to_fit(); + rob_chr = 0; + set_motion.clear(); + disp = true; + motion_data.reset(); +} + +pv_disp2d::pv_disp2d() : pv_id(), title_start_2d_field(), title_end_2d_field(), +title_start_2d_low_field(), title_end_2d_low_field(), title_start_3d_field(), title_end_3d_field(), +target_shadow_type(), pv_spr_set_id(), pv_aet_set_id(), pv_main_aet_id() { + +} + +pv_disp2d::~pv_disp2d() { + +} + +pv_game_dsc_data::pv_game_dsc_data() { + +} + +pv_game_dsc_data::~pv_game_dsc_data() { + +} + +pv_game_data_chara::pv_game_data_chara() { + +} + +pv_game_data_chara::~pv_game_data_chara() { + +} + +pv_game_data_field::pv_game_data_field() { + +} + +pv_game_data_field::~pv_game_data_field() { + +} + +struc_78::struc_78() { + +} + +struc_78::~struc_78() { + +} + +pv_game_data_chreff::pv_game_data_chreff() { + +} + +pv_game_data_chreff::~pv_game_data_chreff() { + +} + +pv_effect_resource::pv_effect_resource() { + +} + +pv_effect_resource::~pv_effect_resource() { + +} + +pv_game_data::pv_game_data() { + +} + +pv_game_data::~pv_game_data() { + +} + +pv_game::pv_game() { + +} + +pv_game::~pv_game() { + +} + +TaskPvGame::Data::Data() { + +} + +TaskPvGame::Data::~Data() { + +} + +TaskPvGame::TaskPvGame() { + +} + +TaskPvGame::~TaskPvGame() { + +} + +bool TaskPvGame::Init() { + TaskPvGame::Load(&data); + return true; +} + +bool TaskPvGame::Ctrl() { + return false; +} + +bool TaskPvGame::Dest() { + return true; +} + +void TaskPvGame::Disp() { + +} + +void TaskPvGame::Window() { + +} + +void TaskPvGame::Load(TaskPvGame::Data* data) { + +} + +void TaskPvGame::Unload() { + +} + +pv_game_old::pv_game_old() : state(), frame(), frame_float(), time(), rob_chara_ids(), dsc_time(), dsc_data_ptr(), dsc_data_ptr_end(), play(), success(), chara_id(), pv_end(), playdata(), scene_rot_y(), branch_mode(), pause(), step_frame() { pv_id = -1; @@ -158,16 +318,16 @@ pv_end(), playdata(), scene_rot_y(), branch_mode(), pause(), step_frame() { scene_rot_mat = mat4u_identity; } -pv_game::~pv_game() { +pv_game_old::~pv_game_old() { } -bool pv_game::Init() { +bool pv_game_old::Init() { task_stage_load("PV_GAME_STAGE"); return true; } -bool pv_game::Ctrl() { +bool pv_game_old::Ctrl() { switch (state) { case 0: return false; @@ -415,13 +575,13 @@ bool pv_game::Ctrl() { return false; } -void pv_game::Disp() { +void pv_game_old::Disp() { if (state != 10) return; } -bool pv_game::Dest() { +bool pv_game_old::Dest() { Unload(); task_stage_unload(); @@ -439,7 +599,7 @@ bool pv_game::Dest() { return true; } -void pv_game::Window() { +void pv_game_old::Window() { if (state != 10) return; @@ -476,35 +636,35 @@ void pv_game::Window() { return; } - w = imguiGetContentRegionAvailWidth(); + w = ImGui::GetContentRegionAvailWidth(); if (ImGui::BeginTable("buttons", 2)) { ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * 0.5f); ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton(pause || (!pause && step_frame) ? "Play (K)" : "Pause (K)", { w, 0.0f })) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed(pause || (!pause && step_frame) ? "Play (K)" : "Pause (K)", { w, 0.0f })) pause ^= true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Step Frame (L)", { w, 0.0f })) { + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Step Frame (L)", { w, 0.0f })) { pause = true; step_frame = true; } ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Stop (Ctrl+K)", { w, 0.0f })) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Stop (Ctrl+K)", { w, 0.0f })) state = 11; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); + w = ImGui::GetContentRegionAvailWidth(); char buf[0x100]; sprintf_s(buf, sizeof(buf), "%d", frame); ImGui::PushStyleColor(ImGuiCol_Button, { 0.0f, 0.0f, 0.0f, 0.0f }); ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.0f, 0.0f, 0.0f, 0.0f }); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, { 0.0f, 0.0f, 0.0f, 0.0f }); - imguiButtonEx(buf, { w, 0.0f }, ImGuiButtonFlags_DontClosePopups + ImGui::ButtonExEnterKeyPressed(buf, { w, 0.0f }, ImGuiButtonFlags_DontClosePopups | ImGuiButtonFlags_NoNavFocus | ImGuiButtonFlags_NoHoveredOnFocus); ImGui::PopStyleColor(3); ImGui::EndTable(); @@ -515,7 +675,7 @@ void pv_game::Window() { ImGui::End(); } -void pv_game::Load(int32_t pv_id, chara_index charas[6], int32_t modules[6]) { +void pv_game_old::Load(int32_t pv_id, chara_index charas[6], int32_t modules[6]) { data_struct* aft_data = &data_list[DATA_AFT]; motion_database* aft_mot_db = &aft_data->data_ft.mot_db; object_database* aft_obj_db = &aft_data->data_ft.obj_db; @@ -580,7 +740,7 @@ void pv_game::Load(int32_t pv_id, chara_index charas[6], int32_t modules[6]) { Glitter::glt_particle_manager.draw_all = false; } -void pv_game::Unload() { +void pv_game_old::Unload() { data_struct* aft_data = &data_list[DATA_AFT]; motion_database* aft_mot_db = &aft_data->data_ft.mot_db; @@ -662,54 +822,6 @@ void pv_game::Unload() { pv_param_task::post_process_task.SetDest(); } -struc_104::struc_104() : rob_chr(), current_time(), -duration(), start_pos(), end_pos(), start_rot(), end_rot() { - mot_smooth_len = 12.0f; -} - -struc_104::~struc_104() { - -} - -void struc_104::reset() { - rob_chr = 0; - current_time = 0.0f; - duration = 0.0f; - start_pos = vec3_null; - end_pos = vec3_null; - start_rot = 0.0f; - end_rot = 0.0f; - mot_smooth_len = 12.0f; - set_motion.clear(); - set_item.clear(); -} - -pv_play_data::pv_play_data() : rob_chr(), disp() { - -} - -pv_play_data::~pv_play_data() { - -} - -void pv_play_data::reset() { - motion.clear(); - rob_chr = 0; - set_motion.clear(); - disp = true; - field_38.reset(); -} - -pv_disp2d::pv_disp2d() : pv_id(), title_start_2d_field(), title_end_2d_field(), -title_start_2d_low_field(), title_end_2d_low_field(), title_start_3d_field(), title_end_3d_field(), -target_shadow_type(), pv_spr_set_id(), pv_aet_set_id(), pv_main_aet_id() { - -} - -pv_disp2d::~pv_disp2d() { - -} - static float_t dsc_time_to_frame(int64_t time) { return (float_t)time / 1000000000.0f * 60.0f; } @@ -775,13 +887,13 @@ static int32_t mouth_anim_id_to_mottbl_index(int32_t mouth_anim_id) { return 131; } -static void sub_140122B60(pv_game* a1, int32_t chara_id, int32_t motion_index, int64_t disp_time) { +static void sub_140122B60(pv_game_old* a1, int32_t chara_id, int32_t motion_index, int64_t disp_time) { if (chara_id < 0 || chara_id > ROB_CHARA_COUNT || motion_index < 0) return; pv_play_data* playdata = &a1->playdata[chara_id]; int64_t dsc_time = a1->dsc_time; - for (dsc_set_motion& i : playdata->field_38.set_motion) { + for (dsc_set_motion& i : playdata->motion_data.set_motion) { int64_t time = (int64_t)i.time * 10000; if (time > dsc_time && i.motion_index == motion_index && (!a1->branch_mode || a1->branch_mode == i.pv_branch_mode)) { @@ -793,11 +905,11 @@ static void sub_140122B60(pv_game* a1, int32_t chara_id, int32_t motion_index, i } } -static void pv_game_change_field(pv_game* pvgm, int32_t field, int64_t dsc_time, int64_t curr_time) { +static void pv_game_change_field(pv_game_old* pvgm, int32_t field, int64_t dsc_time, int64_t curr_time) { light_param_storage_data_set_pv_cut(field); } -static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { +static bool pv_game_dsc_process(pv_game_old* a1, int64_t curr_time) { dsc_ft_func func = (dsc_ft_func)a1->dsc_data_ptr->func; uint32_t* data = a1->dsc_m.get_func_data(a1->dsc_data_ptr); if (a1->branch_mode) { @@ -885,7 +997,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { sub_1405430F0(chara_id, 2); }*/ - //pv_game::set_data_itmpv_visibility(a1->pv_game, a1->chara_id, true); + //pv_game_old::set_data_itmpv_visibility(a1->pv_game_old, a1->chara_id, true); for (pv_play_data_set_motion& i : playdata->set_motion) { bool v45 = rob_chr->set_motion_id(i.motion_id, i.frame, i.duration, i.field_10, 0, i.blend_type, aft_bone_data, aft_mot_db); @@ -894,14 +1006,14 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { rob_chr->data.motion.step_data.step = i.frame_speed; //if (v45) // pv_expression_array_set_motion(a1->chara_id, i.motion_id); - //if (!a1->pv_game->data.pv->disable_calc_motfrm_limit) + //if (!a1->pv_game_old->data.pv->disable_calc_motfrm_limit) sub_140122B60(a1, a1->chara_id, i.motion_index, i.dsc_time); } playdata->set_motion.clear(); } else { rob_chr->set_visibility(false); - //pv_game::set_data_itmpv_visibility(a1->pv_game, a1->chara_id, false); + //pv_game_old::set_data_itmpv_visibility(a1->pv_game_old, a1->chara_id, false); } } break; case DSC_FT_MIKU_SHADOW: { @@ -1027,7 +1139,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { rob_chr->data.motion.step_data.step = v519.frame_speed; //if (v84) // pv_expression_array_set_motion(a1->chara_id, motion_id); - //if (!a1->pv_game->data.pv->disable_calc_motfrm_limit) + //if (!a1->pv_game_old->data.pv->disable_calc_motfrm_limit) sub_140122B60(a1, a1->chara_id, motion_index, v56 ? v56->time : 0); } else { @@ -1120,7 +1232,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { duration /= a1->anim_frame_speed; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_eyelid_mottbl_motion_from_face(v115, duration, -1.0f, offset, aft_mot_db); @@ -1193,11 +1305,11 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { int32_t mottbl_index = mouth_anim_id_to_mottbl_index(mouth_anim_id); duration /= a1->anim_frame_speed; - //if (a1->pv_game->data.field_2D090 && mottbl_index != 144) + //if (a1->pv_game_old->data.field_2D090 && mottbl_index != 144) // value = 0.0f; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, @@ -1241,7 +1353,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { duration /= a1->anim_frame_speed; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; switch (hand_index) { @@ -1292,7 +1404,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { duration /= a1->anim_frame_speed; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_eyes_mottbl_motion(0, mottbl_index, value, @@ -1336,11 +1448,11 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { duration /= a1->anim_frame_speed; bool v168 = true; - //if (a1->has_perf_id && (a1->pv_game->data.pv->edit - 1) <= 1) + //if (a1->has_perf_id && (a1->pv_game_old->data.pv->edit - 1) <= 1) // v168 = false; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_face_mottbl_motion(0, mottbl_index, value, mottbl_index >= 214 @@ -1393,10 +1505,10 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { bool v237 = true; //if (a1->has_perf_id) - // v237 = (a1->pv_game->data.pv->edit - 1) > 1; + // v237 = (a1->pv_game_old->data.pv->edit - 1) > 1; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_face_mottbl_motion(0, mottbl_index, 1.0f, mottbl_index >= 214 @@ -1406,7 +1518,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { int32_t mottbl_index = mouth_anim_id_to_mottbl_index(v234); float_t value = 1.0f; - //if (a1->pv_game->data.field_2D090 && mottbl_index != 144) + //if (a1->pv_game_old->data.field_2D090 && mottbl_index != 144) // value = 0.0f; rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, 0, @@ -1448,11 +1560,11 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { duration *= a1->target_anim_fps; float_t value = 1.0f; - //if (a1->pv_game->data.field_2D090 && mottbl_index != 144) + //if (a1->pv_game_old->data.field_2D090 && mottbl_index != 144) // value = 0.0f; float_t offset = 0.0f; - //if (a1->pv_game->data.pv->is_old_pv) + //if (a1->pv_game_old->data.pv->is_old_pv) // offset = 1.0f; rob_chr->set_mouth_mottbl_motion(0, mottbl_index, value, @@ -1577,7 +1689,7 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { //if (a1->chara_id < a1->pp->chara.size()) // chara_index = (::chara_index)a1->pp->chara[a1->chara_id].chara_effect.base_chara; - //chara_index chara_index = pv_db_pv::get_performer_chara(a1->pv_game->data.pv, a1->chara_id); + //chara_index chara_index = pv_db_pv::get_performer_chara(a1->pv_game_old->data.pv, a1->chara_id); chara_size_index = chara_init_data_get_chara_size_index(chara_index); } else if (chara_size == 2) @@ -1833,13 +1945,13 @@ static bool pv_game_dsc_process(pv_game* a1, int64_t curr_time) { return true; } -static void pv_game_reset_field(pv_game* pvgm) { +static void pv_game_reset_field(pv_game_old* pvgm) { task_stage_info v14; task_stage_set_stage(&v14); Glitter::glt_particle_manager.FreeScenes(); } -static dsc_data* sub_1401216D0(pv_game* a1, dsc_ft_func func_name, +static dsc_data* sub_1401216D0(pv_game_old* a1, dsc_ft_func func_name, int32_t* time, int32_t* pv_branch_mode, dsc_data* start, dsc_data* end) { int32_t _time = -1; for (dsc_data* i = start; i != end; i++) @@ -1865,14 +1977,14 @@ static dsc_data* sub_1401216D0(pv_game* a1, dsc_ft_func func_name, return 0; } -static void sub_140121A80(pv_game* a1, int32_t chara_id) { +static void sub_140121A80(pv_game_old* a1, int32_t chara_id) { if (chara_id < 0 || chara_id >= ROB_CHARA_COUNT) return; int32_t pv_branch_mode = 0; int32_t time = -1; int32_t prev_time = -1; - a1->playdata[chara_id].field_38.set_item.clear(); + a1->playdata[chara_id].motion_data.set_item.clear(); dsc_data* i = a1->dsc_m.data.data(); dsc_data* i_end = a1->dsc_m.data.data() + a1->dsc_m.data.size(); @@ -1893,21 +2005,21 @@ static void sub_140121A80(pv_game* a1, int32_t chara_id) { v14.item_index = data[1]; v14.time = time; v14.pv_branch_mode = pv_branch_mode; - a1->playdata[chara_id].field_38.set_item.push_back(v14); + a1->playdata[chara_id].motion_data.set_item.push_back(v14); } prev_time = time; i++; } } -static void sub_140122770(pv_game* a1, int32_t chara_id) { +static void sub_140122770(pv_game_old* a1, int32_t chara_id) { if (chara_id < 0 || chara_id >= ROB_CHARA_COUNT) return; int32_t pv_branch_mode = 0; int32_t time = -1; int32_t prev_time = -1; - a1->playdata[chara_id].field_38.set_motion.clear(); + a1->playdata[chara_id].motion_data.set_motion.clear(); dsc_data* i = a1->dsc_m.data.data(); dsc_data* i_end = a1->dsc_m.data.data() + a1->dsc_m.data.size(); @@ -1928,7 +2040,7 @@ static void sub_140122770(pv_game* a1, int32_t chara_id) { v14.motion_index = data[1]; v14.time = time; v14.pv_branch_mode = pv_branch_mode; - a1->playdata[chara_id].field_38.set_motion.push_back(v14); + a1->playdata[chara_id].motion_data.set_motion.push_back(v14); } prev_time = time; i++; diff --git a/src/CLOUD/pv_game.hpp b/src/CLOUD/pv_game.hpp index 4f0bd699..875dd95a 100644 --- a/src/CLOUD/pv_game.hpp +++ b/src/CLOUD/pv_game.hpp @@ -3,7 +3,6 @@ GitHub/GitLab: korenkonder */ -#if defined(CLOUD_DEV) #pragma once #include @@ -13,12 +12,12 @@ #include #include #include "../KKdLib/dsc.hpp" +#include "../CRE/rob/rob.hpp" #include "../CRE/auth_3d.hpp" #include "../CRE/pv_db.hpp" -#include "../CRE/rob.hpp" #include "../CRE/stage.hpp" #include "../CRE/task.hpp" -#include "classes.h" +#include "classes.hpp" struct pv_play_data_set_motion { float_t frame_speed; @@ -51,7 +50,7 @@ struct dsc_set_motion { int32_t pv_branch_mode; }; -struct struc_104 { +struct pv_play_data_motion_data { rob_chara* rob_chr; float_t current_time; float_t duration; @@ -63,8 +62,8 @@ struct struc_104 { std::vector set_motion; std::vector set_item; - struc_104(); - ~struc_104(); + pv_play_data_motion_data(); + ~pv_play_data_motion_data(); void reset(); }; @@ -74,7 +73,9 @@ struct pv_play_data { rob_chara* rob_chr; std::list set_motion; bool disp; - struc_104 field_38; + int8_t field_31; + int32_t field_34; + pv_play_data_motion_data motion_data; pv_play_data(); ~pv_play_data(); @@ -100,19 +101,242 @@ struct pv_disp2d { virtual ~pv_disp2d(); }; +struct pv_data_camera { + bool enable; + int32_t id; + int64_t time; +}; + +struct pv_data_set_motion { + int32_t motion_id; + float_t frame; + int32_t stage_index; +}; + +struct pv_game_dsc_data_change_field { + int32_t time; + int32_t field; +}; + +struct struc_540 { + int32_t field_0; + vec2 field_4; + vec2 field_C; + int32_t field_14; + int32_t field_18; + int32_t field_1C; + int32_t field_20; +}; + +struct struc_498 { + int32_t field_0; + struc_540 field_4[4]; + int32_t field_94; + int64_t field_98; + int64_t field_A0; + int32_t field_A8; + int32_t field_AC; +}; + +struct struc_563 { + int64_t field_0; + int64_t field_8; + int64_t field_10; + int64_t field_18; + int64_t dsc_time; + int64_t field_28; +}; + +struct struc_676 { + bool field_0[6]; + pv_play_data_set_motion field_8[6]; + int64_t field_128; + int64_t field_130; + int64_t field_138; + int64_t field_140; + bool field_148[6]; + struc_563 field_150[6]; + float_t field_270[6]; + bool field_288[6]; + int32_t field_290[6]; + float_t field_2A8[6]; + int8_t field_2C0; + int32_t field_2C4; + int32_t field_2C8; + float_t field_2CC; + int64_t field_2D0; +}; + +struct pv_game; + +struct pv_game_dsc_data { + int8_t field_0; + int32_t state; + bool play; + uint32_t dsc_buffer[45000]; + int32_t dsc_buffer_counter; + int64_t field_2BF30; + int64_t field_2BF38; + int64_t curr_time; + float_t curr_time_float; + float_t prev_time_float; + int8_t field_2BF50; + int64_t field_2BF58; + int8_t field_2BF60; + int32_t field_2BF64; + int64_t field_2BF68; + int32_t chara_id; + pv_game* pv_game; + //struc_162* field_2BF80; + //struc_646* field_2BF88; + p_file_handler dsc_file_handler; + float_t target_anim_fps; + float_t anim_frame_speed; + float_t target_flying_time; + int32_t time_signature; + ssize_t dsc_time; + int32_t field_2BFB0; + int32_t field_2BFB4; + int32_t field_2BFB8; + int32_t field_2BFBC; + int8_t field_2BFC0; + bool music_play; + int32_t field_2BFC4; + bool pv_end; + float_t fov; + float_t min_dist; + int8_t field_2BFD4; + int8_t field_2BFD5; + pv_play_data playdata[6]; + pv_data_camera data_camera[3]; + std::vector data_camera_branch_fail; + std::vector data_camera_branch_success; + std::vector set_motion[6]; + std::vector change_field_branch_fail; + std::vector change_field_branch_success; + int64_t change_field_branch_time; + bool scene_fade_enable; + float_t scene_fade_frame; + float_t scene_fade_duration; + float_t scene_fade_start_alpha; + float_t scene_fade_end_alpha; + vec3 scene_fade_color; + bool has_signature; + bool has_perf_id; + int32_t field_2C4E4; + std::vector field_2C4E8; + int64_t field_2C500; + float_t scene_rot_y; + mat4 scene_rot_mat; + float_t field_2C54C; + int32_t field_2C550; + int32_t branch_mode; + int32_t first_challenge_note; + int32_t last_challenge_note; + struc_676 field_2C560; + + pv_game_dsc_data(); + ~pv_game_dsc_data(); +}; + +struct pv_game_data_chara { + chara_index chara_index; + int32_t module_index; + int32_t chara_id; + rob_chara_pv_data pv_data; + rob_chara* rob_chr; + std::vector motion_ids; + std::vector motion_face_ids; + + pv_game_data_chara(); + ~pv_game_data_chara(); +}; + +struct struc_675 { + int8_t field_0; + float_t field_4; + float_t field_8; + float_t field_C; + float_t field_10; + int8_t field_14; +}; + +struct pv_game_data_field { + int32_t stage_index; + std::vector auth_3d_uids; + std::vector auth_3d_ids; + std::map auth_3d_frame_list; + int32_t light_auth_3d_uid; + int32_t light_auth_3d_id; + int32_t light_frame; + std::vector aet_set_names[4]; + std::vector aet_set_ids[4]; + std::map, int32_t> aet[4]; + int32_t spr_set_back_id; + bool stage_flag; + int32_t npr_type; + int32_t cam_blur; + bool sdw_off; + std::vector play_eff_list; + std::vector stop_eff_list; + std::vector field_1A0; + + pv_game_data_field(); + ~pv_game_data_field(); +}; + +struct pv_game_data_itmpv { + int32_t auth_3d_id; + int32_t field_4; + int64_t time; +}; + +struct struc_78 { + std::vector field_0; + std::vector field_18; + int32_t field_30; + int32_t field_34; + + struc_78(); + ~struc_78(); +}; + +struct pv_game_data_chreff { + chara_index src_chara_index; + chara_index dst_chara_index; + std::bitset<128>* type; + std::string src_auth_3d; + std::string dst_auth_3d; + std::string src_auth_3d_category; + std::string dst_auth_3d_category; + int32_t src_auth_3d_uid; + int32_t dst_auth_3d_uid; + + pv_game_data_chreff(); + ~pv_game_data_chreff(); +}; + +struct pv_effect_resource { + std::string name; + float_t emission; + + pv_effect_resource(); + ~pv_effect_resource(); +}; + struct pv_game_data { - //struc_490 field_0; - //struc_155 field_2C838; - int field_2CE98; - char field_2CE9C[128]; - int field_2CF1C; - char field_2CF20; - int field_2CF24; + pv_game_dsc_data dsc_data; + //pv_game_ui_data ui_data; + int32_t field_2CE98; + int8_t field_2CE9C[128]; + int32_t field_2CF1C; + int8_t field_2CF20; + int32_t field_2CF24; float_t field_2CF28; float_t field_2CF2C; - int field_2CF30; - int field_2CF34; - int field_2CF38; + int32_t field_2CF30; + int32_t field_2CF34; + int32_t field_2CF38; int32_t life_gauge; int32_t score_final; int32_t challenge_time_total_bonus; @@ -123,40 +347,40 @@ struct pv_game_data { int32_t hit_count[5]; int32_t current_reference_score; int32_t target_count; - int field_2CF84; - int field_2CF88; + int32_t field_2CF84; + int32_t field_2CF88; float_t field_2CF8C; int32_t score_slide_chain_bonus; int32_t slide_chain_length; - int field_2CF98; - int field_2CF9C; + int32_t field_2CF98; + int32_t field_2CF9C; __int16 field_2CFA0; - int field_2CFA4; + int32_t field_2CFA4; pv_db_pv* pv; - int field_2CFB0; - int field_2CFB4; + int32_t field_2CFB0; + int32_t field_2CFB4; int32_t reference_score; - int field_2CFBC; - int field_2CFC0; - int field_2CFC4; + int32_t field_2CFBC; + int32_t field_2CFC0; + int32_t field_2CFC4; std::vector field_2CFC8; - int field_2CFE0; - int field_2CFE4; + int32_t field_2CFE0; + int32_t field_2CFE4; size_t notes_passed; - int field_2CFF0; + int32_t field_2CFF0; float_t score_percentage; float_t score_percentage_clear; float_t score_percentage_border; int32_t life_gauge_safety_time; int32_t life_gauge_border; - int field_2D008; - char field_2D00C; + int32_t field_2D008; + int8_t field_2D00C; bool no_fail; - char field_2D00E; + int8_t field_2D00E; bool field_2D00F; int64_t challenge_time_start; int64_t challenge_time_end; - uint64_t max_time; + int64_t max_time; float_t max_time_float; float_t current_time_float; uint64_t current_time; @@ -170,51 +394,51 @@ struct pv_game_data { pv_disp2d* pv_disp2d; int32_t life_gauge_final; bool hit_border; - char field_2D05D; - char field_2D05E; - char field_2D05F; - char field_2D060; - char field_2D061; - char field_2D062; - char field_2D063; - bool field_2D064; - char field_2D065; - char field_2D066[2]; - char field_2D068; - char field_2D069; - char field_2D06A[2]; - int field_2D06C; - uint32_t field_2D070; - int field_2D074; - int field_2D078; - int field_2D07C; - int field_2D080; - int field_2D084; + int8_t field_2D05D; + int8_t field_2D05E; + int8_t field_2D05F; + bool title_image_init; + int8_t field_2D061; + int8_t field_2D062; + int8_t field_2D063; + bool has_auth_3d_frame; + bool has_light_frame; + int8_t field_2D066[2]; + int8_t field_2D068; + int8_t field_2D069; + int8_t field_2D06A[2]; + int32_t field_2D06C; + uint32_t field_index; + int32_t edit_effect_index; + int32_t slidertouch_counter; + int32_t change_field_branch_success_counter; + int32_t field_2D080; + int32_t field_2D084; int32_t life_gauge_bonus; int32_t life_gauge_total_bonus; - char field_2D090; - char field_2D091; - char field_2D092; - char field_2D093; + int8_t field_2D090; + int8_t field_2D091; + int8_t field_2D092; + int8_t field_2D093; uint8_t field_2D094; - char field_2D095; - char field_2D096; + int8_t field_2D095; + int8_t field_2D096; bool success; - int field_2D098; - int field_2D09C; - char field_2D0A0; + int32_t field_2D098; + int32_t field_2D09C; + int8_t field_2D0A0; bool pv_end_fadeout; float_t rival_percentage; - int field_2D0A8; - int field_2D0AC; - int field_2D0B0[3]; + int32_t field_2D0A8; + int32_t field_2D0AC; + int32_t field_2D0B0[3]; bool field_2D0BC; - char field_2D0BD; - char field_2D0BE; - char field_2D0BF; - int field_2D0C0; - int field_2D0C4; - //struc_154 chrcam_chrmot[6]; + int8_t field_2D0BD; + int8_t field_2D0BE; + int8_t field_2D0BF; + int32_t field_2D0C0; + int32_t field_2D0C4; + pv_game_data_chara chara[6]; std::vector motion_set_ids; std::vector motion_set_face_ids; std::vector obj_set_itmpv; @@ -225,75 +449,126 @@ struct pv_game_data { std::vector ex_song_ex_auth_obj_set_ids; std::vector stage_indices; std::vector stage_infos; - char field_2D7E8; - int field_2D7EC; - std::vector field_2D7F0; - int field_2D808; - int field_2D80C; - std::vector field_2D810; - std::vector field_2D828; - std::vector field_2D840; - int field_2D858; - float_t field_2D85C; - float_t field_2D860; - float_t field_2D864; - float_t field_2D868; - char field_2D86C; - int camera_auth_3d_uid; - int field_2D874; + int8_t field_2D7E8; + int32_t field_2D7EC; + std::vector spr_set_back_ids; + int32_t field_2D808; + int32_t field_2D80C; + std::vector edit_effect_aet_set_ids; + std::vector edit_effect_spr_set_ids; + std::vector edit_effect_aet_ids; + struc_675 field_2D858; + int32_t camera_auth_3d_uid; + int32_t field_2D874; bool field_2D878; - int field_2D87C; + int32_t field_2D87C; size_t current_field; - //std::vector field_data; - char field_2D8A0; - int field_2D8A4; - __int64 field_2D8A8; - int field_2D8B0; - int field_2D8B4; - __int64 field_2D8B8; - __int64 field_2D8C0; - int field_2D8C8; - int field_2D8CC; - int field_2D8D0; - int field_2D8D4; - int field_2D8D8; - int field_2D8DC; - int field_2D8E0; - int field_2D8E4; - int field_2D8E8; - int field_2D8EC; - int field_2D8F0; - int field_2D8F4; - int field_2D8F8; - int field_2D8FC; - int field_2D900; - int field_2D904; + std::vector field_data; + int8_t field_2D8A0; + int32_t field_2D8A4; + std::map auth_3d_time; + std::map light_time; + std::map, int64_t> aet_time[4]; std::string campv_string; std::vector campv_auth_3d_uids; std::map campv; - int data_camera_id; - int field_2D954; + int32_t data_camera_id; + int32_t field_2D954; std::string itmpv_string; std::vector itmpv_auth_3d_uids; - //std::map itmpv[6]; + std::map itmpv[6]; std::vector field_2D9F0; - //struc_78 field_2DA08[3]; + struc_78 field_2DA08[3]; std::vector loaded_auth_3d_uids; - char field_2DAC8; - int field_2DACC; + int8_t field_2DAC8; + int32_t field_2DACC; std::vector auth_3d_categories; std::map auth_3d; - //std::vector chreff_auth_3d; - //std::vector chreff_auth_3d_obj; - char field_2DB28; + std::vector chreff_auth_3d; + std::vector chreff_auth_3d_obj; + int8_t field_2DB28; vec2 field_2DB2C; - int field_2DB34; + int32_t field_2DB34; time_struct field_2DB38; - std::vector field_2DB48; - //std::vector field_2DB60; + std::vector effect_rs_list_hashes; + std::vector effect_rs_list; + + pv_game_data(); + ~pv_game_data(); }; -class pv_game : public app::TaskWindow { +struct struc_653 { + bool field_0[4]; +}; + +struct pv_game { + bool loaded; + bool field_1; + bool field_2; + bool end_pv; + int32_t field_4; + int32_t state; + int32_t field_C; + int32_t pv_id; + int32_t field_14; + int32_t modules[6]; + rob_chara_pv_data_item items[6]; + struc_653 field_90[6]; + pv_game_data data; + + pv_game(); + ~pv_game(); +}; + +class TaskPvGame : public app::TaskWindow { +public: + struct Data { + int32_t field_0; + int32_t field_4; + int64_t field_8; + int32_t score_percentage_clear; + int32_t life_gauge_safety_time; + int32_t life_gauge_border; + int32_t field_1C; + int32_t modules[6]; + rob_chara_pv_data_item items[6]; + int64_t field_98; + int64_t field_A0; + int64_t field_A8; + std::string field_B0; + std::string field_D0; + std::string field_F0; + std::string field_110; + std::string field_130; + std::string field_150; + std::string field_170; + int8_t field_190; + int8_t field_191; + bool no_fail; + int8_t field_193; + int8_t field_194; + int8_t field_195; + int8_t field_196; + int32_t field_198; + + Data(); + ~Data(); + } data; + + TaskPvGame(); + virtual ~TaskPvGame() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Window() override; + + static void Load(Data* data); + static void Unload(); +}; + +class pv_game_old : public app::TaskWindow { public: int32_t pv_id; @@ -334,8 +609,9 @@ public: bool pause; bool step_frame; - pv_game(); - virtual ~pv_game() override; + pv_game_old(); + virtual ~pv_game_old() override; + virtual bool Init() override; virtual bool Ctrl() override; virtual bool Dest() override; @@ -345,7 +621,3 @@ public: void Load(int32_t pv_id, chara_index charas[6], int32_t modules[6]); void Unload(); }; - -extern pv_game pv_game_data; - -#endif diff --git a/src/CLOUD/render.c b/src/CLOUD/render.cpp similarity index 89% rename from src/CLOUD/render.c rename to src/CLOUD/render.cpp index d0db9579..2197fe3a 100644 --- a/src/CLOUD/render.c +++ b/src/CLOUD/render.cpp @@ -5,7 +5,7 @@ Some code is from LearnOpenGL */ -#include "render.h" +#include "render.hpp" #include #include #define GLFW_EXPOSE_NATIVE_WIN32 @@ -15,30 +15,31 @@ #include #include #include "../CRE/Glitter/glitter.hpp" -#include "../CRE/camera.h" +#include "../CRE/rob/rob.hpp" +#include "../CRE/camera.hpp" #include "../CRE/data.hpp" #include "../CRE/fbo.hpp" #include "../CRE/file_handler.hpp" -#include "../CRE/gl_state.h" +#include "../CRE/gl_state.hpp" #include "../CRE/light_param.hpp" -#include "../CRE/lock.h" +#include "../CRE/lock.hpp" #include "../CRE/object.hpp" #include "../CRE/pv_db.hpp" -#include "../CRE/rob.hpp" -#include "../CRE/shader.h" -#include "../CRE/shader_ft.h" +#include "../CRE/shader.hpp" +#include "../CRE/shader_ft.hpp" #include "../CRE/shader_glsl.hpp" #include "../CRE/stage.hpp" -#include "../CRE/static_var.h" +#include "../CRE/stage_modern.hpp" +#include "../CRE/static_var.hpp" #include "../CRE/task.hpp" #include "../CRE/texture.hpp" -#include "../CRE/timer.h" +#include "../CRE/timer.hpp" #include "../CRE/post_process.hpp" #include "../KKdLib/io/path.hpp" #include "../KKdLib/database/item_table.hpp" #include "../KKdLib/sort.hpp" #include "../KKdLib/str_utils.hpp" -#include "classes/imgui_helper.h" +#include "classes/imgui_helper.hpp" #include "input.hpp" #include "pv_game.hpp" #include "x_pv_game.hpp" @@ -51,11 +52,11 @@ #define CUBE_LINE_SIZE (0.0025f) #define CUBE_LINE_POINT_SIZE (CUBE_LINE_SIZE * 1.5f) -shader_glsl cube_line_shader; -shader_glsl cube_line_point_shader; -shader_glsl grid_shader; +shader_glsl* cube_line_shader; +shader_glsl* cube_line_point_shader; +shader_glsl* grid_shader; -timer render_timer; +timer* render_timer; #define grid_size 50.0f #define grid_spacing 1.0f @@ -144,18 +145,18 @@ lock imgui_context_lock; bool global_context_menu; extern size_t frame_counter; render_context* rctx_ptr; -int32_t stage_index = -1; +bool task_stage_is_modern; int32_t render_main(void* arg) { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); timeBeginPeriod(1); - timer_init(&render_timer, 60.0); + render_timer = new timer(60.0); state = RENDER_UNINITIALIZED; lock_init(&render_lock); if (!lock_check_init(&render_lock)) { - timer_dispose(&render_timer); + delete render_timer; return 0; } @@ -279,9 +280,9 @@ int32_t render_main(void* arg) { gl_state_disable_stencil_test(); #pragma endregion - timer_reset(&render_timer); + render_timer->reset(); while (!close && !reload_render) { - timer_start_of_cycle(&render_timer); + render_timer->start_of_cycle(); glfwPollEvents(); ImGui_ImplGlfw_NewFrame(); ImGui_ImplOpenGL3_NewFrame(); @@ -295,7 +296,7 @@ int32_t render_main(void* arg) { close |= !!glfwWindowShouldClose(window); frame_counter++; Input::EndFrame(); - timer_end_of_cycle(&render_timer); + render_timer->end_of_cycle(); } lock_lock(&state_lock); @@ -303,13 +304,13 @@ int32_t render_main(void* arg) { lock_unlock(&state_lock); bool threads_wait = false; - timer_reset(&render_timer); + render_timer->reset(); do { - timer_start_of_cycle(&render_timer); + render_timer->start_of_cycle(); lock_lock(&state_lock); threads_wait = thread_flags & ~THREAD_RENDER; lock_unlock(&state_lock); - timer_end_of_cycle(&render_timer); + render_timer->end_of_cycle(); } while (threads_wait); lock_lock(&render_lock); @@ -327,7 +328,7 @@ int32_t render_main(void* arg) { glfwTerminate(); #pragma endregion lock_free(&render_lock); - timer_dispose(&render_timer); + delete render_timer; return 0; } @@ -412,7 +413,11 @@ static render_context* render_load() { app::task_work_init(); rob_init(); auth_3d_data_init(); + task_stage_init(); + dtm_stg_init(); + task_stage_modern_init(); light_param_storage_data_init(); + task_pv_db_init(); Glitter::glt_particle_manager.bone_data = aft_bone_data; @@ -559,17 +564,20 @@ static render_context* render_load() { " gl_FragDepth = texelFetch(g_depth, ivec2(gl_FragCoord.xy), 0).r;\n" "}\n"; + cube_line_shader = new shader_glsl; shader_glsl_param param = {}; param.name = "Cube Line"; - cube_line_shader.load(cube_line_vert_shader, cube_line_frag_shader, 0, ¶m); + cube_line_shader->load(cube_line_vert_shader, cube_line_frag_shader, 0, ¶m); + cube_line_point_shader = new shader_glsl; param = {}; param.name = "Cube Line Point"; - cube_line_point_shader.load(cube_line_point_vert_shader, cube_line_point_frag_shader, 0, ¶m); + cube_line_point_shader->load(cube_line_point_vert_shader, cube_line_point_frag_shader, 0, ¶m); + grid_shader = new shader_glsl; param = {}; param.name = "Grid"; - grid_shader.load(grid_vert_shader, grid_frag_shader, 0, ¶m); + grid_shader->load(grid_vert_shader, grid_frag_shader, 0, ¶m); render_resize_fb(rctx, false); @@ -602,14 +610,18 @@ static render_context* render_load() { //object_storage_load_set(aft_obj_db, "MIKITM681"); //object_storage_load_set(aft_obj_db, "MIKITM981"); - timer_reset(&render_timer); - for (int32_t i = 0; i < 30; i++) { - timer_start_of_cycle(&render_timer); + uint32_t dbg_set_id = aft_obj_db->get_object_set_id("DBG"); + object_storage_load_set(aft_data, aft_obj_db, dbg_set_id); + + render_timer->reset(); + for (int32_t i = 0; i < 30 || object_storage_load_obj_set_check_not_read(dbg_set_id); i++) { + render_timer->start_of_cycle(); lock_lock(&render_lock); app::TaskWork::Ctrl(); file_handler_storage_ctrl(); + app::TaskWork::Basic(); lock_unlock(&render_lock); - timer_end_of_cycle(&render_timer); + render_timer->end_of_cycle(); } motion_set_load_motion(aft_mot_db->get_motion_set_id("CMN"), 0, aft_mot_db); @@ -706,20 +718,16 @@ static render_context* render_load() { camera* cam = rctx->camera; - camera_initialize(cam, aspect, internal_3d_res.x, internal_3d_res.y); - //camera_set_position(cam, &((vec3){ 1.35542f, 1.41634f, 1.27852f })); - //camera_rotate(cam, &((vec2d){ -45.0, -32.5 })); - //camera_set_position(cam, &((vec3){ -6.67555f, 4.68882f, -3.67537f })); - //camera_rotate(cam, &((vec2d){ 136.5, -20.5 })); - vec3 view_point = { 0.0f, 1.0f, 3.45f }; - camera_set_view_point(cam, &view_point); - vec3 interest = { 0.0f, 1.0f, 0.0f }; - camera_set_interest(cam, &interest); - //camera_set_fov(cam, 70.0); - view_point = { 0.0f, 1.375f, 1.0f }; - camera_set_view_point(cam, &view_point); - interest = { 0.0f, 1.375f, 0.0f }; - camera_set_interest(cam, &interest); + cam->initialize(aspect, internal_3d_res.x, internal_3d_res.y); + //cam->set_position(cam, { 1.35542f, 1.41634f, 1.27852f }); + //cam->rotate(cam, { -45.0, -32.5 }); + //cam->set_position(cam, { -6.67555f, 4.68882f, -3.67537f }); + //cam->rotate(cam, { 136.5, -20.5 }); + cam->set_view_point({ 0.0f, 1.0f, 3.45f }); + cam->set_interest({ 0.0f, 1.0f, 0.0f }); + //cam->set_fov(cam, 70.0); + cam->set_view_point({ 0.0f, 1.375f, 1.0f }); + cam->set_interest({ 0.0f, 1.375f, 0.0f }); imgui_context = ImGui::CreateContext(0); lock_init(&imgui_context_lock); @@ -738,39 +746,38 @@ static render_context* render_load() { clear_color = { 0x60, 0x60, 0x60, 0xFF }; set_clear_color = true; - /*chara_index charas[6]; - charas[0] = CHARA_MIKU; - charas[1] = CHARA_MIKU;//CHARA_RIN; - charas[2] = CHARA_MIKU;//CHARA_LEN; - charas[3] = CHARA_MIKU;//CHARA_LUKA; - charas[4] = CHARA_MIKU;//CHARA_KAITO; - charas[5] = CHARA_MIKU;//CHARA_MEIKO; - - int32_t modules[6]; - modules[0] = 0;//168; - modules[1] = 0;//46; - modules[2] = 0;//39; - modules[3] = 0;//41; - modules[4] = 0;//40; - modules[5] = 0;//31; - pv_game_data.Load(739, charas, modules);*/ - chara_index charas[6]; + int32_t modules[6]; + charas[0] = CHARA_MIKU; charas[1] = CHARA_MIKU;//CHARA_RIN; charas[2] = CHARA_MIKU;//CHARA_LEN; charas[3] = CHARA_MIKU;//CHARA_LUKA; - charas[4] = CHARA_MIKU;//CHARA_KAITO; - charas[5] = CHARA_MIKU;//CHARA_MEIKO; + charas[4] = CHARA_MIKU;//CHARA_MEIKO; + charas[5] = CHARA_MIKU;//CHARA_KAITO; - int32_t modules[6]; modules[0] = 0;//168; modules[1] = 0;//46; modules[2] = 0;//39; modules[3] = 0;//41; modules[4] = 0;//40; modules[5] = 0;//31; - x_pv_game_data.Load(826, 26, charas, modules); + //pv_game_data.Load(739, charas, modules); + + charas[0] = CHARA_LUKA; + charas[1] = CHARA_LUKA;//CHARA_RIN; + charas[2] = CHARA_LUKA;//CHARA_LEN; + charas[3] = CHARA_LUKA;//CHARA_LUKA; + charas[4] = CHARA_LUKA;//CHARA_KAITO; + charas[5] = CHARA_LUKA;//CHARA_MEIKO; + + modules[0] = 0;//168; + modules[1] = 0;//46; + modules[2] = 0;//39; + modules[3] = 0;//41; + modules[4] = 0;//40; + modules[5] = 0;//31; + x_pv_game_data.Load(824, 24, charas, modules); shaders_ft.env_vert_set(3, vec4_identity); shaders_ft.env_vert_set(4, vec4_null); @@ -782,7 +789,6 @@ extern vec2d input_move; extern vec2d input_rotate; extern double_t input_roll; extern bool input_reset; -extern bool input_shaders_reload; int32_t global_ctrl_frames = 0; @@ -807,7 +813,7 @@ static void render_ctrl(render_context* rctx) { if (old_width != width || old_height != height || old_scale != scale) { render_resize_fb(rctx, true); - camera_set_res(cam, internal_3d_res.x, internal_3d_res.y); + cam->set_res(internal_3d_res.x, internal_3d_res.y); } old_width = width; old_height = height; @@ -825,30 +831,24 @@ static void render_ctrl(render_context* rctx) { } lock_unlock(&imgui_context_lock); - if (input_shaders_reload) { - input_shaders_reload = false; - render_shaders_free(); - render_shaders_load(); - } - if (window_handle == GetForegroundWindow()) { if (input_reset) { input_reset = false; - camera_reset(cam); - //camera_set_position(cam, &((vec3){ 1.35542f, 1.41634f, 1.27852f })); - //camera_rotate(cam, &((vec2d){ -45.0, -32.5 })); - //camera_set_position(cam, &((vec3){ -6.67555f, 4.68882f, -3.67537f })); - //camera_rotate(cam, &((vec2d){ 136.5, -20.5 })); - vec3 view_point = { 0.0f, 1.0f, 3.45f }; - camera_set_view_point(cam, &view_point); - vec3 interest = { 0.0f, 1.0f, 0.0f }; - camera_set_interest(cam, &interest); - //camera_set_fov(cam, 70.0); + cam->reset(); + //cam->set_position({ 1.35542f, 1.41634f, 1.27852f }); + //cam->rotate({ -45.0, -32.5 }); + //cam->set_position({ -6.67555f, 4.68882f, -3.67537f }); + //cam->rotate({ 136.5, -20.5 }); + cam->set_view_point({ 0.0f, 1.0f, 3.45f }); + cam->set_interest({ 0.0f, 1.0f, 0.0f }); + //cam->set_fov(70.0); + cam->set_fast_change_hist0(true); } else { - camera_rotate(cam, &input_rotate); - camera_move(cam, &input_move); - camera_roll(cam, input_roll); + cam->rotate(input_rotate); + cam->move(input_move); + if (input_roll != 0.0) + cam->set_roll(cam->get_roll() + input_roll); } } @@ -882,8 +882,8 @@ static void render_ctrl(render_context* rctx) { glBufferSubData(GL_UNIFORM_BUFFER, 0, COMMON_DATA_SIZE, &common_data); gl_state_bind_uniform_buffer(0); - cube_line_shader.set("vp", false, cam->view_projection); - cube_line_point_shader.set("vp", false, cam->view_projection); + cube_line_shader->set("vp", false, cam->view_projection); + cube_line_point_shader->set("vp", false, cam->view_projection); } static void cube_line_draw(shader_glsl* shader, camera* cam, vec3* trans, float_t line_size, vec4* color) { @@ -956,7 +956,7 @@ static void render_draw(render_context* rctx) { glViewport(0, 0, internal_3d_res.x, internal_3d_res.y); - render_texture_bind(&rctx->post_process.rend_texture, 0); + rctx->post_process.rend_texture.bind(); gl_state_set_depth_mask(GL_TRUE); glClearBufferfv(GL_COLOR, 0, color_clear); glClearBufferfv(GL_DEPTH, 0, &depth_clear); @@ -969,14 +969,14 @@ static void render_draw(render_context* rctx) { glClearBufferfv(GL_COLOR, 0, (GLfloat*)&_clear_color); } - camera_update(cam); + cam->update(); rctx->disp(); int32_t screen_x_offset = (width - internal_2d_res.x) / 2 + (width - internal_2d_res.x) % 2; int32_t screen_y_offset = (height - internal_2d_res.y) / 2 + (width - internal_2d_res.x) % 2; glViewport(screen_x_offset, screen_y_offset, internal_2d_res.x, internal_2d_res.y); - render_texture_bind(&rctx->post_process.screen_texture, 0); + rctx->post_process.screen_texture.bind(); gl_state_bind_uniform_buffer_base(0, common_data_ubo); classes_process_draw(classes, classes_count); @@ -1000,7 +1000,7 @@ static void render_draw(render_context* rctx) { size_t object_bone_count = rob_bone_data->object_bone_count; size_t total_bone_count = rob_bone_data->total_bone_count; size_t ik_bone_count = rob_bone_data->ik_bone_count; - cube_line_shader.use(); + cube_line_shader->use(); for (bone_node& j : rob_bone_data->nodes) { if (!j.parent) continue; @@ -1010,7 +1010,7 @@ static void render_draw(render_context* rctx) { mat4_get_translation(j.mat, &trans[1]); if (memcmp(&trans[0], &trans[1], sizeof(vec3))) - cube_line_draw(&cube_line_shader, cam, trans, CUBE_LINE_SIZE, &bone_color); + cube_line_draw(cube_line_shader, cam, trans, CUBE_LINE_SIZE, &bone_color); } gl_state_bind_array_buffer(0); @@ -1059,11 +1059,11 @@ static void render_draw(render_context* rctx) { mat4_mult_vec3(&cam->inv_view_rot, &trans[3], &trans[3]); gl_state_bind_vertex_array(cube_line_point_vao); - cube_line_point_shader.use(); - cube_line_point_shader.set("trans", 4, trans); - cube_line_point_shader.set("dark_border_end", + cube_line_point_shader->use(); + cube_line_point_shader->set("trans", 4, trans); + cube_line_point_shader->set("dark_border_end", ((CUBE_LINE_POINT_SIZE - (CUBE_LINE_SIZE * 1.125f)) / (2.0f * CUBE_LINE_POINT_SIZE))); - cube_line_point_shader.set("dark_border_start", + cube_line_point_shader->set("dark_border_start", (1.0f - ((CUBE_LINE_POINT_SIZE - (CUBE_LINE_SIZE * 1.125f)) / (2.0f * CUBE_LINE_POINT_SIZE)))); glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, (GLsizei)cube_line_points.size()); cube_line_points.clear(); @@ -1090,6 +1090,11 @@ static void render_dispose(render_context* rctx) { ImGui::DestroyContext(imgui_context); lock_free(&imgui_context_lock); + data_struct* aft_data = &data_list[DATA_AFT]; + motion_database* aft_mot_db = &aft_data->data_ft.mot_db; + object_database* aft_obj_db = &aft_data->data_ft.obj_db; + motion_set_unload_motion(aft_mot_db->get_motion_set_id("CMN")); + task_rob_manager_free_task(); //pv_game_data.SetDest(); x_pv_game_data.SetDest(); @@ -1098,19 +1103,41 @@ static void render_dispose(render_context* rctx) { task_pv_db_free_task(); //rob_chara_array_free_chara_id(0); - timer_reset(&render_timer); + render_timer->reset(); for (int32_t i = 0; i < 30; i++) { - timer_start_of_cycle(&render_timer); + render_timer->start_of_cycle(); lock_lock(&render_lock); app::TaskWork::Ctrl(); file_handler_storage_ctrl(); + app::TaskWork::Basic(); lock_unlock(&render_lock); - timer_end_of_cycle(&render_timer); + render_timer->end_of_cycle(); } light_param_data_storage::unload(); + if (grid_shader) { + delete grid_shader; + grid_shader = 0; + } + + if (cube_line_point_shader) { + delete cube_line_point_shader; + cube_line_point_shader = 0; + } + + if (cube_line_shader) { + delete cube_line_shader; + cube_line_shader = 0; + } + + object_storage_unload_set(aft_obj_db, "DBG"); + + task_pv_db_free(); light_param_storage_data_free(); + task_stage_modern_free(); + dtm_stg_free(); + task_stage_free(); auth_3d_data_free(); rob_free(); app::task_work_free(); @@ -1120,10 +1147,6 @@ static void render_dispose(render_context* rctx) { render_shaders_free(); - grid_shader.unload(); - cube_line_point_shader.unload(); - cube_line_shader.unload(); - glDeleteBuffers(1, &common_data_ubo); glDeleteBuffers(1, &grid_vbo); glDeleteBuffers(1, &cube_line_point_instance_vbo); diff --git a/src/CLOUD/render.h b/src/CLOUD/render.hpp similarity index 95% rename from src/CLOUD/render.h rename to src/CLOUD/render.hpp index fb1c7bf4..74ab19ce 100644 --- a/src/CLOUD/render.h +++ b/src/CLOUD/render.hpp @@ -5,7 +5,7 @@ #pragma once -#include "shared.h" +#include "shared.hpp" #include "../KKdLib/vec.hpp" struct render_init_struct { diff --git a/src/CLOUD/shared.c b/src/CLOUD/shared.cpp similarity index 93% rename from src/CLOUD/shared.c rename to src/CLOUD/shared.cpp index 482fd942..7448a368 100644 --- a/src/CLOUD/shared.c +++ b/src/CLOUD/shared.cpp @@ -3,12 +3,12 @@ GitHub/GitLab: korenkonder */ -#include "shared.h" -#include "classes/data_test.h" -#include "classes/data_view.h" -#include "classes/glitter_editor.h" -#include "classes/graphics.h" -#include "classes/information.h" +#include "shared.hpp" +#include "classes/data_test.hpp" +#include "classes/data_view.hpp" +#include "classes/glitter_editor.hpp" +#include "classes/graphics.hpp" +#include "classes/information.hpp" classes_data classes[] = { { diff --git a/src/CLOUD/shared.h b/src/CLOUD/shared.hpp similarity index 96% rename from src/CLOUD/shared.h rename to src/CLOUD/shared.hpp index 8300e810..d80f8f38 100644 --- a/src/CLOUD/shared.h +++ b/src/CLOUD/shared.hpp @@ -5,7 +5,7 @@ #pragma once -#include "classes.h" +#include "classes.hpp" #define CIMGUI_DEFINE_ENUMS_AND_STRUCTS #include #include diff --git a/src/CLOUD/sound.c b/src/CLOUD/sound.cpp similarity index 75% rename from src/CLOUD/sound.c rename to src/CLOUD/sound.cpp index d9e8c039..653bd84a 100644 --- a/src/CLOUD/sound.c +++ b/src/CLOUD/sound.cpp @@ -3,18 +3,18 @@ GitHub/GitLab: korenkonder */ -#include "sound.h" -#include "../CRE/timer.h" +#include "sound.hpp" +#include "../CRE/timer.hpp" #include -timer sound_timer; +timer* sound_timer; extern bool close; int32_t sound_main(void* arg) { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); timeBeginPeriod(1); - timer_init(&sound_timer, 60.0); + sound_timer = new timer(60.0); bool state_wait = false; bool state_disposed = false; @@ -24,10 +24,10 @@ int32_t sound_main(void* arg) { state_disposed = state == RENDER_DISPOSING; lock_unlock(&state_lock); if (state_disposed) { - timer_dispose(&sound_timer); + delete sound_timer; return 0; } - timer_sleep(&sound_timer, 0.0625); + sound_timer->sleep(0.0625); } while (state_wait); lock_lock(&state_lock); @@ -35,17 +35,17 @@ int32_t sound_main(void* arg) { lock_unlock(&state_lock); bool local_close = false; - timer_reset(&sound_timer); + sound_timer->reset(); while (!close && !local_close) { - timer_start_of_cycle(&sound_timer); + sound_timer->start_of_cycle(); lock_lock(&state_lock); local_close = state == RENDER_DISPOSING; lock_unlock(&state_lock); classes_process_sound(classes, classes_count); - timer_end_of_cycle(&sound_timer); + sound_timer->end_of_cycle(); } - timer_dispose(&sound_timer); + delete sound_timer; lock_lock(&state_lock); enum_and(thread_flags, ~THREAD_SOUND); diff --git a/src/CLOUD/sound.h b/src/CLOUD/sound.hpp similarity index 83% rename from src/CLOUD/sound.h rename to src/CLOUD/sound.hpp index 428aa628..c9d727bd 100644 --- a/src/CLOUD/sound.h +++ b/src/CLOUD/sound.hpp @@ -5,6 +5,6 @@ #pragma once -#include "shared.h" +#include "shared.hpp" extern int32_t sound_main(void* arg); diff --git a/src/CLOUD/unedat.c b/src/CLOUD/unedat.c deleted file mode 100644 index 351655ac..00000000 --- a/src/CLOUD/unedat.c +++ /dev/null @@ -1,426 +0,0 @@ -#include "unedat.h" -#define AES128 -#include "../KKdLib/aes.hpp" -#include "lz.h" -#include - -void aescbc128_decrypt(uint8_t* key, uint8_t* iv, uint8_t* in, uint8_t* out, int len) { - aes128_ctx ctx; - aes128_init_ctx_iv(&ctx, key, iv); - memcpy(out, in, len); - aes128_cbc_decrypt_buffer(&ctx, out, len); - - // Reset the IV. - memset(iv, 0, 0x10); -} - -void aescbc128_encrypt(uint8_t* key, uint8_t* iv, uint8_t* in, uint8_t* out, int len) { - aes128_ctx ctx; - aes128_init_ctx_iv(&ctx, key, iv); - memcpy(out, in, len); - aes128_cbc_encrypt_buffer(&ctx, out, len); - - // Reset the IV. - memset(iv, 0, 0x10); -} - -void aesecb128_encrypt(uint8_t* key, uint8_t* in, uint8_t* out) { - aes128_ctx ctx; - aes128_init_ctx(&ctx, key); - memcpy(out, in, 0x10); - aes128_ecb_encrypt(&ctx, out); -} - -void rap_to_rif(uint8_t* rap, uint8_t* rif) { - int i; - int round; - aes128_ctx ctx; - - uint8_t key[0x10]; - uint8_t iv[0x10]; - memcpy(key, rap, 0x10); - memset(iv, 0, 0x10); - - // Initial decrypt. - aes128_init_ctx_iv(&ctx, RAP_KEY, iv); - aes128_cbc_decrypt_buffer(&ctx, key, 0x10); - - // rap2rifkey round. - for (round = 0; round < 5; ++round) { - for (i = 0; i < 16; ++i) { - int p = RAP_PBOX[i]; - key[p] ^= RAP_E1[p]; - } - - for (i = 15; i > 0; --i) { - int p = RAP_PBOX[i]; - int pp = RAP_PBOX[i - 1]; - key[p] ^= key[pp]; - } - - uint8_t o = 0; - for (i = 0; i < 16; ++i) { - int p = RAP_PBOX[i]; - uint8_t kc = key[p] - o; - uint8_t ec2 = RAP_E2[p]; - if (!o || kc != 0xFF) - o = kc < ec2 ? 1 : 0; - key[p] = kc - ec2; - } - } - - memcpy(rif, key, 0x10); -} - -void generate_key(int crypto_mode, int version, uint8_t* key_final, uint8_t* iv_final, uint8_t* key, uint8_t* iv) { - int mode = crypto_mode & 0xF0000000; - switch (mode) { - case 0x10000000: - // Encrypted ERK. - // Decrypt the key with EDAT_KEY + EDAT_IV and copy the original IV. - aescbc128_decrypt(version ? EDAT_KEY_1 : EDAT_KEY_0, EDAT_IV, key, key_final, 0x10); - memcpy(iv_final, iv, 0x10); - break; - case 0x20000000: - // Default ERK. - // Use EDAT_KEY and EDAT_IV. - memcpy(key_final, version ? EDAT_KEY_1 : EDAT_KEY_0, 0x10); - memcpy(iv_final, EDAT_IV, 0x10); - break; - case 0x00000000: - // Unencrypted ERK. - // Use the original key and iv. - memcpy(key_final, key, 0x10); - memcpy(iv_final, iv, 0x10); - break; - }; -} - -void generate_hash(int hash_mode, int version, uint8_t* hash_final, uint8_t* hash) { - int mode = hash_mode & 0xF0000000; - switch (mode) { - case 0x10000000: - // Encrypted HASH. - // Decrypt the hash with EDAT_KEY + EDAT_IV. - aescbc128_decrypt(version ? EDAT_KEY_1 : EDAT_KEY_0, EDAT_IV, hash, hash_final, 0x10); - break; - case 0x20000000: - // Default HASH. - // Use EDAT_HASH. - memcpy(hash_final, version ? EDAT_HASH_1 : EDAT_HASH_0, 0x10); - break; - case 0x00000000: - // Unencrypted ERK. - // Use the original hash. - memcpy(hash_final, hash, 0x10); - break; - }; -} - -bool decrypt(int crypto_mode, int version, uint8_t* in, uint8_t* out, int length, uint8_t* key, uint8_t* iv) { - // Setup buffers for key, iv and hash. - uint8_t key_final[0x10]; - uint8_t iv_final[0x10]; - - memset(key_final, 0, 0x10); - memset(iv_final, 0, 0x10); - - // Generate crypto key and hash. - generate_key(crypto_mode, version, key_final, iv_final, key, iv); - - if ((crypto_mode & 0xFF) == 0x01) // No algorithm. - memcpy(out, in, length); - else if ((crypto_mode & 0xFF) == 0x02) // AES128-CBC - aescbc128_decrypt(key_final, iv_final, in, out, length); - else - return false; - return true; -} - -// EDAT/SDAT functions. -void get_block_key(int block, NPD_HEADER* npd, uint8_t* dest_key) { - uint8_t empty_key[0x10]; - memset(empty_key, 0, 0x10); - uint8_t* src_key = (npd->version <= 1) ? empty_key : npd->dev_hash; - memcpy(dest_key, src_key, 0xC); - store_reverse_endianness_int32_t(block, &dest_key[0xC]); -} - -// for out data, allocate a buffer the size of 'edat->block_size' -// Also, set 'in file' to the beginning of the encrypted data, which may be offset -// if inside another file, but normally just reset to beginning of file -// returns number of bytes written, -1 for error -int decrypt_block(stream& in, uint8_t* out, EDAT_HEADER* edat, NPD_HEADER* npd, - uint8_t* crypt_key, uint32_t block_num, uint32_t total_blocks, int64_t size_left) { - // Get metadata info and setup buffers. - const int64_t metadata_section_size = edat->flags & (EDAT_COMPRESSED_FLAG | EDAT_FLAG_0x20) ? 0x20 : 0x10; - const int metadata_offset = 0x100; - - uint8_t key_result[0x10] = { 0 }; - - uint64_t offset = 0; - uint64_t metadata_sec_offset = 0; - int32_t length = 0; - int32_t compression_end = 0; - uint8_t empty_iv[0x10]; - memset(empty_iv, 0, 0x10); - - size_t file_offset = in.get_position(); - - // Decrypt the metadata. - if (edat->flags & EDAT_COMPRESSED_FLAG) { - metadata_sec_offset = metadata_offset + block_num * metadata_section_size; - - in.set_position(file_offset + metadata_sec_offset, SEEK_SET); - - uint8_t metadata[0x20]; - memset(metadata, 0, 0x20); - in.read(metadata, 0x20); - - // If the data is compressed, decrypt the metadata. - // NOTE: For NPD version 1 the metadata is not encrypted. - if (npd->version <= 1) { - offset = load_reverse_endianness_uint64_t(&metadata[0x10]); - length = load_reverse_endianness_int32_t(&metadata[0x18]); - compression_end = load_reverse_endianness_int32_t(&metadata[0x1C]); - } - else { - uint8_t dec[0x10]; - dec[0x00] = metadata[0xC] ^ metadata[0x8] ^ metadata[0x10]; - dec[0x01] = metadata[0xD] ^ metadata[0x9] ^ metadata[0x11]; - dec[0x02] = metadata[0xE] ^ metadata[0xA] ^ metadata[0x12]; - dec[0x03] = metadata[0xF] ^ metadata[0xB] ^ metadata[0x13]; - dec[0x04] = metadata[0x4] ^ metadata[0x8] ^ metadata[0x14]; - dec[0x05] = metadata[0x5] ^ metadata[0x9] ^ metadata[0x15]; - dec[0x06] = metadata[0x6] ^ metadata[0xA] ^ metadata[0x16]; - dec[0x07] = metadata[0x7] ^ metadata[0xB] ^ metadata[0x17]; - dec[0x08] = metadata[0xC] ^ metadata[0x0] ^ metadata[0x18]; - dec[0x09] = metadata[0xD] ^ metadata[0x1] ^ metadata[0x19]; - dec[0x0A] = metadata[0xE] ^ metadata[0x2] ^ metadata[0x1A]; - dec[0x0B] = metadata[0xF] ^ metadata[0x3] ^ metadata[0x1B]; - dec[0x0C] = metadata[0x4] ^ metadata[0x0] ^ metadata[0x1C]; - dec[0x0D] = metadata[0x5] ^ metadata[0x1] ^ metadata[0x1D]; - dec[0x0E] = metadata[0x6] ^ metadata[0x2] ^ metadata[0x1E]; - dec[0x0F] = metadata[0x7] ^ metadata[0x3] ^ metadata[0x1F]; - - offset = load_reverse_endianness_uint64_t(&dec[0x00]); - length = load_reverse_endianness_int32_t(&dec[0x08]); - compression_end = load_reverse_endianness_int32_t(&dec[0x0C]); - } - } - else if (edat->flags & EDAT_FLAG_0x20) { - // If FLAG 0x20, the metadata precedes each data block. - metadata_sec_offset = metadata_offset + block_num * (metadata_section_size + edat->block_size); - - in.set_position(file_offset + metadata_sec_offset, SEEK_SET); - - uint8_t metadata[0x20]; - memset(metadata, 0, 0x20); - in.read(metadata, 0x20); - - offset = metadata_sec_offset + 0x20; - length = edat->block_size; - - if ((block_num == (total_blocks - 1)) && (edat->file_size % edat->block_size)) - length = (int32_t)(edat->file_size % edat->block_size); - } - else { - metadata_sec_offset = metadata_offset + (uint64_t)block_num * metadata_section_size; - in.set_position(file_offset + metadata_sec_offset, SEEK_SET); - offset = metadata_offset + (uint64_t)block_num * edat->block_size + total_blocks * metadata_section_size; - length = edat->block_size; - - if ((block_num == (total_blocks - 1)) && (edat->file_size % edat->block_size)) - length = (int32_t)(edat->file_size % edat->block_size); - } - - // Locate the real data. - const int pad_length = length; - length = (pad_length + 0xF) & 0xFFFFFFF0; - - // Setup buffers for decryption and read the data. - memset(key_result, 0, 0x10); - - uint8_t* enc_data = force_malloc_s(uint8_t, length); - uint8_t* dec_data = force_malloc_s(uint8_t, length); - in.set_position(file_offset + offset, 0); - in.read(enc_data, length); - - // Generate a key for the current block. - uint8_t b_key[16]; - get_block_key(block_num, npd, b_key); - - // Encrypt the block key with the crypto key. - aesecb128_encrypt(crypt_key, b_key, key_result); - - // Setup the crypto and hashing mode based on the extra flags. - int crypto_mode = ((edat->flags & EDAT_FLAG_0x02) == 0) ? 0x2 : 0x1; - - if (edat->flags & EDAT_ENCRYPTED_KEY_FLAG) - crypto_mode |= 0x10000000; - - if (edat->flags & EDAT_DEBUG_DATA_FLAG) { - // Reset the flags. - crypto_mode |= 0x01000000; - // Simply copy the data without the header or the footer. - memcpy(dec_data, enc_data, length); - } - else { - // IV is null if NPD version is 1 or 0. - uint8_t* iv = (npd->version <= 1) ? empty_iv : npd->digest; - // Call main crypto routine on this data block. - if (!decrypt(crypto_mode, (npd->version == 4), enc_data, dec_data, length, key_result, iv)) - return -1; - } - - // Apply additional de-compression if needed and write the decrypted data. - if ((edat->flags & EDAT_COMPRESSED_FLAG) && compression_end) { - int res = decompress(out, dec_data, edat->block_size); - size_left -= res; - - if (size_left == 0 && res < 0) - return -1; - return res; - } - - memcpy(out, dec_data, pad_length); - return pad_length; -} - -// EDAT/SDAT decryption. -// reset file to beginning of data before calling -int decrypt_data(stream& in, stream& out, EDAT_HEADER* edat, NPD_HEADER* npd, unsigned char* crypt_key) { - const int total_blocks = (int)((edat->file_size + edat->block_size - 1) / edat->block_size); - int64_t size_left = edat->file_size; - uint8_t* data = force_malloc_s(uint8_t, edat->block_size); - - for (int i = 0; i < total_blocks; i++) { - in.set_position(0, 0); - memset(data, 0, edat->block_size); - int res = decrypt_block(in, data, edat, npd, crypt_key, i, total_blocks, size_left); - if (res == -1) - return 1; - - size_left -= res; - out.write(data, res); - } - free(data); - - return 0; -} - -void read_npd_edat_header(stream& input, NPD_HEADER* NPD, EDAT_HEADER* EDAT) { - char npd_header[0x80]; - char edat_header[0x10]; - input.read(npd_header, sizeof(npd_header)); - input.read(edat_header, sizeof(edat_header)); - - memcpy(&NPD->magic, npd_header, 0x04); - NPD->version = load_reverse_endianness_int32_t(&npd_header[0x04]); - NPD->license = load_reverse_endianness_int32_t(&npd_header[0x08]); - NPD->type = load_reverse_endianness_int32_t(&npd_header[0x0C]); - memcpy(&NPD->content_id, &npd_header[0x10], 0x30); - memcpy(&NPD->digest, &npd_header[0x40], 0x10); - memcpy(&NPD->title_hash, &npd_header[0x50], 0x10); - memcpy(&NPD->dev_hash, &npd_header[0x60], 0x10); - NPD->unk1 = load_reverse_endianness_int64_t(&npd_header[0x70]); - NPD->unk2 = load_reverse_endianness_int64_t(&npd_header[0x78]); - - EDAT->flags = load_reverse_endianness_int32_t(&edat_header[0x00]); - EDAT->block_size = load_reverse_endianness_int32_t(&edat_header[0x04]); - EDAT->file_size = load_reverse_endianness_int64_t(&edat_header[0x08]); -} - -bool extract_all_data(stream& input, stream& output, uint8_t* devKlic, uint8_t* rifKey) { - // Setup NPD and EDAT/SDAT structs. - NPD_HEADER NPD; - EDAT_HEADER EDAT; - - // Read in the NPD and EDAT/SDAT headers. - read_npd_edat_header(input, &NPD, &EDAT); - - const char* npd_magic = "NPD"; - if (memcmp(&NPD.magic, npd_magic, 0x04)) - return 1; - - // Set decryption key. - uint8_t key[16]; - - // Check EDAT/SDAT flag. - if ((EDAT.flags & SDAT_FLAG) == SDAT_FLAG) - // Generate SDAT key. - for (int i = 0; i < 16; i++) - key[i] = NPD.dev_hash[i] ^ SDAT_KEY[i]; - else if (NPD.license == 0x3) // Type 3: Use supplied devklic. - memcpy(key, devKlic, 0x10); - else if (NPD.license == 0x2) // Type 2: Use key from RAP file (RIF key). - memcpy(key, rifKey, 0x10); - else if (NPD.license == 0x1) // Type 1: Use network activation. - memcpy(key, rifKey, 0x10); - - input.set_position(0, 0); - if (decrypt_data(input, output, &EDAT, &NPD, key)) - return 1; - - return 0; -} - -void GetEdatRifKeyFromRapFile(stream& rap_file, uint8_t* rifKey) { - uint8_t rapKey[0x10]; - rap_file.read(rapKey, 0x10); - rap_to_rif(rapKey, rifKey); -} - -// Decrypts full file -void DecryptEDAT(stream& input, stream& output, int mode, const char* rap_file_name, uint8_t* custom_klic) { - if (!rap_file_name) - return; - - // Prepare the files. - input.set_position(0, 0); - - // Set keys (RIF and DEVKLIC). - uint8_t rifKey[16]; - uint8_t devklic[16]; - - // Select the EDAT key mode. - switch (mode) { - case 0: - break; - case 1: - memcpy(devklic, NP_KLIC_FREE, 0x10); - break; - case 2: - memcpy(devklic, NP_OMAC_KEY_2, 0x10); - break; - case 3: - memcpy(devklic, NP_OMAC_KEY_3, 0x10); - break; - case 4: - memcpy(devklic, NP_KLIC_KEY, 0x10); - break; - case 5: - memcpy(devklic, NP_PSX_KEY, 0x10); - break; - case 6: - memcpy(devklic, NP_PSP_KEY_1, 0x10); - break; - case 7: - memcpy(devklic, NP_PSP_KEY_2, 0x10); - break; - case 8: - if (custom_klic) - memcpy(devklic, custom_klic, 0x10); - break; - } - - // Read the RAP file, if provided. - if (*rap_file_name) { - stream rap; - rap.open(rap_file_name, "rb"); - if (rap.io.stream) - GetEdatRifKeyFromRapFile(rap, rifKey); - } - - extract_all_data(input, output, devklic, rifKey); -} diff --git a/src/CLOUD/unedat.h b/src/CLOUD/unedat.h deleted file mode 100644 index 9bc1a0ce..00000000 --- a/src/CLOUD/unedat.h +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once - -#include "../KKdLib/default.hpp" -#include "../KKdLib/io/stream.hpp" - -#define SDAT_FLAG 0x01000000 -#define EDAT_COMPRESSED_FLAG 0x00000001 -#define EDAT_FLAG_0x02 0x00000002 -#define EDAT_ENCRYPTED_KEY_FLAG 0x00000008 -#define EDAT_FLAG_0x10 0x00000010 -#define EDAT_FLAG_0x20 0x00000020 -#define EDAT_DEBUG_DATA_FLAG 0x80000000 - -static uint8_t NP_KLIC_FREE[0x10] = { - 0x72, 0xF9, 0x90, 0x78, 0x8F, 0x9C, 0xFF, 0x74, 0x57, 0x25, 0xF0, 0x8E, 0x4C, 0x12, 0x83, 0x87 -}; - -static uint8_t NP_OMAC_KEY_2[0x10] = { - 0x6B, 0xA5, 0x29, 0x76, 0xEF, 0xDA, 0x16, 0xEF, 0x3C, 0x33, 0x9F, 0xB2, 0x97, 0x1E, 0x25, 0x6B -}; - -static uint8_t NP_OMAC_KEY_3[0x10] = { - 0x9B, 0x51, 0x5F, 0xEA, 0xCF, 0x75, 0x06, 0x49, 0x81, 0xAA, 0x60, 0x4D, 0x91, 0xA5, 0x4E, 0x97 -}; - -static uint8_t NP_KLIC_KEY[0x10] = { - 0xF2, 0xFB, 0xCA, 0x7A, 0x75, 0xB0, 0x4E, 0xDC, 0x13, 0x90, 0x63, 0x8C, 0xCD, 0xFD, 0xD1, 0xEE -}; - -static uint8_t NP_RIF_KEY[0x10] = { - 0xDA, 0x7D, 0x4B, 0x5E, 0x49, 0x9A, 0x4F, 0x53, 0xB1, 0xC1, 0xA1, 0x4A, 0x74, 0x84, 0x44, 0x3B -}; - -// PSP Minis -static uint8_t NP_PSP_KEY_1[0x10] = { - 0x2A, 0x6A, 0xFB, 0xCF, 0x43, 0xD1, 0x57, 0x9F, 0x7D, 0x73, 0x87, 0x41, 0xA1, 0x3B, 0xD4, 0x2E -}; - -// PSP Remasters -static uint8_t NP_PSP_KEY_2[0x10] = { - 0x0D, 0xB8, 0x57, 0x32, 0x36, 0x6C, 0xD7, 0x34, 0xFC, 0x87, 0x9E, 0x74, 0x33, 0x43, 0xBB, 0x4F -}; - -static uint8_t NP_PSX_KEY[0x10] = { - 0x52, 0xC0, 0xB5, 0xCA, 0x76, 0xD6, 0x13, 0x4B, 0xB4, 0x5F, 0xC6, 0x6C, 0xA6, 0x37, 0xF2, 0xC1 -}; - -static uint8_t RAP_KEY[0x10] = { - 0x86, 0x9F, 0x77, 0x45, 0xC1, 0x3F, 0xD8, 0x90, 0xCC, 0xF2, 0x91, 0x88, 0xE3, 0xCC, 0x3E, 0xDF -}; - -static uint8_t RAP_PBOX[0x10] = { - 0x0C, 0x03, 0x06, 0x04, 0x01, 0x0B, 0x0F, 0x08, 0x02, 0x07, 0x00, 0x05, 0x0A, 0x0E, 0x0D, 0x09 -}; - -static uint8_t RAP_E1[0x10] = { - 0xA9, 0x3E, 0x1F, 0xD6, 0x7C, 0x55, 0xA3, 0x29, 0xB7, 0x5F, 0xDD, 0xA6, 0x2A, 0x95, 0xC7, 0xA5 -}; - -static uint8_t RAP_E2[0x10] = { - 0x67, 0xD4, 0x5D, 0xA3, 0x29, 0x6D, 0x00, 0x6A, 0x4E, 0x7C, 0x53, 0x7B, 0xF5, 0x53, 0x8C, 0x74 -}; - -static uint8_t SDAT_KEY[0x10] = { - 0x0D, 0x65, 0x5E, 0xF8, 0xE6, 0x74, 0xA9, 0x8A, 0xB8, 0x50, 0x5C, 0xFA, 0x7D, 0x01, 0x29, 0x33 -}; - -static uint8_t EDAT_KEY_0[0x10] = { - 0xBE, 0x95, 0x9C, 0xA8, 0x30, 0x8D, 0xEF, 0xA2, 0xE5, 0xE1, 0x80, 0xC6, 0x37, 0x12, 0xA9, 0xAE -}; - -static uint8_t EDAT_HASH_0[0x10] = { - 0xEF, 0xFE, 0x5B, 0xD1, 0x65, 0x2E, 0xEB, 0xC1, 0x19, 0x18, 0xCF, 0x7C, 0x04, 0xD4, 0xF0, 0x11 -}; - -static uint8_t EDAT_KEY_1[0x10] = { - 0x4C, 0xA9, 0xC1, 0x4B, 0x01, 0xC9, 0x53, 0x09, 0x96, 0x9B, 0xEC, 0x68, 0xAA, 0x0B, 0xC0, 0x81 -}; - -static uint8_t EDAT_HASH_1[0x10] = { - 0x3D, 0x92, 0x69, 0x9B, 0x70, 0x5B, 0x07, 0x38, 0x54, 0xD8, 0xFC, 0xC6, 0xC7, 0x67, 0x27, 0x47 -}; - -static uint8_t EDAT_IV[0x10] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -typedef struct NPD_HEADER { - uint32_t magic; - int32_t version; - int32_t license; - int32_t type; - uint8_t content_id[0x30]; - uint8_t digest[0x10]; - uint8_t title_hash[0x10]; - uint8_t dev_hash[0x10]; - int64_t unk1; - int64_t unk2; -} NPD_HEADER; - -typedef struct EDAT_HEADER { - int32_t flags; - int32_t block_size; - int64_t file_size; -} EDAT_HEADER; - -// Decrypts full file, or null/empty file -extern void rap_to_rif(uint8_t* rap, uint8_t* rif); -extern void DecryptEDAT(stream& input, stream& output, int mode, const char* rap_file_name, uint8_t* custom_klic); -extern void GetEdatRifKeyFromRapFile(stream& rap_file, uint8_t* rifKey); diff --git a/src/CLOUD/x_pv_game.cpp b/src/CLOUD/x_pv_game.cpp index 9cd6785a..fe8c4e70 100644 --- a/src/CLOUD/x_pv_game.cpp +++ b/src/CLOUD/x_pv_game.cpp @@ -18,7 +18,7 @@ #include "../KKdLib/farc.hpp" #include "../KKdLib/sort.hpp" #include "input.hpp" -#include "classes/imgui_helper.h" +#include "classes/imgui_helper.hpp" enum dsc_x_func { DSC_X_END = 0, @@ -395,10 +395,7 @@ bool x_pv_game::Ctrl() { auth_3d_data_load_category(light_category.c_str()); - for (pvpp_chara& i : pp->chara) - if (i.chara_effect_init) - for (pvpp_chara_effect_a3da& j : i.chara_effect.effect_a3da) - auth_3d_data_load_category(x_data, camera_category.c_str(), camera_category_hash); + auth_3d_data_load_category(camera_category.c_str()); bool pv_glt = pv_glitter->hash != hash_murmurhash_empty; bool stg_glt = stage_glitter->hash != hash_murmurhash_empty; @@ -1016,35 +1013,35 @@ void x_pv_game::Window() { return; } - w = imguiGetContentRegionAvailWidth(); + w = ImGui::GetContentRegionAvailWidth(); if (ImGui::BeginTable("buttons", 2)) { ImGui::TableSetupColumn("", ImGuiTableColumnFlags_WidthFixed, w * 0.5f); ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton(pause || (!pause && step_frame) ? "Play (K)" : "Pause (K)", { w, 0.0f })) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed(pause || (!pause && step_frame) ? "Play (K)" : "Pause (K)", { w, 0.0f })) pause ^= true; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Step Frame (L)", { w, 0.0f })) { + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Step Frame (L)", { w, 0.0f })) { pause = true; step_frame = true; } ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Stop (Ctrl+K)", { w, 0.0f })) + w = ImGui::GetContentRegionAvailWidth(); + if (ImGui::ButtonEnterKeyPressed("Stop (Ctrl+K)", { w, 0.0f })) state = 11; ImGui::TableNextColumn(); - w = imguiGetContentRegionAvailWidth(); + w = ImGui::GetContentRegionAvailWidth(); char buf[0x100]; sprintf_s(buf, sizeof(buf), "%d", frame); ImGui::PushStyleColor(ImGuiCol_Button, { 0.0f, 0.0f, 0.0f, 0.0f }); ImGui::PushStyleColor(ImGuiCol_ButtonActive, { 0.0f, 0.0f, 0.0f, 0.0f }); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, { 0.0f, 0.0f, 0.0f, 0.0f }); - imguiButtonEx(buf, { w, 0.0f }, ImGuiButtonFlags_DontClosePopups + ImGui::ButtonExEnterKeyPressed(buf, { w, 0.0f }, ImGuiButtonFlags_DontClosePopups | ImGuiButtonFlags_NoNavFocus | ImGuiButtonFlags_NoHoveredOnFocus); ImGui::PopStyleColor(3); ImGui::EndTable(); @@ -1520,7 +1517,7 @@ bool mot_write_motion(void* data, const char* path, const char* file, uint32_t h } void x_pv_game::Unload() { - if (pv_id == 826) { + if (false && pv_id == 826) { data_struct* aft_data = &data_list[DATA_AFT]; motion_database* aft_mot_db = &aft_data->data_ft.mot_db; @@ -1626,6 +1623,8 @@ void x_pv_game::Unload() { auth_3d_data_unload_category(light_category.c_str()); + auth_3d_data_unload_category(camera_category.c_str()); + category_load.clear(); category_load.shrink_to_fit(); effchrpv_category_load.clear(); @@ -1725,7 +1724,9 @@ void x_struc_104::reset() { end_rot = 0.0f; mot_smooth_len = 12.0f; set_motion.clear(); + set_motion.shrink_to_fit(); set_item.clear(); + set_item.shrink_to_fit(); } x_pv_play_data::x_pv_play_data() : rob_chr(), disp() { @@ -1738,6 +1739,7 @@ x_pv_play_data::~x_pv_play_data() { void x_pv_play_data::reset() { motion.clear(); + motion.shrink_to_fit(); rob_chr = 0; set_motion.clear(); disp = true; @@ -3627,10 +3629,12 @@ static void sub_140122770(x_pv_game* a1, int32_t chara_id) { if (chara_id < 0 || chara_id >= ROB_CHARA_COUNT) return; + x_pv_play_data* playdata = &a1->playdata[chara_id]; + int32_t pv_branch_mode = 0; int32_t time = -1; int32_t prev_time = -1; - a1->playdata[chara_id].field_38.set_motion.clear(); + playdata->field_38.set_motion.clear(); dsc_data* i = a1->dsc_m.data.data(); dsc_data* i_end = a1->dsc_m.data.data() + a1->dsc_m.data.size(); @@ -3651,7 +3655,7 @@ static void sub_140122770(x_pv_game* a1, int32_t chara_id) { motion.motion_index = data[1]; motion.time = time; motion.pv_branch_mode = pv_branch_mode; - a1->playdata[chara_id].field_38.set_motion.push_back(motion); + playdata->field_38.set_motion.push_back(motion); } prev_time = time; i++; diff --git a/src/CLOUD/x_pv_game.hpp b/src/CLOUD/x_pv_game.hpp index 4e15c5b3..9809f117 100644 --- a/src/CLOUD/x_pv_game.hpp +++ b/src/CLOUD/x_pv_game.hpp @@ -15,10 +15,10 @@ #include "../KKdLib/dsc.hpp" #include "../KKdLib/pvpp.hpp" #include "../KKdLib/pvsr.hpp" +#include "../CRE/rob/rob.hpp" #include "../CRE/auth_3d.hpp" -#include "../CRE/rob.hpp" #include "../CRE/task.hpp" -#include "classes.h" +#include "classes.hpp" struct x_pv_game_glitter { std::string name; @@ -265,6 +265,7 @@ public: x_pv_game(); virtual ~x_pv_game() override; + virtual bool Init() override; virtual bool Ctrl() override; virtual bool Dest() override; diff --git a/src/CRE/Glitter/effect_inst.cpp b/src/CRE/Glitter/effect_inst.cpp index 9ff27b83..99db9aa1 100644 --- a/src/CRE/Glitter/effect_inst.cpp +++ b/src/CRE/Glitter/effect_inst.cpp @@ -5,8 +5,8 @@ #include "glitter.hpp" #include "../../KKdLib/str_utils.hpp" +#include "../rob/rob.hpp" #include "../auth_3d.hpp" -#include "../rob.hpp" namespace Glitter { EffectInst::EffectInst(GPM, GLT, Effect* eff, diff --git a/src/CRE/Glitter/emitter_inst.cpp b/src/CRE/Glitter/emitter_inst.cpp index 3e7a8943..bbf5ec83 100644 --- a/src/CRE/Glitter/emitter_inst.cpp +++ b/src/CRE/Glitter/emitter_inst.cpp @@ -574,7 +574,7 @@ namespace Glitter { bool mult = true; mat4 dir_mat; switch (data.direction) { - case DIRECTION_BILLBOARD: + case DIRECTION_BILLBOARD: { if (eff_inst->data.flags & EFFECT_LOCAL) { dir_mat = ((render_context*)GPM_VAL->rctx)->camera->view; mat4_clear_trans(&dir_mat, &dir_mat); @@ -587,7 +587,7 @@ namespace Glitter { mat4_from_mat3(&((render_context*)GPM_VAL->rctx)->camera->inv_view_mat3, &inv_view_mat); mat4_mult(&dir_mat, &inv_view_mat, &dir_mat); mat4_clear_trans(&dir_mat, &dir_mat); - break; + } break; case DIRECTION_Y_AXIS: mat4_rotate_y((float_t)M_PI_2, &dir_mat); break; diff --git a/src/CRE/Glitter/glitter.hpp b/src/CRE/Glitter/glitter.hpp index ab00a396..b1cbc0bf 100644 --- a/src/CRE/Glitter/glitter.hpp +++ b/src/CRE/Glitter/glitter.hpp @@ -19,7 +19,7 @@ #include "../../KKdLib/vec.hpp" #include "../file_handler.hpp" #include "../frame_rate_control.hpp" -#include "../static_var.h" +#include "../static_var.hpp" #include "../task.hpp" #include "../texture.hpp" diff --git a/src/CRE/Glitter/render_group.cpp b/src/CRE/Glitter/render_group.cpp index dfd83a30..60d40d88 100644 --- a/src/CRE/Glitter/render_group.cpp +++ b/src/CRE/Glitter/render_group.cpp @@ -4,7 +4,7 @@ */ #include "glitter.hpp" -#include "../gl_state.h" +#include "../gl_state.hpp" namespace Glitter { RenderGroup::RenderGroup() : flags(), type(), draw_type(), pivot(), diff --git a/src/CRE/Glitter/render_scene.cpp b/src/CRE/Glitter/render_scene.cpp index 1afeb46f..aa79b449 100644 --- a/src/CRE/Glitter/render_scene.cpp +++ b/src/CRE/Glitter/render_scene.cpp @@ -4,12 +4,12 @@ */ #include "glitter.hpp" -#include "../draw_task.h" -#include "../gl_state.h" +#include "../draw_task.hpp" +#include "../gl_state.hpp" #include "../render_context.hpp" -#include "../shader.h" -#include "../shader_ft.h" -#include "../static_var.h" +#include "../shader.hpp" +#include "../shader_ft.hpp" +#include "../static_var.hpp" namespace Glitter { RenderScene::RenderScene() : ctrl_quad(), ctrl_line(), ctrl_locus(), diff --git a/src/CRE/auth_3d.cpp b/src/CRE/auth_3d.cpp index 6b7c0310..3c6b06c9 100644 --- a/src/CRE/auth_3d.cpp +++ b/src/CRE/auth_3d.cpp @@ -6,10 +6,12 @@ #include "auth_3d.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/interpolation.h" +#include "../KKdLib/sort.hpp" #include "../KKdLib/str_utils.hpp" -#include "draw_task.h" +#include "rob/rob.hpp" +#include "draw_task.hpp" #include "object.hpp" -#include "rob.hpp" +#include "pv_db.hpp" #include "stage.hpp" namespace auth_3d_detail { @@ -347,10 +349,10 @@ void auth_3d::ctrl(render_context* rctx) { mat4_mult_vec3_trans(&mat, &view_point, &view_point); camera* cam = rctx->camera; - camera_set_interest(cam, &interest); - camera_set_view_point(cam, &view_point); - camera_set_fov(cam, fov * RAD_TO_DEG); - camera_set_roll(cam, roll * RAD_TO_DEG); + cam->set_interest(interest); + cam->set_view_point(view_point); + cam->set_fov(fov * RAD_TO_DEG); + cam->set_roll(roll * RAD_TO_DEG); break; } @@ -1605,344 +1607,6 @@ bool Auth3dTestTask::Dest() { return true; } -/* -void __fastcall sub_140248480(string *a1, list_int32_t *a2) -{ - list_int32_t_node *v4; // rcx - list_int32_t_node *v5; // rbx - char *v6; // rcx - int32_t *i; // rbx - const char *v8; // rax - size_t v9; // r8 - size_t v10; // rsi - char *v11; // rdi - _BYTE *v12; // rax - _BYTE *v13; // r9 - int v14; // ecx - char *v15; // rax - ssize_t v16; // r9 - char *v17; // rcx - list_int32_t_node *v18; // rdi - list_int32_t_node *v19; // rax - size_t v20; // rdx - int32_t v21; // eax - pv_db_pv *v22; // rax - pv_db_pv_difficulty *v23; // rcx - string_union v24; // kr00_16 - pv_item *__shifted(pv_item,8) v25; // rbx - const char *v26; // rcx - object_info v27; // eax - list_int32_t_node *v28; // rdi - list_int32_t_node *v29; // rax - size_t v30; // rdx - pv_item *__shifted(pv_item,0x20) v31; // rbx - char *v32; // rcx - list_int32_t_node *v33; // rbx - list_int32_t_node *v34; // rdx - size_t v35; // rax - ssize_t v36; // rax - string *v37; // rbx - ssize_t v38; // rax - string *v39; // rbx - char *v40; // rcx - list_int32_t_node *v41; // rbx - list_int32_t_node *v42; // rdx - size_t v43; // rax - char *v44; // rcx - list_int32_t_node *v45; // rbx - list_int32_t_node *v46; // rcx - size_t v47; // rax - int32_t a4; // [rsp+20h] [rbp-49h] BYREF - __int64 v49; // [rsp+28h] [rbp-41h] - string Dst; // [rsp+30h] [rbp-39h] BYREF - string v51; // [rsp+30h] [rbp-39h] FORCED BYREF - string Memory; // [rsp+50h] [rbp-19h] BYREF - vector_int32_t uids; // [rsp+70h] [rbp+7h] BYREF - - v49 = -2i64; - v4 = a2->head->next; - a2->head->next = a2->head; - a2->head->prev = a2->head; - a2->size = 0i64; - if ( v4 != a2->head ) - { - do - { - v5 = v4->next; - operator delete(v4); - v4 = v5; - } - while ( v5 != a2->head ); - } - uids.begin = 0i64; - uids.end = 0i64; - uids.capacity_end = 0i64; - if ( a1->capacity < 0x10 ) - v6 = (char *)a1; - else - v6 = a1->data.ptr; - auth_3d_data_get_category_uids(v6, &uids); - for ( i = uids.begin; i != uids.end; ++i ) - { - v8 = auth_3d_data_get_uid_name(*i); - Dst.capacity = 15i64; - Dst.length = 0i64; - Dst.data.data[0] = 0; - if ( *v8 ) - { - v9 = -1i64; - do - ++v9; - while ( v8[v9] ); - } - else - { - v9 = 0i64; - } - string_assign_char_str(&Dst, v8, v9); - v10 = Dst.length; - if ( Dst.length ) - { - v11 = (char *)&Dst; - if ( Dst.capacity >= 0x10 ) - v11 = Dst.data.ptr; - while ( v10 ) - { - v12 = memchr(v11, '_', v10); - v13 = v12; - if ( !v12 ) - break; - if ( *v12 == asc_14096CDF0[0] ) - v14 = 0; - else - v14 = *v12 < asc_14096CDF0[0] ? -1 : 1; - if ( !v14 ) - { - v15 = (char *)&Dst; - if ( Dst.capacity >= 0x10 ) - v15 = Dst.data.ptr; - v16 = v13 - v15; - if ( v16 != -1 ) - { - sub_1400215A0(&Dst, &Memory, 0i64, v16); - v17 = (char *)&Memory; - if ( Memory.capacity >= 0x10 ) - v17 = Memory.data.ptr; - a4 = obj_database_get_object_set(v17); - if ( a4 != -1 ) - { - v18 = a2->head; - v19 = list_int32_t_buy_node(a2, a2->head, a2->head->prev, &a4); - v20 = a2->size; - if ( v20 == 0xAAAAAAAAAAAAAA9i64 ) - ThrowException("list too long"); - a2->size = v20 + 1; - v18->prev = v19; - v19->prev->next = v19; - } - if ( Memory.capacity >= 0x10 ) - operator delete(Memory.data.ptr); - } - break; - } - v10 += v11 - v12 - 1; - v11 = v12 + 1; - } - } - if ( Dst.capacity >= 0x10 ) - operator delete(Dst.data.ptr); - } - if ( !string::find(a1, "ITMPV", 0i64, 5ui64) ) - { - sub_1400215A0(a1, &Memory, 5i64, -1i64); - v21 = sub_1400D29A0(&Memory, 0xAu); - v22 = task_pv_db_get_pv(v21); - if ( v22 ) - { - v23 = v22->difficulty[2].begin; - if ( v22->difficulty[2].end - v23 ) - { - v51.data = 0ui64; - v51.length = 0i64; - sub_14023FDE0((vector_pv_item *)&v51, &v23->pv_item); - v24 = v51.data; - if ( v51.data.ptr != *(char **)&v51.data.data[8] ) - { - v25 = (pv_item *__shifted(pv_item,8))(v51.data.ptr + 8); - do - { - if ( ADJ(v25)->index > 0 ) - { - if ( ADJ(v25)->name.capacity < 0x10 ) - v26 = (const char *)v25; - else - v26 = ADJ(v25)->name.data.ptr; - v27 = obj_database_get_object_info(v26); - if ( v27 != -1 ) - { - a4 = HIWORD(*(unsigned int *)&v27); - v28 = a2->head; - v29 = sub_14023B3E0(a2, a2->head, a2->head->prev, &a4); - v30 = a2->size; - if ( v30 == 0xAAAAAAAAAAAAAA9i64 ) - ThrowException("list too long"); - a2->size = v30 + 1; - v28->prev = v29; - v29->prev->next = v29; - } - } - ++v25; - } - while ( ADJ(v25) != *(pv_item *__shifted(pv_item,8) *)&v24.data[8] ); - } - if ( v24.ptr ) - { - if ( v24.ptr != *(char **)&v24.data[8] ) - { - v31 = (pv_item *__shifted(pv_item,0x20))(v24.ptr + 32); - do - { - if ( ADJ(v31)->name.capacity >= 0x10 ) - operator delete(ADJ(v31)->name.data.ptr); - ADJ(v31)->name.capacity = 15i64; - ADJ(v31)->name.length = 0i64; - ADJ(v31++)->name.data.data[0] = 0; - } - while ( ADJ(v31) != *(pv_item *__shifted(pv_item,0x20) *)&v24.data[8] ); - } - operator delete(v24.ptr); - } - } - } - if ( Memory.capacity >= 0x10 ) - operator delete(Memory.data.ptr); - } - if ( !string::find(a1, "EFFCHRPV", 0i64, 8ui64) ) - { - if ( a1->capacity < 0x10 ) - v32 = (char *)a1; - else - v32 = a1->data.ptr; - a4 = obj_database_get_object_set(v32); - if ( a4 != -1 ) - { - v33 = a2->head; - v34 = list_int32_t_buy_node(a2, a2->head, a2->head->prev, &a4); - v35 = a2->size; - if ( v35 == 0xAAAAAAAAAAAAAA9i64 ) - ThrowException("list too long"); - a2->size = v35 + 1; - v33->prev = v34; - v34->prev->next = v34; - } - } - sub_14023EF10(a2); - sub_14023F860(a2); - v51.capacity = 15i64; - v51.length = 0i64; - v51.data.data[0] = 0; - string_assign_char_str(&v51, null_string, 0i64); - v36 = string::find(a1, "STGPV", 0i64, 5ui64); - if ( v36 != -1 ) - { - v37 = sub_1400215A0(a1, &Memory, v36, 8i64); - if ( &v51 != v37 ) - { - if ( v51.capacity >= 0x10 ) - operator delete(v51.data.ptr); - v51.capacity = 15i64; - v51.length = 0i64; - v51.data.data[0] = 0; - if ( v37->capacity >= 0x10 ) - { - v51.data.ptr = v37->data.ptr; - v37->data.ptr = 0i64; - } - else if ( v37->length != -1i64 ) - { - memmove(&v51, v37, v37->length + 1); - } - v51.length = v37->length; - v51.capacity = v37->capacity; - v37->capacity = 15i64; - v37->length = 0i64; - v37->data.data[0] = 0; - } - if ( Memory.capacity >= 0x10 ) - operator delete(Memory.data.ptr); - } - v38 = string::find(a1, "STGD2PV", 0i64, 7ui64); - if ( v38 != -1 ) - { - v39 = sub_1400215A0(a1, &Memory, v38, 10i64); - if ( &v51 != v39 ) - { - if ( v51.capacity >= 0x10 ) - operator delete(v51.data.ptr); - v51.capacity = 15i64; - v51.length = 0i64; - v51.data.data[0] = 0; - if ( v39->capacity >= 0x10 ) - { - v51.data.ptr = v39->data.ptr; - v39->data.ptr = 0i64; - } - else if ( v39->length != -1i64 ) - { - memmove(&v51, v39, v39->length + 1); - } - v51.length = v39->length; - v51.capacity = v39->capacity; - v39->capacity = 15i64; - v39->length = 0i64; - v39->data.data[0] = 0; - } - if ( Memory.capacity >= 0x10 ) - operator delete(Memory.data.ptr); - } - if ( v51.length ) - { - v40 = (char *)&v51; - if ( v51.capacity >= 0x10 ) - v40 = v51.data.ptr; - a4 = obj_database_get_object_set(v40); - if ( a4 != -1 ) - { - v41 = a2->head->next; - v42 = list_int32_t_buy_node(a2, v41, v41->prev, &a4); - v43 = a2->size; - if ( v43 == 0xAAAAAAAAAAAAAA9i64 ) - ThrowException("list too long"); - a2->size = v43 + 1; - v41->prev = v42; - v42->prev->next = v42; - } - } - sub_14000BF30(&Memory, &v51, "HRC"); - v44 = (char *)&Memory; - if ( Memory.capacity >= 0x10 ) - v44 = Memory.data.ptr; - a4 = obj_database_get_object_set(v44); - if ( a4 != -1 ) - { - v45 = a2->head; - v46 = list_int32_t_buy_node(a2, a2->head, a2->head->prev, &a4); - v47 = a2->size; - if ( 0xAAAAAAAAAAAAAA9i64 == v47 ) - ThrowException("list too long"); - a2->size = v47 + 1; - v45->prev = v46; - v46->prev->next = v46; - } - if ( Memory.capacity >= 0x10 ) - operator delete(Memory.data.ptr); - if ( v51.capacity >= 0x10 ) - operator delete(v51.data.ptr); - if ( uids.begin ) - operator delete(uids.begin); -} -*/ - void auth_3d_data_init() { auth_3d_data = new auth_3d_data_struct; } @@ -2128,24 +1792,6 @@ bool auth_3d_data_get_left_right_reverse(int32_t* id) { return true; } -bool auth_3d_data_get_paused(int32_t* id) { - if (*id >= 0 && ((*id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[*id & 0x7FFF]; - if (auth->id == *id) - return auth->paused; - } - return true; -} - -bool auth_3d_data_get_repeat(int32_t* id) { - if (*id >= 0 && ((*id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { - auth_3d* auth = &auth_3d_data->data[*id & 0x7FFF]; - if (auth->id == *id) - return auth->repeat; - } - return true; -} - float_t auth_3d_data_get_play_control_begin(int32_t* id) { if (*id >= 0 && ((*id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { auth_3d* auth = &auth_3d_data->data[*id & 0x7FFF]; @@ -2164,20 +1810,96 @@ float_t auth_3d_data_get_play_control_size(int32_t* id) { return 0.0f; } -void auth_3d_data_load_auth_3d_db(auth_3d_database* auth_3d_db) { - auth_3d_data->farcs.clear(); - auth_3d_data->farcs.resize(auth_3d_db->category.size()); +bool auth_3d_data_get_paused(int32_t* id) { + if (*id >= 0 && ((*id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { + auth_3d* auth = &auth_3d_data->data[*id & 0x7FFF]; + if (auth->id == *id) + return auth->paused; + } + return true; +} - size_t cat_index = 0; - for (auth_3d_farc& i : auth_3d_data->farcs) - i.name = auth_3d_db->category[cat_index++].name; +bool auth_3d_data_get_repeat(int32_t* id) { + if (*id >= 0 && ((*id & 0x7FFF) < AUTH_3D_DATA_COUNT)) { + auth_3d* auth = &auth_3d_data->data[*id & 0x7FFF]; + if (auth->id == *id) + return auth->repeat; + } + return true; +} - auth_3d_data->uid_files.clear(); - auth_3d_data->uid_files.resize(auth_3d_db->uid.size()); +void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector& obj_sets, + auth_3d_database* auth_3d_db, object_database* obj_db) { + obj_sets.clear(); - size_t uid_index = 0; - for (auth_3d_uid_file& i : auth_3d_data->uid_files) - i.uid = (int32_t)(uid_index++); + std::vector uid; + auth_3d_db->get_category_uids(name.c_str(), uid); + for (int32_t& i : uid) { + const char* uid_name = auth_3d_data_get_uid_name(i, auth_3d_db); + if (!uid_name) + continue; + + const char* s = strchr(uid_name, '_'); + if (!s) + break; + + uint32_t obj_set = obj_db->get_object_set_id(std::string(uid_name, s - uid_name).c_str()); + if (obj_set != -1) + obj_sets.push_back(obj_set); + break; + } + + if (!name.find("ITMPV")) { + int32_t pv_id = atoi(name.substr(5, 3).c_str()); + pv_db_pv* pv = task_pv_db_get_pv(pv_id); + if (pv && pv->difficulty[PV_DIFFICULTY_HARD].size()) { + pv_db_pv_difficulty& diff = pv->difficulty[PV_DIFFICULTY_HARD][0]; + + for (pv_db_pv_item& i : diff.pv_item) { + if (i.index <= 0) + continue; + + object_info info = obj_db->get_object_info(i.name.c_str()); + if (info.not_null()) + obj_sets.push_back(info.set_id); + } + } + } + + if (!name.find("EFFCHRPV")) { + uint32_t obj_set = obj_db->get_object_set_id(name.c_str()); + if (obj_set != -1) + obj_sets.push_back(obj_set); + } + + uint32_t prev_obj_set = -1; + radix_sort_uint32_t(obj_sets.data(), obj_sets.size()); + for (std::vector::iterator i = obj_sets.begin(); i != obj_sets.end();) + if (*i != prev_obj_set) + prev_obj_set = *i++; + else + i = obj_sets.erase(i); + + std::string stgpv; + size_t stgpv_offset = name.find("STGPV"); + if (stgpv_offset != -1) + stgpv = name.substr(stgpv_offset, 8); + + size_t stgd2pv_offset = name.find("STGD2PV"); + if (stgd2pv_offset != -1) + stgpv = name.substr(stgd2pv_offset, 10); + + if (stgpv.size()) { + uint32_t obj_set = obj_db->get_object_set_id(stgpv.c_str()); + if (obj_set != -1) + obj_sets.push_back(obj_set); + } + + stgpv += "HRC"; + + uint32_t obj_set = obj_db->get_object_set_id(stgpv.c_str()); + if (obj_set != -1) + obj_sets.push_back(obj_set); } int32_t auth_3d_data_get_uid(int32_t* id) { @@ -2199,6 +1921,22 @@ const char* auth_3d_data_get_uid_name(int32_t uid, auth_3d_database* auth_3d_db) return 0; } +void auth_3d_data_load_auth_3d_db(auth_3d_database* auth_3d_db) { + auth_3d_data->farcs.clear(); + auth_3d_data->farcs.resize(auth_3d_db->category.size()); + + size_t cat_index = 0; + for (auth_3d_farc& i : auth_3d_data->farcs) + i.name = auth_3d_db->category[cat_index++].name; + + auth_3d_data->uid_files.clear(); + auth_3d_data->uid_files.resize(auth_3d_db->uid.size()); + + size_t uid_index = 0; + for (auth_3d_uid_file& i : auth_3d_data->uid_files) + i.uid = (int32_t)(uid_index++); +} + void auth_3d_data_load_category(const char* category_name, const char* mdata_dir) { auth_3d_data_struct_load_category(auth_3d_data, category_name, mdata_dir); } @@ -2436,6 +2174,10 @@ void task_auth_3d_append_task() { app::TaskWork::AppendTask(&task_auth_3d, "AUTH_3D"); } +bool task_auth_3d_check_task_ready() { + return app::TaskWork::CheckTaskReady(&task_auth_3d); +} + void task_auth_3d_free_task() { task_auth_3d.SetDest(); } @@ -2931,7 +2673,7 @@ static void auth_3d_camera_root_ctrl(auth_3d_camera_root* cr, || auth_3d_key_detect_fast_change(&cr->interest.translation.y, frame, 0.3f) || auth_3d_key_detect_fast_change(&cr->interest.translation.z, frame, 0.3f)) { frame = (float_t)(int32_t)frame; - camera_set_fast_change(cam, true); + cam->set_fast_change(true); } else { float_t frame_prev = frame - get_delta_frame(); @@ -2943,7 +2685,7 @@ static void auth_3d_camera_root_ctrl(auth_3d_camera_root* cr, || auth_3d_key_detect_fast_change(&cr->interest.translation.x, frame_prev, 0.3f) || auth_3d_key_detect_fast_change(&cr->interest.translation.y, frame_prev, 0.3f) || auth_3d_key_detect_fast_change(&cr->interest.translation.z, frame_prev, 0.3f)) - camera_set_fast_change_hist0(cam, true); + cam->set_fast_change_hist0(true); } } @@ -3052,7 +2794,7 @@ static void auth_3d_dof_set(auth_3d_dof* d, render_context* rctx) { return; vec3 view_point; - camera_get_view_point(rctx->camera, &view_point); + rctx->camera->get_view_point(view_point); float_t focus; vec3_distance(d->model_transform.translation_value, view_point, focus); @@ -3132,20 +2874,18 @@ static void auth_3d_fog_restore_prev_value(auth_3d_fog* f, render_context* rctx) if (id < FOG_DEPTH || id > FOG_BUMP) return; - fog* data = &rctx->fog_data[id]; - if (f->flags_init & AUTH_3D_FOG_COLOR) { - vec4 color = f->color_init; - fog_set_color(data, &color); - } + fog* data = &rctx->fog[id]; + if (f->flags_init & AUTH_3D_FOG_COLOR) + data->set_color(f->color_init); if (f->flags_init & AUTH_3D_FOG_DENSITY) - fog_set_density(data, f->density_value); + data->set_density(f->density_value); if (f->flags_init & AUTH_3D_FOG_END) - fog_set_end(data, f->end_value); + data->set_end(f->end_value); if (f->flags_init & AUTH_3D_FOG_START) - fog_set_start(data, f->start_value); + data->set_start(f->start_value); } static void auth_3d_fog_set(auth_3d_fog* f, render_context* rctx) { @@ -3153,44 +2893,43 @@ static void auth_3d_fog_set(auth_3d_fog* f, render_context* rctx) { if (id < FOG_DEPTH || id > FOG_BUMP) return; - fog* data = &rctx->fog_data[id]; + fog* data = &rctx->fog[id]; if (f->flags & AUTH_3D_FOG_COLOR) { if (~f->flags_init & AUTH_3D_FOG_COLOR) { vec4 color_init; - fog_get_color(data, &color_init); + data->get_color(color_init); f->color_init = color_init; enum_or(f->flags_init, AUTH_3D_FOG_COLOR); } - vec4 color = f->color.value; - fog_set_color(data, &color); + data->set_color(f->color.value); } if (f->flags & AUTH_3D_FOG_DENSITY) { if (~f->flags_init & AUTH_3D_FOG_DENSITY) { - f->density_init = fog_get_density(data); + f->density_init = data->get_density(); enum_or(f->flags_init, AUTH_3D_FOG_DENSITY); } - fog_set_density(data, f->density_value); + data->set_density(f->density_value); } if (f->flags & AUTH_3D_FOG_END) { if (~f->flags_init & AUTH_3D_FOG_END) { - f->end_init = fog_get_end(data); + f->end_init = data->get_end(); enum_or(f->flags_init, AUTH_3D_FOG_END); } - fog_set_end(data, f->end_value); + data->set_end(f->end_value); } if (f->flags & AUTH_3D_FOG_START) { if (~f->flags_init & AUTH_3D_FOG_START) { - f->start_init = fog_get_start(data); + f->start_init = data->get_start(); enum_or(f->flags_init, AUTH_3D_FOG_START); } - fog_set_start(data, f->start_value); + data->set_start(f->start_value); } } @@ -3296,34 +3035,28 @@ static void auth_3d_light_load(auth_3d* auth, auth_3d_light* l, auth_3d_light_fi } static void auth_3d_light_restore_prev_value(auth_3d_light* l, render_context* rctx) { - light_set* set_data = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set_data = &rctx->light_set[LIGHT_SET_MAIN]; light_id id = l->id; if (id < LIGHT_CHARA || id > LIGHT_PROJECTION) return; light_data* data = &set_data->lights[id]; - if (l->flags_init & AUTH_3D_LIGHT_AMBIENT) { - vec4 ambient_init = l->ambient_init; - light_set_ambient(data, &ambient_init); - } + if (l->flags_init & AUTH_3D_LIGHT_AMBIENT) + data->set_ambient(l->ambient_init); - if (l->flags_init & AUTH_3D_LIGHT_DIFFUSE) { - vec4 diffuse_init = l->diffuse_init; - light_set_diffuse(data, &diffuse_init); - } + if (l->flags_init & AUTH_3D_LIGHT_DIFFUSE) + data->set_diffuse(l->diffuse_init); - if (l->flags_init & AUTH_3D_LIGHT_SPECULAR) { - vec4 specular_init = l->specular_init; - light_set_specular(data, &specular_init); - } + if (l->flags_init & AUTH_3D_LIGHT_SPECULAR) + data->set_specular(l->specular_init); if (l->flags_init & AUTH_3D_LIGHT_TONE_CURVE) - light_set_tone_curve(data, &l->tone_curve_init); + data->set_tone_curve(l->tone_curve_init); } static void auth_3d_light_set(auth_3d_light* l, render_context* rctx) { - light_set* set_data = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set_data = &rctx->light_set[LIGHT_SET_MAIN]; light_id id = l->id; if (id < LIGHT_CHARA || id > LIGHT_PROJECTION) @@ -3333,52 +3066,49 @@ static void auth_3d_light_set(auth_3d_light* l, render_context* rctx) { if (l->flags & AUTH_3D_LIGHT_AMBIENT) { if (~l->flags_init & AUTH_3D_LIGHT_AMBIENT) { vec4 ambient_init; - light_get_ambient(data, &ambient_init); + data->get_ambient(ambient_init); l->ambient_init = ambient_init; enum_or(l->flags_init, AUTH_3D_LIGHT_AMBIENT); } - vec4 ambient = l->ambient.value; - light_set_ambient(data, &ambient); + data->set_ambient(l->ambient.value); } if (l->flags & AUTH_3D_LIGHT_DIFFUSE) { if (~l->flags_init & AUTH_3D_LIGHT_DIFFUSE) { vec4 diffuse_init; - light_get_diffuse(data, &diffuse_init); + data->get_diffuse(diffuse_init); l->diffuse_init = diffuse_init; enum_or(l->flags_init, AUTH_3D_LIGHT_DIFFUSE); } - vec4 diffuse = l->diffuse.value; - light_set_diffuse(data, &diffuse); + data->set_diffuse(l->diffuse.value); } if (l->flags & AUTH_3D_LIGHT_POSITION) - light_set_position(data, &l->position.translation_value); + data->set_position(l->position.translation_value); if (l->flags & AUTH_3D_LIGHT_SPECULAR) { if (~l->flags_init & AUTH_3D_LIGHT_SPECULAR) { vec4 specular_init; - light_get_specular(data, &specular_init); + data->get_specular(specular_init); l->specular_init = specular_init; enum_or(l->flags_init, AUTH_3D_LIGHT_SPECULAR); } - vec4 specular = l->specular.value; - light_set_specular(data, &specular); + data->set_specular(l->specular.value); } if (l->flags & AUTH_3D_LIGHT_SPOT_DIRECTION) - light_set_spot_direction(data, &l->spot_direction.translation_value); + data->set_spot_direction(l->spot_direction.translation_value); if (l->flags & AUTH_3D_LIGHT_TONE_CURVE) { if (~l->flags_init & AUTH_3D_LIGHT_TONE_CURVE) { - light_get_tone_curve(data, &l->tone_curve_init); + data->get_tone_curve(l->tone_curve_init); enum_or(l->flags_init, AUTH_3D_LIGHT_TONE_CURVE); } - light_set_tone_curve(data, (vec3*)&l->tone_curve.value); + data->set_tone_curve(*(vec3*)&l->tone_curve.value); } } @@ -4508,7 +4238,7 @@ static void auth_3d_data_struct_unload_category( static void auth_3d_farc_free_data(auth_3d_farc* a3da_farc) { if (a3da_farc->state == 1) - a3da_farc->file_handler.call_free_func_free_data(); + a3da_farc->file_handler.call_free_callback(); else if (a3da_farc->state == 2) { delete a3da_farc->farc; a3da_farc->farc = 0; @@ -4719,53 +4449,10 @@ static void Auth3dTestTask__SetAuth3dId(Auth3dTestTask* tt) { if (tt->field_394 == 1) { data_struct* data = rctx_ptr->data; + auth_3d_database* auth_3d_db = &data->data_ft.auth_3d_db; object_database* obj_db = &data->data_ft.obj_db; - const char* cat_str = tt->category.c_str(); - size_t cat_len = tt->category.size(); - - if (!memcmp(cat_str, "ITMPV", 5)) { - uint32_t set_id = obj_db->get_object_set_id(cat_str); - if (set_id != (uint32_t)-1) { - object_storage_load_set(data, obj_db, set_id); - tt->obj_sets.push_back(set_id); - } - } - - if (!memcmp(cat_str, "EFFCHRPV", 8)) { - uint32_t set_id = obj_db->get_object_set_id(cat_str); - if (set_id != (uint32_t)-1) { - object_storage_load_set(data, obj_db, set_id); - tt->obj_sets.push_back(set_id); - } - } - - size_t off; - std::string obj; - if ((off = tt->category.find("STGNS", 0)) != -1) - obj = std::string(&cat_str[off], 8); - - if ((off = tt->category.find("STGD2NS", 0)) != -1) - obj = std::string(&cat_str[off], 10); - - if ((off = tt->category.find("STGPV", 0)) != -1) - obj = std::string(&cat_str[off], 8); - - if ((off = tt->category.find("STGD2PV", 0)) != -1) - obj = std::string(&cat_str[off], 10); - - uint32_t set_id = obj_db->get_object_set_id(obj.c_str()); - if (set_id != (uint32_t)-1) { - object_storage_load_set(data, obj_db, set_id); - tt->obj_sets.push_back(set_id); - } - - obj += "HRC"; - uint32_t hrc_set_id = obj_db->get_object_set_id(obj.c_str()); - if (hrc_set_id != (uint32_t)-1) { - object_storage_load_set(data, obj_db, hrc_set_id); - tt->obj_sets.push_back(hrc_set_id); - } + auth_3d_data_get_obj_sets_from_category(tt->category, tt->obj_sets, auth_3d_db, obj_db); for (uint32_t& i : tt->obj_sets) object_storage_load_set(data, obj_db, i); diff --git a/src/CRE/auth_3d.hpp b/src/CRE/auth_3d.hpp index cda4ff2a..b9c21ee7 100644 --- a/src/CRE/auth_3d.hpp +++ b/src/CRE/auth_3d.hpp @@ -863,6 +863,8 @@ extern bool auth_3d_data_get_paused(int32_t* id); extern float_t auth_3d_data_get_play_control_begin(int32_t* id); extern float_t auth_3d_data_get_play_control_size(int32_t* id); extern bool auth_3d_data_get_repeat(int32_t* id); +void auth_3d_data_get_obj_sets_from_category(std::string& name, std::vector& obj_sets, + auth_3d_database* auth_3d_db, object_database* obj_db); extern int32_t auth_3d_data_get_uid(int32_t* id); extern const char* auth_3d_data_get_uid_name(int32_t uid, auth_3d_database* auth_3d_db); extern void auth_3d_data_load_auth_3d_db(auth_3d_database* auth_3d_db); @@ -893,4 +895,5 @@ extern void auth_3d_data_unload_id(int32_t id, render_context* rctx); extern void auth_3d_data_free(); extern void task_auth_3d_append_task(); +extern bool task_auth_3d_check_task_ready(); extern void task_auth_3d_free_task(); diff --git a/src/CRE/camera.c b/src/CRE/camera.c deleted file mode 100644 index 6aefe081..00000000 --- a/src/CRE/camera.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#include "camera.h" - -camera* camera_init() { - camera* c = force_malloc_s(camera, 1); - return c; -} - -static void camera_calculate_projection(camera* c); -static void camera_calculate_view(camera* c); -static void camera_calculate_forward(camera* c); - -void camera_initialize(camera* c, double_t aspect, int32_t width, int32_t height) { - c->aspect = aspect; - c->fov = 0.0; - c->forward = { 0.0f, 0.0f, -1.0f }; - c->rotation = { 0.0f, 0.0f, 0.0f }; - c->view_point = { 0.0, 0.0f, 0.0f }; - c->interest = { 0.0f, 0.0f, -1.0f }; - c->width = width; - c->height = height; - c->view = mat4_identity; - c->inv_view = mat4_identity; - c->projection = mat4_identity; - c->inv_projection = mat4_identity; - c->view_projection = mat4_identity; - c->inv_view_projection = mat4_identity; - c->view_projection_prev = mat4_identity; - c->inv_view_projection_prev = mat4_identity; - c->min_distance = 0.05; - c->max_distance = 6000.0; - c->changed_proj = true; - c->changed_view = true; - camera_set_pitch(c, 0.0); - camera_set_yaw(c, 0.0); - camera_set_roll(c, 0.0); - camera_set_fov(c, 32.2673416137695); - camera_calculate_forward(c); - camera_set_position(c, &vec3_null); - camera_update(c); -} - -double_t camera_get_min_distance(camera* c) { - return c->min_distance; -} - -void camera_set_min_distance(camera* c, double_t value) { - if (value != c->min_distance) { - c->min_distance = value; - c->changed_proj = true; - } -} - -double_t camera_get_max_distance(camera* c) { - return c->max_distance; -} - -void camera_set_max_distance(camera* c, double_t value) { - if (value != c->max_distance) { - c->max_distance = value; - c->changed_proj = true; - } -} - -double_t camera_get_aspect(camera* c) { - return c->aspect; -} - -void camera_set_aspect(camera* c, double_t value) { - if (value != c->aspect) { - c->aspect = value; - c->changed_proj = true; - } -} - -double_t camera_get_fov(camera* c) { - return c->fov; -} - -void camera_set_fov(camera* c, double_t value) { - value = clamp(value, 1.0, 180.0); - if (value != c->fov) { - c->fov = value; - c->fov_rad = value * DEG_TO_RAD; - c->changed_proj = true; - } -} - -double_t camera_get_pitch(camera* c) { - return c->pitch; -} - -void camera_set_pitch(camera* c, double_t value) { - value = fmod(value, 360.0); - value = clamp(value, -89.5, 89.5); - if (c->pitch != value) { - c->pitch = value; - c->changed_view = true; - } -} - -double_t camera_get_yaw(camera* c) { - return c->yaw; -} - -void camera_set_yaw(camera* c, double_t value) { - value = fmod(value, 360.0); - if (c->yaw != value) { - c->yaw = value; - c->changed_view = true; - } -} - -double_t camera_get_roll(camera* c) { - return -c->roll; -} - -void camera_set_roll(camera* c, double_t value) { - value = fmod(value, 360.0); - if (c->roll != value) { - c->roll = value; - c->changed_view = true; - } -} - -void camera_get_view_point(camera* c, vec3* value) { - *value = c->view_point; -} - -void camera_set_view_point(camera* c, const vec3* value) { - if (c->view_point.x != value->x - || c->view_point.y != value->y - || c->view_point.z != value->z) { - c->view_point = *value; - c->changed_view = true; - } -} - -void camera_get_interest(camera* c, vec3* value) { - *value = c->interest; -} - -void camera_set_interest(camera* c, const vec3* value) { - if (c->interest.x != value->x - || c->interest.y != value->y - || c->interest.z != value->z) { - c->interest = *value; - c->changed_view = true; - } -} - -void camera_get_res(camera* c, int32_t* width, int32_t* height) { - *width = c->width; - *height = c->height; -} - -void camera_set_res(camera* c, int32_t width, int32_t height) { - if (c->width != width || c->height != height) { - c->width = width; - c->height = height; - c->changed_proj = true; - } -} - -void camera_set_fast_change(camera* c, bool value) { - c->fast_change = value; -} - -void camera_set_fast_change_hist0(camera* c, bool value) { - c->fast_change_hist0 = value; -} - -void camera_reset(camera* c) { - camera_set_pitch(c, 0.0); - camera_set_yaw(c, 0.0); - camera_set_roll(c, 0.0); - camera_set_fov(c, 32.2673416137695); - camera_calculate_forward(c); - camera_set_position(c, (vec3*)&vec3_null); - camera_update(c); -} - -void camera_move(camera* c, vec2d* move) { - if (move->x != 0.0 || move->y != 0.0) { - vec3 temp; - vec3 view_point; - vec3 interest; - vec3 up = { 0.0f, 1.0f, 0.0f }; - vec3_cross(c->forward, up, temp); - vec3_normalize(temp, temp); - vec3_mult_scalar(temp, (float_t)move->y, temp); - vec3_add(c->view_point, temp, view_point); - vec3_mult_scalar(c->forward, (float_t)move->x, temp); - vec3_add(view_point, temp, view_point); - - vec3_add(view_point, c->forward, interest); - camera_set_view_point(c, &view_point); - camera_set_interest(c, &interest); - } -} - -void camera_rotate(camera* c, vec2d* rotate) { - if (rotate->x != 0.0) - camera_set_yaw(c, camera_get_yaw(c) + rotate->x); - - if (rotate->y != 0.0) - camera_set_pitch(c, camera_get_pitch(c) + rotate->y); - - if (rotate->x != 0.0 || rotate->y != 0.0) { - camera_calculate_forward(c); - - vec3 interest; - vec3_add(c->view_point, c->forward, interest); - camera_set_interest(c, &interest); - } -} - -void camera_roll(camera* c, double_t roll) { - if (roll != 0.0f) - camera_set_roll(c, -camera_get_roll(c) - roll); -} - -void camera_set(camera* c, const vec3* view_point, const vec3* interest, - const vec3* trans, const vec3* rot, const vec3* scale, double_t roll, double_t fov) { - vec3 _vp; - vec3 _int; - double_t _roll; - double_t _fov; - - _vp = *view_point; - _int = *interest; - _roll = roll; - _fov = fov; - - mat4 cam; - mat4_translate(trans->x, trans->y, trans->z, &cam); - mat4_rotate_mult(&cam, rot->x, rot->y, rot->z, &cam); - mat4_scale_rot(&cam, scale->x, scale->y, scale->z, &cam); - mat4_mult_vec3_trans(&cam, &_vp, &_vp); - mat4_mult_vec3_trans(&cam, &_int, &_int); - - camera_set_view_point(c, &_vp); - camera_set_interest(c, &_int); - camera_set_roll(c, _roll); - camera_set_fov(c, _fov); -} - -void camera_set_position(camera* c, const vec3* pos) { - vec3 interest; - vec3_add(*pos, c->forward, interest); - camera_set_view_point(c, pos); - camera_set_interest(c, &interest); -} - -void camera_update(camera* c) { - if (c->changed_proj) - camera_calculate_projection(c); - - if (c->changed_view) - camera_calculate_view(c); - - if (c->changed_proj || c->changed_view) { - mat4_mult(&c->view, &c->projection, &c->view_projection); - mat4_inverse(&c->view_projection, &c->inv_view_projection); - } - - c->changed_proj = false; - c->changed_view = false; - - c->fast_change_hist1 = c->fast_change_hist0; - c->fast_change_hist0 = c->fast_change; - c->fast_change = false; -} - -void camera_dispose(camera* c) { - free(c); -} - -static void camera_calculate_forward(camera* c) { - c->forward.x = (float_t)(cos(c->pitch * DEG_TO_RAD) * sin(c->yaw * DEG_TO_RAD)); - c->forward.y = (float_t)sin(c->pitch * DEG_TO_RAD); - c->forward.z = (float_t)(cos(c->pitch * DEG_TO_RAD) * -cos(c->yaw * DEG_TO_RAD)); -} - -static void camera_calculate_projection(camera* c) { - mat4_persp(c->fov_rad, c->aspect, c->min_distance, c->max_distance, &c->projection); - mat4_inverse(&c->projection, &c->inv_projection); - - float_t fov_correct_height = (float_t)(((double_t)c->height * 0.5) / tan(c->fov_rad * 0.5)); - float_t height = (float_t)c->height * 0.5f; - float_t width = (float_t)c->height * (float_t)c->aspect * 0.5f; - - c->field_1E4.x = fov_correct_height; - c->field_1E4.y = 0.0f; - c->field_1E4.z = -width; - vec3_normalize(c->field_1E4, c->field_1E4); - c->field_1F0.x = -fov_correct_height; - c->field_1F0.y = 0.0f; - c->field_1F0.z = -width; - vec3_normalize(c->field_1F0, c->field_1F0); - c->field_1FC.x = 0.0f; - c->field_1FC.y = fov_correct_height; - c->field_1FC.z = -height; - vec3_normalize(c->field_1FC, c->field_1FC); - c->field_208.x = 0.0f; - c->field_208.y = -fov_correct_height; - c->field_208.z = -height; - vec3_normalize(c->field_208, c->field_208); -} - -static void camera_calculate_view(camera* c) { - vec3 dist; - vec3_sub(c->view_point, c->interest, dist); - - vec3 rotation; - rotation.x = atan2f(-dist.y, sqrtf(dist.x * dist.x + dist.z * dist.z)); - rotation.y = atan2f(dist.x, dist.z); - rotation.z = (float_t)(c->roll * DEG_TO_RAD); - - c->rotation = rotation; - vec3_negate(rotation, rotation); - - vec3 view_point; - vec3_negate(c->view_point, view_point); - - c->view = mat4_identity; - mat4_rot_z(&c->view, rotation.z, &c->view); - mat4_rot_x(&c->view, rotation.x, &c->view); - mat4_rot_y(&c->view, rotation.y, &c->view); - mat4_translate_mult(&c->view, view_point.x, view_point.y, view_point.z, &c->view); - - mat4_inverse(&c->view, &c->inv_view); - mat3_from_mat4(&c->view, &c->view_mat3); - mat3_inverse(&c->view_mat3, &c->inv_view_mat3); - mat4_from_mat3(&c->view_mat3, &c->view_rot); - mat4_from_mat3(&c->inv_view_mat3, &c->inv_view_rot); - - if (fabs(c->rotation.x * RAD_TO_DEG - c->pitch) > 0.01 - || fabs(-c->rotation.y * RAD_TO_DEG - c->yaw) > 0.01) { - c->pitch = c->rotation.x * RAD_TO_DEG; - c->yaw = -c->rotation.y * RAD_TO_DEG; - camera_calculate_forward(c); - } -} diff --git a/src/CRE/camera.cpp b/src/CRE/camera.cpp new file mode 100644 index 00000000..8094730b --- /dev/null +++ b/src/CRE/camera.cpp @@ -0,0 +1,380 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "camera.hpp" + +static void camera_calculate_projection(camera* c); +static void camera_calculate_view(camera* c); +static void camera_calculate_forward(camera* c); + +camera::camera() : view(), inv_view(), projection(), inv_projection(), view_projection(), +inv_view_projection(), view_projection_prev(), inv_view_projection_prev(), view_mat3(), inv_view_mat3(), +view_rot(), inv_view_rot(), forward(), rotation(), view_point(), interest(), width(), height(), field_1E4(), +field_1F0(), field_1FC(), field_208(), yaw(), pitch(), roll(), aspect(), fov(), fov_rad(),max_distance(), +min_distance(), changed_view(), changed_proj(), fast_change(), fast_change_hist0(), fast_change_hist1() { + +} + +camera::~camera() { + +} + +void camera::initialize(double_t aspect, int32_t width, int32_t height) { + this->aspect = aspect; + fov = 0.0; + forward = { 0.0f, 0.0f, -1.0f }; + rotation = { 0.0f, 0.0f, 0.0f }; + view_point = { 0.0, 0.0f, 0.0f }; + interest = { 0.0f, 0.0f, -1.0f }; + this->width = width; + this->height = height; + view = mat4_identity; + inv_view = mat4_identity; + projection = mat4_identity; + inv_projection = mat4_identity; + view_projection = mat4_identity; + inv_view_projection = mat4_identity; + view_projection_prev = mat4_identity; + inv_view_projection_prev = mat4_identity; + min_distance = 0.05; + max_distance = 6000.0; + changed_proj = true; + changed_view = true; + set_pitch(0.0); + set_yaw(0.0); + set_roll(0.0); + set_fov(32.2673416137695); + camera_calculate_forward(this); + set_position(vec3_null); + update(); +} + +double_t camera::get_min_distance() { + return min_distance; +} + +void camera::set_min_distance(double_t value) { + if (value != min_distance) { + min_distance = value; + changed_proj = true; + } +} + +double_t camera::get_max_distance() { + return max_distance; +} + +void camera::set_max_distance(double_t value) { + if (value != max_distance) { + max_distance = value; + changed_proj = true; + } +} + +double_t camera::get_aspect() { + return aspect; +} + +void camera::set_aspect(double_t value) { + if (value != aspect) { + aspect = value; + changed_proj = true; + } +} + +double_t camera::get_fov() { + return fov; +} + +void camera::set_fov(double_t value) { + value = clamp(value, 1.0, 180.0); + if (value != fov) { + fov = value; + fov_rad = value * DEG_TO_RAD; + changed_proj = true; + } +} + +double_t camera::get_pitch() { + return pitch; +} + +void camera::set_pitch(double_t value) { + value = fmod(value, 360.0); + value = clamp(value, -89.5, 89.5); + if (pitch != value) { + pitch = value; + changed_view = true; + } +} + +double_t camera::get_yaw() { + return yaw; +} + +void camera::set_yaw(double_t value) { + value = fmod(value, 360.0); + if (yaw != value) { + yaw = value; + changed_view = true; + } +} + +double_t camera::get_roll() { + return roll; +} + +void camera::set_roll(double_t value) { + value = fmod(value, 360.0); + if (roll != value) { + roll = value; + changed_view = true; + } +} + +void camera::get_view_point(vec3& value) { + value = view_point; +} + +void camera::set_view_point(const vec3& value) { + if (memcmp(&value, &view_point, sizeof(vec3))) { + view_point = value; + changed_view = true; + } +} + +void camera::set_view_point(const vec3&& value) { + if (memcmp(&value, &view_point, sizeof(vec3))) { + view_point = value; + changed_view = true; + } +} + +void camera::get_interest(vec3& value) { + value = interest; +} + +void camera::set_interest(const vec3& value) { + if (memcmp(&value, &interest, sizeof(vec3))) { + interest = value; + changed_view = true; + } +} + +void camera::set_interest(const vec3&& value) { + if (memcmp(&value, &interest, sizeof(vec3))) { + interest = value; + changed_view = true; + } +} + +void camera::get_res(int32_t& width, int32_t& height) { + width = this->width; + height = this->height; +} + +void camera::set_res(int32_t width, int32_t height) { + if (this->width != width || this->height != height) { + this->width = width; + this->height = height; + changed_proj = true; + } +} + +void camera::set_fast_change(bool value) { + fast_change = value; +} + +void camera::set_fast_change_hist0(bool value) { + fast_change_hist0 = value; +} + +void camera::set_fast_change_hist1(bool value) { + fast_change_hist1 = value; +} + +void camera::reset() { + set_pitch(0.0); + set_yaw(0.0); + set_roll(0.0); + set_fov(32.2673416137695); + camera_calculate_forward(this); + set_position(vec3_null); + update(); +} + +void camera::move(vec2d& move) { + if (memcmp(&move, &vec2d_null, sizeof(vec2d))) { + vec3 temp; + vec3 view_point; + vec3 interest; + vec3 up = { 0.0f, 1.0f, 0.0f }; + vec3_cross(forward, up, temp); + vec3_normalize(temp, temp); + vec3_mult_scalar(temp, (float_t)move.y, temp); + vec3_add(this->view_point, temp, view_point); + vec3_mult_scalar(forward, (float_t)move.x, temp); + vec3_add(view_point, temp, view_point); + + vec3_add(view_point, forward, interest); + set_view_point(view_point); + set_interest(interest); + } +} + +void camera::move(vec2d&& move) { + this->move(*(vec2d*)&move); +} + +void camera::rotate(vec2d& rotate) { + if (rotate.x != 0.0) + set_yaw(get_yaw() + rotate.x); + + if (rotate.y != 0.0) + set_pitch(get_pitch() + rotate.y); + + if (memcmp(&rotate, &vec2d_null, sizeof(vec2d))) { + camera_calculate_forward(this); + + vec3 interest; + vec3_add(view_point, forward, interest); + set_interest(interest); + } +} + +void camera::rotate(vec2d&& rotate) { + this->rotate(*(vec2d*)&rotate); +} + +void camera::set(const vec3& view_point, const vec3& interest, + const vec3& trans, const vec3& rot, const vec3& scale, double_t roll, double_t fov) { + vec3 _vp; + vec3 _int; + double_t _roll; + double_t _fov; + + _vp = view_point; + _int = interest; + _roll = roll; + _fov = fov; + + mat4 cam; + mat4_translate(trans.x, trans.y, trans.z, &cam); + mat4_rotate_mult(&cam, rot.x, rot.y, rot.z, &cam); + mat4_scale_rot(&cam, scale.x, scale.y, scale.z, &cam); + mat4_mult_vec3_trans(&cam, &_vp, &_vp); + mat4_mult_vec3_trans(&cam, &_int, &_int); + + set_view_point(_vp); + set_interest(_int); + set_roll(_roll); + set_fov(_fov); +} + +void camera::set(const vec3&& view_point, const vec3&& interest, + const vec3&& trans, const vec3&& rot, const vec3&& scale, double_t roll, double_t fov) { + set(*(vec3*)&view_point, *(vec3*)&interest, *(vec3*)&trans, *(vec3*)&rot, *(vec3*)&scale, roll, fov); +} + +void camera::set_position(const vec3& pos) { + vec3 interest; + vec3_add(pos, forward, interest); + set_view_point(pos); + set_interest(interest); +} + +void camera::set_position(const vec3&& pos) { + vec3 interest; + vec3_add(pos, forward, interest); + set_view_point(pos); + set_interest(interest); +} + +void camera::update() { + if (changed_proj) + camera_calculate_projection(this); + + if (changed_view) + camera_calculate_view(this); + + if (changed_proj || changed_view) { + mat4_mult(&view, &projection, &view_projection); + mat4_inverse(&view_projection, &inv_view_projection); + } + + changed_proj = false; + changed_view = false; + + fast_change_hist1 = fast_change_hist0; + fast_change_hist0 = fast_change; + fast_change = false; +} + +static void camera_calculate_forward(camera* c) { + c->forward.x = (float_t)(cos(c->pitch * DEG_TO_RAD) * sin(c->yaw * DEG_TO_RAD)); + c->forward.y = (float_t)sin(c->pitch * DEG_TO_RAD); + c->forward.z = (float_t)(cos(c->pitch * DEG_TO_RAD) * -cos(c->yaw * DEG_TO_RAD)); +} + +static void camera_calculate_projection(camera* c) { + mat4_persp(c->fov_rad, c->aspect, c->min_distance, c->max_distance, &c->projection); + mat4_inverse(&c->projection, &c->inv_projection); + + float_t fov_correct_height = (float_t)(((double_t)c->height * 0.5) / tan(c->fov_rad * 0.5)); + float_t height = (float_t)c->height * 0.5f; + float_t width = (float_t)c->height * (float_t)c->aspect * 0.5f; + + c->field_1E4.x = fov_correct_height; + c->field_1E4.y = 0.0f; + c->field_1E4.z = -width; + vec3_normalize(c->field_1E4, c->field_1E4); + c->field_1F0.x = -fov_correct_height; + c->field_1F0.y = 0.0f; + c->field_1F0.z = -width; + vec3_normalize(c->field_1F0, c->field_1F0); + c->field_1FC.x = 0.0f; + c->field_1FC.y = fov_correct_height; + c->field_1FC.z = -height; + vec3_normalize(c->field_1FC, c->field_1FC); + c->field_208.x = 0.0f; + c->field_208.y = -fov_correct_height; + c->field_208.z = -height; + vec3_normalize(c->field_208, c->field_208); +} + +static void camera_calculate_view(camera* c) { + vec3 dist; + vec3_sub(c->view_point, c->interest, dist); + + vec3 rotation; + rotation.x = atan2f(-dist.y, sqrtf(dist.x * dist.x + dist.z * dist.z)); + rotation.y = atan2f(dist.x, dist.z); + rotation.z = (float_t)(c->roll * DEG_TO_RAD); + + c->rotation = rotation; + vec3_negate(rotation, rotation); + + vec3 view_point; + vec3_negate(c->view_point, view_point); + + c->view = mat4_identity; + mat4_rot_z(&c->view, rotation.z, &c->view); + mat4_rot_x(&c->view, rotation.x, &c->view); + mat4_rot_y(&c->view, rotation.y, &c->view); + mat4_translate_mult(&c->view, view_point.x, view_point.y, view_point.z, &c->view); + + mat4_inverse(&c->view, &c->inv_view); + mat3_from_mat4(&c->view, &c->view_mat3); + mat3_inverse(&c->view_mat3, &c->inv_view_mat3); + mat4_from_mat3(&c->view_mat3, &c->view_rot); + mat4_from_mat3(&c->inv_view_mat3, &c->inv_view_rot); + + if (fabs(c->rotation.x * RAD_TO_DEG - c->pitch) > 0.01 + || fabs(-c->rotation.y * RAD_TO_DEG - c->yaw) > 0.01) { + c->pitch = c->rotation.x * RAD_TO_DEG; + c->yaw = -c->rotation.y * RAD_TO_DEG; + camera_calculate_forward(c); + } +} diff --git a/src/CRE/camera.h b/src/CRE/camera.h deleted file mode 100644 index 2f2921f1..00000000 --- a/src/CRE/camera.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include "../KKdLib/default.hpp" -#include "../KKdLib/mat.hpp" -#include "../KKdLib/vec.hpp" - -struct camera { - mat4 view; - mat4 inv_view; - mat4 projection; - mat4 inv_projection; - mat4 view_projection; - mat4 inv_view_projection; - mat4 view_projection_prev; - mat4 inv_view_projection_prev; - mat3 view_mat3; - mat3 inv_view_mat3; - mat4 view_rot; - mat4 inv_view_rot; - vec3 forward; - vec3 rotation; - vec3 view_point; - vec3 interest; - int32_t width; - int32_t height; - vec3 field_1E4; - vec3 field_1F0; - vec3 field_1FC; - vec3 field_208; - double_t yaw; - double_t pitch; - double_t roll; - double_t aspect; - double_t fov; - double_t fov_rad; - double_t max_distance; - double_t min_distance; - bool changed_view; - bool changed_proj; - bool fast_change; - bool fast_change_hist0; - bool fast_change_hist1; -}; - -extern camera* camera_init(); -extern void camera_initialize(camera* c, double_t aspect, int32_t width, int32_t height); -extern double_t camera_get_min_distance(camera* c); -extern void camera_set_min_distance(camera* c, double_t value); -extern double_t camera_get_max_distance(camera* c); -extern void camera_set_max_distance(camera* c, double_t value); -extern double_t camera_get_aspect(camera* c); -extern void camera_set_aspect(camera* c, double_t value); -extern double_t camera_get_fov(camera* c); -extern void camera_set_fov(camera* c, double_t value); -extern double_t camera_get_pitch(camera* c); -extern void camera_set_pitch(camera* c, double_t value); -extern double_t camera_get_yaw(camera* c); -extern void camera_set_yaw(camera* c, double_t value); -extern double_t camera_get_roll(camera* c); -extern void camera_set_roll(camera* c, double_t value); -extern void camera_get_view_point(camera* c, vec3* value); -extern void camera_set_view_point(camera* c, const vec3* value); -extern void camera_get_interest(camera* c, vec3* value); -extern void camera_set_interest(camera* c, const vec3* value); -extern void camera_get_res(camera* c, int32_t* width, int32_t* height); -extern void camera_set_res(camera* c, int32_t width, int32_t height); -extern void camera_set_fast_change(camera* c, bool value); -extern void camera_set_fast_change_hist0(camera* c, bool value); -extern void camera_reset(camera* c); -extern void camera_move(camera* c, vec2d* move); -extern void camera_rotate(camera* c, vec2d* rotate); -extern void camera_roll(camera* c, double_t roll); -extern void camera_set(camera* c, const vec3* view_point, const vec3* interest, - const vec3* trans, const vec3* rot, const vec3* scale, double_t roll, double_t fov); -extern void camera_set_position(camera* c, const vec3* pos); -extern void camera_update(camera* c); -extern void camera_dispose(camera* c); diff --git a/src/CRE/camera.hpp b/src/CRE/camera.hpp new file mode 100644 index 00000000..55f85810 --- /dev/null +++ b/src/CRE/camera.hpp @@ -0,0 +1,90 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "../KKdLib/default.hpp" +#include "../KKdLib/mat.hpp" +#include "../KKdLib/vec.hpp" + +struct camera { + mat4 view; + mat4 inv_view; + mat4 projection; + mat4 inv_projection; + mat4 view_projection; + mat4 inv_view_projection; + mat4 view_projection_prev; + mat4 inv_view_projection_prev; + mat3 view_mat3; + mat3 inv_view_mat3; + mat4 view_rot; + mat4 inv_view_rot; + vec3 forward; + vec3 rotation; + vec3 view_point; + vec3 interest; + int32_t width; + int32_t height; + vec3 field_1E4; + vec3 field_1F0; + vec3 field_1FC; + vec3 field_208; + double_t yaw; + double_t pitch; + double_t roll; + double_t aspect; + double_t fov; + double_t fov_rad; + double_t max_distance; + double_t min_distance; + bool changed_view; + bool changed_proj; + bool fast_change; + bool fast_change_hist0; + bool fast_change_hist1; + + camera(); + virtual ~camera(); + + void initialize(double_t aspect, int32_t width, int32_t height); + double_t get_min_distance(); + void set_min_distance(double_t value); + double_t get_max_distance(); + void set_max_distance(double_t value); + double_t get_aspect(); + void set_aspect(double_t value); + double_t get_fov(); + void set_fov(double_t value); + double_t get_pitch(); + void set_pitch(double_t value); + double_t get_yaw(); + void set_yaw(double_t value); + double_t get_roll(); + void set_roll(double_t value); + void get_view_point(vec3& value); + void set_view_point(const vec3& value); + void set_view_point(const vec3&& value); + void get_interest(vec3& value); + void set_interest(const vec3& value); + void set_interest(const vec3&& value); + void get_res(int32_t& width, int32_t& height); + void set_res(int32_t width, int32_t height); + void set_fast_change(bool value); + void set_fast_change_hist0(bool value); + void set_fast_change_hist1(bool value); + void reset(); + void move(vec2d& move); + void move(vec2d&& move); + void rotate(vec2d& rotate); + void rotate(vec2d&& rotate); + void set(const vec3& view_point, const vec3& interest, + const vec3& trans, const vec3& rot, const vec3& scale, double_t roll, double_t fov); + void set(const vec3&& view_point, const vec3&& interest, + const vec3&& trans, const vec3&& rot, const vec3&& scale, double_t roll, double_t fov); + void set_position(const vec3& pos); + void set_position(const vec3&& pos); + void update(); +}; diff --git a/src/CRE/draw_object.c b/src/CRE/draw_object.cpp similarity index 89% rename from src/CRE/draw_object.c rename to src/CRE/draw_object.cpp index 895a43eb..a86cf072 100644 --- a/src/CRE/draw_object.c +++ b/src/CRE/draw_object.cpp @@ -3,10 +3,10 @@ GitHub/GitLab: korenkonder */ -#include "draw_object.h" +#include "draw_object.hpp" #include "light_param/light.hpp" -#include "shader_ft.h" -#include "static_var.h" +#include "shader_ft.hpp" +#include "static_var.hpp" #include "texture.hpp" #define enable_vertex_attrib_array(index) \ @@ -44,14 +44,10 @@ void draw_object_draw(render_context* rctx, draw_object* draw, mat4* model, shaders_ft.state_matrix_set_program(7, mat); } + mat4 mat; for (int32_t i = 0; i < draw->mat_count; i++, mats++) { - union { - mat4 m; - vec4 v[4]; - } mat; - - mat4_transpose(mats, &mat.m); - shaders_ft.buffer_set((size_t)i * 3, 3, mat.v); + mat4_transpose(mats, &mat); + shaders_ft.buffer_set((size_t)i * 3, 3, &mat.row0); } shaders_ft.state_matrix_set_modelview(0, rctx->view_mat, true); @@ -416,11 +412,11 @@ static bool draw_object_blend_set(render_context* rctx, GLenum src_blend_factor = blend_factor_table[attrib.src_blend_factor]; GLenum dst_blend_factor = blend_factor_table[attrib.dst_blend_factor]; if (draw->chara_color) { - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; light_data* chara_color = &set->lights[LIGHT_CHARA_COLOR]; vec4 specular; - light_get_specular(chara_color, &specular); - if (specular.w >= 4.0f && light_get_type(chara_color) == LIGHT_PARALLEL + chara_color->get_specular(specular); + if (specular.w >= 4.0f && chara_color->get_type() == LIGHT_PARALLEL && (src_blend_factor != GL_ONE || dst_blend_factor)) { int32_t shader_index = rctx->draw_state.shader_index; if (rctx->draw_state.shader_index == -1) { @@ -453,11 +449,11 @@ static bool draw_object_blend_set(render_context* rctx, static void draw_object_chara_color_fog_set(render_context* rctx, draw_object* draw, bool disable_fog) { uniform_value[U_CHARA_COLOR] = 0; if (draw->chara_color) { - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; light_data* chara_color = &set->lights[LIGHT_CHARA_COLOR]; vec4 specular; - light_get_specular(chara_color, &specular); - if (specular.w > 0.0f && light_get_type(chara_color) == LIGHT_PARALLEL) + chara_color->get_specular(specular); + if (specular.w > 0.0f && chara_color->get_type() == LIGHT_PARALLEL) uniform_value[U_CHARA_COLOR] = 1; } @@ -884,7 +880,7 @@ static void draw_object_vertex_attrib_reset_default(draw_object* draw) { draw->vertex_attrib_array[i] = false; } - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) uniform_value[U_BONE_MAT] = 0; if (draw->morph_array_buffer) { @@ -909,7 +905,7 @@ static void draw_object_vertex_attrib_reset_default_compressed(draw_object* draw draw->vertex_attrib_array[i] = false; } - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) uniform_value[U_BONE_MAT] = 0; if (draw->morph_array_buffer) { @@ -939,7 +935,7 @@ static void draw_object_vertex_attrib_reset_reflect(draw_object* draw) { draw->vertex_attrib_array[i] = false; } - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) uniform_value[U_BONE_MAT] = 0; if (draw->morph_array_buffer) { @@ -962,7 +958,7 @@ inline static void draw_object_vertex_attrib_reset_reflect_compressed(draw_objec draw->vertex_attrib_array[i] = false; } - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) uniform_value[U_BONE_MAT] = 0; if (draw->morph_array_buffer) { @@ -989,7 +985,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { gl_state_bind_array_buffer(draw->array_buffer); size_t offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -997,7 +993,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(0, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1005,7 +1001,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(2, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(6); glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1013,7 +1009,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(5, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) + if (vertex_format & OBJ_VERTEX_BINORMAL) offset += 12; bool texcoord_mat_set[4] = { false }; @@ -1030,7 +1026,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { if (material->material.texdata[i].shader_info.m.tex_type == OBJ_MATERIAL_TEXTURE_COLOR) j++; - if (vertex_format & (OBJ_VERTEX_FORMAT_TEXCOORD0 << sub_mesh->uv_index[l])) { + if (vertex_format & (OBJ_VERTEX_TEXCOORD0 << sub_mesh->uv_index[l])) { enable_vertex_attrib_array(8 + texcoord_index); glVertexAttribPointer(8 + texcoord_index, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)(offset + 8ULL * sub_mesh->uv_index[l])); @@ -1058,16 +1054,16 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { if (!draw->vertex_attrib_array[8 + i]) glVertexAttrib4f(8 + i, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (vertex_format & OBJ_VERTEX_TEXCOORD0) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (vertex_format & OBJ_VERTEX_TEXCOORD1) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { enable_vertex_attrib_array(3); glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1075,10 +1071,10 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) + if (vertex_format & OBJ_VERTEX_COLOR1) offset += 16; - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { + if (vertex_format & OBJ_VERTEX_BONE_DATA) { uniform_value[U_BONE_MAT] = 1; enable_vertex_attrib_array(1); @@ -1090,11 +1086,11 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { offset += 16; } else { - glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 1.0f); - glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 1.0f); + glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 0.0f); + glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 0.0f); } - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) { + if (vertex_format & OBJ_VERTEX_UNKNOWN) { enable_vertex_attrib_array(7); glVertexAttribPointer(7, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1108,7 +1104,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { gl_state_bind_array_buffer(draw->morph_array_buffer); offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(10); glVertexAttribPointer(10, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1116,7 +1112,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(10, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(11); glVertexAttribPointer(11, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1124,7 +1120,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(11, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(12); glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1132,10 +1128,10 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(12, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) + if (vertex_format & OBJ_VERTEX_BINORMAL) offset += 12; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(13); glVertexAttribPointer(13, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1143,7 +1139,7 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(13, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { enable_vertex_attrib_array(14); glVertexAttribPointer(14, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1151,12 +1147,12 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(14, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { uniform_value[U_MORPH_COLOR] = 1; enable_vertex_attrib_array(5); @@ -1166,13 +1162,13 @@ static void draw_object_vertex_attrib_set_default(draw_object* draw) { else glVertexAttrib4f(5, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) + if (vertex_format & OBJ_VERTEX_COLOR1) offset += 16; - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) offset += 32; - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) + if (vertex_format & OBJ_VERTEX_UNKNOWN) offset += 16; shaders_ft.env_vert_set(13, draw->morph_value, 1.0f - draw->morph_value, 0.0f, 0.0f); @@ -1194,7 +1190,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* gl_state_bind_array_buffer(draw->array_buffer); size_t offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1202,7 +1198,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(0, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(2); glVertexAttribPointer(2, 3, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1210,7 +1206,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(2, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(6); glVertexAttribPointer(6, 4, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1232,7 +1228,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* if (material->material.texdata[i].shader_info.m.tex_type == OBJ_MATERIAL_TEXTURE_COLOR) j++; - if (vertex_format & (OBJ_VERTEX_FORMAT_TEXCOORD0 << sub_mesh->uv_index[l])) { + if (vertex_format & (OBJ_VERTEX_TEXCOORD0 << sub_mesh->uv_index[l])) { enable_vertex_attrib_array(8 + texcoord_index); glVertexAttribPointer(8 + texcoord_index, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)(offset + 4ULL * sub_mesh->uv_index[l])); @@ -1260,16 +1256,16 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* if (!draw->vertex_attrib_array[8 + i]) glVertexAttrib4f(8 + i, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (vertex_format & OBJ_VERTEX_TEXCOORD0) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (vertex_format & OBJ_VERTEX_TEXCOORD1) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { enable_vertex_attrib_array(3); glVertexAttribPointer(3, 4, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1277,7 +1273,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { + if (vertex_format & OBJ_VERTEX_BONE_DATA) { uniform_value[U_BONE_MAT] = 1; enable_vertex_attrib_array(1); @@ -1289,8 +1285,8 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* offset += 8; } else { - glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 1.0f); - glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 1.0f); + glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 0.0f); + glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 0.0f); } if (draw->morph_array_buffer) { @@ -1299,7 +1295,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* gl_state_bind_array_buffer(draw->morph_array_buffer); offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(10); glVertexAttribPointer(10, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1307,7 +1303,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(10, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(11); glVertexAttribPointer(11, 3, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1315,7 +1311,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(11, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(12); glVertexAttribPointer(12, 4, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1323,7 +1319,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(12, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(13); glVertexAttribPointer(13, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 4; @@ -1331,7 +1327,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(13, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { enable_vertex_attrib_array(14); glVertexAttribPointer(14, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 4; @@ -1339,12 +1335,12 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(14, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { uniform_value[U_MORPH_COLOR] = 1; enable_vertex_attrib_array(5); @@ -1354,7 +1350,7 @@ inline static void draw_object_vertex_attrib_set_default_compressed(draw_object* else glVertexAttrib4f(5, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) offset += 16; shaders_ft.env_vert_set(13, draw->morph_value, 1.0f - draw->morph_value, 0.0f, 0.0f); @@ -1381,7 +1377,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { gl_state_bind_array_buffer(draw->array_buffer); size_t offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1389,7 +1385,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(0, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1397,15 +1393,15 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(2, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) + if (vertex_format & OBJ_VERTEX_TANGENT) offset += 16; - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) + if (vertex_format & OBJ_VERTEX_BINORMAL) offset += 12; obj_material_data* material = draw->material; if (material->material.texdata[0].tex_index != -1) { - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(8); glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)(offset + 8ULL * sub_mesh->uv_index[0])); @@ -1429,16 +1425,16 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { for (int32_t i = 1; i < 4; i++) glVertexAttrib4f(8 + i, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (vertex_format & OBJ_VERTEX_TEXCOORD0) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (vertex_format & OBJ_VERTEX_TEXCOORD1) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { enable_vertex_attrib_array(3); glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1446,10 +1442,10 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) + if (vertex_format & OBJ_VERTEX_COLOR1) offset += 16; - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { + if (vertex_format & OBJ_VERTEX_BONE_DATA) { uniform_value[U_BONE_MAT] = 1; enable_vertex_attrib_array(1); @@ -1461,11 +1457,11 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { offset += 16; } else { - glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 1.0f); - glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 1.0f); + glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 0.0f); + glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 0.0f); } - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) + if (vertex_format & OBJ_VERTEX_UNKNOWN) offset += 16; if (draw->morph_array_buffer) { @@ -1474,7 +1470,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { gl_state_bind_array_buffer(draw->morph_array_buffer); offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(10); glVertexAttribPointer(10, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1482,7 +1478,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(10, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(11); glVertexAttribPointer(11, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1490,7 +1486,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(11, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(12); glVertexAttribPointer(12, 4, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 16; @@ -1498,10 +1494,10 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(12, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) + if (vertex_format & OBJ_VERTEX_BINORMAL) offset += 12; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(13); glVertexAttribPointer(13, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1509,7 +1505,7 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(13, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { enable_vertex_attrib_array(14); glVertexAttribPointer(14, 2, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1517,12 +1513,12 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(14, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 8; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { uniform_value[U_MORPH_COLOR] = 1; enable_vertex_attrib_array(5); @@ -1532,13 +1528,13 @@ static void draw_object_vertex_attrib_set_reflect(draw_object* draw) { else glVertexAttrib4f(5, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) + if (vertex_format & OBJ_VERTEX_COLOR1) offset += 16; - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) offset += 32; - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) + if (vertex_format & OBJ_VERTEX_UNKNOWN) offset += 16; shaders_ft.env_vert_set(13, draw->morph_value, 1.0f - draw->morph_value, 0.0f, 0.0f); @@ -1557,7 +1553,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* gl_state_bind_array_buffer(draw->array_buffer); size_t offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1565,7 +1561,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(0, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(2); glVertexAttribPointer(2, 3, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1573,12 +1569,12 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(2, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) + if (vertex_format & OBJ_VERTEX_TANGENT) offset += 8; obj_material_data* material = draw->material; if (material->material.texdata[0].tex_index != -1) { - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(8); glVertexAttribPointer(8, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)(offset + 4ULL * sub_mesh->uv_index[0])); @@ -1602,16 +1598,16 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* for (int32_t i = 1; i < 4; i++) glVertexAttrib4f(8 + i, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (vertex_format & OBJ_VERTEX_TEXCOORD0) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (vertex_format & OBJ_VERTEX_TEXCOORD1) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { enable_vertex_attrib_array(3); glVertexAttribPointer(3, 4, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 8; @@ -1619,7 +1615,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(3, 1.0f, 1.0f, 1.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { + if (vertex_format & OBJ_VERTEX_BONE_DATA) { uniform_value[U_BONE_MAT] = 1; enable_vertex_attrib_array(1); @@ -1631,8 +1627,8 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* offset += 8; } else { - glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 1.0f); - glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 1.0f); + glVertexAttrib4f(1, 0.0f, 0.0f, 0.0f, 0.0f); + glVertexAttrib4f(15, 0.0f, 0.0f, 0.0f, 0.0f); } if (draw->morph_array_buffer) { @@ -1641,7 +1637,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* gl_state_bind_array_buffer(draw->morph_array_buffer); offset = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { + if (vertex_format & OBJ_VERTEX_POSITION) { enable_vertex_attrib_array(10); glVertexAttribPointer(10, 3, GL_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 12; @@ -1649,7 +1645,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(10, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { + if (vertex_format & OBJ_VERTEX_NORMAL) { enable_vertex_attrib_array(11); glVertexAttribPointer(11, 3, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1657,7 +1653,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(11, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { + if (vertex_format & OBJ_VERTEX_TANGENT) { enable_vertex_attrib_array(12); glVertexAttribPointer(12, 4, GL_SHORT, GL_TRUE, size_vertex, (void*)offset); offset += 8; @@ -1665,7 +1661,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(12, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { enable_vertex_attrib_array(13); glVertexAttribPointer(13, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 4; @@ -1673,7 +1669,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(13, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { enable_vertex_attrib_array(14); glVertexAttribPointer(14, 2, GL_HALF_FLOAT, GL_FALSE, size_vertex, (void*)offset); offset += 4; @@ -1681,12 +1677,12 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(14, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (vertex_format & OBJ_VERTEX_TEXCOORD2) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (vertex_format & OBJ_VERTEX_TEXCOORD3) offset += 4; - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { + if (vertex_format & OBJ_VERTEX_COLOR0) { uniform_value[U_MORPH_COLOR] = 1; enable_vertex_attrib_array(5); @@ -1696,7 +1692,7 @@ inline static void draw_object_vertex_attrib_set_reflect_compressed(draw_object* else glVertexAttrib4f(5, 0.0f, 0.0f, 0.0f, 1.0f); - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (vertex_format & OBJ_VERTEX_BONE_DATA) offset += 16; shaders_ft.env_vert_set(13, draw->morph_value, 1.0f - draw->morph_value, 0.0f, 0.0f); diff --git a/src/CRE/draw_object.h b/src/CRE/draw_object.hpp similarity index 100% rename from src/CRE/draw_object.h rename to src/CRE/draw_object.hpp diff --git a/src/CRE/draw_pass.c b/src/CRE/draw_pass.cpp similarity index 92% rename from src/CRE/draw_pass.c rename to src/CRE/draw_pass.cpp index 3d3bde69..3eab67ec 100644 --- a/src/CRE/draw_pass.c +++ b/src/CRE/draw_pass.cpp @@ -3,17 +3,17 @@ GitHub/GitLab: korenkonder */ -#include "draw_pass.h" +#include "draw_pass.hpp" #include "Glitter/glitter.hpp" #include "light_param/fog.hpp" #include "light_param/light.hpp" -#include "gl_state.h" +#include "rob/rob.hpp" +#include "gl_state.hpp" #include "post_process.hpp" -#include "rob.hpp" -#include "render_texture.h" -#include "shader_ft.h" +#include "render_texture.hpp" +#include "shader_ft.hpp" #include "shader_glsl.hpp" -#include "static_var.h" +#include "static_var.hpp" #include "texture.hpp" struct draw_preprocess { @@ -55,7 +55,7 @@ static void texture_params_restore(texture_param* tex_0_param, texture_param* tex_1_param, texture_param* tex_2_param); extern bool draw_grid_3d; -extern shader_glsl grid_shader; +extern shader_glsl* grid_shader; extern GLuint grid_vbo; extern size_t grid_vertex_count; extern vec4u8 clear_color; @@ -107,7 +107,7 @@ void draw_pass_main(render_context* rctx) { draw_pass_pre_process(rctx, &rctx->draw_pass); break; case DRAW_PASS_CLEAR: { - render_texture_bind(&rctx->post_process.rend_texture, 0); + rctx->post_process.rend_texture.bind(); vec4 _clear_color; vec4u8_to_vec4(clear_color, _clear_color); vec4_mult_scalar(_clear_color, (float_t)(1.0 / 255.0), _clear_color); @@ -139,7 +139,7 @@ void draw_pass_main(render_context* rctx) { inline static void draw_pass_begin(draw_pass* a1) { if (a1->wait_for_gpu) glFinish(); - time_struct_get_timestamp(&a1->time); + a1->time.get_timestamp(); } static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { @@ -158,7 +158,7 @@ static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { if (draw_pass_shadow_litproj(rctx, rctx->litproj)) { draw_pass_set_camera(rctx->camera); for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) - light_set_data_set(&rctx->light_set_data[i], &rctx->face, (light_set_id)i); + rctx->light_set[i].data_set(rctx->face, (light_set_id)i); gl_state_bind_vertex_array(rctx->vao); draw_task_draw_objects_by_type(rctx, DRAW_OBJECT_OPAQUE, 0, 0, true, -1); draw_task_draw_objects_by_type(rctx, DRAW_OBJECT_TRANSPARENT, 0, 0, true, -1); @@ -197,7 +197,7 @@ static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { int32_t index = v11[i]; texture* tex = shad->field_158[0]->color_texture; - render_texture_bind(shad->field_158[0], 0); + shad->field_158[0]->bind(); glViewport(0, 0, tex->width, tex->height); glScissor(0, 0, tex->width, tex->height); gl_state_enable_depth_test(); @@ -261,29 +261,29 @@ static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { if (v5 && v6 && v7) { texture_param tex_params[3]; texture_params_get(v5, &tex_params[0], v7, &tex_params[1], v6, &tex_params[2]); - render_texture_bind(&shad->field_8[6], 0); + shad->field_8[6].bind(); uniform_value[U_ESM_FILTER] = 0; shaders_ft.set(SHADER_FT_ESMFILT); shaders_ft.local_frag_set(0, 1.0f / (float_t)tex_params[1].width, 1.0f / (float_t)tex_params[1].height, 0.0f, 0.0f); gl_state_active_bind_texture_2d(0, v7); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); - render_texture_bind(&shad->field_8[5], 0); + shad->field_8[5].bind(); uniform_value[U_ESM_FILTER] = 1; shaders_ft.set(SHADER_FT_ESMFILT); shaders_ft.local_frag_set(0, 0.75f / (float_t)tex_params[2].width, 0.75f / (float_t)tex_params[2].height, 0.0f, 0.0f); gl_state_active_bind_texture_2d(0, v6); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); texture_params_restore(&tex_params[0], &tex_params[1], &tex_params[2]); } } render_texture* rend_tex = shad->field_158[1 + index]; - render_texture_bind(rend_tex, 0); + rend_tex->bind(); GLuint v11 = shad->field_158[1 + index]->color_texture->tex; GLuint v12 = shad->field_158[0]->color_texture->tex; @@ -303,11 +303,11 @@ static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { shaders_ft.state_matrix_set_texture(7, mat4_identity); gl_state_active_bind_texture_2d(0, v12); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); texture_params_restore(&tex_params[0], &tex_params[1], 0); } - render_texture_bind(rend_tex, 0); + rend_tex->bind(); if (shad->blur_filter_enable[index]) for (int32_t i = 0; i < shad->near_blur; i++) blur_filter_apply(rend_tex->color_texture->tex, @@ -331,7 +331,7 @@ static void draw_pass_shadow(render_context* rctx, draw_pass* a1) { for (int32_t i = 1; i < 3; i++) for (int32_t j = 0; j < 4; j++) { - render_texture_bind(shad->field_158[i], j); + shad->field_158[i]->bind(j); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); } @@ -362,7 +362,7 @@ static void draw_pass_shadow_filter(render_texture* a1, render_texture* a2, for (int32_t i = 0; i < 8; i++) ((float_t*)v15)[i] = (float_t)(exp((double_t)((ssize_t)i * i) * v8) * v6); - render_texture_bind(a2, 0); + a2->bind(); uniform_value[U_LIGHT_PROJ] = enable_lit_proj ? 1 : 0; shaders_ft.set(SHADER_FT_ESMGAUSS); shaders_ft.local_frag_set(0, 1.0f / (float_t)tex_params[0].width, 0.0f, 0.0f, 0.0f); @@ -383,16 +383,16 @@ static void draw_pass_shadow_filter(render_texture* a1, render_texture* a2, } gl_state_active_bind_texture_2d(0, v11); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); - render_texture_bind(a1, 0); + a1->bind(); shaders_ft.local_frag_set(0, 0.0f, 1.0f / (float_t)tex_params[0].height, 0.0f, 0.0f); shaders_ft.local_frag_set(1, v15[0]); shaders_ft.local_frag_set(2, v15[1]); shaders_ft.local_frag_set(3, far_texel_offset, far_texel_offset, 0.0f, 0.0f); gl_state_active_bind_texture_2d(0, v9); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); shader::unbind(); texture_params_restore(&tex_params[0], &tex_params[1], 0); } @@ -405,7 +405,7 @@ static bool draw_pass_shadow_litproj(render_context* rctx, light_proj* litproj) if (!tex) return false; - render_texture_bind(&litproj->draw_texture, 0); + litproj->draw_texture.bind(); glViewport(0, 0, litproj->draw_texture.color_texture->width, litproj->draw_texture.color_texture->height); @@ -448,11 +448,11 @@ static void draw_pass_sss(render_context* rctx, draw_pass* a1) { // sss->npr_contour = false; if (sss->npr_contour) { - render_texture_bind(&pp->rend_texture, 0); + pp->rend_texture.bind(); glViewport(0, 0, pp->render_width, pp->render_height); } else { - render_texture_bind(&sss->textures[0], 0); + sss->textures[0].bind(); glViewport(0, 0, 640, 360); } @@ -461,7 +461,7 @@ static void draw_pass_sss(render_context* rctx, draw_pass* a1) { draw_pass_set_camera(rctx->camera); for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) - light_set_data_set(&rctx->light_set_data[i], &rctx->face, (light_set_id)i); + rctx->light_set[i].data_set(rctx->face, (light_set_id)i); if (a1->shadow) draw_pass_3d_shadow_set(a1->shadow_ptr, rctx); @@ -485,7 +485,7 @@ static void draw_pass_sss(render_context* rctx, draw_pass* a1) { draw_pass_sss_contour(rctx, pp); } else if (a1->npr) { - render_texture_bind(&pp->rend_texture, 0); + pp->rend_texture.bind(); glViewport(0, 0, pp->render_width, pp->render_height); glClear(GL_DEPTH_BUFFER_BIT); rctx->draw_state.shader_index = SHADER_FT_SSS_SKIN; @@ -506,7 +506,7 @@ static void draw_pass_sss(render_context* rctx, draw_pass* a1) { } static void draw_pass_sss_contour(render_context* rctx, post_process* pp) { - render_texture_bind(&pp->sss_contour_texture, 0); + pp->sss_contour_texture.bind(); shaders_ft.state_matrix_set_modelview(0, mat4_identity, false); shaders_ft.state_matrix_set_projection(mat4_identity, true); gl_state_enable_depth_test(); @@ -543,7 +543,7 @@ static void draw_pass_sss_contour(render_context* rctx, post_process* pp) { v9 = 0.0f; shaders_ft.local_frag_set(4, v9 * 0.004f + 0.0027f, 0.003f, v3 * 0.35f, 0.0008f); - render_texture_draw_params(&shaders_ft, pp->render_width, pp->render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, pp->render_width, pp->render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } static void draw_pass_sss_filter_calc_coef(double_t a1, size_t a2, double_t a3, size_t a4, @@ -655,7 +655,7 @@ static void draw_pass_sss_filter(render_context* rctx, sss_data* a1) { gl_state_active_texture(0); if (a1->npr_contour) { - render_texture_bind(a1->textures, 0); + a1->textures->bind(); glViewport(0, 0, 640, 360); post_process* pp = &rctx->post_process; gl_state_bind_texture_2d(pp->rend_texture.color_texture->tex); @@ -663,15 +663,15 @@ static void draw_pass_sss_filter(render_context* rctx, sss_data* a1) { shaders_ft.set(SHADER_FT_REDUCE); shaders_ft.state_matrix_set_texture(0, mat4_identity); - render_texture_draw_params(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); + render_texture::draw_params(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); } - render_texture_bind(&a1->textures[2], 0); + a1->textures[2].bind(); glViewport(0, 0, 320, 180); gl_state_bind_texture_2d(a1->textures[0].color_texture->tex); uniform_value[U_SSS_FILTER] = 0; shaders_ft.set(SHADER_FT_SSS_FILT); - render_texture_draw_params(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); - render_texture_bind(&a1->textures[1], 0); + render_texture::draw_params(&shaders_ft, 640, 360, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f); + a1->textures[1].bind(); uniform_value[U_SSS_FILTER] = 3; shaders_ft.set(SHADER_FT_SSS_FILT); shaders_ft.local_frag_set(1, 5.0f, 0.0f, 0.0f, 0.0f); @@ -697,36 +697,36 @@ static void draw_pass_sss_filter(render_context* rctx, sss_data* a1) { shaders_ft.local_frag_set(1, (float_t)(sss_count - 1), 0.0f, 1.0f, 1.0f); glViewport(0, 0, 320, 180); gl_state_bind_texture_2d(a1->textures[2].color_texture->tex); - render_texture_draw_params(&shaders_ft, 320, 180, 1.0f, 1.0f, 0.96f, 1.0f, 0.0f); + render_texture::draw_params(&shaders_ft, 320, 180, 1.0f, 1.0f, 0.96f, 1.0f, 0.0f); gl_state_bind_texture_2d(0); } static void draw_pass_reflect(render_context* rctx, draw_pass* a1) { - render_texture* reflect_texture = &rctx->draw_pass.reflect_texture; - render_texture_bind(reflect_texture, 0); + render_texture& reflect_texture = rctx->draw_pass.reflect_texture; + reflect_texture.bind(); if (draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_OPAQUE) || draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_TRANSPARENT) || draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_TRANSLUCENT) || draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_CHARA_OPAQUE) || draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_CHARA_TRANSPARENT) || draw_task_get_count(rctx, DRAW_OBJECT_REFLECT_CHARA_TRANSLUCENT)) { - texture* refl_tex = reflect_texture->color_texture; + texture* refl_tex = reflect_texture.color_texture; glViewport(0, 0, refl_tex->width, refl_tex->height); draw_pass_set_camera(rctx->camera); for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) - light_set_data_set(&rctx->light_set_data[i], &rctx->face, (light_set_id)i); + rctx->light_set[i].data_set(rctx->face, (light_set_id)i); for (int32_t i = FOG_DEPTH; i < FOG_BUMP; i++) - fog_data_set(&rctx->fog_data[i], (fog_id)i); + rctx->fog[i].data_set((fog_id)i); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rctx->draw_state.shader_index = SHADER_FT_S_REFL; bool clip_plane[4]; - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; - light_get_clip_plane(&set->lights[LIGHT_SPOT], clip_plane); + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; + set->lights[LIGHT_SPOT].get_clip_plane(clip_plane); uniform_value[U_REFLECT] = 2; uniform_value[U_CLIP_PLANE] = clip_plane[1]; gl_state_bind_vertex_array(rctx->vao); @@ -751,10 +751,10 @@ static void draw_pass_reflect(render_context* rctx, draw_pass* a1) { uniform_value[U_REFLECT] = 0; rctx->draw_state.shader_index = -1; - render_texture_bind(reflect_texture, 0); + reflect_texture.bind(); for (int32_t i = a1->reflect_blur_num; i > 0; i--) - blur_filter_apply(reflect_texture->color_texture->tex, - reflect_texture->color_texture->tex, a1->reflect_blur_filter); + blur_filter_apply(reflect_texture.color_texture->tex, + reflect_texture.color_texture->tex, a1->reflect_blur_filter); } else { vec4 clear_color; @@ -766,20 +766,20 @@ static void draw_pass_reflect(render_context* rctx, draw_pass* a1) { } static void draw_pass_refract(render_context* rctx, draw_pass* a1) { - render_texture* refract_texture = &rctx->draw_pass.refract_texture; - render_texture_bind(refract_texture, 0); + render_texture& refract_texture = rctx->draw_pass.refract_texture; + refract_texture.bind(); if (draw_task_get_count(rctx, DRAW_OBJECT_REFRACT_OPAQUE) || draw_task_get_count(rctx, DRAW_OBJECT_REFRACT_TRANSPARENT) || draw_task_get_count(rctx, DRAW_OBJECT_REFRACT_TRANSLUCENT)) { - texture* refr_tex = refract_texture->color_texture; + texture* refr_tex = refract_texture.color_texture; glViewport(0, 0, refr_tex->width, refr_tex->height); draw_pass_set_camera(rctx->camera); for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) - light_set_data_set(&rctx->light_set_data[i], &rctx->face, (light_set_id)i); + rctx->light_set[i].data_set(rctx->face, (light_set_id)i); for (int32_t i = FOG_DEPTH; i < FOG_BUMP; i++) - fog_data_set(&rctx->fog_data[i], (fog_id)i); + rctx->fog[i].data_set((fog_id)i); vec4 clear_color; glGetFloatv(GL_COLOR_CLEAR_VALUE, (GLfloat*)&clear_color); @@ -813,7 +813,7 @@ static void draw_pass_pre_process(render_context* rctx, draw_pass* a1) { static void draw_pass_3d(render_context* rctx, draw_pass* a1) { rctx->view_mat = rctx->camera->view; - render_texture_bind(&rctx->post_process.rend_texture, 0); + rctx->post_process.rend_texture.bind(); glViewport(0, 0, rctx->post_process.render_width, rctx->post_process.render_height); draw_pass_set_camera(rctx->camera); if (!a1->sss_data.enable || !a1->sss_data.npr_contour || draw_pass_3d_get_translucent_count(rctx)) @@ -822,9 +822,9 @@ static void draw_pass_3d(render_context* rctx, draw_pass* a1) { gl_state_bind_vertex_array(rctx->vao); for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) - light_set_data_set(&rctx->light_set_data[i], &rctx->face, (light_set_id)i); + rctx->light_set[i].data_set(rctx->face, (light_set_id)i); for (int32_t i = FOG_DEPTH; i < FOG_MAX; i++) - fog_data_set(&rctx->fog_data[i], (fog_id)i); + rctx->fog[i].data_set((fog_id)i); if (a1->shadow) draw_pass_3d_shadow_set(a1->shadow_ptr, rctx); @@ -1038,12 +1038,12 @@ static void draw_pass_3d_shadow_set(shadow* shad, render_context* rctx) { } gl_state_active_texture(0); - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; light_data* data = &set->lights[LIGHT_SHADOW]; vec4 ambient; - if (light_get_type(data) == LIGHT_PARALLEL) - light_get_ambient(data, &ambient); + if (data->get_type() == LIGHT_PARALLEL) + data->get_ambient(ambient); else { ambient.x = shad->ambient; ambient.y = shad->ambient; @@ -1070,7 +1070,7 @@ static void draw_pass_show_vector(render_context* rctx, draw_pass* a1) { return; rctx->view_mat = rctx->camera->view; - render_texture_bind(&rctx->post_process.rend_texture, 0); + rctx->post_process.rend_texture.bind(); glViewport(0, 0, rctx->post_process.render_width, rctx->post_process.render_height); draw_pass_set_camera(rctx->camera); @@ -1094,8 +1094,8 @@ static void draw_pass_post_process(render_context* rctx, draw_pass* a1) { texture* light_proj_tex = 0; light_proj* litproj = rctx->litproj; if (litproj && litproj->enable) { - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; - if (light_get_type(&set->lights[LIGHT_PROJECTION]) == LIGHT_SPOT + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; + if (set->lights[LIGHT_PROJECTION].get_type() == LIGHT_SPOT && texture_storage_get_texture(litproj->texture_id)) light_proj_tex = litproj->draw_texture.color_texture; } @@ -1107,12 +1107,11 @@ static void draw_pass_sprite(render_context* rctx, draw_pass* a1) { } inline static void draw_pass_end(draw_pass* pass, draw_pass_type type) { - pass->cpu_time[type] = time_struct_calc_time(&pass->time); + pass->cpu_time[type] = pass->time.calc_time(); if (pass->wait_for_gpu) { time_struct t; - time_struct_get_timestamp(&t); glFinish(); - pass->gpu_time[type] = time_struct_calc_time(&t); + pass->gpu_time[type] = t.calc_time(); } else pass->gpu_time[type] = 0; @@ -1126,8 +1125,8 @@ static void draw_pass_3d_grid(render_context* rctx) { gl_state_set_depth_func(GL_LEQUAL); gl_state_set_depth_mask(GL_TRUE); - grid_shader.use(); - grid_shader.set("vp", false, rctx->camera->view_projection); + grid_shader->use(); + grid_shader->set("vp", false, rctx->camera->view_projection); gl_state_bind_array_buffer(grid_vbo); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, @@ -1281,6 +1280,6 @@ static void blur_filter_apply(GLuint tex_0, GLuint tex_1, blur_filter_mode filte } gl_state_active_bind_texture_2d(0, tex_1); shaders_ft.state_matrix_set_mvp(mat4_identity); - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); texture_params_restore(&tex_params[0], &tex_params[1], 0); } diff --git a/src/CRE/draw_pass.h b/src/CRE/draw_pass.hpp similarity index 89% rename from src/CRE/draw_pass.h rename to src/CRE/draw_pass.hpp index 3d7a90fe..f8c1ee07 100644 --- a/src/CRE/draw_pass.h +++ b/src/CRE/draw_pass.hpp @@ -8,6 +8,6 @@ #include "../KKdLib/default.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/vec.hpp" -#include "draw_task.h" +#include "draw_task.hpp" extern void draw_pass_main(render_context* rctx); diff --git a/src/CRE/draw_primitive.c b/src/CRE/draw_primitive.cpp similarity index 67% rename from src/CRE/draw_primitive.c rename to src/CRE/draw_primitive.cpp index d4daff1d..c6639ad9 100644 --- a/src/CRE/draw_primitive.c +++ b/src/CRE/draw_primitive.cpp @@ -3,4 +3,4 @@ GitHub/GitLab: korenkonder */ -#include "draw_object.h" +#include "draw_object.hpp" diff --git a/src/CRE/draw_primitive.h b/src/CRE/draw_primitive.hpp similarity index 87% rename from src/CRE/draw_primitive.h rename to src/CRE/draw_primitive.hpp index 42dbca5d..b1c0e686 100644 --- a/src/CRE/draw_primitive.h +++ b/src/CRE/draw_primitive.hpp @@ -8,4 +8,4 @@ #include "../KKdLib/default.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/vec.hpp" -#include "gl_state.h" +#include "gl_state.hpp" diff --git a/src/CRE/draw_task.c b/src/CRE/draw_task.cpp similarity index 97% rename from src/CRE/draw_task.c rename to src/CRE/draw_task.cpp index b3ad8818..41aa7cd0 100644 --- a/src/CRE/draw_task.c +++ b/src/CRE/draw_task.cpp @@ -3,13 +3,13 @@ GitHub/GitLab: korenkonder */ -#include "draw_task.h" +#include "draw_task.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/sort.hpp" -#include "camera.h" +#include "camera.hpp" #include "fbo.hpp" #include "post_process.hpp" -#include "shader_ft.h" +#include "shader_ft.hpp" static void draw_task_add(render_context* rctx, draw_object_type type, draw_task* task); static void draw_task_object_init(draw_task* task, object_data* object_data, mat4* mat, @@ -253,12 +253,12 @@ void draw_task_draw_objects_by_type_translucent(render_context* rctx, bool opaqu gl_state_disable_blend(); } - render_texture_bind(&rctx->post_process.buf_texture, 0); - render_texture_shader_set_glsl(&rctx->post_process.alpha_layer_shader); + rctx->post_process.buf_texture.bind(); + render_texture::shader_set_glsl(&rctx->post_process.alpha_layer_shader); gl_state_active_bind_texture_2d(0, rctx->post_process.alpha_layer_texture.color_texture->tex); gl_state_active_bind_texture_2d(1, rctx->post_process.rend_texture.color_texture->tex); glUniform1f(0, (float_t)(alpha * (1.0 / 255.0))); - render_texture_draw_custom_glsl(); + render_texture::draw_custom_glsl(); fbo::blit(rctx->post_process.buf_texture.fbos[0], rctx->post_process.rend_texture.fbos[0], @@ -290,8 +290,7 @@ bool draw_task_add_draw_object(render_context* rctx, obj* object, obj_mesh* mesh = &object->mesh_array[i]; obj_mesh* mesh_morph = 0; if (obj_vertex_buf && obj_morph_vertex_buf) { - if (obj_mesh_vertex_buffer_get_size(&obj_vertex_buf[i]) - != obj_mesh_vertex_buffer_get_size(&obj_morph_vertex_buf[i])) + if (obj_vertex_buf[i].get_size() != obj_morph_vertex_buf[i].get_size()) continue; if (object_morph && i < object_morph->num_mesh) @@ -313,7 +312,7 @@ bool draw_task_add_draw_object(render_context* rctx, obj* object, for (uint32_t j = 0; j < mesh->num_submesh; j++) { obj_sub_mesh* sub_mesh = &mesh->submesh_array[j]; obj_sub_mesh* sub_mesh_morph = 0; - if (sub_mesh->attrib.m.flag_3) + if (sub_mesh->attrib.m.cloth) continue; if (object_data->object_culling && !instances_count && !bone_mat) { @@ -384,7 +383,7 @@ bool draw_task_add_draw_object(render_context* rctx, obj* object, GLuint morph_array_buffer = 0; if (obj_morph_vertex_buf) - morph_array_buffer = obj_mesh_vertex_buffer_get_buffer(&obj_morph_vertex_buf[i]); + morph_array_buffer = obj_morph_vertex_buf[i].get_buffer(); GLuint element_array_buffer = 0; if (obj_index_buf) @@ -392,7 +391,7 @@ bool draw_task_add_draw_object(render_context* rctx, obj* object, GLuint array_buffer = 0; if (obj_vertex_buf) - array_buffer = obj_mesh_vertex_buffer_get_buffer(&obj_vertex_buf[i]); + array_buffer = obj_vertex_buf[i].get_buffer(); uint32_t material_hash = hash_utf8_murmurhash(material->material.name); @@ -621,6 +620,18 @@ bool draw_task_add_draw_object(render_context* rctx, obj* object, return true; } +inline void draw_task_add_draw_object_by_obj(render_context* rctx, mat4* mat, obj* obj, std::vector* textures, + obj_mesh_vertex_buffer* obj_vert_buf, obj_mesh_index_buffer* obj_index_buf, 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; + + draw_task_add_draw_object(rctx, obj, obj_vert_buf, obj_index_buf, mat, textures, blend_color_ptr, + bone_mat, 0, 0, 0, 0, 0, !!bone_mat); +} + inline bool draw_task_add_draw_object_by_object_info(render_context* rctx, mat4* mat, object_info obj_info, mat4* bone_mat) { vec4 blend_color = vec4_identity; diff --git a/src/CRE/draw_task.h b/src/CRE/draw_task.hpp similarity index 89% rename from src/CRE/draw_task.h rename to src/CRE/draw_task.hpp index f616a66a..6e1c9fb0 100644 --- a/src/CRE/draw_task.h +++ b/src/CRE/draw_task.hpp @@ -8,8 +8,8 @@ #include "../KKdLib/default.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/vec.hpp" -#include "draw_object.h" -#include "draw_primitive.h" +#include "draw_object.hpp" +#include "draw_primitive.hpp" extern void draw_task_draw_objects_by_type(render_context* rctx, draw_object_type type, int32_t a2, int32_t a3, bool a4, int32_t alpha); @@ -22,6 +22,8 @@ extern bool draw_task_add_draw_object(render_context* rctx, obj* object, std::vector* textures, vec4* blend_color, mat4* bone_mat, obj* object_morph, obj_mesh_vertex_buffer* obj_morph_vertex_buf, int32_t instances_count, mat4* instances_mat, void(*draw_object_func)(draw_object*), bool enable_bone_mat); +extern void draw_task_add_draw_object_by_obj(render_context* rctx, mat4* mat, obj* obj, std::vector* textures, + obj_mesh_vertex_buffer* obj_vert_buf, obj_mesh_index_buffer* obj_index_buf, mat4* bone_mat, float_t alpha); extern bool draw_task_add_draw_object_by_object_info(render_context* rctx, mat4* mat, object_info obj_info, mat4* bone_mat = 0); extern bool draw_task_add_draw_object_by_object_info(render_context* rctx, mat4* mat, diff --git a/src/CRE/fbo.cpp b/src/CRE/fbo.cpp index a5f8fcc1..ab43f1ed 100644 --- a/src/CRE/fbo.cpp +++ b/src/CRE/fbo.cpp @@ -4,7 +4,7 @@ */ #include "fbo.hpp" -#include "gl_state.h" +#include "gl_state.hpp" fbo::fbo() : flags(), width(), height(), buffer(), count(), textures() { diff --git a/src/CRE/fbo.hpp b/src/CRE/fbo.hpp index ff472e95..e5a420ae 100644 --- a/src/CRE/fbo.hpp +++ b/src/CRE/fbo.hpp @@ -5,7 +5,7 @@ #pragma once -#include "shared.h" +#include "shared.hpp" enum fbo_flags { FBO_DEPTH_ATTACHMENT = 0x01, diff --git a/src/CRE/file_handler.cpp b/src/CRE/file_handler.cpp index 2a3ff9d3..a99ba9cc 100644 --- a/src/CRE/file_handler.cpp +++ b/src/CRE/file_handler.cpp @@ -331,13 +331,13 @@ p_file_handler::p_file_handler() { p_file_handler::~p_file_handler() { if (ptr) { if (check_not_ready()) - call_free_func_free_data(); + call_free_callback(); else free_data(); } } -void p_file_handler::call_free_func_free_data() { +void p_file_handler::call_free_callback() { if (ptr) ptr->call_callback(1); free_data(); diff --git a/src/CRE/file_handler.hpp b/src/CRE/file_handler.hpp index b6130283..75f6df6d 100644 --- a/src/CRE/file_handler.hpp +++ b/src/CRE/file_handler.hpp @@ -50,7 +50,7 @@ struct p_file_handler { p_file_handler(); virtual ~p_file_handler(); - void call_free_func_free_data(); + void call_free_callback(); bool check_not_ready(); void free_data(); const void* get_data(); diff --git a/src/CRE/frame_rate_control.cpp b/src/CRE/frame_rate_control.cpp index 417df13d..ed80aa9b 100644 --- a/src/CRE/frame_rate_control.cpp +++ b/src/CRE/frame_rate_control.cpp @@ -4,7 +4,7 @@ */ #include "frame_rate_control.hpp" -#include "static_var.h" +#include "static_var.hpp" SysFrameRate sys_frame_rate; DivaPvFrameRate diva_pv_frame_rate; diff --git a/src/CRE/gl_state.c b/src/CRE/gl_state.cpp similarity index 99% rename from src/CRE/gl_state.c rename to src/CRE/gl_state.cpp index 28fefa9e..7ace286a 100644 --- a/src/CRE/gl_state.c +++ b/src/CRE/gl_state.cpp @@ -3,7 +3,7 @@ GitHub/GitLab: korenkonder */ -#include "gl_state.h" +#include "gl_state.hpp" gl_state_struct gl_state; diff --git a/src/CRE/gl_state.h b/src/CRE/gl_state.hpp similarity index 100% rename from src/CRE/gl_state.h rename to src/CRE/gl_state.hpp diff --git a/src/CRE/light_param.cpp b/src/CRE/light_param.cpp index aa390fb6..dd933fe0 100644 --- a/src/CRE/light_param.cpp +++ b/src/CRE/light_param.cpp @@ -152,7 +152,7 @@ static int32_t light_param_storage_load_file(light_param_data_storage* a1, bool if (load_error) { for (int32_t i = 0; i < 6; i++) - a1->file_handlers[i].call_free_func_free_data(); + a1->file_handlers[i].call_free_callback(); a1->state = 0; return 0; } @@ -507,7 +507,7 @@ static void light_param_storage_load_stages(light_param_data_storage* a1, std::v if (a1->state) for (int32_t i = 0; i < 6; ++i) if (a1->file_handlers[i].check_not_ready()) - a1->file_handlers[i].call_free_func_free_data(); + a1->file_handlers[i].call_free_callback(); a1->stage_index = -1; a1->stage.clear(); @@ -537,7 +537,7 @@ static void light_param_storage_load_stages(light_param_data_storage* a1, if (a1->state) for (int32_t i = 0; i < 6; ++i) if (a1->file_handlers[i].check_not_ready()) - a1->file_handlers[i].call_free_func_free_data(); + a1->file_handlers[i].call_free_callback(); a1->stage_index = -1; a1->stage.clear(); diff --git a/src/CRE/light_param/face.cpp b/src/CRE/light_param/face.cpp index 258f323a..e65f07c9 100644 --- a/src/CRE/light_param/face.cpp +++ b/src/CRE/light_param/face.cpp @@ -12,34 +12,42 @@ face::face() { direction = vec3_null; } -inline float_t face_get_offset(face* face) { - return face->offset; +float_t face::get_offset() { + return offset; } -inline void face_set_offset(face* face, float_t value) { - face->scale = value; +void face::set_offset(float_t value) { + scale = value; } -inline float_t face_get_scale(face* face) { - return face->scale; +float_t face::get_scale() { + return scale; } -inline void face_set_scale(face* face, float_t value) { - face->scale = value; +void face::set_scale(float_t value) { + scale = value; } -inline void face_get_position(face* face, vec3* value) { - *value = face->position; +void face::get_position(vec3& value) { + value = position; } -inline void face_set_position(face* face, vec3* value) { - face->position = *value; +void face::set_position(vec3& value) { + position = value; } -inline void face_get_direction(face* face, vec3* value) { - *value = face->direction; +void face::set_position(vec3&& value) { + position = value; } -inline void face_set_direction(face* face, vec3* value) { - face->direction = *value; +void face::get_direction(vec3& value) { + value = direction; +} + +void face::set_direction(vec3& value) { + direction = value; +} + +void face::set_direction(vec3&& value) { + direction = value; } diff --git a/src/CRE/light_param/face.hpp b/src/CRE/light_param/face.hpp index f83cf321..88a84df7 100644 --- a/src/CRE/light_param/face.hpp +++ b/src/CRE/light_param/face.hpp @@ -8,7 +8,7 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/light_param/face.hpp" #include "../../KKdLib/vec.hpp" -#include "../static_var.h" +#include "../static_var.hpp" struct face { float_t offset; @@ -17,13 +17,15 @@ struct face { vec3 direction; face(); -}; -extern float_t face_get_offset(face* face); -extern void face_set_offset(face* face, float_t value); -extern float_t face_get_scale(face* face); -extern void face_set_scale(face* face, float_t value); -extern void face_get_position(face* face, vec3* value); -extern void face_set_position(face* face, vec3* value); -extern void face_get_direction(face* face, vec3* value); -extern void face_set_direction(face* face, vec3* value); + float_t get_offset(); + void set_offset(float_t value); + float_t get_scale(); + void set_scale(float_t value); + void get_position(vec3& value); + void set_position(vec3& value); + void set_position(vec3&& value); + void get_direction(vec3& value); + void set_direction(vec3& value); + void set_direction(vec3&& value); +}; diff --git a/src/CRE/light_param/fog.cpp b/src/CRE/light_param/fog.cpp index 11d27baf..64ce4e71 100644 --- a/src/CRE/light_param/fog.cpp +++ b/src/CRE/light_param/fog.cpp @@ -4,7 +4,7 @@ */ #include "fog.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" fog::fog() { type = FOG_NONE; @@ -15,62 +15,66 @@ fog::fog() { color = { 1.0f, 1.0f, 1.0f, 0.0f }; } -inline fog_type fog_get_type(fog* fog) { - return fog->type; +fog_type fog::get_type() { + return type; } -inline void fog_set_type(fog* fog, fog_type value) { - fog->type = value; +void fog::set_type(fog_type value) { + type = value; } -inline float_t fog_get_density(fog* fog) { - return fog->density; +float_t fog::get_density() { + return density; } -inline void fog_set_density(fog* fog, float_t value) { - fog->density = value; +void fog::set_density(float_t value) { + density = value; } -inline float_t fog_get_start(fog* fog) { - return fog->start; +float_t fog::get_start() { + return start; } -inline void fog_set_start(fog* fog, float_t value) { - fog->start = value; +void fog::set_start(float_t value) { + start = value; } -inline float_t fog_get_end(fog* fog) { - return fog->end; +float_t fog::get_end() { + return end; } -inline void fog_set_end(fog* fog, float_t value) { - fog->end = value; +void fog::set_end(float_t value) { + end = value; } -inline int32_t fog_get_index(fog* fog) { - return fog->index; +int32_t fog::get_index() { + return index; } -inline void fog_set_index(fog* fog, int32_t value) { - fog->index = value; +void fog::set_index(int32_t value) { + index = value; } -inline void fog_get_color(fog* fog, vec4* value) { - *value = fog->color; +void fog::get_color(vec4& value) { + value = color; } -inline void fog_set_color(fog* fog, vec4* value) { - fog->color = *value; +void fog::set_color(vec4& value) { + color = value; } -void fog_data_set(fog* fog, fog_id id) { - fog_type type = fog_get_type(fog); +void fog::set_color(vec4&& value) { + color = value; +} + +void fog::data_set(fog_id id) { + fog_type type = get_type(); if (type == FOG_NONE) return; - float_t density = fog_get_density(fog); - float_t start = fog_get_start(fog); - float_t end = fog_get_end(fog); + float_t density = get_density(); + float_t start = get_start(); + float_t end = get_end(); if (start >= end) start = end - 0.01f; @@ -83,7 +87,7 @@ void fog_data_set(fog* fog, fog_id id) { switch (id) { case FOG_DEPTH: { vec4 color; - fog_get_color(fog, &color); + get_color(color); shaders_ft.env_vert_set(29, color); shaders_ft.env_frag_set(4, color); @@ -93,7 +97,7 @@ void fog_data_set(fog* fog, fog_id id) { } break; case FOG_HEIGHT: { vec4 color; - fog_get_color(fog, &color); + get_color(color); shaders_ft.env_vert_set(30, color); shaders_ft.env_frag_set(11, color); shaders_ft.env_vert_set(14, params); diff --git a/src/CRE/light_param/fog.hpp b/src/CRE/light_param/fog.hpp index 253e0511..0accb065 100644 --- a/src/CRE/light_param/fog.hpp +++ b/src/CRE/light_param/fog.hpp @@ -8,7 +8,7 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/light_param/fog.hpp" #include "../../KKdLib/vec.hpp" -#include "../static_var.h" +#include "../static_var.hpp" struct fog { fog_type type; @@ -19,18 +19,19 @@ struct fog { vec4 color; fog(); -}; -extern fog_type fog_get_type(fog* fog); -extern void fog_set_type(fog* fog, fog_type value); -extern float_t fog_get_density(fog* fog); -extern void fog_set_density(fog* fog, float_t value); -extern float_t fog_get_start(fog* fog); -extern void fog_set_start(fog* fog, float_t value); -extern float_t fog_get_end(fog* fog); -extern void fog_set_end(fog* fog, float_t value); -extern int32_t fog_get_index(fog* fog); -extern void fog_set_index(fog* fog, int32_t value); -extern void fog_get_color(fog* fog, vec4* value); -extern void fog_set_color(fog* fog, vec4* value); -extern void fog_data_set(fog* fog, fog_id id); + fog_type get_type(); + void set_type(fog_type value); + float_t get_density(); + void set_density(float_t value); + float_t get_start(); + void set_start(float_t value); + float_t get_end(); + void set_end(float_t value); + int32_t get_index(); + void set_index(int32_t value); + void get_color(vec4& value); + void set_color(vec4& value); + void set_color(vec4&& value); + void data_set(fog_id id); +}; diff --git a/src/CRE/light_param/light.cpp b/src/CRE/light_param/light.cpp index f1378900..6af37ab9 100644 --- a/src/CRE/light_param/light.cpp +++ b/src/CRE/light_param/light.cpp @@ -5,7 +5,7 @@ #include "light.hpp" #include "../../KKdLib/mat.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" extern bool light_chara_ambient; extern vec4 npr_spec_color; @@ -15,231 +15,272 @@ static void light_get_direction_from_position(vec4* pos_dir, light_data* light, light_data::light_data() : type(), ambient(), diffuse(), specular(), position(), spot_direction(), spot_exponent(), spot_cutoff(), constant(), linear(), quadratic(), ibl_specular(), ibl_back(), ibl_direction(), tone_curve(),clip_plane() { - vec3 temp3; - vec4 temp4; - light_set_type(this, LIGHT_OFF); - temp4 = { 0.0f, 0.0, 0.0f, 1.0f }; - light_set_ambient(this, &temp4); - temp4 = { 1.0f, 1.0, 1.0f, 0.0f }; - light_set_diffuse(this, &temp4); - temp4 = { 1.0f, 1.0f, 1.0f, 0.0f }; - light_set_specular(this, &temp4); - temp3 = { 0.0f, 1.0f, 1.0f }; - light_set_position(this, &temp3); - temp3 = { 0.0f, 0.0f, -1.0f }; - light_set_spot_direction(this, &temp3); - light_set_spot_exponent(this, 0.0f); - light_set_spot_cutoff(this, 45.0f); - light_set_constant(this, 1.0f); - light_set_linear(this, 0.0f); - light_set_quadratic(this, 0.0f); - temp4 = { 0.0f, 0.0f, 0.0f, 0.0f }; - light_set_ibl_specular(this, &temp4); - temp4 = { 0.0f, 0.0f, 0.0f, 0.0f }; - light_set_ibl_back(this, &temp4); - temp4 = { 0.0f, 0.0f, 0.0f, 0.0f }; - light_set_ibl_direction(this, &temp4); - temp3 = { 0.0f, 0.0f, 0.0f }; - light_set_tone_curve(this, &temp3); + set_type(LIGHT_OFF); + set_ambient({ 0.0f, 0.0, 0.0f, 1.0f }); + set_diffuse({ 1.0f, 1.0, 1.0f, 0.0f }); + set_specular({ 1.0f, 1.0f, 1.0f, 0.0f }); + set_position({ 0.0f, 1.0f, 1.0f, 0.0f }); + set_spot_direction({ 0.0f, 0.0f, -1.0f }); + set_spot_exponent(0.0f); + set_spot_cutoff(45.0f); + set_constant(1.0f); + set_linear(0.0f); + set_quadratic(0.0f); + set_ibl_specular({ 0.0f, 0.0f, 0.0f, 0.0f }); + set_ibl_back({ 0.0f, 0.0f, 0.0f, 0.0f }); + set_ibl_direction({ 0.0f, 0.0f, 0.0f, 0.0f }); + set_tone_curve({ 0.0f, 0.0f, 0.0f }); } light_set::light_set() : ambient_intensity(), irradiance_r(), irradiance_g(), irradiance_b() { - vec4 temp; - temp = { 0.2f, 0.2f, 0.2f, 1.0f }; - light_set_set_ambient_intensity(this, &temp); - temp = { 1.0f, 1.0f, 1.0f, 1.0f }; - light_set_diffuse(&lights[LIGHT_CHARA], &temp); - temp = { 1.0f, 1.0f, 1.0f, 1.0f }; - light_set_specular(&lights[LIGHT_CHARA], &temp); - light_set_set_irradiance(this, &mat4_identity, &mat4_identity, &mat4_identity); + set_ambient_intensity({ 0.2f, 0.2f, 0.2f, 1.0f }); + lights[LIGHT_CHARA].set_diffuse({ 1.0f, 1.0f, 1.0f, 1.0f }); + lights[LIGHT_CHARA].set_specular({ 1.0f, 1.0f, 1.0f, 1.0f }); + set_irradiance(mat4_identity, mat4_identity, mat4_identity); } -inline light_type light_get_type(light_data* light) { - return light->type; +light_type light_data::get_type() { + return type; } -inline void light_set_type(light_data* light, light_type value) { - light->type = value; +void light_data::set_type(light_type value) { + type = value; if (value < LIGHT_POINT) - light->position.w = 0.0f; + position.w = 0.0f; else - light->position.w = 1.0f; + position.w = 1.0f; } -inline void light_get_ambient(light_data* light, vec4* value) { - *value = light->ambient; +void light_data::get_ambient(vec4& value) { + value = ambient; } -inline void light_set_ambient(light_data* light, const vec4* value) { - light->ambient = *value; +void light_data::set_ambient(const vec4& value) { + ambient = value; } -inline void light_get_diffuse(light_data* light, vec4* value) { - *value = light->diffuse; +void light_data::set_ambient(const vec4&& value) { + ambient = value; } -inline void light_set_diffuse(light_data* light, const vec4* value) { - light->diffuse = *value; +void light_data::get_diffuse(vec4& value) { + value = diffuse; } -inline void light_get_specular(light_data* light, vec4* value) { - *value = light->specular; +void light_data::set_diffuse(const vec4& value) { + diffuse = value; } -inline void light_set_specular(light_data* light, const vec4* value) { - light->specular = *value; +void light_data::set_diffuse(const vec4&& value) { + diffuse = value; } -inline void light_get_position(light_data* light, vec3* value) { - *value = *(vec3*)&light->position; +void light_data::get_specular(vec4& value) { + value = specular; } -inline void light_set_position(light_data* light, const vec3* value) { - *(vec3*)&light->position = *value; +void light_data::set_specular(const vec4& value) { + specular = value; } -inline void light_get_position_vec4(light_data* light, vec4* value) { - *value = light->position; +void light_data::set_specular(const vec4&& value) { + specular = value; } -inline void light_set_position_vec4(light_data* light, const vec4* value) { - light->position = *value; +void light_data::get_position(vec3& value) { + value = *(vec3*)&position; } -inline void light_get_spot_direction(light_data* light, vec3* value) { - *value = light->spot_direction; +void light_data::set_position(const vec3& value) { + *(vec3*)&position = value; } -inline void light_set_spot_direction(light_data* light, const vec3* value) { - light->spot_direction = *value; +void light_data::set_position(const vec3&& value) { + *(vec3*)&position = value; } -inline float_t light_get_spot_exponent(light_data* light) { - return light->spot_exponent; +void light_data::get_position(vec4& value) { + value = position; } -inline void light_set_spot_exponent(light_data* light, float_t value) { - light->spot_exponent = value; +void light_data::set_position(const vec4& value) { + position = value; } -inline float_t light_get_spot_cutoff(light_data* light) { - return light->spot_cutoff; +void light_data::set_position(const vec4&& value) { + position = value; } -inline void light_set_spot_cutoff(light_data* light, float_t value) { - light->spot_cutoff = value; +void light_data::get_spot_direction(vec3& value) { + value = spot_direction; } -inline float_t light_get_constant(light_data* light) { - return light->constant; +void light_data::set_spot_direction(const vec3& value) { + spot_direction = value; } -inline void light_set_constant(light_data* light, float_t value) { - light->constant = value; +void light_data::set_spot_direction(const vec3&& value) { + spot_direction = value; } -inline float_t light_get_linear(light_data* light) { - return light->linear; +float_t light_data::get_spot_exponent() { + return spot_exponent; } -inline void light_set_linear(light_data* light, float_t value) { - light->linear = value; +void light_data::set_spot_exponent(float_t value) { + spot_exponent = value; } -inline float_t light_get_quadratic(light_data* light) { - return light->quadratic; +float_t light_data::get_spot_cutoff() { + return spot_cutoff; } -inline void light_set_quadratic(light_data* light, float_t value) { - light->quadratic = value; +void light_data::set_spot_cutoff(float_t value) { + spot_cutoff = value; } -inline void light_get_attenuation(light_data* light, vec3* value) { - value->x = light->constant; - value->y = light->linear; - value->z = light->quadratic; +float_t light_data::get_constant() { + return constant; } -inline void light_set_attenuation(light_data* light, const vec3* value) { - light->constant = value->x; - light->linear = value->y; - light->quadratic = value->z; +void light_data::set_constant(float_t value) { + constant = value; } -inline void light_get_ibl_specular(light_data* light, vec4* value) { - *value = light->ibl_specular; +float_t light_data::get_linear() { + return linear; } -inline void light_set_ibl_specular(light_data* light, const vec4* value) { - light->ibl_specular = *value; +void light_data::set_linear(float_t value) { + linear = value; } -inline void light_get_ibl_back(light_data* light, vec4* value) { - *value = light->ibl_back; +float_t light_data::get_quadratic() { + return quadratic; } -inline void light_set_ibl_back(light_data* light, const vec4* value) { - light->ibl_back = *value; +void light_data::set_quadratic(float_t value) { + quadratic = value; } -inline void light_get_ibl_direction(light_data* light, vec4* value) { - *value = light->ibl_direction; +void light_data::get_attenuation(vec3& value) { + value.x = constant; + value.y = linear; + value.z = quadratic; } -inline void light_set_ibl_direction(light_data* light, const vec4* value) { - light->ibl_direction = *value; +void light_data::set_attenuation(const vec3& value) { + constant = value.x; + linear = value.y; + quadratic = value.z; } -inline void light_get_tone_curve(light_data* light, vec3* value) { - *value = light->tone_curve; +void light_data::set_attenuation(const vec3&& value) { + constant = value.x; + linear = value.y; + quadratic = value.z; } -inline void light_set_tone_curve(light_data* light, const vec3* value) { - light->tone_curve = *value; +void light_data::get_ibl_specular(vec4& value) { + value = ibl_specular; } -inline void light_get_clip_plane(light_data* light, bool value[4]) { - value[0] = light->clip_plane[0]; - value[1] = light->clip_plane[1]; - value[2] = light->clip_plane[2]; - value[3] = light->clip_plane[3]; +void light_data::set_ibl_specular(const vec4& value) { + ibl_specular = value; } -inline void light_set_clip_plane(light_data* light, const bool value[4]) { - light->clip_plane[0] = value[0]; - light->clip_plane[1] = value[1]; - light->clip_plane[2] = value[2]; - light->clip_plane[3] = value[3]; +void light_data::set_ibl_specular(const vec4&& value) { + ibl_specular = value; } -inline void light_set_get_ambient_intensity(light_set* set, vec4* value) { - *value = set->ambient_intensity; +void light_data::get_ibl_back(vec4& value) { + value = ibl_back; } -inline void light_set_set_ambient_intensity(light_set* set, const vec4* value) { - set->ambient_intensity = *value; +void light_data::set_ibl_back(const vec4& value) { + ibl_back = value; } -inline void light_set_get_irradiance(light_set* set, mat4* r, mat4* g, mat4* b) { - *r = set->irradiance_r; - *g = set->irradiance_g; - *b = set->irradiance_b; +void light_data::set_ibl_back(const vec4&& value) { + ibl_back = value; } -inline void light_set_set_irradiance(light_set* set, const mat4* r, const mat4* g, const mat4* b) { - set->irradiance_r = *r; - set->irradiance_g = *g; - set->irradiance_b = *b; +void light_data::get_ibl_direction(vec4& value) { + value = ibl_direction; } -void light_set_data_set(light_set* set, face* face, light_set_id id) { +void light_data::set_ibl_direction(const vec4& value) { + ibl_direction = value; +} + +void light_data::set_ibl_direction(const vec4&& value) { + ibl_direction = value; +} + +void light_data::get_tone_curve(vec3& value) { + value = tone_curve; +} + +void light_data::set_tone_curve(const vec3& value) { + tone_curve = value; +} + +void light_data::set_tone_curve(const vec3&& value) { + tone_curve = value; +} + +void light_data::get_clip_plane(bool value[4]) { + value[0] = clip_plane[0]; + value[1] = clip_plane[1]; + value[2] = clip_plane[2]; + value[3] = clip_plane[3]; +} + +void light_data::set_clip_plane(const bool value[4]) { + clip_plane[0] = value[0]; + clip_plane[1] = value[1]; + clip_plane[2] = value[2]; + clip_plane[3] = value[3]; +} + +void light_set::get_ambient_intensity(vec4& value) { + value = ambient_intensity; +} + +void light_set::set_ambient_intensity(const vec4& value) { + ambient_intensity = value; +} + +void light_set::set_ambient_intensity(const vec4&& value) { + ambient_intensity = value; +} + +void light_set::get_irradiance(mat4& r, mat4& g, mat4& b) { + r = irradiance_r; + g = irradiance_g; + b = irradiance_b; +} + +void light_set::set_irradiance(const mat4& r, const mat4& g, const mat4& b) { + irradiance_r = r; + irradiance_g = g; + irradiance_b = b; +} + +void light_set::set_irradiance(const mat4&& r, const mat4&& g, const mat4&& b) { + irradiance_r = r; + irradiance_g = g; + irradiance_b = b; +} + +void light_set::data_set(face& face, light_set_id id) { vec4 ambient_intensity; - light_set_get_ambient_intensity(set, &ambient_intensity); + get_ambient_intensity(ambient_intensity); shaders_ft.state_lightmodel_set_ambient(false, ambient_intensity); for (int32_t i = LIGHT_CHARA; i <= LIGHT_PROJECTION; i++) { - light_data* light = &set->lights[i]; + light_data* light = &lights[i]; if (light_chara_ambient || i != LIGHT_CHARA) { vec4 ambient = light->ambient; shaders_ft.state_light_set_ambient(i, ambient); @@ -276,12 +317,12 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { vec4 ibl_back; vec4 ibl_direction; vec4 temp; - light_get_position_vec4(&set->lights[LIGHT_CHARA], &position); - light_get_direction_from_position(&position, &set->lights[LIGHT_CHARA], false); - light_get_ibl_specular(&set->lights[LIGHT_CHARA], &ibl_specular); - light_get_ibl_back(&set->lights[LIGHT_CHARA], &ibl_back); - light_get_diffuse(&set->lights[LIGHT_CHARA], &diffuse); - light_get_specular(&set->lights[LIGHT_CHARA], &specular); + lights[LIGHT_CHARA].get_position(position); + light_get_direction_from_position(&position, &lights[LIGHT_CHARA], false); + lights[LIGHT_CHARA].get_ibl_specular(ibl_specular); + lights[LIGHT_CHARA].get_ibl_back(ibl_back); + lights[LIGHT_CHARA].get_diffuse(diffuse); + lights[LIGHT_CHARA].get_specular(specular); shaders_ft.env_vert_set(5, position); shaders_ft.env_frag_set(5, position); @@ -304,11 +345,11 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { shaders_ft.env_vert_set(9, temp); shaders_ft.env_frag_set(9, temp); - light_get_position_vec4(&set->lights[LIGHT_STAGE], &position); - light_get_direction_from_position(&position, &set->lights[LIGHT_STAGE], false); - light_get_ibl_specular(&set->lights[LIGHT_STAGE], &ibl_specular); - light_get_diffuse(&set->lights[LIGHT_STAGE], &diffuse); - light_get_specular(&set->lights[LIGHT_STAGE], &specular); + lights[LIGHT_STAGE].get_position(position); + light_get_direction_from_position(&position, &lights[LIGHT_STAGE], false); + lights[LIGHT_STAGE].get_ibl_specular(ibl_specular); + lights[LIGHT_STAGE].get_diffuse(diffuse); + lights[LIGHT_STAGE].get_specular(specular); shaders_ft.env_vert_set(10, position); shaders_ft.env_frag_set(14, position); @@ -325,20 +366,20 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { mat4 irradiance_r; mat4 irradiance_g; mat4 irradiance_b; - light_set_get_irradiance(set, &irradiance_r, &irradiance_g, &irradiance_b); + get_irradiance(irradiance_r, irradiance_g, irradiance_b); shaders_ft.state_matrix_set_program(0, irradiance_r); shaders_ft.state_matrix_set_program(1, irradiance_g); shaders_ft.state_matrix_set_program(2, irradiance_b); - float_t offset = face_get_offset(face); + float_t offset = face.get_offset(); float_t v28 = (float_t)(1.0 - exp(offset * -0.44999999)) * 2.0f; offset = max(offset, 0.0f); shaders_ft.env_vert_set(0x11, v28 * 0.1f, offset * 0.06f, 1.0, 1.0); - if (light_get_type(&set->lights[LIGHT_CHARA_COLOR]) == LIGHT_PARALLEL) { - light_get_ambient(&set->lights[LIGHT_CHARA_COLOR], &ambient); - light_get_diffuse(&set->lights[LIGHT_CHARA_COLOR], &diffuse); - light_get_specular(&set->lights[LIGHT_CHARA_COLOR], &specular); + if (lights[LIGHT_CHARA_COLOR].get_type() == LIGHT_PARALLEL) { + lights[LIGHT_CHARA_COLOR].get_ambient(ambient); + lights[LIGHT_CHARA_COLOR].get_diffuse(diffuse); + lights[LIGHT_CHARA_COLOR].get_specular(specular); if (specular.w > 1.0) specular.w = 1.0; shaders_ft.env_frag_set(33, ambient); @@ -351,15 +392,16 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { shaders_ft.env_frag_set(35, vec4_null); } - if (light_get_type(&set->lights[LIGHT_TONE_CURVE]) == LIGHT_PARALLEL) { + if (lights[LIGHT_TONE_CURVE].get_type() == LIGHT_PARALLEL) { uniform_value[U_TONE_CURVE] = 1; - light_get_position_vec4(&set->lights[LIGHT_TONE_CURVE], &position); - light_get_direction_from_position(&position, &set->lights[LIGHT_TONE_CURVE], false); - light_get_ambient(&set->lights[LIGHT_TONE_CURVE], &ambient); - light_get_diffuse(&set->lights[LIGHT_TONE_CURVE], &diffuse); - light_get_specular(&set->lights[LIGHT_TONE_CURVE], &specular); + lights[LIGHT_TONE_CURVE].get_position(position); + light_get_direction_from_position(&position, &lights[LIGHT_TONE_CURVE], false); + lights[LIGHT_TONE_CURVE].get_ambient(ambient); + lights[LIGHT_TONE_CURVE].get_diffuse(diffuse); + lights[LIGHT_TONE_CURVE].get_specular(specular); + vec3 tone_curve; - light_get_tone_curve(&set->lights[LIGHT_TONE_CURVE], &tone_curve); + lights[LIGHT_TONE_CURVE].get_tone_curve(tone_curve); tone_curve.y = min(tone_curve.y, 1.0f) - tone_curve.x; if (tone_curve.y > 0.0f) tone_curve.y = 1.0f / tone_curve.y; @@ -381,7 +423,7 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { shaders_ft.env_frag_set(40, 0.0f, 0.0f, 0.0f, 0.0f); } - light_get_position_vec4(&set->lights[LIGHT_CHARA], &position); + lights[LIGHT_CHARA].get_position(position); if (fabs(position.x) <= 0.000001f && fabs(position.z) <= 0.000001f && fabs(position.z) <= 0.000001f) position = { 0.0f, 1.0f, 0.0f, 1.0f }; else { @@ -394,19 +436,19 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { shaders_ft.env_vert_set(15, position.x, position.y, position.z, 1.0f); shaders_ft.env_vert_set(16, -position.x, -position.y, -position.z, 1.0f); - if (light_get_type(&set->lights[LIGHT_REFLECT]) == LIGHT_SPOT) { + if (lights[LIGHT_REFLECT].get_type() == LIGHT_SPOT) { vec4 spot_direction; - light_get_spot_direction(&set->lights[LIGHT_REFLECT], (vec3*)&spot_direction); + lights[LIGHT_REFLECT].get_spot_direction(*(vec3*)&spot_direction); vec3_negate(*(vec3*)&spot_direction, *(vec3*)&spot_direction); - light_get_direction_from_position(&spot_direction, &set->lights[LIGHT_REFLECT], true); - light_get_position_vec4(&set->lights[LIGHT_REFLECT], &position); + light_get_direction_from_position(&spot_direction, &lights[LIGHT_REFLECT], true); + lights[LIGHT_REFLECT].get_position(position); vec3_dot(*(vec3*)&position, *(vec3*)&spot_direction, spot_direction.w); spot_direction.w = -spot_direction.w; shaders_ft.env_vert_set(28, spot_direction); shaders_ft.env_frag_set(22, spot_direction); } - else if (light_get_type(&set->lights[LIGHT_REFLECT]) == LIGHT_POINT) { + else if (lights[LIGHT_REFLECT].get_type() == LIGHT_POINT) { shaders_ft.env_vert_set(28, 0.0f, -1.0f, 0.0f, 9999.0f); shaders_ft.env_frag_set(22, 0.0f, -1.0f, 0.0f, 9999.0f); } @@ -418,8 +460,8 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { mat4 v63 = mat4_identity; mat4 v64 = mat4_identity; - light_get_ibl_direction(&set->lights[LIGHT_CHARA], &ibl_direction); - light_get_position_vec4(&set->lights[LIGHT_CHARA], &position); + lights[LIGHT_CHARA].get_ibl_direction(ibl_direction); + lights[LIGHT_CHARA].get_position(position); float_t length; vec3_length(*(vec3*)&ibl_direction, length); @@ -457,7 +499,7 @@ void light_set_data_set(light_set* set, face* face, light_set_id id) { } static void light_get_direction_from_position(vec4* pos_dir, light_data* light, bool force) { - if (force || light_get_type(light) == LIGHT_PARALLEL) { + if (force || light->get_type() == LIGHT_PARALLEL) { float_t length; vec3_length(*(vec3*)pos_dir, length); if (length <= 0.000001) diff --git a/src/CRE/light_param/light.hpp b/src/CRE/light_param/light.hpp index d6bd3064..5c74cf20 100644 --- a/src/CRE/light_param/light.hpp +++ b/src/CRE/light_param/light.hpp @@ -8,7 +8,7 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/light_param/light.hpp" #include "../../KKdLib/vec.hpp" -#include "../static_var.h" +#include "../static_var.hpp" #include "face.hpp" struct light_data { @@ -30,6 +30,54 @@ struct light_data { bool clip_plane[4]; light_data(); + + light_type get_type(); + void set_type(light_type value); + void get_ambient(vec4& value); + void set_ambient(const vec4& value); + void set_ambient(const vec4&& value); + void get_diffuse(vec4& value); + void set_diffuse(const vec4& value); + void set_diffuse(const vec4&& value); + void get_specular(vec4& value); + void set_specular(const vec4& value); + void set_specular(const vec4&& value); + void get_position(vec3& value); + void set_position(const vec3& value); + void set_position(const vec3&& value); + void get_position(vec4& value); + void set_position(const vec4& value); + void set_position(const vec4&& value); + void get_spot_direction(vec3& value); + void set_spot_direction(const vec3& value); + void set_spot_direction(const vec3&& value); + float_t get_spot_exponent(); + void set_spot_exponent(float_t value); + float_t get_spot_cutoff(); + void set_spot_cutoff(float_t value); + float_t get_constant(); + void set_constant(float_t value); + float_t get_linear(); + void set_linear(float_t value); + float_t get_quadratic(); + void set_quadratic(float_t value); + void get_attenuation(vec3& value); + void set_attenuation(const vec3& value); + void set_attenuation(const vec3&& value); + void get_ibl_specular(vec4& value); + void set_ibl_specular(const vec4& value); + void set_ibl_specular(const vec4&& value); + void get_ibl_back(vec4& value); + void set_ibl_back(const vec4& value); + void set_ibl_back(const vec4&& value); + void get_ibl_direction(vec4& value); + void set_ibl_direction(const vec4& value); + void set_ibl_direction(const vec4&& value); + void get_tone_curve(vec3& value); + void set_tone_curve(const vec3& value); + void set_tone_curve(const vec3&& value); + void get_clip_plane(bool value[4]); + void set_clip_plane(const bool value[4]); }; struct light_set { @@ -40,45 +88,12 @@ struct light_set { mat4u irradiance_b; light_set(); + + void get_ambient_intensity(vec4& value); + void set_ambient_intensity(const vec4& value); + void set_ambient_intensity(const vec4&& value); + void get_irradiance(mat4& r, mat4& g, mat4& b); + void set_irradiance(const mat4& r, const mat4& g, const mat4& b); + void set_irradiance(const mat4&& r, const mat4&& g, const mat4&& b); + void data_set(face& face, light_set_id id); }; -extern light_type light_get_type(light_data* light); -extern void light_set_type(light_data* light, light_type value); -extern void light_get_ambient(light_data* light, vec4* value); -extern void light_set_ambient(light_data* light, const vec4* value); -extern void light_get_diffuse(light_data* light, vec4* value); -extern void light_set_diffuse(light_data* light, const vec4* value); -extern void light_get_specular(light_data* light, vec4* value); -extern void light_set_specular(light_data* light, const vec4* value); -extern void light_get_position(light_data* light, vec3* value); -extern void light_set_position(light_data* light, const vec3* value); -extern void light_get_position_vec4(light_data* light, vec4* value); -extern void light_set_position_vec4(light_data* light, const vec4* value); -extern void light_get_spot_direction(light_data* light, vec3* value); -extern void light_set_spot_direction(light_data* light, const vec3* value); -extern float_t light_get_spot_exponent(light_data* light); -extern void light_set_spot_exponent(light_data* light, float_t value); -extern float_t light_get_spot_cutoff(light_data* light); -extern void light_set_spot_cutoff(light_data* light, float_t value); -extern float_t light_get_constant(light_data* light); -extern void light_set_constant(light_data* light, float_t value); -extern float_t light_get_linear(light_data* light); -extern void light_set_linear(light_data* light, float_t value); -extern float_t light_get_quadratic(light_data* light); -extern void light_set_quadratic(light_data* light, float_t value); -extern void light_get_attenuation(light_data* light, vec3* value); -extern void light_set_attenuation(light_data* light, const vec3* value); -extern void light_get_ibl_specular(light_data* light, vec4* value); -extern void light_set_ibl_specular(light_data* light, const vec4* value); -extern void light_get_ibl_back(light_data* light, vec4* value); -extern void light_set_ibl_back(light_data* light, const vec4* value); -extern void light_get_ibl_direction(light_data* light, vec4* value); -extern void light_set_ibl_direction(light_data* light, const vec4* value); -extern void light_get_tone_curve(light_data* light, vec3* value); -extern void light_set_tone_curve(light_data* light, const vec3* value); -extern void light_get_clip_plane(light_data* light, bool value[4]); -extern void light_set_clip_plane(light_data* light, const bool value[4]); -extern void light_set_get_ambient_intensity(light_set* set, vec4* value); -extern void light_set_set_ambient_intensity(light_set* set, const vec4* value); -extern void light_set_get_irradiance(light_set* set, mat4* r, mat4* g, mat4* b); -extern void light_set_set_irradiance(light_set* set, const mat4* r, const mat4* g, const mat4* b); -extern void light_set_data_set(light_set* set, face* face, light_set_id id); diff --git a/src/CRE/light_param/wind.hpp b/src/CRE/light_param/wind.hpp index 63675a17..1480582c 100644 --- a/src/CRE/light_param/wind.hpp +++ b/src/CRE/light_param/wind.hpp @@ -8,7 +8,7 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/light_param/wind.hpp" #include "../../KKdLib/vec.hpp" -#include "../static_var.h" +#include "../static_var.hpp" #include "../task.hpp" struct wind_spc { diff --git a/src/CRE/lock.c b/src/CRE/lock.cpp similarity index 94% rename from src/CRE/lock.c rename to src/CRE/lock.cpp index deec2d44..f1f5397d 100644 --- a/src/CRE/lock.c +++ b/src/CRE/lock.cpp @@ -3,7 +3,7 @@ GitHub/GitLab: korenkonder */ -#include "lock.h" +#include "lock.hpp" inline void lock_init(lock* l) { l->init = InitializeCriticalSectionAndSpinCount(&l->cs, 0); diff --git a/src/CRE/lock.h b/src/CRE/lock.hpp similarity index 100% rename from src/CRE/lock.h rename to src/CRE/lock.hpp diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 28df8f19..ccd77392 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -8,23 +8,11 @@ #include #include "object.hpp" #include "data.hpp" -#include "gl_state.h" -#include "shader_ft.h" +#include "gl_state.hpp" +#include "shader_ft.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" -struct material_change_handler { - int32_t load_count; - material_change data; -}; - -static bool obj_mesh_index_buffer_load(obj_mesh_index_buffer* buffer, obj_mesh* mesh); -static GLuint obj_mesh_index_buffer_load_data(size_t size, void* data); -static void obj_mesh_index_buffer_free(obj_mesh_index_buffer* buffer); -static bool obj_mesh_vertex_buffer_load(obj_mesh_vertex_buffer* buffer, obj_mesh* mesh); -static bool obj_mesh_vertex_buffer_load_data(obj_mesh_vertex_buffer* buffer, - size_t size, void* data, int32_t count); -static void obj_mesh_vertex_buffer_free(obj_mesh_vertex_buffer* buffer); static void obj_set_handler_calc_axis_aligned_bounding_box(obj_set_handler* handler); static void obj_set_handler_get_shader_index_texture_index(obj_set_handler* handler); static bool obj_set_handler_index_buffer_load(obj_set_handler* handler); @@ -48,6 +36,404 @@ static size_t obj_vertex_format_get_vertex_size_comp(obj_vertex_format format); std::vector object_storage_data; std::list object_storage_data_modern; +obj_mesh_index_buffer::obj_mesh_index_buffer() : buffer(), size() { + +} + +bool obj_mesh_index_buffer::load(obj_mesh& mesh) { + int32_t indices_count = 0; + for (uint32_t i = 0; i < mesh.num_submesh; i++) + indices_count += mesh.submesh_array[i].indices_count; + + if (!indices_count) { + buffer = 0; + return true; + } + + uint16_t* indices = force_malloc_s(uint16_t, indices_count); + uint16_t* _indices = indices; + for (uint32_t k = 0; k < mesh.num_submesh; k++) { + obj_sub_mesh& sub_mesh = mesh.submesh_array[k]; + int32_t indices_count = sub_mesh.indices_count; + uint32_t* sub_mesh_indices = sub_mesh.indices; + for (int32_t l = 0; l < indices_count; l++) + *_indices++ = (uint16_t)sub_mesh_indices[l]; + } + + _indices = indices; + for (uint32_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.indices_offset = 0; + if (sub_mesh.index_format != OBJ_INDEX_U16) + continue; + + uint16_t first_index = 0xFFFF; + uint16_t last_index = 0; + int32_t indices_count = sub_mesh.indices_count; + uint32_t* sub_mesh_indices = sub_mesh.indices; + for (int32_t j = 0; j < indices_count; j++) { + uint16_t index = *_indices++; + if (index == 0xFFFF) + continue; + + if (index < first_index) + first_index = index; + if (index > last_index) + last_index = index; + } + + sub_mesh.first_index = first_index; + sub_mesh.last_index = last_index; + sub_mesh.indices_offset = (int32_t)(sizeof(uint16_t) * offset); + offset += sub_mesh.indices_count; + } + + bool ret = load_data((size_t)indices_count * sizeof(uint16_t), indices); + free(indices); + return ret; +} + +bool obj_mesh_index_buffer::load_data(size_t size, const void* data) { + if (!size) + return false; + + this->size = (GLsizeiptr)size; + glGenBuffers(1, &buffer); + gl_state_bind_element_array_buffer(buffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); + gl_state_bind_element_array_buffer(0); + return true; +} + +void obj_mesh_index_buffer::unload() { + if (buffer) + glDeleteBuffers(1, &buffer); + + buffer = 0; + size = 0; +} + +obj_mesh_vertex_buffer::obj_mesh_vertex_buffer() : count(), buffers(), size(), index() { + +} + +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; +} + +GLsizeiptr obj_mesh_vertex_buffer::get_size() { + if (buffers[0]) + return size; + return 0; +} + +bool obj_mesh_vertex_buffer::load(obj_mesh& mesh) { + if (!mesh.num_vertex || !mesh.vertex) + return false; + + { + const vec4u attib_default = { 0.0f, 0.0f, 0.0f, 1.0f }; + + obj_vertex_format vertex_format = mesh.vertex_format; + obj_vertex_data* vertex_file = mesh.vertex; + int32_t num_vertex = mesh.num_vertex; + obj_vertex_format _vertex_format = vertex_format; + enum_and(_vertex_format, ~(OBJ_VERTEX_TEXCOORD0 | OBJ_VERTEX_TEXCOORD1 | OBJ_VERTEX_TEXCOORD2 + | OBJ_VERTEX_TEXCOORD3 | OBJ_VERTEX_COLOR0 | OBJ_VERTEX_COLOR1 | OBJ_VERTEX_BONE_DATA | OBJ_VERTEX_UNKNOWN)); + for (int32_t i = 0; i < num_vertex && _vertex_format != vertex_format; i++) { + if (~_vertex_format & OBJ_VERTEX_TEXCOORD0 && vertex_format & OBJ_VERTEX_TEXCOORD0 + && memcmp(&vertex_file[i].texcoord0, &vec2_null, sizeof(vec2))) + enum_or(_vertex_format, OBJ_VERTEX_TEXCOORD0); + + if (~_vertex_format & OBJ_VERTEX_TEXCOORD1 && vertex_format & OBJ_VERTEX_TEXCOORD1 + && memcmp(&vertex_file[i].texcoord1, &vec2_null, sizeof(vec2))) + enum_or(_vertex_format, OBJ_VERTEX_TEXCOORD1); + + if (~_vertex_format & OBJ_VERTEX_TEXCOORD2 && vertex_format & OBJ_VERTEX_TEXCOORD2 + && memcmp(&vertex_file[i].texcoord2, &vec2_null, sizeof(vec2))) + enum_or(_vertex_format, OBJ_VERTEX_TEXCOORD2); + + if (~_vertex_format & OBJ_VERTEX_TEXCOORD3 && vertex_format & OBJ_VERTEX_TEXCOORD3 + && memcmp(&vertex_file[i].texcoord3, &vec2_null, sizeof(vec2))) + enum_or(_vertex_format, OBJ_VERTEX_TEXCOORD3); + + if (~_vertex_format & OBJ_VERTEX_COLOR0 && vertex_format & OBJ_VERTEX_COLOR0 + && memcmp(&vertex_file[i].normal, &vec4u_identity, sizeof(vec4u))) + enum_or(_vertex_format, OBJ_VERTEX_COLOR0); + + if (~_vertex_format & OBJ_VERTEX_COLOR1 && vertex_format & OBJ_VERTEX_COLOR1 + && memcmp(&vertex_file[i].normal, &vec4u_identity, sizeof(vec4u))) + enum_or(_vertex_format, OBJ_VERTEX_COLOR1); + + if (~_vertex_format & OBJ_VERTEX_BONE_DATA && vertex_format & OBJ_VERTEX_BONE_DATA + && memcmp(&vertex_file[i].bone_index, &vec4iu_null, sizeof(vec4iu)) + && memcmp(&vertex_file[i].bone_weight, &vec4u_null, sizeof(vec4u))) + enum_or(_vertex_format, OBJ_VERTEX_BONE_DATA); + + if (~_vertex_format & OBJ_VERTEX_UNKNOWN && vertex_format & OBJ_VERTEX_UNKNOWN + && memcmp(&vertex_file[i].unknown, &attib_default, sizeof(vec4u))) + enum_or(_vertex_format, OBJ_VERTEX_UNKNOWN); + } + + if (mesh.vertex_format != _vertex_format) + mesh.vertex_format = _vertex_format; + } + + size_t size_vertex; + if (~mesh.attrib.m.compressed) + size_vertex = obj_vertex_format_get_vertex_size(mesh.vertex_format); + else + size_vertex = obj_vertex_format_get_vertex_size_comp(mesh.vertex_format); + + void* vertex = force_malloc(size_vertex * mesh.num_vertex); + if (vertex) { + obj_vertex_format vertex_format = mesh.vertex_format; + obj_vertex_data* vertex_file = mesh.vertex; + int32_t num_vertex = mesh.num_vertex; + size_t d = (size_t)vertex; + if (~mesh.attrib.m.compressed) { + for (int32_t i = 0; i < num_vertex; i++) { + if (vertex_format & OBJ_VERTEX_POSITION) { + *(vec3*)d = vertex_file[i].position; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_NORMAL) { + *(vec3*)d = vertex_file[i].normal; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_TANGENT) { + *(vec4u*)d = vertex_file[i].tangent; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_BINORMAL) { + *(vec3*)d = vertex_file[i].binormal; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + *(vec2*)d = vertex_file[i].texcoord0; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + *(vec2*)d = vertex_file[i].texcoord1; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + *(vec2*)d = vertex_file[i].texcoord2; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + *(vec2*)d = vertex_file[i].texcoord3; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_COLOR0) { + *(vec4u*)d = vertex_file[i].color0; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_COLOR1) { + *(vec4u*)d = vertex_file[i].color1; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + *(vec4u*)d = vertex_file[i].bone_weight; + d += 16; + *(vec4iu*)d = vertex_file[i].bone_index; + d += 16; + } + + if (vertex_format & OBJ_VERTEX_UNKNOWN) { + *(vec4u*)d = vertex_file[i].unknown; + d += 16; + } + } + } + else { + for (int32_t i = 0; i < num_vertex; i++) { + if (vertex_format & OBJ_VERTEX_POSITION) { + *(vec3*)d = vertex_file[i].position; + d += 12; + } + + if (vertex_format & OBJ_VERTEX_NORMAL) { + vec3 normal; + vec3_mult_scalar(vertex_file[i].normal, 32727.0f, normal); + vec3_to_vec3i16(normal, *(vec3i16*)d); + *(int16_t*)(d + 6) = 0; + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TANGENT) { + vec4 tangent = vertex_file[i].tangent; + vec4_mult_scalar(tangent, 32727.0f, tangent); + vec4_to_vec4i16(tangent, *(vec4i16*)d); + d += 8; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + vec2_to_vec2h(vertex_file[i].texcoord0, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + vec2_to_vec2h(vertex_file[i].texcoord1, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + vec2_to_vec2h(vertex_file[i].texcoord2, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + vec2_to_vec2h(vertex_file[i].texcoord3, *(vec2h*)d); + d += 4; + } + + if (vertex_format & OBJ_VERTEX_COLOR0) { + vec4 color0 = vertex_file[i].color0; + vec4_to_vec4h(color0, *(vec4h*)d); + d += 8; + } + + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + vec4 bone_weight = vertex_file[i].bone_weight; + vec4_mult_scalar(bone_weight, 65535.0f, bone_weight); + vec4_to_vec4u16(bone_weight, *(vec4u16*)d); + d += 8; + + vec4i bone_index = vertex_file[i].bone_index; + vec4i_to_vec4u16(bone_index, *(vec4u16*)d); + d += 8; + } + } + } + } + mesh.size_vertex = (int32_t)size_vertex; + + bool ret = load_data(size_vertex * mesh.num_vertex, vertex, mesh.attrib.m.double_buffer ? 2 : 1); + free(vertex); + return ret; +} + +bool obj_mesh_vertex_buffer::load_data(size_t size, const void* data, int32_t count) { + if (!size || count > 3) + return false; + + this->count = count; + this->size = (GLsizeiptr)size; + + glGenBuffers(count, buffers); + for (int32_t i = 0; i < count; i++) { + gl_state_bind_array_buffer(buffers[i]); + glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); + } + gl_state_bind_array_buffer(0); + return true; +} + +void obj_mesh_vertex_buffer::unload() { + if (buffers[0]) + glDeleteBuffers(count, buffers); + + count = 0; + buffers[0] = 0; + size = 0; + index = 0; +} + +obj_index_buffer::obj_index_buffer() : mesh_num(), mesh_data() { + +} + +bool obj_index_buffer::load(obj& obj) { + mesh_num = obj.num_mesh; + mesh_data = new obj_mesh_index_buffer[obj.num_mesh]; + if (!mesh_data) + return false; + + for (uint32_t i = 0; i < mesh_num; i++) + if (!mesh_data[i].load(obj.mesh_array[i])) + return false; + return true; +} + +void obj_index_buffer::unload() { + if (mesh_data) { + for (uint32_t i = 0; i < mesh_num; i++) + mesh_data[i].unload(); + delete[] mesh_data; + } + mesh_data = 0; + mesh_num = 0; +} + +obj_vertex_buffer::obj_vertex_buffer() : mesh_num(), mesh_data() { + +} + +bool obj_vertex_buffer::load(obj& obj) { + mesh_num = obj.num_mesh; + mesh_data = new obj_mesh_vertex_buffer[obj.num_mesh]; + if (!mesh_data) + return false; + + for (uint32_t i = 0; i < mesh_num; i++) + if (!mesh_data[i].load(obj.mesh_array[i])) + return false; + return true; +} + +void obj_vertex_buffer::unload() { + if (mesh_data) { + for (uint32_t i = 0; i < mesh_num; i++) + mesh_data[i].unload(); + delete[] mesh_data; + } + mesh_data = 0; + mesh_num = 0; +} + +obj_set_handler::obj_set_handler() : obj_loaded(), tex_loaded(), obj_set(), +tex_num(), tex_data(), set_id(), vertex_buffer_num(), vertex_buffer_data(), +index_buffer_num(), index_buffer_data(), load_count(), modern() { + +} + +obj_set_handler::~obj_set_handler() { + for (uint32_t i = 0; i < tex_num; i++) + texture_free(tex_data[i]); + free(tex_data); + + obj_set_handler_index_buffer_free(this); + obj_set_handler_vertex_buffer_free(this); + delete obj_set; + while (tex_file_handler.ptr && tex_file_handler.ptr->count) + tex_file_handler.free_data(); + while (obj_file_handler.ptr && obj_file_handler.ptr->count) + obj_file_handler.free_data(); + while (farc_file_handler.ptr && farc_file_handler.ptr->count) + farc_file_handler.free_data(); +} + inline int32_t obj_material_texture_type_get_texcoord_index( obj_material_texture_type type, int32_t index) { switch (type) { @@ -87,24 +473,6 @@ inline int32_t obj_material_texture_type_get_texture_index( return -1; } -inline GLuint obj_mesh_vertex_buffer_get_buffer(obj_mesh_vertex_buffer* buffer) { - if (buffer->index < buffer->count) - return buffer->buffers[buffer->index]; - else - return 0; -} - -inline int32_t obj_mesh_vertex_buffer_get_size(obj_mesh_vertex_buffer* buffer) { - if (!buffer->buffers[0]) - return 0; - - int32_t size = 0; - gl_state_bind_array_buffer(buffer->buffers[0]); - glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &size); - gl_state_bind_array_buffer(buffer->buffers[0]); - return size; -} - void obj_skin_set_matrix_buffer(obj_skin* s, mat4* matrices, mat4* ex_data_matrices, mat4* matrix_buffer, mat4* mat, mat4* global_mat) { if (!s->bones_count) @@ -217,17 +585,9 @@ inline obj_mesh* object_storage_get_obj_mesh(object_info obj_info, const char* m if (!set) return 0; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].id != obj_info.id) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return &obj->mesh_array[k]; - return 0; - } + for (uint32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j].id == obj_info.id) + return set->obj_data[j].get_obj_mesh(mesh_name); return 0; } @@ -239,17 +599,9 @@ inline obj_mesh* object_storage_get_obj_mesh(object_info obj_info, const char* m if (!set) return 0; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].id != obj_info.id) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return &obj->mesh_array[k]; - return 0; - } + for (uint32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j].id == obj_info.id) + return set->obj_data[j].get_obj_mesh(mesh_name); return 0; } return 0; @@ -268,9 +620,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_index(object_info obj_info, uint if (set->obj_data[j].id != obj_info.id) continue; - obj* obj = &set->obj_data[j]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; + obj& obj = set->obj_data[j]; + if (index >= 0 && index < obj.num_mesh) + return &obj.mesh_array[index]; return 0; } return 0; @@ -288,9 +640,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_index(object_info obj_info, uint if (set->obj_data[j].id != obj_info.id) continue; - obj* obj = &set->obj_data[j]; - if (index >= 0 && index < obj->num_mesh) - return &obj->mesh_array[index]; + obj& obj = set->obj_data[j]; + if (index >= 0 && index < obj.num_mesh) + return &obj.mesh_array[index]; return 0; } return 0; @@ -304,17 +656,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_object_hash(uint32_t hash, const if (!set) continue; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].hash != hash) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return &obj->mesh_array[k]; - return 0; - } + for (uint32_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 (obj_set_handler& i : object_storage_data_modern) { @@ -322,17 +666,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_object_hash(uint32_t hash, const if (!set) continue; - for (uint32_t j = 0; j < set->obj_num; j++) { + for (uint32_t j = 0; j < set->obj_num; j++) if (set->obj_data[j].hash == hash) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return &obj->mesh_array[k]; - return 0; - } + return set->obj_data[j].get_obj_mesh(mesh_name); } return 0; } @@ -347,9 +683,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_object_hash_index(uint32_t hash, 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]; + obj& obj = set->obj_data[j]; + if (index >= 0 && index < obj.num_mesh) + return &obj.mesh_array[index]; return 0; } } @@ -363,9 +699,9 @@ inline obj_mesh* object_storage_get_obj_mesh_by_object_hash_index(uint32_t hash, 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]; + obj& obj = set->obj_data[j]; + if (index >= 0 && index < obj.num_mesh) + return &obj.mesh_array[index]; return 0; } } @@ -381,17 +717,9 @@ inline uint32_t object_storage_get_obj_mesh_index(object_info obj_info, const ch if (!set) return -1; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].id != obj_info.id) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return k; - return -1; - } + for (uint32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j].id == obj_info.id) + return set->obj_data[j].get_obj_mesh_index(mesh_name); } for (obj_set_handler& i : object_storage_data_modern) { @@ -402,17 +730,9 @@ inline uint32_t object_storage_get_obj_mesh_index(object_info obj_info, const ch if (!set) return -1; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].id != obj_info.id) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return k; - return -1; - } + for (uint32_t j = 0; j < set->obj_num; j++) + if (set->obj_data[j].id == obj_info.id) + return set->obj_data[j].get_obj_mesh_index(mesh_name); } return -1; } @@ -423,17 +743,9 @@ inline uint32_t object_storage_get_obj_mesh_index_by_hash(uint32_t hash, const c if (!set) continue; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].hash != hash) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return k; - return -1; - } + for (uint32_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 (obj_set_handler& i : object_storage_data_modern) { @@ -441,17 +753,9 @@ inline uint32_t object_storage_get_obj_mesh_index_by_hash(uint32_t hash, const c if (!set) continue; - for (uint32_t j = 0; j < set->obj_num; j++) { - if (set->obj_data[j].hash != hash) - continue; - - uint32_t mesh_name_hash = hash_utf8_murmurhash(mesh_name); - obj* obj = &set->obj_data[j]; - for (uint32_t k = 0; k < obj->num_mesh; k++) - if (hash_utf8_murmurhash(obj->mesh_array[k].name) == mesh_name_hash) - return k; - return -1; - } + for (uint32_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; } @@ -630,26 +934,26 @@ int32_t object_storage_load_set(void* data, object_database* obj_db, const char* if (!handler) return 1; - if (handler->load_count >= 0) { + if (handler->load_count > 0) { handler->load_count++; return 1; } - std::string* archive_file_name = &set_info->archive_file_name; - std::string* object_file_name = &set_info->object_file_name; - std::string* texture_file_name = &set_info->texture_file_name; - if (!object_file_name->size() || !texture_file_name->size()) + std::string& archive_file_name = set_info->archive_file_name; + std::string& object_file_name = set_info->object_file_name; + 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()) { + if (archive_file_name.size()) { handler->obj_file_handler.read_file(data, "rom/objset/", - archive_file_name->c_str(), object_file_name->c_str(), false); + archive_file_name.c_str(), object_file_name.c_str(), false); handler->tex_file_handler.read_file(data, "rom/objset/", - archive_file_name->c_str(), texture_file_name->c_str(), false); + archive_file_name.c_str(), texture_file_name.c_str(), false); } else { - handler->obj_file_handler.read_file(data, "rom/objset/", object_file_name->c_str()); - handler->tex_file_handler.read_file(data, "rom/objset/", texture_file_name->c_str()); + handler->obj_file_handler.read_file(data, "rom/objset/", object_file_name.c_str()); + handler->tex_file_handler.read_file(data, "rom/objset/", texture_file_name.c_str()); } handler->load_count = 1; @@ -674,21 +978,21 @@ int32_t object_storage_load_set(void* data, object_database* obj_db, uint32_t se handler->modern = false; - std::string* archive_file_name = &set_info->archive_file_name; - std::string* object_file_name = &set_info->object_file_name; - std::string* texture_file_name = &set_info->texture_file_name; - if (!object_file_name->size() || !texture_file_name->size()) + std::string& archive_file_name = set_info->archive_file_name; + std::string& object_file_name = set_info->object_file_name; + 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()) { + if (archive_file_name.size()) { handler->obj_file_handler.read_file(data, "rom/objset/", - archive_file_name->c_str(), object_file_name->c_str(), false); + archive_file_name.c_str(), object_file_name.c_str(), false); handler->tex_file_handler.read_file(data, "rom/objset/", - archive_file_name->c_str(), texture_file_name->c_str(), false); + archive_file_name.c_str(), texture_file_name.c_str(), false); } else { - handler->obj_file_handler.read_file(data, "rom/objset/", object_file_name->c_str()); - handler->tex_file_handler.read_file(data, "rom/objset/", texture_file_name->c_str()); + handler->obj_file_handler.read_file(data, "rom/objset/", object_file_name.c_str()); + handler->tex_file_handler.read_file(data, "rom/objset/", texture_file_name.c_str()); } handler->load_count = 1; @@ -783,18 +1087,18 @@ bool object_storage_load_obj_set_check_not_read(uint32_t set_id, farc f; f.read(data, size, true); - std::string* file = &handler->farc_file_handler.ptr->file; + std::string& file = handler->farc_file_handler.ptr->file; - size_t file_len = file->size(); + size_t file_len = file.size(); if (file_len >= 0x100) return false; - const char* t = strrchr(file->c_str(), '.'); + const char* t = strrchr(file.c_str(), '.'); if (t) - file_len = t - file->c_str(); + file_len = t - file.c_str(); char buf[0x100]; - memcpy(buf, file->c_str(), file_len); + memcpy(buf, file.c_str(), file_len); char* ext = buf + file_len; size_t ext_len = sizeof(buf) - file_len; @@ -874,6 +1178,42 @@ bool object_storage_load_obj_set_check_not_read(uint32_t set_id, return true; } +inline void object_storage_unload_set(object_database* obj_db, const char* name) { + object_set_info* set_info = 0; + if (!obj_db->get_object_set_info(name, &set_info)) + return; + + obj_set_handler* handler = object_storage_get_obj_set_handler(set_info->id); + if (!handler || handler->load_count <= 0) + return; + + if (--handler->load_count > 0) + return; + + handler->obj_id_data.clear(); + handler->tex_id_data.clear(); + handler->gentex.clear(); + + texture** tex_data = handler->tex_data; + int32_t tex_num = handler->tex_num; + for (int32_t i = 0; i < tex_num; i++) + texture_free(tex_data[i]); + free(tex_data); + handler->tex_data = 0; + handler->tex_num = 0; + + obj_set_handler_index_buffer_free(handler); + obj_set_handler_vertex_buffer_free(handler); + handler->load_count = 0; + handler->tex_loaded = false; + handler->obj_loaded = false; + delete handler->obj_set; + handler->obj_set = 0; + handler->tex_file_handler.free_data(); + handler->obj_file_handler.free_data(); + handler->farc_file_handler.free_data(); +} + inline void object_storage_unload_set(uint32_t set_id) { obj_set_handler* handler = object_storage_get_obj_set_handler(set_id); if (!handler || handler->load_count <= 0) @@ -918,263 +1258,21 @@ inline void object_storage_free() { object_storage_data_modern.clear(); } -static bool obj_mesh_index_buffer_load(obj_mesh_index_buffer* buffer, obj_mesh* mesh) { - int32_t indices_count = 0; - for (uint32_t i = 0; i < mesh->num_submesh; i++) - indices_count += mesh->submesh_array[i].indices_count; - - if (!indices_count) { - buffer->buffer = 0; - return true; - } - - uint16_t* indices = force_malloc_s(uint16_t, indices_count); - uint16_t* _indices = indices; - for (uint32_t k = 0; k < mesh->num_submesh; k++) { - obj_sub_mesh* sub_mesh = &mesh->submesh_array[k]; - int32_t indices_count = sub_mesh->indices_count; - uint32_t* sub_mesh_indices = sub_mesh->indices; - for (int32_t l = 0; l < indices_count; l++) - *_indices++ = (uint16_t)sub_mesh_indices[l]; - } - - _indices = indices; - for (uint32_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->indices_offset = 0; - if (sub_mesh->index_format != OBJ_INDEX_U16) - continue; - - uint16_t first_index = 0xFFFF; - uint16_t last_index = 0; - int32_t indices_count = sub_mesh->indices_count; - uint32_t* sub_mesh_indices = sub_mesh->indices; - for (int32_t j = 0; j < indices_count; j++) { - uint16_t index = *_indices++; - if (index == 0xFFFF) - continue; - - if (index < first_index) - first_index = index; - if (index > last_index) - last_index = index; - } - - sub_mesh->first_index = first_index; - sub_mesh->last_index = last_index; - sub_mesh->indices_offset = (int32_t)(sizeof(uint16_t) * offset); - offset += sub_mesh->indices_count; - } - - buffer->buffer = obj_mesh_index_buffer_load_data((size_t)indices_count * sizeof(uint16_t), indices); - free(indices); - return true; -} - -static GLuint obj_mesh_index_buffer_load_data(size_t size, void* data) { - if (!size) - return 0; - - GLuint buffer = 0; - glGenBuffers(1, &buffer); - gl_state_bind_element_array_buffer(buffer); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); - gl_state_bind_element_array_buffer(0); - return buffer; -} - -static void obj_mesh_index_buffer_free(obj_mesh_index_buffer* buffer) { - glDeleteBuffers(1, &buffer->buffer); -} - -static bool obj_mesh_vertex_buffer_load(obj_mesh_vertex_buffer* buffer, obj_mesh* mesh) { - if (!mesh->num_vertex || !mesh->vertex) - return false; - - size_t size_vertex; - if (~mesh->attrib.m.compressed) - size_vertex = obj_vertex_format_get_vertex_size(mesh->vertex_format); - else - size_vertex = obj_vertex_format_get_vertex_size_comp(mesh->vertex_format); - - void* vertex = force_malloc(size_vertex * mesh->num_vertex); - if (vertex) { - obj_vertex_format vertex_format = mesh->vertex_format; - obj_vertex_data* vertex_file = mesh->vertex; - int32_t num_vertex = mesh->num_vertex; - size_t d = (size_t)vertex; - if (~mesh->attrib.m.compressed) { - for (int32_t i = 0; i < num_vertex; i++) { - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { - *(vec3*)d = vertex_file[i].position; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { - *(vec3*)d = vertex_file[i].normal; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { - *(vec4u*)d = vertex_file[i].tangent; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) { - *(vec3*)d = vertex_file[i].binormal; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { - *(vec2*)d = vertex_file[i].texcoord0; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { - *(vec2*)d = vertex_file[i].texcoord1; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) { - *(vec2*)d = vertex_file[i].texcoord2; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) { - *(vec2*)d = vertex_file[i].texcoord3; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { - *(vec4u*)d = vertex_file[i].color0; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) { - *(vec4u*)d = vertex_file[i].color1; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { - *(vec4u*)d = vertex_file[i].bone_weight; - d += 16; - *(vec4iu*)d = vertex_file[i].bone_index; - d += 16; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) { - *(vec4u*)d = vertex_file[i].unknown; - d += 16; - } - } - } - else { - for (int32_t i = 0; i < num_vertex; i++) { - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { - *(vec3*)d = vertex_file[i].position; - d += 12; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { - vec3 normal; - vec3_mult_scalar(vertex_file[i].normal, 32727.0f, normal); - vec3_to_vec3i16(normal, *(vec3i16*)d); - *(int16_t*)(d + 6) = 0; - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { - vec4 tangent = vertex_file[i].tangent; - vec4_mult_scalar(tangent, 32727.0f, tangent); - vec4_to_vec4i16(tangent, *(vec4i16*)d); - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { - vec2_to_vec2h(vertex_file[i].texcoord0, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { - vec2_to_vec2h(vertex_file[i].texcoord1, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) { - vec2_to_vec2h(vertex_file[i].texcoord2, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) { - vec2_to_vec2h(vertex_file[i].texcoord3, *(vec2h*)d); - d += 4; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { - vec4 color0 = vertex_file[i].color0; - vec4_to_vec4h(color0, *(vec4h*)d); - d += 8; - } - - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { - vec4 bone_weight = vertex_file[i].bone_weight; - vec4_mult_scalar(bone_weight, 65535.0f, bone_weight); - vec4_to_vec4u16(bone_weight, *(vec4u16*)d); - d += 8; - - vec4i bone_index = vertex_file[i].bone_index; - vec4i_to_vec4u16(bone_index, *(vec4u16*)d); - d += 8; - } - } - } - } - mesh->size_vertex = (int32_t)size_vertex; - - bool ret = obj_mesh_vertex_buffer_load_data(buffer, size_vertex * mesh->num_vertex, - vertex, mesh->attrib.m.flag_0 ? 2 : 1); - free(vertex); - return ret; -} - -static bool obj_mesh_vertex_buffer_load_data(obj_mesh_vertex_buffer* buffer, - size_t size, void* data, int32_t count) { - if (!size || count > 3) - return false; - - buffer->count = count; - - glGenBuffers(count, buffer->buffers); - for (int32_t i = 0; i < count; i++) { - gl_state_bind_array_buffer(buffer->buffers[i]); - glBufferData(GL_ARRAY_BUFFER, (GLsizeiptr)size, data, GL_STATIC_DRAW); - } - gl_state_bind_array_buffer(0); - return true; -} - -static void obj_mesh_vertex_buffer_free(obj_mesh_vertex_buffer* buffer) { - glDeleteBuffers(buffer->count, buffer->buffers); -} - static void obj_set_handler_calc_axis_aligned_bounding_box(obj_set_handler* handler) { obj_set* set = handler->obj_set; for (uint32_t i = 0; i < set->obj_num; i++) { - obj* obj = &set->obj_data[i]; - for (uint32_t j = 0; j < obj->num_mesh; j++) { - obj_mesh* mesh = &obj->mesh_array[j]; - for (uint32_t k = 0; k < mesh->num_submesh; k++) { + obj& obj = set->obj_data[i]; + for (uint32_t j = 0; j < obj.num_mesh; j++) { + obj_mesh& mesh = obj.mesh_array[j]; + for (uint32_t k = 0; k < mesh.num_submesh; k++) { vec3 _min = { 9999999.0f, 9999999.0f, 9999999.0f }; vec3 _max = { -100000000.0f, -100000000.0f, -100000000.0f }; - obj_sub_mesh* sub_mesh = &mesh->submesh_array[k]; - uint32_t* indices = (uint32_t*)sub_mesh->indices; - uint32_t indices_count = sub_mesh->indices_count; - obj_vertex_data* vertex = mesh->vertex; - if (sub_mesh->index_format == OBJ_INDEX_U16) + obj_sub_mesh& sub_mesh = mesh.submesh_array[k]; + uint32_t* indices = (uint32_t*)sub_mesh.indices; + uint32_t indices_count = sub_mesh.indices_count; + obj_vertex_data* vertex = mesh.vertex; + if (sub_mesh.index_format == OBJ_INDEX_U16) for (uint32_t l = 0; l < indices_count; l++) { if (indices[l] == 0xFFFFFFFF) continue; @@ -1195,8 +1293,8 @@ static void obj_set_handler_calc_axis_aligned_bounding_box(obj_set_handler* hand vec3_add(_max, _min, center); vec3_mult_scalar(center, 0.5f, center); vec3_sub(_max, center, size); - sub_mesh->axis_aligned_bounding_box.center = center; - sub_mesh->axis_aligned_bounding_box.size = size; + sub_mesh.axis_aligned_bounding_box.center = center; + sub_mesh.axis_aligned_bounding_box.size = size; } } } @@ -1205,29 +1303,32 @@ static void obj_set_handler_calc_axis_aligned_bounding_box(obj_set_handler* hand static void obj_set_handler_get_shader_index_texture_index(obj_set_handler* handler) { obj_set* set = handler->obj_set; for (uint32_t i = 0; i < set->obj_num; i++) { - obj* obj = &set->obj_data[i]; - uint32_t num_material = obj->num_material; + obj& obj = set->obj_data[i]; + uint32_t num_material = obj.num_material; for (uint32_t j = 0; j < num_material; j++) { - obj_material_data* material_data = &obj->material_array[j]; - obj_material* material = &material_data->material; + obj_material_data& material_data = obj.material_array[j]; + obj_material& material = material_data.material; - if (*(int32_t*)&material->shader.name[4] != 0xDEADFF) { - material->shader.index = shaders_ft.get_index_by_name(material->shader.name); - *(int32_t*)&material->shader.name[4] = 0xDEADFF; + if (*(int32_t*)&material.shader.name[4] != 0xDEADFF) { + material.shader.index = shaders_ft.get_index_by_name(material.shader.name); + *(int32_t*)&material.shader.name[4] = 0xDEADFF; } - for (obj_material_texture_data& k : material->texdata) { - obj_material_texture_data* texture = &k; - uint32_t texture_id = texture->tex_index; - texture->tex_index = 0; - texture->texture_index = 0; + for (obj_material_texture_data& k : material.texdata) { + if (k.tex_index == -1) + continue; + + obj_material_texture_data& texture = k; + uint32_t texture_id = texture.tex_index; + texture.tex_index = 0; + texture.texture_index = 0; std::pair* tex_id_data = handler->tex_id_data.data(); uint32_t tex_id_num = (uint32_t)handler->tex_id_data.size(); for (uint32_t l = tex_id_num; l; l--, tex_id_data++) if (tex_id_data->first == texture_id) { - texture->tex_index = texture_id; - texture->texture_index = tex_id_data->second; + texture.tex_index = texture_id; + texture.texture_index = tex_id_data->second; break; } } @@ -1238,38 +1339,23 @@ static void obj_set_handler_get_shader_index_texture_index(obj_set_handler* hand static bool obj_set_handler_index_buffer_load(obj_set_handler* handler) { obj_set* set = handler->obj_set; handler->index_buffer_num = set->obj_num; - handler->index_buffer_data = force_malloc_s(obj_index_buffer, set->obj_num); + handler->index_buffer_data = new obj_index_buffer[set->obj_num]; if (!handler->index_buffer_data) return true; - for (uint32_t i = 0; i < set->obj_num; i++) { - obj* obj = &set->obj_data[i]; - obj_index_buffer* buffer = &handler->index_buffer_data[i]; - - buffer->mesh_num = obj->num_mesh; - buffer->mesh_data = force_malloc_s(obj_mesh_index_buffer, obj->num_mesh); - if (!buffer->mesh_data) + for (uint32_t i = 0; i < set->obj_num; i++) + if (!handler->index_buffer_data[i].load(set->obj_data[i])) return false; - - for (uint32_t j = 0; j < buffer->mesh_num; j++) - if (!obj_mesh_index_buffer_load(&buffer->mesh_data[j], &obj->mesh_array[j])) - return false; - } return true; } static void obj_set_handler_index_buffer_free(obj_set_handler* handler) { - if (!handler->index_buffer_data) - return; - - for (uint32_t i = 0; i < handler->index_buffer_num; i++) { - obj_index_buffer* buffer = &handler->index_buffer_data[i]; - if (buffer->mesh_data) - for (uint32_t j = 0; j < buffer->mesh_num; j++) - obj_mesh_index_buffer_free(&buffer->mesh_data[j]); - free(buffer->mesh_data); + if (handler->index_buffer_data) { + for (uint32_t i = 0; i < handler->index_buffer_num; i++) + handler->index_buffer_data[i].unload(); + delete[] handler->index_buffer_data; } - free(handler->index_buffer_data); + handler->index_buffer_data = 0; handler->index_buffer_num = 0; } @@ -1335,38 +1421,23 @@ static bool obj_set_handler_load_textures_modern(obj_set_handler* handler, const static bool obj_set_handler_vertex_buffer_load(obj_set_handler* handler) { obj_set* set = handler->obj_set; handler->vertex_buffer_num = set->obj_num; - handler->vertex_buffer_data = force_malloc_s(obj_vertex_buffer, set->obj_num); + handler->vertex_buffer_data = new obj_vertex_buffer[set->obj_num]; if (!handler->vertex_buffer_data) return true; - for (uint32_t i = 0; i < set->obj_num; i++) { - obj* obj = &set->obj_data[i]; - obj_vertex_buffer* buffer = &handler->vertex_buffer_data[i]; - - buffer->mesh_num = obj->num_mesh; - buffer->mesh_data = force_malloc_s(obj_mesh_vertex_buffer, obj->num_mesh); - if (!buffer->mesh_data) + for (uint32_t i = 0; i < set->obj_num; i++) + if (!handler->vertex_buffer_data[i].load(set->obj_data[i])) return false; - - for (uint32_t j = 0; j < buffer->mesh_num; j++) - if (!obj_mesh_vertex_buffer_load(&buffer->mesh_data[j], &obj->mesh_array[j])) - return false; - } return true; } static void obj_set_handler_vertex_buffer_free(obj_set_handler* handler) { - if (!handler->vertex_buffer_data) - return; - - for (uint32_t i = 0; i < handler->vertex_buffer_num; i++) { - obj_vertex_buffer* buffer = &handler->vertex_buffer_data[i]; - if (buffer->mesh_data) - for (uint32_t j = 0; j < buffer->mesh_num; j++) - obj_mesh_vertex_buffer_free(&buffer->mesh_data[j]); - free(buffer->mesh_data); + if (handler->vertex_buffer_data) { + for (uint32_t i = 0; i < handler->vertex_buffer_num; i++) + handler->vertex_buffer_data[i].unload(); + delete[] handler->vertex_buffer_data; } - free(handler->vertex_buffer_data); + handler->vertex_buffer_data = 0; handler->vertex_buffer_num = 0; } @@ -1402,74 +1473,52 @@ inline static void obj_skin_block_node_free(obj_skin_block_node* node) { inline static size_t obj_vertex_format_get_vertex_size(obj_vertex_format format) { size_t size = 0; - if (format & OBJ_VERTEX_FORMAT_POSITION) + if (format & OBJ_VERTEX_POSITION) size += 12; - if (format & OBJ_VERTEX_FORMAT_NORMAL) + if (format & OBJ_VERTEX_NORMAL) size += 12; - if (format & OBJ_VERTEX_FORMAT_TANGENT) + if (format & OBJ_VERTEX_TANGENT) size += 16; - if (format & OBJ_VERTEX_FORMAT_BINORMAL) + if (format & OBJ_VERTEX_BINORMAL) size += 12; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (format & OBJ_VERTEX_TEXCOORD0) size += 8; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (format & OBJ_VERTEX_TEXCOORD1) size += 8; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (format & OBJ_VERTEX_TEXCOORD2) size += 8; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (format & OBJ_VERTEX_TEXCOORD3) size += 8; - if (format & OBJ_VERTEX_FORMAT_COLOR0) + if (format & OBJ_VERTEX_COLOR0) size += 16; - if (format & OBJ_VERTEX_FORMAT_COLOR1) + if (format & OBJ_VERTEX_COLOR1) size += 16; - if (format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (format & OBJ_VERTEX_BONE_DATA) size += 32; - if (format & OBJ_VERTEX_FORMAT_UNKNOWN) + if (format & OBJ_VERTEX_UNKNOWN) size += 16; return size; } inline static size_t obj_vertex_format_get_vertex_size_comp(obj_vertex_format format) { size_t size = 0; - if (format & OBJ_VERTEX_FORMAT_POSITION) + if (format & OBJ_VERTEX_POSITION) size += 12; - if (format & OBJ_VERTEX_FORMAT_NORMAL) + if (format & OBJ_VERTEX_NORMAL) size += 8; - if (format & OBJ_VERTEX_FORMAT_TANGENT) + if (format & OBJ_VERTEX_TANGENT) size += 8; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD0) + if (format & OBJ_VERTEX_TEXCOORD0) size += 4; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD1) + if (format & OBJ_VERTEX_TEXCOORD1) size += 4; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD2) + if (format & OBJ_VERTEX_TEXCOORD2) size += 4; - if (format & OBJ_VERTEX_FORMAT_TEXCOORD3) + if (format & OBJ_VERTEX_TEXCOORD3) size += 4; - if (format & OBJ_VERTEX_FORMAT_COLOR0) + if (format & OBJ_VERTEX_COLOR0) size += 8; - if (format & OBJ_VERTEX_FORMAT_BONE_DATA) + if (format & OBJ_VERTEX_BONE_DATA) size += 16; return size; } - -obj_set_handler::obj_set_handler(): obj_loaded(), tex_loaded(), obj_set(), -tex_num(), tex_data(), set_id(), vertex_buffer_num(), vertex_buffer_data(), -index_buffer_num(), index_buffer_data(), load_count(), modern() { - -} - -obj_set_handler::~obj_set_handler() { - for (uint32_t i = 0; i < tex_num; i++) - texture_free(tex_data[i]); - free(tex_data); - - obj_set_handler_index_buffer_free(this); - obj_set_handler_vertex_buffer_free(this); - delete obj_set; - while (tex_file_handler.ptr && tex_file_handler.ptr->count) - tex_file_handler.free_data(); - while (obj_file_handler.ptr && obj_file_handler.ptr->count) - obj_file_handler.free_data(); - while (farc_file_handler.ptr && farc_file_handler.ptr->count) - farc_file_handler.free_data(); -} diff --git a/src/CRE/object.hpp b/src/CRE/object.hpp index e1f283ff..925a5cf4 100644 --- a/src/CRE/object.hpp +++ b/src/CRE/object.hpp @@ -13,7 +13,7 @@ #include "../KKdLib/txp.hpp" #include "../KKdLib/vec.hpp" #include "file_handler.hpp" -#include "static_var.h" +#include "static_var.hpp" #include "texture.hpp" struct material_change { @@ -24,22 +24,49 @@ struct material_change { struct obj_mesh_index_buffer { GLuint buffer; + GLsizeiptr size; + + obj_mesh_index_buffer(); + + bool load(obj_mesh& mesh); + bool load_data(size_t size, const void* data); + void unload(); }; struct obj_mesh_vertex_buffer { uint32_t count; GLuint buffers[3]; + GLsizeiptr size; uint32_t index; + + obj_mesh_vertex_buffer(); + + void cycle_index(); + GLuint get_buffer(); + GLsizeiptr get_size(); + bool load(obj_mesh& mesh); + bool load_data(size_t size, const void* data, int32_t count); + void unload(); }; struct obj_index_buffer { uint32_t mesh_num; obj_mesh_index_buffer* mesh_data; + + obj_index_buffer(); + + bool load(obj& obj); + void unload(); }; struct obj_vertex_buffer { uint32_t mesh_num; obj_mesh_vertex_buffer* mesh_data; + + obj_vertex_buffer(); + + bool load(obj& obj); + void unload(); }; struct obj_set_handler { @@ -71,8 +98,6 @@ 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( obj_material_texture_type type, int32_t base_index); -extern GLuint obj_mesh_vertex_buffer_get_buffer(obj_mesh_vertex_buffer* buffer); -extern int32_t obj_mesh_vertex_buffer_get_size(obj_mesh_vertex_buffer* buffer); extern void obj_skin_set_matrix_buffer(obj_skin* s, mat4* matrices, mat4* ex_data_matrices, mat4* matrix_buffer, mat4* global_mat, mat4* mat); @@ -104,5 +129,6 @@ extern int32_t object_storage_load_set(void* data, object_database* obj_db, uint extern int32_t object_storage_load_set_hash(void* data, uint32_t hash); extern bool object_storage_load_obj_set_check_not_read(uint32_t set_id, object_database* obj_db = 0, texture_database* tex_db = 0); +extern void object_storage_unload_set(object_database* obj_db, const char* name); extern void object_storage_unload_set(uint32_t set_id); extern void object_storage_free(); \ No newline at end of file diff --git a/src/CRE/post_process.cpp b/src/CRE/post_process.cpp index 744ae52f..cdbb721b 100644 --- a/src/CRE/post_process.cpp +++ b/src/CRE/post_process.cpp @@ -5,13 +5,15 @@ #include "post_process.hpp" #include "fbo.hpp" -#include "gl_state.h" -#include "render_texture.h" -#include "shader_ft.h" -#include "static_var.h" +#include "gl_state.hpp" +#include "render_texture.hpp" +#include "shader_ft.hpp" +#include "stage.hpp" +#include "stage_modern.hpp" +#include "static_var.hpp" #include "texture.hpp" -extern int32_t stage_index; +extern bool task_stage_is_modern; post_process::post_process() : ssaa(), mlaa(), parent_bone_node(), render_textures_data(), movie_textures_data(), lens_flare_texture(), lens_shaft_texture(), lens_ghost_texture(), @@ -151,15 +153,6 @@ post_process::~post_process() { tone_map = 0; } - ::render_texture_free(&rend_texture); - ::render_texture_free(&buf_texture); - ::render_texture_free(&sss_contour_texture); - ::render_texture_free(&pre_texture); - ::render_texture_free(&post_texture); - ::render_texture_free(&fbo_texture); - ::render_texture_free(&alpha_layer_texture); - ::render_texture_free(&screen_texture); - if (samplers[0]) { glDeleteSamplers(2, samplers); samplers[0] = 0; @@ -205,7 +198,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param if (!render_textures_data[i]) continue; - render_texture_bind(&render_textures[i], 0); + render_textures[i].bind(); texture* t = render_textures_data[i]; if (render_width > t->width * 2ULL || render_height > t->height * 2ULL) @@ -217,7 +210,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); gl_state_bind_sampler(0, samplers[0]); shaders_ft.set(SHADER_FT_REDUCE); - render_texture_draw_params(&shaders_ft, render_width, + render_texture::draw_params(&shaders_ft, render_width, render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } @@ -225,7 +218,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param 0, 0, render_width, render_height, 0, 0, render_width, render_height, GL_COLOR_BUFFER_BIT, GL_LINEAR); - render_texture_bind(&screen_texture, 0); + screen_texture.bind(); glViewport(screen_x_offset, screen_y_offset, sprite_width, sprite_height); if (ssaa) { gl_state_active_bind_texture_2d(0, rend_texture.color_texture->tex); @@ -233,7 +226,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param uniform_value[U01] = parent_bone_node ? 1 : 0; uniform_value[U_REDUCE] = 0; shaders_ft.set(SHADER_FT_REDUCE); - render_texture_draw_params(&shaders_ft, render_width, + render_texture::draw_params(&shaders_ft, render_width, render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U01] = 0; } @@ -259,7 +252,7 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param } shaders_ft.set(SHADER_FT_MAGNIFY); - render_texture_draw_params(&shaders_ft, render_width, + render_texture::draw_params(&shaders_ft, render_width, render_height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } shader::unbind(); @@ -275,14 +268,16 @@ void post_process::apply(camera* cam, texture* light_proj_tex, int32_t npr_param void post_process::ctrl(camera* cam) { view_point_prev = view_point; interest_prev = interest; - camera_get_view_point(cam, &view_point); - camera_get_interest(cam, &interest); + cam->get_view_point(view_point); + cam->get_interest(interest); stage_index_prev = stage_index; - stage_index = ::stage_index; + if (task_stage_is_modern) + stage_index = (int32_t)task_stage_modern_get_current_stage_hash(); + else + stage_index = task_stage_get_current_stage_index(); - bool reset_exposure = cam->fast_change_hist1 && !cam->fast_change_hist0; - this->reset_exposure = reset_exposure; + reset_exposure = cam->fast_change_hist1 && !cam->fast_change_hist0; if (reset_exposure) { float_t view_point_dist; vec3_distance(view_point, view_point_prev, view_point_dist); @@ -328,18 +323,12 @@ void post_process::init_fbo(int32_t render_width, int32_t render_height, dof->init_fbo(render_width, render_height); exposure->init_fbo(); tone_map->init_fbo(); - render_texture_init(&rend_texture, render_width, - render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); - render_texture_init(&buf_texture, render_width, - render_height, 0, GL_RGBA16F, 0); - render_texture_init(&sss_contour_texture, render_width, - render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); - render_texture_init(&pre_texture, render_width, - render_height, 0, GL_RGBA16F, 0); - render_texture_init(&post_texture, render_width, - render_height, 0, GL_RGBA16F, 0); - render_texture_init(&alpha_layer_texture, render_width, - render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); + rend_texture.init(render_width, render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); + buf_texture.init(render_width, render_height, 0, GL_RGBA16F, 0); + sss_contour_texture.init(render_width, render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); + pre_texture.init(render_width, render_height, 0, GL_RGBA16F, 0); + post_texture.init(render_width, render_height, 0, GL_RGBA16F, 0); + alpha_layer_texture.init(render_width, render_height, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); gl_state_bind_texture_2d(rend_texture.depth_texture->tex); GLint swizzle[] = { GL_RED, GL_RED, GL_RED, GL_ONE }; glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle); @@ -357,10 +346,8 @@ void post_process::init_fbo(int32_t render_width, int32_t render_height, screen_y_offset = (screen_height - sprite_height) / 2 + (screen_height - sprite_height) % 2; if (this->screen_width != screen_width || this->screen_height != screen_height) { - render_texture_init(&fbo_texture, screen_width, - screen_height, 0, GL_RGBA16F, 0); - render_texture_init(&screen_texture, screen_width, - screen_height, 0, GL_R11F_G11F_B10F, 0); + fbo_texture.init(screen_width, screen_height, 0, GL_RGBA16F, 0); + screen_texture.init(screen_width, screen_height, 0, GL_R11F_G11F_B10F, 0); this->screen_width = screen_width; this->screen_height = screen_height; } @@ -376,8 +363,7 @@ int32_t post_process::movie_texture_set(texture* movie_texture) { return -1; movie_textures_data[index] = movie_texture; - render_texture_set_color_depth_textures(&movie_textures[index], - movie_texture->tex, 0, 0, false); + movie_textures[index].set_color_depth_textures(movie_texture->tex, 0, 0, false); return index; } @@ -391,7 +377,7 @@ void post_process::movie_texture_free(texture* movie_texture) { return; movie_textures_data[index] = 0; - ::render_texture_free(&movie_textures[index]); + movie_textures[index].free_data(); } int32_t post_process::render_texture_set(texture* render_texture, bool task_photo) { @@ -407,8 +393,7 @@ int32_t post_process::render_texture_set(texture* render_texture, bool task_phot return -1; render_textures_data[index] = render_texture; - render_texture_set_color_depth_textures(&render_textures[index], - render_texture->tex, 0, 0, false); + render_textures[index].set_color_depth_textures(render_texture->tex, 0, 0, false); return index; } @@ -425,7 +410,7 @@ void post_process::render_texture_free(texture* render_texture, bool task_photo) return; render_textures_data[index] = 0; - ::render_texture_free(&render_textures[index]); + render_textures[index].free_data(); } void post_process::reset() { diff --git a/src/CRE/post_process.hpp b/src/CRE/post_process.hpp index 125cb360..9e2ab75c 100644 --- a/src/CRE/post_process.hpp +++ b/src/CRE/post_process.hpp @@ -12,7 +12,7 @@ #include "post_process/dof.hpp" #include "post_process/exposure.hpp" #include "post_process/tone_map.hpp" -#include "camera.h" +#include "camera.hpp" enum post_process_mag_filter_type { POST_PROCESS_MAG_FILTER_NEAREST = 0, diff --git a/src/CRE/post_process/aa.cpp b/src/CRE/post_process/aa.cpp index aea83c8b..6c106f3f 100644 --- a/src/CRE/post_process/aa.cpp +++ b/src/CRE/post_process/aa.cpp @@ -5,9 +5,9 @@ #include "aa.hpp" #include "../fbo.hpp" -#include "../gl_state.h" +#include "../gl_state.hpp" #include "../post_process.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" static void post_process_aa_calculate_area_texture_data(uint8_t* a1, int32_t a2, int32_t a3); static void post_process_aa_calculate_area_texture_data_sub(float_t* a1, @@ -32,21 +32,19 @@ post_process_aa::~post_process_aa() { if (!this) return; - render_texture_free(&mlaa_buffer[0]); - render_texture_free(&mlaa_buffer[1]); glDeleteTextures(1, &mlaa_area_texture); } void post_process_aa::apply_mlaa(render_texture* rt, render_texture* buf_rt, GLuint* samplers, int32_t a4) { - render_texture_bind(mlaa_buffer, 0); + mlaa_buffer->bind(); gl_state_active_bind_texture_2d(0, rt->color_texture->tex); gl_state_bind_sampler(0, samplers[1]); uniform_value[U_MLAA] = 0; shaders_ft.set(SHADER_FT_MLAA); - render_texture_draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - render_texture_bind(&mlaa_buffer[1], 0); + mlaa_buffer[1].bind(); gl_state_active_bind_texture_2d(0, mlaa_buffer[0].color_texture->tex); gl_state_active_bind_texture_2d(1, mlaa_area_texture); gl_state_bind_sampler(0, samplers[0]); @@ -54,16 +52,16 @@ void post_process_aa::apply_mlaa(render_texture* rt, uniform_value[U20] = 2; uniform_value[U_MLAA] = 1; shaders_ft.set(SHADER_FT_MLAA); - render_texture_draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); - render_texture_bind(buf_rt, 0); + buf_rt->bind(); gl_state_active_bind_texture_2d(0, rt->color_texture->tex); gl_state_active_bind_texture_2d(1, mlaa_buffer[1].color_texture->tex); gl_state_bind_sampler(0, samplers[1]); uniform_value[U_MLAA] = 2; uniform_value[U01] = a4 ? 1 : 0; shaders_ft.set(SHADER_FT_MLAA); - render_texture_draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U01] = 0; gl_state_active_bind_texture_2d(0, 0); gl_state_active_bind_texture_2d(1, 0); @@ -77,11 +75,11 @@ void post_process_aa::init_fbo(int32_t width, int32_t height) { if (!this || (this->width == width && this->height == height)) return; - this->width = width > 1 ? width : 1; - this->height = height > 1 ? height : 1; + this->width = max(width, 1); + this->height = max(height, 1); - render_texture_init(&mlaa_buffer[0], this->width, this->height, 0, GL_RGBA8, 0); - render_texture_init(&mlaa_buffer[1], this->width, this->height, 0, GL_RGBA8, 0); + mlaa_buffer[0].init(this->width, this->height, 0, GL_RGBA8, 0); + mlaa_buffer[1].init(this->width, this->height, 0, GL_RGBA8, 0); } static void post_process_aa_calculate_area_texture_data(uint8_t* a1, int32_t a2, int32_t a3) { diff --git a/src/CRE/post_process/aa.hpp b/src/CRE/post_process/aa.hpp index a677495d..7d96babb 100644 --- a/src/CRE/post_process/aa.hpp +++ b/src/CRE/post_process/aa.hpp @@ -7,8 +7,8 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/vec.hpp" -#include "../shared.h" -#include "../render_texture.h" +#include "../shared.hpp" +#include "../render_texture.hpp" struct post_process_aa { int32_t width; diff --git a/src/CRE/post_process/blur.cpp b/src/CRE/post_process/blur.cpp index 4617954c..09a8e472 100644 --- a/src/CRE/post_process/blur.cpp +++ b/src/CRE/post_process/blur.cpp @@ -5,9 +5,9 @@ #include "blur.hpp" #include "../fbo.hpp" -#include "../gl_state.h" +#include "../gl_state.hpp" #include "../post_process.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" static void post_process_blur_radius_calculate(post_process_blur* blur); static void post_process_blur_radius_calculate_gaussian_kernel(float_t* gaussian_kernel, @@ -15,7 +15,12 @@ static void post_process_blur_radius_calculate_gaussian_kernel(float_t* gaussian post_process_blur::post_process_blur() : data(), width(), height(), width_down(), height_down(), tex_down(), count_down() { - + tex[0].init(256, 144, 0, GL_RGBA16F, 0); + tex[1].init(128, 72, 0, GL_RGBA16F, 0); + tex[2].init(64, 36, 0, GL_RGBA16F, 0); + tex[3].init(32, 18, 0, GL_RGBA16F, 0); + tex[4].init(8, 8, 0, GL_R32F, 0); + tex[5].init(256, 144, 0, GL_RGBA16F, 0); } post_process_blur:: ~post_process_blur() { @@ -23,9 +28,7 @@ post_process_blur:: ~post_process_blur() { return; for (int32_t i = 0; i < count_down; i++) - render_texture_free(&tex_down[i]); - for (int32_t i = 0; i < 6; i++) - render_texture_free(&tex[i]); + tex_down[i].free_data(); free(tex_down); free(height_down); free(width_down); @@ -37,70 +40,70 @@ void post_process_blur::get_blur(render_texture* rt) { int32_t i = 0; if (count_down > 0) { uniform_value[U_REDUCE] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); for (; i < count_down; i++) { glViewport(0, 0, width_down[i], height_down[i]); - render_texture_bind(&tex_down[i], 0); + tex_down[i].bind(); gl_state_active_bind_texture_2d(0, i ? tex_down[i - 1].color_texture->tex : rt->color_texture->tex); - render_texture_draw_params(&shaders_ft, + render_texture::draw_params(&shaders_ft, width_down[i], height_down[i], 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } i--; } uniform_value[U_REDUCE] = 3; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); shaders_ft.local_frag_set(2, 1.1f, 1.1f, 1.1f, 0.0f); glViewport(0, 0, 256, 144); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, count_down > 0 ? tex_down[i].color_texture->tex : rt->color_texture->tex); - render_texture_draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, width, height, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U_GAUSS] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_GAUSS); + render_texture::shader_set(&shaders_ft, SHADER_FT_GAUSS); glViewport(0, 0, 256, 144); - render_texture_bind(&tex[5], 0); + tex[5].bind(); gl_state_active_bind_texture_2d(0, tex[0].color_texture->tex); - render_texture_draw_params(&shaders_ft, 256, 144, + render_texture::draw_params(&shaders_ft, 256, 144, 1.0f, data.intensity.x * 0.5f, data.intensity.y * 0.5f, data.intensity.z * 0.5f, 1.0f); uniform_value[U_REDUCE] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); glViewport(0, 0, 128, 72); - render_texture_bind(&tex[1], 0); + tex[1].bind(); gl_state_active_bind_texture_2d(0, tex[0].color_texture->tex); - render_texture_draw_params(&shaders_ft, 256, 144, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 256, 144, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U_REDUCE] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); glViewport(0, 0, 64, 36); - render_texture_bind(&tex[2], 0); + tex[2].bind(); gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); - render_texture_draw_params(&shaders_ft, 128, 72, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 128, 72, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U_REDUCE] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); glViewport(0, 0, 32, 18); - render_texture_bind(&tex[3], 0); + tex[3].bind(); gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); - render_texture_draw_params(&shaders_ft, 64, 36, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 64, 36, 0.75f, 1.0f, 1.0f, 1.0f, 1.0f); uniform_value[U_EXPOSURE] = 0; - render_texture_shader_set(&shaders_ft, SHADER_FT_EXPOSURE); + render_texture::shader_set(&shaders_ft, SHADER_FT_EXPOSURE); glViewport(0, 0, 8, 8); - render_texture_bind(&tex[4], 0); + tex[4].bind(); gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); - render_texture_draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); vec3 intensity = data.intensity; vec3* gauss = data.gauss; @@ -110,31 +113,31 @@ void post_process_blur::get_blur(render_texture* rt) { vec3_mult(gauss[i], intensity, v[i]); uniform_value[U_GAUSS] = 0; - render_texture_shader_set(&shaders_ft, SHADER_FT_GAUSS); + render_texture::shader_set(&shaders_ft, SHADER_FT_GAUSS); shaders_ft.local_frag_set(1, 1.0f, 0.0f, 1.0f, 0.0f); for (int32_t i = 0; i < POST_PROCESS_BLUR_GAUSSIAN_KERNEL_SIZE; i++) shaders_ft.local_frag_set(4ULL + i, v[i].x, v[i].y, v[i].z, 0.0f); glViewport(0, 0, 128, 72); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); - render_texture_draw_params(&shaders_ft, 128, 72, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 128, 72, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[1].fbos[0], 0, 0, 128, 72, 0, 0, 128, 72, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 64, 36); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); - render_texture_draw_params(&shaders_ft, 64, 36, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 64, 36, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[2].fbos[0], 0, 0, 64, 36, 0, 0, 64, 36, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 32, 18); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); - render_texture_draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[3].fbos[0], 0, 0, 32, 18, 0, 0, 32, 18, GL_COLOR_BUFFER_BIT, GL_LINEAR); @@ -142,58 +145,45 @@ void post_process_blur::get_blur(render_texture* rt) { shaders_ft.local_frag_set(1, 0.0f, 1.0f, 0.0f, 1.0f); glViewport(0, 0, 128, 72); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[1].color_texture->tex); - render_texture_draw_params(&shaders_ft, 128, 72, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 128, 72, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[1].fbos[0], 0, 0, 128, 72, 0, 0, 128, 72, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 64, 36); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[2].color_texture->tex); - render_texture_draw_params(&shaders_ft, 64, 36, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 64, 36, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[2].fbos[0], 0, 0, 64, 36, 0, 0, 64, 36, GL_COLOR_BUFFER_BIT, GL_LINEAR); glViewport(0, 0, 32, 18); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[3].color_texture->tex); - render_texture_draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 32, 18, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); fbo::blit(tex[0].fbos[0], tex[3].fbos[0], 0, 0, 32, 18, 0, 0, 32, 18, GL_COLOR_BUFFER_BIT, GL_LINEAR); uniform_value[U_REDUCE] = 7; - render_texture_shader_set(&shaders_ft, SHADER_FT_REDUCE); + render_texture::shader_set(&shaders_ft, SHADER_FT_REDUCE); glViewport(0, 0, 256, 144); - render_texture_bind(&tex[0], 0); + tex[0].bind(); gl_state_active_bind_texture_2d(0, tex[5].color_texture->tex); gl_state_active_bind_texture_2d(1, tex[1].color_texture->tex); gl_state_active_bind_texture_2d(2, tex[2].color_texture->tex); gl_state_active_bind_texture_2d(3, tex[3].color_texture->tex); - render_texture_draw_params(&shaders_ft, 32, 18, 0.25f, 0.15f, 0.25f, 0.25f, 0.25f); + render_texture::draw_params(&shaders_ft, 32, 18, 0.25f, 0.15f, 0.25f, 0.25f, 0.25f); } void post_process_blur::init_fbo(int32_t width, int32_t height) { if (!this || (this->width == width && this->height == height)) return; - if (!tex[0].color_texture) - render_texture_init(&tex[0], 256, 144, 0, GL_RGBA16F, 0); - if (!tex[1].color_texture) - render_texture_init(&tex[1], 128, 72, 0, GL_RGBA16F, 0); - if (!tex[2].color_texture) - render_texture_init(&tex[2], 64, 36, 0, GL_RGBA16F, 0); - if (!tex[3].color_texture) - render_texture_init(&tex[3], 32, 18, 0, GL_RGBA16F, 0); - if (!tex[4].color_texture) - render_texture_init(&tex[4], 8, 8, 0, GL_R32F, 0); - if (!tex[5].color_texture) - render_texture_init(&tex[5], 256, 144, 0, GL_RGBA16F, 0); - this->width = width > 1 ? width : 1; this->height = height > 1 ? height : 1; @@ -249,7 +239,7 @@ void post_process_blur::init_fbo(int32_t width, int32_t height) { } for (i = 0; i < count_down; i++) - render_texture_init(&tex_down[i], width_down[i], height_down[i], 0, GL_RGBA16F, 0); + tex_down[i].init(width_down[i], height_down[i], 0, GL_RGBA16F, 0); gl_state_bind_framebuffer(0); diff --git a/src/CRE/post_process/blur.hpp b/src/CRE/post_process/blur.hpp index 84411343..77b5c08b 100644 --- a/src/CRE/post_process/blur.hpp +++ b/src/CRE/post_process/blur.hpp @@ -7,8 +7,8 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/vec.hpp" -#include "../shared.h" -#include "../render_texture.h" +#include "../shared.hpp" +#include "../render_texture.hpp" #define POST_PROCESS_BLUR_GAUSSIAN_KERNEL_SIZE 7 diff --git a/src/CRE/post_process/dof.cpp b/src/CRE/post_process/dof.cpp index c6e81fe5..c116678a 100644 --- a/src/CRE/post_process/dof.cpp +++ b/src/CRE/post_process/dof.cpp @@ -5,8 +5,8 @@ #include "dof.hpp" #include "../../KKdLib/str_utils.hpp" -#include "../gl_state.h" -#include "../rob.hpp" +#include "../rob/rob.hpp" +#include "../gl_state.hpp" struct post_process_dof_shader_data { vec4 g_depth_params; @@ -1056,7 +1056,7 @@ namespace renderer { void DOF3::upsample(post_process_dof* dof, render_texture* rt, GLuint* samplers, GLuint color_texture, GLuint depth_texture, bool f2) { - render_texture_bind(rt, 0); + rt->bind(); glViewport(0, 0, dof->width, dof->height); if (f2) gl_state_use_program(dof->program[8]); diff --git a/src/CRE/post_process/dof.hpp b/src/CRE/post_process/dof.hpp index b450c456..c01643bc 100644 --- a/src/CRE/post_process/dof.hpp +++ b/src/CRE/post_process/dof.hpp @@ -7,10 +7,10 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/vec.hpp" -#include "../camera.h" +#include "../camera.hpp" #include "../fbo.hpp" -#include "../render_texture.h" -#include "../shared.h" +#include "../render_texture.hpp" +#include "../shared.hpp" enum dof_debug_flags { DOF_DEBUG_USE_UI_PARAMS = 0x01, diff --git a/src/CRE/post_process/exposure.cpp b/src/CRE/post_process/exposure.cpp index c459e140..b379aae8 100644 --- a/src/CRE/post_process/exposure.cpp +++ b/src/CRE/post_process/exposure.cpp @@ -4,11 +4,11 @@ */ #include "exposure.hpp" +#include "../rob/rob.hpp" #include "../fbo.hpp" -#include "../gl_state.h" +#include "../gl_state.hpp" #include "../post_process.hpp" -#include "../rob.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" static void sub_1405163C0(rob_chara* rob_chr, int32_t a2, mat4* mat); @@ -16,6 +16,7 @@ post_process_exposure::post_process_exposure() : exposure_history_counter(), chara_data(), query_index() { chara_data = new post_process_exposure_chara_data[ROB_CHARA_COUNT]; for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) { + memset(&chara_data[i], 0, sizeof(post_process_exposure_chara_data)); chara_data[i].query_data[0] = -1; chara_data[i].query_data[1] = -1; chara_data[i].query_data[2] = -1; @@ -26,9 +27,6 @@ post_process_exposure::~post_process_exposure() { if (!this) return; - render_texture_free(&exposure_history); - render_texture_free(&exposure); - for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) glDeleteQueries(3, chara_data[i].query); @@ -39,6 +37,9 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, int32_t render_height, bool reset_exposure, GLuint in_tex_0, GLuint in_tex_1) { bool v2 = false; if (!reset_exposure) { + for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) + memset(&chara_data[i], 0, sizeof(post_process_exposure_chara_data)); + post_process_exposure_chara_data* v6 = chara_data; float_t v18 = (float_t)render_height / (float_t)render_width; float_t v20 = powf(tanf((float_t)(cam->fov_rad * 0.5f)) * 3.4f, 2.0f); @@ -141,7 +142,7 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, if (!v2 || reset_exposure) { uniform_value[U_EXPOSURE] = 1; - render_texture_shader_set(&shaders_ft, SHADER_FT_EXPOSURE); + render_texture::shader_set(&shaders_ft, SHADER_FT_EXPOSURE); shaders_ft.local_frag_set(1, chara_data[0].field_80, chara_data[1].field_80, @@ -156,19 +157,19 @@ void post_process_exposure::get_exposure(camera* cam, int32_t render_width, glViewport(0, 0, 32, 1); else glViewport(exposure_history_counter, 0, 1, 1); - render_texture_bind(&exposure_history, 0); + exposure_history.bind(); gl_state_active_bind_texture_2d(0, in_tex_0); gl_state_active_bind_texture_2d(1, in_tex_1); - render_texture_draw_params(&shaders_ft, + render_texture::draw_params(&shaders_ft, reset_exposure ? 32 : 1, 1, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); exposure_history_counter++; exposure_history_counter %= 32; } glViewport(0, 0, 1, 1); - render_texture_bind(&exposure, 0); + exposure.bind(); gl_state_active_bind_texture_2d(0, exposure_history.color_texture->tex); - render_texture_draw_params(&shaders_ft, 1, 1, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); + render_texture::draw_params(&shaders_ft, 1, 1, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f); } void post_process_exposure::get_exposure_chara_data(void* pp, camera* cam) { @@ -220,9 +221,9 @@ void post_process_exposure::init_fbo() { exposure_history_counter = 0; if (!exposure_history.color_texture) - render_texture_init(&exposure_history, 32, 1, 0, GL_R32F, 0); + exposure_history.init(32, 1, 0, GL_R32F, 0); if (!exposure.color_texture) - render_texture_init(&exposure, 1, 1, 0, GL_R32F, 0); + exposure.init(1, 1, 0, GL_R32F, 0); for (int32_t i = 0; i < ROB_CHARA_COUNT; i++) if (!chara_data[i].query[0]) diff --git a/src/CRE/post_process/exposure.hpp b/src/CRE/post_process/exposure.hpp index bbce8009..c2df9111 100644 --- a/src/CRE/post_process/exposure.hpp +++ b/src/CRE/post_process/exposure.hpp @@ -7,9 +7,9 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/vec.hpp" -#include "../camera.h" -#include "../render_texture.h" -#include "../shared.h" +#include "../camera.hpp" +#include "../render_texture.hpp" +#include "../shared.hpp" struct post_process_exposure_chara_data { vec4 field_0[8]; diff --git a/src/CRE/post_process/tone_map.cpp b/src/CRE/post_process/tone_map.cpp index d2ca026a..c2eafb59 100644 --- a/src/CRE/post_process/tone_map.cpp +++ b/src/CRE/post_process/tone_map.cpp @@ -5,9 +5,9 @@ #include "tone_map.hpp" #include "../fbo.hpp" -#include "../gl_state.h" +#include "../gl_state.hpp" #include "../post_process.hpp" -#include "../shader_ft.h" +#include "../shader_ft.hpp" static void post_process_tone_map_calculate_data(post_process_tone_map* tm); static void post_process_tone_map_calculate_tex(post_process_tone_map* tm); @@ -67,7 +67,7 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te uniform_value[U25] = 0; glViewport(0, 0, rt->color_texture->width, rt->color_texture->height); - render_texture_bind(buf_rt, 0); + buf_rt->bind(); shaders_ft.set(SHADER_FT_TONEMAP); shaders_ft.state_matrix_set_texture(4, lens_flare_mat); shaders_ft.state_matrix_set_texture(5, lens_shaft_mat); @@ -99,7 +99,7 @@ void post_process_tone_map::apply(render_texture* in_tex, texture* light_proj_te glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } - render_texture_draw_custom(&shaders_ft); + render_texture::draw_custom(&shaders_ft); gl_state_active_texture(2); glBindTexture(GL_TEXTURE_1D, 0); uniform_value[U16] = 1; diff --git a/src/CRE/post_process/tone_map.hpp b/src/CRE/post_process/tone_map.hpp index 3a7f7a96..9c7488ad 100644 --- a/src/CRE/post_process/tone_map.hpp +++ b/src/CRE/post_process/tone_map.hpp @@ -8,8 +8,8 @@ #include "../../KKdLib/default.hpp" #include "../../KKdLib/light_param/glow.hpp" #include "../../KKdLib/vec.hpp" -#include "../shared.h" -#include "../render_texture.h" +#include "../shared.hpp" +#include "../render_texture.hpp" #define POST_PROCESS_TONE_MAP_SAT_GAMMA_SAMPLES 32 diff --git a/src/CRE/pv_db.cpp b/src/CRE/pv_db.cpp index 6becbcb0..64fa0ce2 100644 --- a/src/CRE/pv_db.cpp +++ b/src/CRE/pv_db.cpp @@ -9,7 +9,7 @@ extern render_context* rctx_ptr; -pv_db::TaskPvDB task_pv_db; +pv_db::TaskPvDB* task_pv_db; pv_db_pv_lyric::pv_db_pv_lyric() : index() { @@ -68,6 +68,31 @@ pv_db_pv_motion::~pv_db_pv_motion() { } +pv_db_pv_field_aet::pv_db_pv_field_aet() { + +} + +pv_db_pv_field_aet::~pv_db_pv_field_aet() { + +} + +void pv_db_pv_field_aet::reset() { + for (std::vector& i : name) { + i.clear(); + i.shrink_to_fit(); + } + + for (std::vector& i : id) { + i.clear(); + i.shrink_to_fit(); + } + + for (std::vector& i : frame) { + i.clear(); + i.shrink_to_fit(); + } +} + pv_db_pv_field::pv_db_pv_field() : index(), stage_index(), ex_stage_index(), light_frame(), light_frame_set(), stage_flag(), npr_type(), cam_blur(), sdw_off() { reset(); @@ -91,22 +116,7 @@ void pv_db_pv_field::reset() { light.shrink_to_fit(); light_frame = -3; light_frame_set = false; - - for (int32_t i = 0; i < 4; i++) { - aet[i].clear(); - aet[i].shrink_to_fit(); - } - - for (int32_t i = 0; i < 4; i++) { - aet_id[i].clear(); - aet_id[i].shrink_to_fit(); - } - - for (int32_t i = 0; i < 4; i++) { - aet_frame[i].clear(); - aet_frame[i].shrink_to_fit(); - } - + aet.reset(); spr_set_back.clear(); spr_set_back.shrink_to_fit(); stage_flag = true; @@ -264,12 +274,12 @@ void pv_db_pv_difficulty::reset() { pv_item.shrink_to_fit(); hand_item.clear(); hand_item.shrink_to_fit(); - field_228.clear(); - field_228.shrink_to_fit(); - field_240.clear(); - field_240.shrink_to_fit(); - field_258.clear(); - field_258.shrink_to_fit(); + + for (std::vector& i : motion) { + i.clear(); + i.shrink_to_fit(); + } + edit_effect.clear(); edit_effect.shrink_to_fit(); title_image.reset(); @@ -935,7 +945,7 @@ namespace pv_db { performer.size = elem->second; } - for (int32_t j = 0; j < 4; j++) { + for (int32_t j = 0; j < PV_PERFORMER_ITEM_MAX; j++) { int32_t item; if (kv.read(performer_item_names[j], item)) performer.item[j] = item; @@ -1119,18 +1129,18 @@ namespace pv_db { kv.read("attribute.extra", attribute_extra); kv.read("attribute.slide", attribute_slide); - diff.resize(count); + diff.reserve(count); for (int32_t j = 0; j < count; j++) { if (!kv.open_scope("%d", j)) continue; - pv_db_pv_difficulty diff; + pv_db_pv_difficulty d; - diff.difficulty = (pv_difficulty)i; + d.difficulty = (pv_difficulty)i; int32_t edition; if (kv.read("edition", edition)) - diff.edition = edition; + d.edition = edition; const char* _attribute_original; if (!kv.read("attribute.original", _attribute_original)) { @@ -1141,8 +1151,8 @@ namespace pv_db { } if (_attribute_original) { - diff.attribute.type = PV_ATTRIBUTE_ORIGINAL; - diff.attribute.bitset.set(0, atoi(_attribute_original) > 0); + d.attribute.type = PV_ATTRIBUTE_ORIGINAL; + d.attribute.bitset.set(0, atoi(_attribute_original) > 0); } const char* _attribute_extra; @@ -1154,8 +1164,8 @@ namespace pv_db { } if (_attribute_extra) { - diff.attribute.type = PV_ATTRIBUTE_EXTRA; - diff.attribute.bitset.set(1, atoi(_attribute_extra) > 0); + d.attribute.type = PV_ATTRIBUTE_EXTRA; + d.attribute.bitset.set(1, atoi(_attribute_extra) > 0); } const char* _attribute_slide; @@ -1167,7 +1177,7 @@ namespace pv_db { } if (_attribute_slide) - diff.attribute.bitset.set(2, atoi(_attribute_slide) > 0); + d.attribute.bitset.set(2, atoi(_attribute_slide) > 0); std::string script_file_name; if (!kv.read("script_file_name", script_file_name) @@ -1176,19 +1186,19 @@ namespace pv_db { continue; } - diff.script_file_name = script_file_name; + d.script_file_name = script_file_name; const char* level; if (kv.read("level", level)) for (int32_t k = PV_LV_00_0; k < PV_LV_MAX; k++) if (!str_utils_compare(level, pv_level_names[k])) { - diff.level = (pv_level)k; + d.level = (pv_level)k; break; } int32_t level_sort_index; if (kv.read("level_sort_index", level_sort_index)) - diff.level_sort_index = level_sort_index; + d.level_sort_index = level_sort_index; key_val_scope diff_scope = *kv.curr_scope; for (int32_t k = 0; k < 2; k++) { @@ -1196,35 +1206,35 @@ namespace pv_db { std::string se_name; if (kv.read("se_name", se_name)) - diff.se_name = se_name; + d.se_name = se_name; std::string pvbranch_success_se_name; if (kv.read("pvbranch_success_se_name", pvbranch_success_se_name)) - diff.pvbranch_success_se_name = pvbranch_success_se_name; + d.pvbranch_success_se_name = pvbranch_success_se_name; std::string slide_name; if (kv.read("slide_name", slide_name)) - diff.slide_name = slide_name; + d.slide_name = slide_name; std::string chainslide_first_name; if (kv.read("chainslide_first_name", chainslide_first_name)) - diff.chainslide_first_name = chainslide_first_name; + d.chainslide_first_name = chainslide_first_name; std::string chainslide_sub_name; if (kv.read("chainslide_sub_name", chainslide_sub_name)) - diff.chainslide_sub_name = chainslide_sub_name; + d.chainslide_sub_name = chainslide_sub_name; std::string chainslide_success_name; if (kv.read("chainslide_success_name", chainslide_success_name)) - diff.chainslide_success_name = chainslide_success_name; + d.chainslide_success_name = chainslide_success_name; std::string chainslide_failure_name; if (kv.read("chainslide_failure_name", chainslide_failure_name)) - diff.chainslide_failure_name = chainslide_failure_name; + d.chainslide_failure_name = chainslide_failure_name; std::string slidertouch_name; if (kv.read("slidertouch_name", slidertouch_name)) - diff.slidertouch_name = slidertouch_name; + d.slidertouch_name = slidertouch_name; for (size_t l = 0; l < ROB_CHARA_COUNT; l++) { if (l) @@ -1234,17 +1244,15 @@ namespace pv_db { continue; for (size_t m = 0; m < 100; m++) { - sprintf_s(buf, sizeof(buf), "%02zu", (size_t)m); - - if (!kv.open_scope(buf)) + if (!kv.open_scope("%02zu", m)) continue; const char* motion_name; - if (kv.read(buf, motion_name)) { + if (kv.read(motion_name)) { pv_db_pv_motion motion; motion.index = (int32_t)m; motion.id = aft_mot_db->get_motion_id(motion_name); - diff.motion[l].push_back(motion); + d.motion[l].push_back(motion); } kv.close_scope(); @@ -1253,7 +1261,7 @@ namespace pv_db { } if (kv.open_scope("pv_item")) { - for (int32_t k = 0; k < 10; k++) { + for (size_t k = 0; k < 10; k++) { if (!kv.open_scope("%02zu", k)) continue; @@ -1262,16 +1270,16 @@ namespace pv_db { continue; pv_db_pv_item item; - item.index = k; + item.index = (int32_t)k; item.name = name; - diff.pv_item.push_back(item); + d.pv_item.push_back(item); kv.close_scope(); } kv.close_scope(); } if (kv.open_scope("hand_item")) { - for (int32_t k = 0; k < 20; k++) { + for (size_t k = 0; k < 20; k++) { if (!kv.open_scope("%02zu", k)) continue; @@ -1280,17 +1288,17 @@ namespace pv_db { continue; pv_db_pv_hand_item hand_item; - hand_item.index = k; + hand_item.index = (int32_t)k; hand_item.id = -1; hand_item.name = name; - diff.hand_item.push_back(hand_item); + d.hand_item.push_back(hand_item); kv.close_scope(); } kv.close_scope(); } if (kv.open_scope("edit_effect")) { - for (int32_t k = 0; k < 0x200; k++) { + for (size_t k = 0; k < 0x200; k++) { if (!kv.open_scope("%02zu", k)) continue; @@ -1301,14 +1309,14 @@ namespace pv_db { pv_db_pv_edit_effect edit_effect; edit_effect.index = atoi(name.c_str()); edit_effect.name = name; - diff.edit_effect.push_back(edit_effect); + d.edit_effect.push_back(edit_effect); kv.close_scope(); } kv.close_scope(); } if (kv.open_scope("edit_effect_low_field")) { - for (int32_t k = 0; k < 0x200; k++) { + for (size_t k = 0; k < 0x200; k++) { if (!kv.open_scope("%02zu", k)) continue; @@ -1316,15 +1324,15 @@ namespace pv_db { if (!kv.read(index)) continue; - if (index < diff.edit_effect.size()) - diff.edit_effect[index].low_field = true; + if (index < d.edit_effect.size()) + d.edit_effect[index].low_field = true; kv.close_scope(); } kv.close_scope(); } if (kv.open_scope("title_image")) { - pv_db_pv_title_image& title_image = diff.title_image; + pv_db_pv_title_image& title_image = d.title_image; float_t time; if (kv.read("time", time)) @@ -1342,7 +1350,7 @@ namespace pv_db { } if (kv.open_scope("songinfo")) { - pv_db_pv_songinfo& songinfo = diff.songinfo; + pv_db_pv_songinfo& songinfo = d.songinfo; std::string music; if (kv.read("music", music)) @@ -1393,7 +1401,7 @@ namespace pv_db { int32_t count; if (!k && kv.read("movie_list", "length", count)) { - diff.movie_list.reserve(count); + d.movie_list.reserve(count); for (int32_t l = 0; l < count; l++) { if (!kv.open_scope(l)) continue; @@ -1401,7 +1409,7 @@ namespace pv_db { pv_db_pv_movie movie; if (kv.read("name", movie.name)) { movie.index = l; - diff.movie_list.push_back(movie); + d.movie_list.push_back(movie); } kv.close_scope(); } @@ -1413,29 +1421,29 @@ namespace pv_db { pv_db_pv_movie movie; movie.index = 0; movie.name = movie_file_name; - diff.movie_list.push_back(movie); + d.movie_list.push_back(movie); } std::string movie_surface; if (kv.read("movie_surface", movie_surface)) { auto elem = movie_surfaces.find(movie_surface); if (elem != movie_surfaces.end()) - diff.movie_surface = elem->second; + d.movie_surface = elem->second; } std::string effect_se_file_name; if (kv.read("effect_se_file_name", effect_se_file_name)) - diff.effect_se_file_name = effect_se_file_name; + d.effect_se_file_name = effect_se_file_name; if (!k && kv.read("effect_se_name_list", "length", count)) { - diff.effect_se_name_list.reserve(count); + d.effect_se_name_list.reserve(count); for (int32_t l = 0; l < count; l++) { if (!kv.open_scope(l)) continue; std::string effect_se_name; if (kv.read(effect_se_name)) - diff.effect_se_name_list.push_back(effect_se_name); + d.effect_se_name_list.push_back(effect_se_name); kv.close_scope(); } kv.close_scope(); @@ -1444,28 +1452,28 @@ namespace pv_db { if (k) { int32_t version; if (kv.read("version", version)) - diff.version = version; + d.version = version; int32_t script_format; if (kv.read("version", script_format)) - diff.script_format = script_format; + d.script_format = script_format; } int32_t high_speed_rate; if (kv.read("high_speed_rate", high_speed_rate)) - diff.high_speed_rate = high_speed_rate; + d.high_speed_rate = high_speed_rate; float_t hidden_timing; if (kv.read("hidden_timing", hidden_timing)) - diff.hidden_timing = hidden_timing; + d.hidden_timing = hidden_timing; float_t sudden_timing; if (kv.read("sudden_timing", sudden_timing)) - diff.sudden_timing = sudden_timing; + d.sudden_timing = sudden_timing; int32_t edit_chara_scale; if (kv.read("edit_chara_scale", edit_chara_scale)) - diff.edit_chara_scale = edit_chara_scale == 1; + d.edit_chara_scale = edit_chara_scale == 1; for (int32_t l = 0; l < ROB_CHARA_COUNT; l++) { if (!kv.open_scope("performer.%d.pv_costume", l)) @@ -1473,12 +1481,12 @@ namespace pv_db { int32_t pv_costume; if (kv.read(pv_costume)) - pv_costumes[l][diff.difficulty] = pv_costume - 1; + pv_costumes[l][d.difficulty] = pv_costume - 1; kv.close_scope(); } } - pv->difficulty[i].push_back(diff); + diff.push_back(d); kv.close_scope(); } @@ -1849,63 +1857,63 @@ namespace pv_db { if (kv.read("light_frame", field.light_frame)) field.light_frame_set = true; - for (int32_t l = 0; l < 4; l++) { + for (int32_t l = 0; l < PV_AET_MAX; l++) { std::string aet; if (kv.read(aet_names[l], aet)) - field.aet[l].push_back(aet); + field.aet.name[l].push_back(aet); int32_t count; if (kv.read(aet_list_names[l], "length", count)) { - field.aet[l].reserve(count); + field.aet.name[l].reserve(count); for (int32_t m = 0; m < count; m++) { if (!kv.open_scope(m)) continue; std::string aet; if (kv.read(aet)) - field.aet[l].push_back(aet); + field.aet.name[l].push_back(aet); kv.close_scope(); } kv.close_scope(); } } - for (int32_t l = 0; l < 4; l++) { + for (int32_t l = 0; l < PV_AET_MAX; l++) { std::string aet_id; if (kv.read(aet_id_names[l], aet_id)) - field.aet_id[l].push_back(aet_id); + field.aet.id[l].push_back(aet_id); int32_t count; if (kv.read(aet_id_list_names[l], "length", count)) { - field.aet_id[l].reserve(count); + field.aet.id[l].reserve(count); for (int32_t m = 0; m < count; m++) { if (!kv.open_scope(m)) continue; std::string aet_id; if (kv.read(aet_id)) - field.aet[l].push_back(aet_id); + field.aet.id[l].push_back(aet_id); kv.close_scope(); } kv.close_scope(); } } - for (int32_t l = 0; l < 4; l++) { + for (int32_t l = 0; l < PV_AET_MAX; l++) { int32_t aet_frame; if (kv.read(aet_id_names[l], aet_frame)) - field.aet_frame[l].push_back(aet_frame); + field.aet.frame[l].push_back(aet_frame); int32_t count; if (kv.read(aet_id_list_names[l], "length", count)) { - field.aet_frame[l].reserve(count); + field.aet.frame[l].reserve(count); for (int32_t m = 0; m < count; m++) { if (!kv.open_scope(m)) continue; int32_t aet_frame; if (kv.read(aet_frame)) - field.aet_frame[l].push_back(aet_frame); + field.aet.frame[l].push_back(aet_frame); kv.close_scope(); } kv.close_scope(); @@ -1986,6 +1994,10 @@ namespace pv_db { } } +void task_pv_db_init() { + task_pv_db = new pv_db::TaskPvDB; +} + bool task_pv_db_append_task() { return app::TaskWork::AppendTask(task_pv_db_get(), "PV DB"); } @@ -1995,7 +2007,7 @@ void task_pv_db_free_task() { } pv_db::TaskPvDB* task_pv_db_get() { - return &task_pv_db; + return task_pv_db; } uint32_t task_pv_db_get_paths_count() { @@ -2031,3 +2043,7 @@ pv_db_pv_difficulty* task_pv_db_get_pv_difficulty(int32_t pv_id, bool task_pv_db_is_paths_empty() { return !task_pv_db_get()->paths.size(); } + +void task_pv_db_free() { + delete task_pv_db; +} diff --git a/src/CRE/pv_db.hpp b/src/CRE/pv_db.hpp index 8e718206..f8f7cf82 100644 --- a/src/CRE/pv_db.hpp +++ b/src/CRE/pv_db.hpp @@ -12,9 +12,17 @@ #include #include "../KKdLib/default.hpp" #include "../KKdLib/key_val.hpp" -#include "rob.hpp" +#include "rob/rob.hpp" #include "task.hpp" +enum pv_aet { + PV_AET_FRONT = 0x00, + PV_AET_FRONT_LOW = 0x01, + PV_AET_FRONT_3D_SURF = 0x02, + PV_AET_BACK = 0x03, + PV_AET_MAX = 0x04, +}; + enum pv_attribute_type { PV_ATTRIBUTE_ORIGINAL = 0x00, PV_ATTRIBUTE_EXTRA = 0x01, @@ -71,6 +79,14 @@ enum pv_level { PV_LV_MAX = 0x15, }; +enum pv_performer_item { + PV_PERFORMER_ITEM_ZUJO = 0x00, + PV_PERFORMER_ITEM_FACE = 0x01, + PV_PERFORMER_ITEM_NECK = 0x02, + PV_PERFORMER_ITEM_BACK = 0x03, + PV_PERFORMER_ITEM_MAX = 0x04, +}; + enum pv_performer_size { PV_PERFORMER_NORMAL = 0x00, PV_PERFORMER_PLAY_CHARA = 0x01, @@ -106,12 +122,12 @@ struct pv_db_pv_performer { pv_performer_type type; int32_t chara; int32_t costume; - int32_t pv_costume[5]; + int32_t pv_costume[PV_DIFFICULTY_MAX]; bool fixed; int32_t exclude; pv_performer_size size; int32_t pseudo_same_id; - int32_t item[4]; + int32_t item[PV_PERFORMER_ITEM_MAX]; pv_db_pv_performer(); @@ -137,6 +153,17 @@ struct pv_db_pv_motion { ~pv_db_pv_motion(); }; +struct pv_db_pv_field_aet { + std::vector name[PV_AET_MAX]; + std::vector id[PV_AET_MAX]; + std::vector frame[PV_AET_MAX]; + + pv_db_pv_field_aet(); + ~pv_db_pv_field_aet(); + + void reset(); +}; + struct pv_db_pv_field { int32_t index; int32_t stage_index; @@ -147,9 +174,7 @@ struct pv_db_pv_field { std::string light; int32_t light_frame; bool light_frame_set; - std::vector aet[4]; - std::vector aet_id[4]; - std::vector aet_frame[4]; + pv_db_pv_field_aet aet; std::string spr_set_back; bool stage_flag; int32_t npr_type; @@ -263,9 +288,6 @@ struct pv_db_pv_difficulty { pv_db_pv_field_parent field; std::vector pv_item; std::vector hand_item; - std::vector field_228; - std::vector field_240; - std::vector field_258; std::vector edit_effect; pv_db_pv_title_image title_image; pv_db_pv_songinfo songinfo; @@ -506,6 +528,7 @@ namespace pv_db { }; } +extern void task_pv_db_init(); extern bool task_pv_db_append_task(); extern void task_pv_db_free_task(); extern pv_db::TaskPvDB* task_pv_db_get(); @@ -516,3 +539,4 @@ extern pv_db_pv_difficulty* task_pv_db_get_pv_difficulty(int32_t pv_id, extern pv_db_pv_difficulty* task_pv_db_get_pv_difficulty(int32_t pv_id, int32_t difficulty, int32_t edition); extern bool task_pv_db_is_paths_empty(); +extern void task_pv_db_free(); diff --git a/src/CRE/pv_param.hpp b/src/CRE/pv_param.hpp index a2bab6a4..6a6aa3bf 100644 --- a/src/CRE/pv_param.hpp +++ b/src/CRE/pv_param.hpp @@ -10,8 +10,8 @@ #include #include "../KKdLib/default.hpp" #include "../KKdLib/vec.hpp" +#include "rob/rob.hpp" #include "light_param.hpp" -#include "rob.hpp" #include "task.hpp" namespace pv_param { diff --git a/src/CRE/render_context.cpp b/src/CRE/render_context.cpp index 6966e3a7..fc9b6ced 100644 --- a/src/CRE/render_context.cpp +++ b/src/CRE/render_context.cpp @@ -5,11 +5,11 @@ #include "render_context.hpp" #include "Glitter/glitter.hpp" -#include "draw_pass.h" -#include "draw_task.h" +#include "rob/rob.hpp" +#include "draw_pass.hpp" +#include "draw_task.hpp" #include "file_handler.hpp" -#include "rob.hpp" -#include "shader_ft.h" +#include "shader_ft.hpp" #include "stage.hpp" float_t delta_frame_history = 0; @@ -27,22 +27,19 @@ sss_data::sss_data() : init(), enable(), npr_contour(), param() { npr_contour = true; param = { 0.0f, 0.0f, 0.0f, 1.0f }; - render_texture_init(&textures[0], 640, 360, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); - render_texture_init(&textures[1], 320, 180, 0, GL_RGBA16F, GL_ZERO); - render_texture_init(&textures[2], 320, 180, 0, GL_RGBA16F, GL_ZERO); - render_texture_init(&textures[3], 320, 180, 0, GL_RGBA16F, GL_ZERO); + textures[0].init(640, 360, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); + textures[1].init(320, 180, 0, GL_RGBA16F, GL_ZERO); + textures[2].init(320, 180, 0, GL_RGBA16F, GL_ZERO); + textures[3].init(320, 180, 0, GL_RGBA16F, GL_ZERO); } sss_data::~sss_data() { - render_texture_free(&textures[0]); - render_texture_free(&textures[1]); - render_texture_free(&textures[2]); - render_texture_free(&textures[3]); + } -draw_pass::draw_pass() : reflect_blur_num(), reflect_blur_filter(), wait_for_gpu(), time(), -reflect_type(), show_vector_flags(), show_vector_length(), show_vector_z_offset(), field_2F8(), -sss_texture(), npr_param(), field_31C(), field_31E(), field_31F(), field_320(), npr() { +draw_pass::draw_pass() :enable(), reflect_blur_num(), reflect_blur_filter(), wait_for_gpu(), cpu_time(), gpu_time(), +time(), draw_pass_3d(), reflect_type(), show_vector_flags(), show_vector_length(), show_vector_z_offset(), +field_2F8(), sss_texture(), npr_param(), field_31C(), field_31D(), field_31E(), field_31F(), field_320(), npr() { for (bool& i : enable) i = true; reflect = true; @@ -52,19 +49,14 @@ sss_texture(), npr_param(), field_31C(), field_31E(), field_31F(), field_320(), alpha_z_sort = true; for (bool& i : draw_pass_3d) i = true; - render_texture_init(&reflect_texture, 512, 256, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); - render_texture_init(&refract_texture, 512, 256, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); - memset(cpu_time, 0, sizeof(cpu_time)); - memset(gpu_time, 0, sizeof(gpu_time)); - time_struct_init(&time); + reflect_texture.init(512, 256, 0, GL_RGBA16F, GL_DEPTH24_STENCIL8); + refract_texture.init(512, 256, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); shadow_ptr = new ::shadow; if (shadow_ptr) shadow_ptr->init_data(); } draw_pass::~draw_pass() { - render_texture_free(&reflect_texture); - render_texture_free(&refract_texture); delete shadow_ptr; } @@ -97,26 +89,20 @@ texture_transform_struct::texture_transform_struct(uint32_t id, mat4u& mat) : id } light_proj::light_proj(int32_t width, int32_t height) : enable(), texture_id() { - render_texture_init(&shadow_texture[0], - 2048, 512, 0, GL_R32F, GL_DEPTH24_STENCIL8); - render_texture_init(&shadow_texture[1], - 2048, 512, 0, GL_R32F, GL_ZERO); - render_texture_init(&draw_texture, - width, height, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); + shadow_texture[0].init(2048, 512, 0, GL_R32F, GL_DEPTH24_STENCIL8); + shadow_texture[1].init(2048, 512, 0, GL_R32F, GL_ZERO); + draw_texture.init(width, height, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); } light_proj::~light_proj() { - render_texture_free(&shadow_texture[0]); - render_texture_free(&shadow_texture[1]); - render_texture_free(&draw_texture); + } void light_proj::resize(int32_t width, int32_t height) { if (!this) return; - render_texture_init(&draw_texture, - width, height, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); + draw_texture.init(width, height, 0, GL_RGBA8, GL_DEPTH24_STENCIL8); } bool light_proj::set(render_context* rctx) { @@ -125,7 +111,7 @@ bool light_proj::set(render_context* rctx) { static const GLfloat depth_clear = 1.0f; - render_texture_bind(&shadow_texture[0], 0); + shadow_texture[0].bind(); glViewport(0, 0, 2048, 512); gl_state_enable_depth_test(); gl_state_set_depth_mask(GL_TRUE); @@ -138,7 +124,7 @@ bool light_proj::set(render_context* rctx) { return true; } else { - render_texture_bind(&draw_texture, 0); + draw_texture.bind(); glViewport(0, 0, draw_texture.color_texture->width, draw_texture.color_texture->height); gl_state_enable_depth_test(); @@ -177,34 +163,30 @@ void light_proj::get_proj_mat(vec3* view_point, vec3* interest, float_t fov, mat } bool light_proj::set_mat(render_context* rctx, bool set_mat) { - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; + light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; light_data* data = &set->lights[LIGHT_PROJECTION]; - if (light_get_type(data) != LIGHT_SPOT) + if (data->get_type() != LIGHT_SPOT) return false; vec3 position; vec3 spot_direction; - light_get_position(data, &position); - light_get_spot_direction(data, &spot_direction); + data->get_position(position); + data->get_spot_direction(spot_direction); float_t length; vec3_length_squared(spot_direction, length); if (length <= 0.000001f) return false; - float_t spot_cutoff = light_get_spot_cutoff(data); + float_t spot_cutoff = data->get_spot_cutoff(); float_t fov = atanf(tanf(spot_cutoff * DEG_TO_RAD_FLOAT) * 0.25f) * (RAD_TO_DEG_FLOAT * 2.0f); vec3 interest; vec3_add(position, spot_direction, interest); if (set_mat) { - union { - mat4 m; - vec4 v[4]; - } mat; - - get_proj_mat(&position, &interest, fov, &mat.m); - shaders_ft.env_vert_set(24, 4, mat.v); + mat4 mat; + get_proj_mat(&position, &interest, fov, &mat); + shaders_ft.env_vert_set(24, 4, &mat.row0); } else get_proj_mat(&position, &interest, fov, 0); @@ -466,13 +448,16 @@ extern render_context* rctx_ptr; render_context::render_context() : litproj(), data(), chara_reflect(), chara_refract(), view_mat(), matrix_buffer() { - camera = camera_init(); + camera = new ::camera; draw_state_init(&draw_state); glGenVertexArrays(1, &vao); } render_context::~render_context() { - camera_dispose(camera); + if (camera) { + delete camera; + camera = 0; + } glDeleteVertexArrays(1, &vao); } @@ -535,49 +520,43 @@ void render_context::disp() { void render_context::light_param_data_light_set(light_param_light * light) { for (int32_t i = LIGHT_SET_MAIN; i < LIGHT_SET_MAX; i++) { light_param_light_group* group = &light->group[i]; - light_set* set = &light_set_data[i]; + ::light_set* set = &light_set[i]; for (int32_t j = LIGHT_CHARA; j < LIGHT_MAX; j++) { light_param_light_data* data = &group->data[j]; light_data* light = &set->lights[j]; if (data->has_type) - light_set_type(light, data->type); + light->set_type(data->type); - if (data->has_ambient) { - vec4 ambient = data->ambient; - light_set_ambient(light, &ambient); - } + if (data->has_ambient) + light->set_ambient(data->ambient); - if (data->has_diffuse) { - vec4 diffuse = data->diffuse; - light_set_diffuse(light, &diffuse); - } + if (data->has_diffuse) + light->set_diffuse(data->diffuse); - if (data->has_specular) { - vec4 specular = data->specular; - light_set_specular(light, &specular); - } + if (data->has_specular) + light->set_specular(data->specular); if (data->has_position) - light_set_position(light, &data->position); + light->set_position(data->position); if (data->has_spot_direction) - light_set_spot_direction(light, &data->spot_direction); + light->set_spot_direction(data->spot_direction); if (data->has_spot_exponent) - light_set_spot_exponent(light, data->spot_exponent); + light->set_spot_exponent(data->spot_exponent); if (data->has_spot_cutoff) - light_set_spot_cutoff(light, data->spot_cutoff); + light->set_spot_cutoff(data->spot_cutoff); if (data->has_attenuation) - light_set_attenuation(light, &data->attenuation); + light->set_attenuation(data->attenuation); - light_set_clip_plane(light, data->clip_plane); + light->set_clip_plane(data->clip_plane); if (data->has_tone_curve) - light_set_tone_curve(light, &data->tone_curve); + light->set_tone_curve(data->tone_curve); } } } @@ -585,23 +564,21 @@ void render_context::light_param_data_light_set(light_param_light * light) { void render_context::light_param_data_fog_set(light_param_fog* f) { for (int32_t i = FOG_DEPTH; i < FOG_MAX; i++) { light_param_fog_group* group = &f->group[i]; - fog* fog = &fog_data[i]; + ::fog* fog = &this->fog[i]; if (group->has_type) - fog_set_type(fog, group->type); + fog->set_type(group->type); if (group->has_density) - fog_set_density(fog, group->density); + fog->set_density(group->density); if (group->has_linear) { - fog_set_start(fog, group->linear_start); - fog_set_end(fog, group->linear_end); + fog->set_start(group->linear_start); + fog->set_end(group->linear_end); } - if (group->has_color) { - vec4 color = group->color; - fog_set_color(fog, &color); - } + if (group->has_color) + fog->set_color(group->color); } } @@ -684,43 +661,30 @@ void render_context::light_param_data_ibl_set( } gl_state_bind_texture_cube_map(0); - light_set* set = &light_set_data[LIGHT_SET_MAIN]; - mat4 irradiance[3]; - irradiance[0] = ibl->diff_coef[1][0]; - irradiance[1] = ibl->diff_coef[1][1]; - irradiance[2] = ibl->diff_coef[1][2]; - light_set_set_irradiance(set, &irradiance[0], &irradiance[1], &irradiance[2]); + ::light_set* set = &light_set[LIGHT_SET_MAIN]; + set->set_irradiance(ibl->diff_coef[1][0], ibl->diff_coef[1][1], ibl->diff_coef[1][2]); float_t len; vec3 pos; light_data* l = &set->lights[LIGHT_CHARA]; - light_get_position(l, &pos); + l->get_position(pos); vec3_length(pos, len); - if (fabsf(len - 1.0f) < 0.02f) { - vec4 position = ibl->lit_dir[0]; - light_set_position_vec4(l, &position); - } + if (fabsf(len - 1.0f) < 0.02f) + l->set_position(ibl->lit_dir[0]); - vec4 ibl_specular = ibl->lit_col[0]; - light_set_ibl_specular(l, &ibl_specular); - vec4 ibl_back = ibl->lit_col[2]; - light_set_ibl_back(l, &ibl_back); - vec4 ibl_direction = ibl->lit_dir[0]; - light_set_ibl_direction(l, &ibl_direction); + l->set_ibl_specular(ibl->lit_col[0]); + l->set_ibl_back(ibl->lit_col[2]); + l->set_ibl_direction(ibl->lit_dir[0]); l = &set->lights[LIGHT_STAGE]; - light_get_position(l, &pos); + l->get_position(pos); vec3_length(pos, len); - if (fabsf(len - 1.0f) < 0.02f) { - vec4 position = ibl->lit_dir[1]; - light_set_position_vec4(l, &position); - } + if (fabsf(len - 1.0f) < 0.02f) + l->set_position(ibl->lit_dir[1]); - ibl_specular = ibl->lit_col[1]; - light_set_ibl_specular(l, &ibl_specular); - ibl_direction = ibl->lit_dir[1]; - light_set_ibl_direction(l, &ibl_specular); + l->set_ibl_specular(ibl->lit_col[1]); + l->set_ibl_direction(ibl->lit_dir[1]); } void render_context::light_param_data_wind_set(light_param_wind* w) { @@ -791,8 +755,7 @@ field_1A8(), view_point_shared(), interest_shared(), field_2F0() { } shadow::~shadow() { - for (render_texture& i : field_8) - render_texture_free(&i); + } void shadow::ctrl(render_context* rctx) { @@ -803,18 +766,18 @@ void shadow::ctrl(render_context* rctx) { view_mat[0] = rctx->camera->view; view_mat[1] = rctx->camera->inv_view; - light_set* set = &rctx->light_set_data[LIGHT_SET_MAIN]; + ::light_set* set = &rctx->light_set[LIGHT_SET_MAIN]; light_data* data = &set->lights[LIGHT_CHARA]; - vec3 direction; + vec3 position; float_t length; - light_get_position(data, &direction); - vec3_negate(direction, direction); - vec3_length(direction, length); + data->get_position(position); + vec3_negate(position, position); + vec3_length(position, length); if (length < 0.000001) - this->direction = { 0.0f, 1.0f, 0.0f }; + direction = { 0.0f, 1.0f, 0.0f }; else - vec3_mult_scalar(direction, 1.0f / length, this->direction); + vec3_mult_scalar(position, 1.0f / length, direction); for (int32_t i = 0; i < 2; i++) if (draw_task_get_count(rctx, (draw_object_type)((int32_t)DRAW_OBJECT_SHADOW_CHARA + i))) @@ -1112,7 +1075,7 @@ int32_t shadow::init_data() { shadow_texture_init_params* v3 = init_params; for (int32_t i = 0; i < 7; i++, v3++) - if (render_texture_init(&field_8[i], v3->width, v3->height, + if (field_8[i].init(v3->width, v3->height, v3->max_level, v3->color_format, v3->depth_format) < 0) return -1; diff --git a/src/CRE/render_context.hpp b/src/CRE/render_context.hpp index ef7822e2..bf7bef70 100644 --- a/src/CRE/render_context.hpp +++ b/src/CRE/render_context.hpp @@ -12,17 +12,16 @@ #include "light_param/light.hpp" #include "light_param/wind.hpp" #include "light_param.hpp" -#include "camera.h" +#include "camera.hpp" #include "data.hpp" -#include "gl_state.h" +#include "gl_state.hpp" #include "light_param.hpp" #include "object.hpp" #include "post_process.hpp" -#include "render_texture.h" +#include "render_texture.hpp" #include "task.hpp" -#include "time.h" -#include "timer.h" -#include "static_var.h" +#include "time.hpp" +#include "static_var.hpp" #define MATRIX_BUFFER_COUNT 320 #define MATERIAL_LIST_COUNT 24 @@ -499,9 +498,9 @@ struct render_context { GLuint vao; face face; - fog fog_data[FOG_MAX]; + fog fog[FOG_MAX]; light_proj* litproj; - light_set light_set_data[LIGHT_SET_MAX]; + light_set light_set[LIGHT_SET_MAX]; data_struct* data; post_process post_process; diff --git a/src/CRE/render_texture.c b/src/CRE/render_texture.cpp similarity index 77% rename from src/CRE/render_texture.c rename to src/CRE/render_texture.cpp index 25f23400..1e723f64 100644 --- a/src/CRE/render_texture.c +++ b/src/CRE/render_texture.cpp @@ -3,8 +3,8 @@ GitHub/GitLab: korenkonder */ -#include "render_texture.h" -#include "gl_state.h" +#include "render_texture.hpp" +#include "gl_state.hpp" #include "texture.hpp" static shader_glsl render_texture_shader; @@ -21,7 +21,59 @@ depth_texture(), binding(), max_level(), fbos(), rbo(), field_2C() { } -int32_t render_texture_init(render_texture* rt, int32_t width, int32_t height, +render_texture::~render_texture() { + free_data(); +} + +int32_t render_texture::bind(int32_t index) { + if (index < 0 || index > max_level) + return -1; + + gl_state_bind_framebuffer(fbos[index]); + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) + return -1; + glGetError(); + return 0; +} + +void render_texture::draw(bool depth) { + gl_state_active_bind_texture_2d(0, color_texture->tex); + if (depth && depth_texture->tex) + gl_state_active_bind_texture_2d(1, depth_texture->tex); + gl_state_bind_vertex_array(render_texture_vao); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); + gl_state_bind_vertex_array(0); +} + +void render_texture::free_data() { + if (depth_texture) { + texture_free(depth_texture); + depth_texture = 0; + } + + if (color_texture) { + texture_free(color_texture); + color_texture = 0; + } + + if (rbo) { + glDeleteRenderbuffers(1, &rbo); + rbo = 0; + } + + if (field_2C) { + glDeleteRenderbuffers(1, &field_2C); + field_2C = 0; + } + + if (fbos[0]) { + glDeleteFramebuffers(max_level + 1, fbos); + memset(fbos, 0, sizeof(fbos)); + } + max_level = 0; +} + +int32_t render_texture::init(int32_t width, int32_t height, int32_t max_level, GLenum color_format, GLenum depth_format) { if (max_level < 0) return -1; @@ -29,18 +81,18 @@ int32_t render_texture_init(render_texture* rt, int32_t width, int32_t height, max_level = min(max_level, 15); if (max_level < 0) return 0; - render_texture_free(rt); + free_data(); GLuint color_texture; if (color_format) { - rt->color_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter), + this->color_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter), color_format, width, height, max_level, 0, 0); - if (!rt->color_texture) + if (!this->color_texture) return -1; render_texture_counter++; - color_texture = rt->color_texture->tex; - gl_state_bind_texture_2d(rt->color_texture->tex); + color_texture = this->color_texture->tex; + gl_state_bind_texture_2d(this->color_texture->tex); if (color_format == GL_RGBA32F) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); @@ -50,70 +102,61 @@ int32_t render_texture_init(render_texture* rt, int32_t width, int32_t height, gl_state_bind_texture_2d(0); } else { - rt->color_texture = 0; + this->color_texture = 0; color_texture = 0; } GLuint depth_texture; bool stencil; if (depth_format) { - rt->depth_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter), + this->depth_texture = texture_load_tex_2d(texture_id(0x23, render_texture_counter), depth_format, width, height, 0, 0, 0); - if (!rt->depth_texture) + if (!this->depth_texture) return -1; render_texture_counter++; - depth_texture = rt->depth_texture->tex; + depth_texture = this->depth_texture->tex; stencil = depth_format == GL_DEPTH24_STENCIL8; } else { - rt->depth_texture = 0; + this->depth_texture = 0; depth_texture = 0; stencil = false; } - rt->max_level = max_level; + this->max_level = max_level; - if (render_texture_framebuffer_init(rt, max_level) >= 0) { + if (render_texture_framebuffer_init(this, max_level) >= 0) { for (int32_t i = 0; i <= max_level; i++) - if (render_texture_framebuffer_set_texture(rt, color_texture, i, depth_texture, stencil) < 0) + if (render_texture_framebuffer_set_texture(this, color_texture, i, depth_texture, stencil) < 0) return -1; } return 0; } -int32_t render_texture_bind(render_texture* rt, int32_t index) { - if (index < 0 || index > rt->max_level) - return -1; - - gl_state_bind_framebuffer(rt->fbos[index]); - if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) - return -1; - glGetError(); - return 0; +int32_t render_texture::set_color_depth_textures(GLuint color_texture, + int32_t max_level, GLuint depth_texture, bool stencil) { + int32_t error = 0; + this->max_level = max_level; + if (!fbos[0]) + error = render_texture_framebuffer_init(this, max_level); + render_texture_framebuffer_set_texture(this, color_texture, max_level, depth_texture, stencil); + return error; } -inline void render_texture_draw(render_texture* rt, bool depth) { - gl_state_active_bind_texture_2d(0, rt->color_texture->tex); - if (depth && rt->depth_texture->tex) - gl_state_active_bind_texture_2d(1, rt->depth_texture->tex); - gl_state_bind_vertex_array(render_texture_vao); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); - gl_state_bind_vertex_array(0); -} -inline void render_texture_draw_custom(shader_set_data* set) { +void render_texture::draw_custom(shader_set_data* set) { gl_state_bind_vertex_array(render_texture_vao); set->draw_arrays(GL_TRIANGLE_STRIP, 0, 3); gl_state_bind_vertex_array(0); } -inline void render_texture_draw_custom_glsl() { +void render_texture::draw_custom_glsl() { gl_state_bind_vertex_array(render_texture_vao); glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); gl_state_bind_vertex_array(0); } -void render_texture_draw_params(shader_set_data* set, int32_t width, int32_t height, +void render_texture::draw_params(shader_set_data* set, int32_t width, int32_t height, float_t scale, float_t param_x, float_t param_y, float_t param_z, float_t param_w) { float_t w = (float_t)max(width, 1); float_t h = (float_t)max(height, 1); @@ -127,58 +170,20 @@ void render_texture_draw_params(shader_set_data* set, int32_t width, int32_t hei gl_state_bind_vertex_array(0); } -int32_t render_texture_set_color_depth_textures(render_texture* rt, - GLuint color_texture, int32_t level, GLuint depth_texture, bool stencil) { - int32_t error = 0; - rt->max_level = level; - if (!rt->fbos[0]) - error = render_texture_framebuffer_init(rt, level); - render_texture_framebuffer_set_texture(rt, color_texture, level, depth_texture, stencil); - return error; -} - -inline void render_texture_shader_set(shader_set_data* set, uint32_t index) { +void render_texture::shader_set(shader_set_data* set, uint32_t index) { if (set && index) set->set(index); else render_texture_shader.use(); } -inline void render_texture_shader_set_glsl(shader_glsl* shader) { +void render_texture::shader_set_glsl(shader_glsl* shader) { if (shader) shader->use(); else render_texture_shader.use(); } -void render_texture_free(render_texture* rt) { - if (rt->depth_texture) { - texture_free(rt->depth_texture); - rt->depth_texture = 0; - } - - if (rt->color_texture) { - texture_free(rt->color_texture); - rt->color_texture = 0; - } - - if (rt->rbo) { - glDeleteRenderbuffers(1, &rt->rbo); - rt->rbo = 0; - } - - if (rt->field_2C) { - glDeleteRenderbuffers(1, &rt->field_2C); - rt->field_2C = 0; - } - - if (rt->fbos[0]) { - glDeleteFramebuffers(rt->max_level + 1, rt->fbos); - memset(rt->fbos, 0, sizeof(rt->fbos)); - } - rt->max_level = 0; -} - void render_texture_data_init() { if (!render_texture_data_initialized) { static const char* render_texture_vert_shader = diff --git a/src/CRE/render_texture.h b/src/CRE/render_texture.h deleted file mode 100644 index 9896a397..00000000 --- a/src/CRE/render_texture.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include "shared.h" -#include "shader.h" -#include "shader_glsl.hpp" -#include "texture.hpp" - -struct render_texture { - texture* color_texture; - texture* depth_texture; - int32_t binding; - int32_t max_level; - GLuint fbos[16]; - GLuint rbo; - GLuint field_2C; - - render_texture(); -}; - -extern int32_t render_texture_init(render_texture* rt, int32_t width, int32_t height, - int32_t max_level, GLenum color_format, GLenum depth_format); -extern int32_t render_texture_bind(render_texture* rt, int32_t index); -extern void render_texture_draw(render_texture* rt, bool depth); -extern void render_texture_draw_custom(shader_set_data* set); -extern void render_texture_draw_custom_glsl(); -extern void render_texture_draw_params(shader_set_data* set, int32_t width, int32_t height, - float_t scale, float_t param_x, float_t param_y, float_t param_z, float_t param_w); -extern int32_t render_texture_set_color_depth_textures(render_texture* rt, - GLuint color_texture, int32_t level, GLuint depth_texture, bool stencil); -extern void render_texture_shader_set(shader_set_data* set, uint32_t index); -extern void render_texture_shader_set_glsl(shader_glsl* shader); -extern void render_texture_free(render_texture* rt); -extern void render_texture_data_init(); -extern void render_texture_data_free(); diff --git a/src/CRE/render_texture.hpp b/src/CRE/render_texture.hpp new file mode 100644 index 00000000..9d3d4245 --- /dev/null +++ b/src/CRE/render_texture.hpp @@ -0,0 +1,42 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "shared.hpp" +#include "shader.hpp" +#include "shader_glsl.hpp" +#include "texture.hpp" + +struct render_texture { + texture* color_texture; + texture* depth_texture; + int32_t binding; + int32_t max_level; + GLuint fbos[16]; + GLuint rbo; + GLuint field_2C; + + render_texture(); + ~render_texture(); + + int32_t bind(int32_t index = 0); + void draw(bool depth = false); + void free_data(); + int32_t init(int32_t width, int32_t height, + int32_t max_level, GLenum color_format, GLenum depth_format); + int32_t set_color_depth_textures(GLuint color_texture, + int32_t max_level, GLuint depth_texture, bool stencil); + + static void draw_custom(shader_set_data* set); + static void draw_custom_glsl(); + static void draw_params(shader_set_data* set, int32_t width, int32_t height, + float_t scale, float_t param_x, float_t param_y, float_t param_z, float_t param_w); + static void shader_set(shader_set_data* set, uint32_t index); + static void shader_set_glsl(shader_glsl* shader); +}; + +extern void render_texture_data_init(); +extern void render_texture_data_free(); diff --git a/src/CRE/rob/ex_block.cpp b/src/CRE/rob/ex_block.cpp new file mode 100644 index 00000000..18980c2a --- /dev/null +++ b/src/CRE/rob/ex_block.cpp @@ -0,0 +1,4661 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "rob.hpp" +#include "../../KKdLib/key_val.hpp" +#include "../../KKdLib/str_utils.hpp" +#include "../draw_task.hpp" + +struct osage_setting { + std::map, osage_setting_osg_cat> cat; + std::map obj; + + osage_setting(); + ~osage_setting(); + + void parse(key_val* kv); + rob_osage_parts parse_parts_string(std::string* s); +}; + +struct exp_func_op1 { + const char* name; + float_t(*func)(float_t v1); +}; + +struct exp_func_op2 { + const char* name; + float_t(*func)(float_t v1, float_t v2); +}; + +struct exp_func_op3 { + const char* name; + float_t(*func)(float_t v1, float_t v2, float_t v3); +}; + +static float_t ex_expression_block_stack_get_value(ex_expression_block_stack* stack); + +static float_t exp_abs(float_t v1); +static float_t exp_acos(float_t v1); +static float_t exp_add(float_t v1, float_t v2); +static float_t exp_and(float_t v1, float_t v2); +static float_t exp_asin(float_t v1); +static float_t exp_atan(float_t v1); +static float_t exp_av(float_t v1); +static float_t exp_ceil(float_t v1); +static float_t exp_cond(float_t v1, float_t v2, float_t v3); +static float_t exp_cos(float_t v1); +static float_t exp_div(float_t v1, float_t v2); +static float_t exp_eq(float_t v1, float_t v2); +static float_t exp_exp(float_t v1); +static float_t exp_floor(float_t v1); +static float_t exp_fmod(float_t v1, float_t v2); +static const exp_func_op1* exp_func_op1_find_func(std::string& name, const exp_func_op1* array); +static const exp_func_op2* exp_func_op2_find_func(std::string& name, const exp_func_op2* array); +static const exp_func_op3* exp_func_op3_find_func(std::string& name, const exp_func_op3* array); +static float_t exp_ge(float_t v1, float_t v2); +static float_t exp_gt(float_t v1, float_t v2); +static float_t exp_le(float_t v1, float_t v2); +static float_t exp_log(float_t v1); +static float_t exp_lt(float_t v1, float_t v2); +static float_t exp_max(float_t v1, float_t v2); +static float_t exp_min(float_t v1, float_t v2); +static float_t exp_mul(float_t v1, float_t v2); +static float_t exp_ne(float_t v1, float_t v2); +static float_t exp_neg(float_t v1); +static float_t exp_or(float_t v1, float_t v2); +static float_t exp_pow(float_t v1, float_t v2); +static float_t exp_rand(float_t v1, float_t v2, float_t v3); +static float_t exp_rand_0_1(float_t v1); +static float_t exp_round(float_t v1); +static float_t exp_sin(float_t v1); +static float_t exp_sqrt(float_t v1); +static float_t exp_sub(float_t v1, float_t v2); +static float_t exp_tan(float_t v1); + +static const osage_setting_osg_cat* osage_setting_data_get_cat_value( + object_info* obj_info, const char* root_node); + +static void sub_140218560(RobCloth* rob_cls, float_t step, bool a3); +static void sub_1402187D0(RobCloth* rob_cls, bool a2); +static void sub_1402196D0(RobCloth* rob_cls); +static void sub_140219940(RobCloth* rob_cls); +static void sub_140219D10(RobCloth* rob_cls); +static float_t sub_14021A290(vec3& a1, vec3& a2, vec3& a3, vec2& a4, vec2& a5, vec2& a6, + vec3& tangent, vec3& binormal, vec3& normal); +static float_t sub_14021A5E0(vec3& a1, vec3& a2, float_t a3, float_t a4, vec3& tangent, vec3& binormal, vec3& normal); +static void sub_14021A890(CLOTHNode* a1, CLOTHNode* a2, CLOTHNode* a3, CLOTHNode* a4, CLOTHNode* a5); +static void sub_14021AA60(RobCloth* rob_cls, float_t step, bool a3); +static void sub_14021D480(RobCloth* rob_cls); +static void sub_14021DC60(RobCloth* rob_cls, float_t step); +static void sub_14021D840(RobCloth* rob_cls); +static void sub_14047C800(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, + float_t step, bool disable_wind, bool ring_coli, bool has_children_node); +static void sub_14047E1C0(RobOsage* rob_osg, vec3* scale); +static void sub_14047EE90(RobOsage* rob_osg, mat4* mat); +static void sub_14047F110(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, bool init_rot); +static void sub_1404803B0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, bool has_children_node); +static void sub_140482180(RobOsageNode* node, float_t a2); +static void sub_140482300(vec3* a1, vec3* a2, vec3* a3, float_t osage_gravity_const, float_t weight); +static void sub_140482490(RobOsageNode* node, float_t step, float_t a3); +static void sub_140482F30(vec3* pos1, vec3* pos2, float_t length); +static int32_t sub_140483B30(vec3* a1, vec3* a2, osage_coli* a3, float_t radius); +static int32_t sub_140483DE0(vec3* a1, vec3* a2, vec3* a3, float_t radius); +static int32_t sub_140483EA0(vec3* a1, vec3* a2, osage_coli* a3, float_t radius); +static int32_t sub_140484540(vec3* a1, vec3* a2, osage_coli* coli, float_t radius); +static int32_t sub_140484780(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius); +static int32_t sub_140485180(osage_coli* a1, vec3* a2, float_t& coli_r); +static int32_t sub_1404851C0(vec3* a1, float_t& coli_r, std::vector* a3, float_t* a4); +static int32_t sub_140485220(vec3* a1, float_t& coli_r, osage_coli* a3, float_t* a4); +static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5); +static void sub_14047C750(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step); +static void sub_14047C770(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5); +static void sub_14047D620(RobOsage* rob_osg, float_t step); +static void sub_14047ECA0(RobOsage* rob_osg, float_t step); +static void sub_14047F990(RobOsage* rob_osg, mat4* a2, vec3* a3, bool a4); +static void sub_140480260(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool v5); +static void sub_140482100(struc_476* a1, opd_blend_data* a2, struc_477* a3); +static void sub_140482DF0(struc_477* dst, struc_477* src0, struc_477* src1, float_t blend); +static bool sub_140482FF0(mat4& mat, vec3& trans, skin_param_hinge* hinge, vec3* rot, int32_t& yz_order); +static int32_t sub_140484450(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius); +static int32_t sub_1404844A0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius); +static int32_t sub_1404844F0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius); +static void sub_140484850(vec3* a1, vec3* a2, vec3* a3, osage_coli* coli); +static void sub_140484E10(vec3* a1, vec3* a2, vec3* a3, vec3* a4); +static int32_t sub_140485000(vec3* a1, vec3* a2, skin_param_osage_node* a3, osage_coli* a4); +static void sub_14053CE30(RobOsageNodeDataNormalRef* normal_ref, mat4* a2); +static bool sub_14053D1B0(vec3* l_trans, vec3* r_trans, + vec3* u_trans, vec3* d_trans, vec3* a5, vec3* a6, vec3* a7); + +static const exp_func_op1 exp_func_op1_array[] = { + { "neg" , exp_neg }, + { "sin" , exp_sin }, + { "cos" , exp_cos }, + { "tan" , exp_tan }, + { "abs" , exp_abs }, + { "sqrt" , exp_sqrt }, + { "av" , exp_av }, + { "floor" , exp_floor }, + { "ceil" , exp_ceil }, + { "round" , exp_round }, + { "asin" , exp_asin }, + { "acos" , exp_acos }, + { "atan" , exp_atan }, + { "log" , exp_log }, + { "exp" , exp_exp }, + { "rand_0_1", exp_rand_0_1 }, + { 0 , 0 }, +}; + +static const exp_func_op2 exp_func_op2_array[] = { + { "+" , exp_add }, + { "-" , exp_sub }, + { "*" , exp_mul }, + { "/" , exp_div }, + { "%" , exp_fmod }, + { "==" , exp_eq }, + { ">" , exp_gt }, + { ">=" , exp_ge }, + { "<" , exp_lt }, + { "<=" , exp_le }, + { "!=" , exp_ne }, + { "&&" , exp_and }, + { "||" , exp_or }, + { "min" , exp_min }, + { "max" , exp_max }, + { "fmod", exp_fmod }, + { "pow" , exp_pow }, + { 0 , 0 }, +}; + +static const exp_func_op3 exp_func_op3_array[] = { + { "rand", exp_rand }, + { "cond", exp_cond }, + { 0 , 0 }, +}; + +osage_setting osage_setting_data; +size_t qword_140FBDF88 = 0; + +static const int32_t rob_cloth_update_vertices_flags = 0x03; +static const bool rob_cloth_update_normals_select = false; + +ExNodeBlock::ExNodeBlock() : bone_node_ptr(), type(), name(), parent_bone_node(), +parent_name(), parent_node(), item_equip_object(), field_58(), field_59(), has_children_node() { + +} + +ExNodeBlock::~ExNodeBlock() { + +} + +void ExNodeBlock::Field_10() { + field_59 = false; +} + +void ExNodeBlock::Reset() { + bone_node_ptr = 0; +} + +void ExNodeBlock::Field_58() { + field_59 = false; +} + +void ExNodeBlock::InitData(bone_node* bone_node, ex_node_type type, + const char* name, rob_chara_item_equip_object* itm_eq_obj) { + bone_node_ptr = bone_node; + this->type = type; + if (name) + this->name = name; + else + this->name = "(null)"; + parent_bone_node = 0; + item_equip_object = itm_eq_obj; +} + +ExNullBlock::ExNullBlock() { + Init(); +} + +ExNullBlock::~ExNullBlock() { + +} + +void ExNullBlock::Init() { + bone_node_ptr = 0; + type = EX_NONE; + name = 0; + parent_bone_node = 0; + item_equip_object = 0; + cns_data = 0; +} + +void ExNullBlock::Field_10() { + field_59 = false; +} + +void ExNullBlock::Field_18(int32_t stage, bool a3) { + +} + +void ExNullBlock::Field_20() { + if (!bone_node_ptr) + return; + + mat4 mat; + mat4 ex_data_mat = *parent_bone_node->ex_data_mat; + bone_node_ptr->exp_data.mat_set(parent_bone_node->exp_data.parent_scale, ex_data_mat, mat); + *bone_node_ptr->ex_data_mat = ex_data_mat; + *bone_node_ptr->mat = mat; +} + +void ExNullBlock::SetOsagePlayData() { + Field_20(); +} + +void ExNullBlock::Disp(mat4* mat, render_context* rctx) { + +} + +void ExNullBlock::Field_40() { + +} + +void ExNullBlock::Field_48() { + Field_20(); +} + +void ExNullBlock::Field_50() { + +} + +void ExNullBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, + obj_skin_block_constraint* cns_data, const char* cns_data_name, bone_database* bone_data) { + bone_node* node = itm_eq_obj->get_bone_node(cns_data_name, bone_data); + type = EX_NONE; + bone_node_ptr = node; + this->cns_data = cns_data; + name = node->name; + item_equip_object = itm_eq_obj; +} + +void RobOsageNodeDataNormalRef::GetMat() { + if (!field_0) + return; + + vec3 n_trans; + vec3 u_trans; + vec3 d_trans; + vec3 l_trans; + vec3 r_trans; + mat4_get_translation(&n->mat, &n_trans); + mat4_get_translation(&u->mat, &u_trans); + mat4_get_translation(&d->mat, &d_trans); + mat4_get_translation(&l->mat, &l_trans); + mat4_get_translation(&r->mat, &r_trans); + + vec3 v21; + vec3 v22; + vec3 v23; + if (sub_14053D1B0(&l_trans, &r_trans, &u_trans, &d_trans, &v22, &v21, &v23)) { + mat4u mat; + mat.row0.x = v23.x; + mat.row0.y = v21.x; + mat.row0.z = v22.x; + mat.row0.w = 0.0f; + mat.row1.x = v23.y; + mat.row1.y = v21.y; + mat.row1.z = v22.y; + mat.row1.w = 0.0f; + mat.row2.x = v23.z; + mat.row2.y = v21.z; + mat.row2.z = v22.z; + mat.row2.w = 0.0f; + vec3_dot(n_trans, v23, mat.row3.x); + vec3_dot(n_trans, v21, mat.row3.y); + vec3_dot(n_trans, v22, mat.row3.z); + vec3_negate(*(vec3*)&mat.row3, *(vec3*)&mat.row3); + mat.row3.w = 1.0f; + mat4_mult(&n->mat, &mat, &mat); + } +} + +skin_param_hinge::skin_param_hinge() { + ymin = -90.0f; + ymax = 90.0f; + zmin = -90.0f; + zmax = 90.0f; +} + +skin_param_hinge::~skin_param_hinge() { + +} + +void skin_param_hinge::limit() { + ymin = max(ymin, -179.0f) * DEG_TO_RAD_FLOAT; + ymax = min(ymax, 179.0f) * DEG_TO_RAD_FLOAT; + zmin = max(zmin, -179.0f) * DEG_TO_RAD_FLOAT; + zmax = min(zmax, 179.0f) * DEG_TO_RAD_FLOAT; +} + +skin_param_osage_node::skin_param_osage_node() : coli_r(0.0f), weight(1.0f), inertial_cancel(0.0f) { + hinge.limit(); +} + +skin_param_osage_node::~skin_param_osage_node() { + +} + +RobOsageNodeData::RobOsageNodeData() : force(), normal_ref() { + +} + +RobOsageNodeData::~RobOsageNodeData() { + +} + +void RobOsageNodeData::Reset() { + force = 0.0f; + boc.clear(); + normal_ref.field_0 = 0; + normal_ref.n = 0; + normal_ref.u = 0; + normal_ref.d = 0; + normal_ref.l = 0; + normal_ref.r = 0; + normal_ref.mat = mat4u_identity; + skp_osg_node.weight = 1.0f; + skp_osg_node.inertial_cancel = 0.0f; + skp_osg_node.coli_r = 0.0f; + skp_osg_node.hinge = skin_param_hinge(); + skp_osg_node.hinge.limit(); +} + +RobOsageNode::RobOsageNode() : length(), trans(), trans_orig(), trans_diff(), field_28(), +child_length(), bone_node_ptr(), bone_node_mat(), sibling_node(), max_distance(), field_94(), +reset_data(), field_C8(), field_CC(1.0f), external_force(), force(1.0f), mat(), field_1B0() { + data_ptr = &data; + opd_data.resize(3); +} + +RobOsageNode::~RobOsageNode() { + +} + +void RobOsageNode::Reset() { + length = 0.0f; + trans = vec3_null; + trans_orig = vec3_null; + trans_diff = vec3_null; + field_28 = vec3_null; + child_length = 0.0f; + bone_node_ptr = 0; + bone_node_mat = 0; + sibling_node = 0; + max_distance = 0.0f; + field_94 = vec3_null; + reset_data.trans = vec3_null; + reset_data.trans_diff = vec3_null; + reset_data.rotation = vec3_null; + reset_data.length = 0.0f; + field_C8 = 0.0f; + field_CC = 1.0f; + external_force = vec3_null; + force = 1.0f; + data.Reset(); + data_ptr = &data; + opd_data.clear(); + opd_data.resize(3); + mat = mat4u_null; +} + +skin_param_osage_root_coli::skin_param_osage_root_coli() : type(), +bone0_index(), bone1_index(), radius(0.2f), bone0_pos(), bone1_pos() { + +} + +skin_param_osage_root_coli::~skin_param_osage_root_coli() { + +} + +skin_param_osage_root_normal_ref::skin_param_osage_root_normal_ref() { + +} + +skin_param_osage_root_normal_ref::~skin_param_osage_root_normal_ref() { + +} + +skin_param_osage_root_boc::skin_param_osage_root_boc() : ed_node(), st_node() { + +} + +skin_param_osage_root_boc::~skin_param_osage_root_boc() { + +} + +skin_param_osage_root::skin_param_osage_root() : field_0(), force(), force_gain(), air_res(0.5f), +rot_y(), rot_z(), init_rot_y(), init_rot_z(), hinge_y(90.0f), hinge_z(90.0f), name("NO-PARAM"), +coli_r(), friction(1.0f), wind_afc(0.5f), yz_order(), coli_type(), stiffness(), move_cancel(-0.01f) { + coli.resize(13); +} + +skin_param_osage_root::~skin_param_osage_root() { + +} + +skin_param::skin_param() : friction(1.0f), wind_afc(), air_res(1.0f), rot(), init_rot(), +coli_type(), stiffness(), move_cancel(-0.01f), coli_r(), force(), force_gain(), colli_tgt_osg() { + hinge.limit(); +} + +skin_param::~skin_param() { + +} + +void skin_param::reset() { + coli.clear(); + friction = 1.0f; + wind_afc = 0.0f; + air_res = 1.0f; + rot = vec3_null; + init_rot = vec3_null; + coli_type = 0; + stiffness = 0.0f; + move_cancel = -0.01f; + coli_r = 0.0f; + hinge = skin_param_hinge(); + hinge.limit(); + force = 0.0f; + force_gain = 0.0f; + colli_tgt_osg = 0; +} + +osage_coli::osage_coli() : type(), radius(), bone0_pos(), bone1_pos(), +bone_pos_diff(), bone_pos_diff_length(), bone_pos_diff_length_squared(), field_34() { + +} + +osage_coli::~osage_coli() { + +} + +void osage_coli::set(osage_coli* coli, skin_param_osage_root_coli* skp_root_coli, mat4* mats) { + coli->type = (skin_param_osage_root_coli_type)0; + if (!skp_root_coli || !mats) + return; + + for (; skp_root_coli->type; coli++, skp_root_coli++) { + coli->type = skp_root_coli->type; + coli->radius = skp_root_coli->radius; + mat4 mat = mats[skp_root_coli->bone0_index]; + mat4_mult_vec3_trans(&mat, &skp_root_coli->bone0_pos, &coli->bone0_pos); + if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER + || skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE) { + mat = mats[skp_root_coli->bone1_index]; + mat4_mult_vec3_trans(&mat, &skp_root_coli->bone1_pos, &coli->bone1_pos); + vec3_sub(coli->bone1_pos, coli->bone0_pos, coli->bone_pos_diff); + vec3_length_squared(coli->bone_pos_diff, coli->bone_pos_diff_length_squared); + coli->bone_pos_diff_length = sqrtf(coli->bone_pos_diff_length_squared); + if (coli->bone_pos_diff_length < 0.01f) + coli->type = SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL; + } + else if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE) + mat4_mult_vec3(&mat, &skp_root_coli->bone1_pos, &coli->bone1_pos); + } + coli->type = (skin_param_osage_root_coli_type)0; +} + +void osage_coli::ring_set(osage_coli* coli, + std::vector& vec_skp_root_coli, mat4* mats) { + if (!vec_skp_root_coli.size()) { + coli->type = (skin_param_osage_root_coli_type)0; + coli->radius = 0.0f; + coli->bone0_pos = vec3_null; + coli->bone1_pos = vec3_null; + coli->bone_pos_diff = vec3_null; + coli->bone_pos_diff_length = 0.0f; + coli->bone_pos_diff_length_squared = 0.0f; + coli->field_34 = 1.0f; + } + else + set(coli, vec_skp_root_coli.data(), mats); +} + +osage_ring_data::osage_ring_data() : ring_rectangle_x(0.0f), ring_rectangle_y(0.0f), ring_rectangle_width(0.0f), +ring_rectangle_height(0.0f), ring_height(-1000.0f), ring_out_height(-1000.0f), field_18() { + +} + +osage_ring_data::~osage_ring_data() { + +} + +CLOTHNode::CLOTHNode() : flags(), trans(), trans_orig(), field_1C(), trans_diff(), normal(), +tangent(), binormal(), tangent_sign(), texcoord(), field_64(), length(), field_74(), +field_78(), field_7C(), field_80(), field_88(), reset_data(), field_B4(), field_D0() { + +} + +CLOTHNode::~CLOTHNode() { + +} + +CLOTH::CLOTH() : field_8(), root_count(), nodes_count(), wind_direction(), +field_44(), set_external_force(), external_force(), skin_param_ptr(), mats() { + Reset(); +} + +CLOTH::~CLOTH() { + +} + +void CLOTH::Init() { + field_58.clear(); + if (nodes_count <= 1) + return; + + struc_341 v69 = {}; + size_t root_count = this->root_count; + for (size_t i = 1; i < nodes_count; i++) { + for (size_t j = 0; j < root_count; j++) { + size_t v8 = (i - 1) * root_count + j; + v69.field_0 = v8; + size_t v7 = i * root_count + j; + v69.field_8 = v7; + vec3_distance(nodes.data()[v7].trans, nodes.data()[v8].trans, v69.length); + field_58.push_back(v69); + if (j < root_count - 1) { + v69.field_0 = v7; + size_t v32 = i * root_count + j + 1; + v69.field_8 = v32; + vec3_distance(nodes.data()[v32].trans, nodes.data()[v7].trans, v69.length); + field_58.push_back(v69); + } + } + + if (field_8 & 0x04) { + v69.field_0 = i * root_count; + v69.field_8 = (i + 1) * root_count - 1; + field_58.push_back(v69); + } + } +} + +void CLOTH::SetSkinParamColiR(float_t coli_r) { + skin_param_ptr->coli_r = coli_r; +} + +void CLOTH::SetSkinParamFriction(float_t friction) { + skin_param_ptr->friction = friction; +} + +void CLOTH::SetSkinParamWindAfc(float_t wind_afc) { + skin_param_ptr->wind_afc = wind_afc; +} + +void CLOTH::SetWindDirection(vec3& wind_direction) { + this->wind_direction = wind_direction; +} + +void CLOTH::Field_30(float_t a2) { + field_44 = a2; +} + +void CLOTH::SetSkinParamHinge(float_t hinge_y, float_t hinge_z) { + skin_param_hinge& hinge = skin_param_ptr->hinge; + hinge.ymax = hinge_y; + hinge.zmax = hinge_z; + hinge.ymin = -hinge_y; + hinge.zmin = -hinge_z; + hinge.limit(); +} + +CLOTHNode* CLOTH::GetNodes() { + return nodes.data(); +} + +void CLOTH::Reset() { + field_8 &= ~1; + root_count = 0; + nodes_count = 0; + nodes.clear(); + wind_direction = vec3_null; + field_44 = 0.0f; + set_external_force = false; + external_force = vec3_null; + skin_param.reset(); + skin_param_ptr = &skin_param; +} + +void CLOTH::ResetData() { + Reset(); +} + +RobClothSubMeshArray::RobClothSubMeshArray() { + arr[0] = {}; + arr[1] = {}; + arr[2] = {}; + arr[3] = {}; +} + +RobCloth::RobCloth() : itm_eq_obj(), cls_root(), cls_data(), move_cancel(), osage_reset(), +mesh(), submesh(), vertex_buffer(), index_buffer(), reset_data_list() { + ResetData(); +} + +RobCloth::~RobCloth() { + ResetData(); +} + +void RobCloth::ResetData() { + Reset(); + mats = 0; + itm_eq_obj = 0; + cls_root = 0; + cls_data = 0; + move_cancel = 0.0f; + osage_reset = false; + mesh[0] = {}; + mesh[1] = {}; + vertex_buffer[0].unload(); + vertex_buffer[1].unload(); + index_buffer[0].buffer = 0; + index_buffer[1].buffer = 0; + motion_reset_data.clear(); + reset_data_list = 0; +} + +void RobCloth::AddMotionResetData(int32_t motion_id, float_t frame) { + int32_t frame_int = (int32_t)roundf(frame * 1000.0f); + + auto elem = motion_reset_data.find({ motion_id, frame_int }); + if (elem != motion_reset_data.end()) + motion_reset_data.erase(elem); + + std::list v28; + CLOTHNode* i_begin = nodes.data() + root_count; + CLOTHNode* i_end = nodes.data() + nodes.size(); + for (CLOTHNode* i = i_begin; i != i_end; i++) + v28.push_back(i->reset_data); + + motion_reset_data.insert({ { motion_id, frame_int }, v28 }); +} + +void RobCloth::ColiSet(mat4* mats) { + if (skin_param_ptr->coli.size()) + osage_coli::set(coli, skin_param_ptr->coli.data(), mats); + osage_coli::ring_set(coli_ring, ring.skp_root_coli, mats); +} + +void RobCloth::Disp(mat4* mat, render_context* rctx) { + obj* obj = object_storage_get_obj(itm_eq_obj->obj_info); + if (!obj) + return; + + std::vector* tex = object_storage_get_obj_set_textures(itm_eq_obj->obj_info.set_id); + + vec3 center; + vec3_add(nodes.data()[0].trans, nodes.data()[root_count * nodes_count - 1].trans, center); + vec3_mult_scalar(center, 0.5f, center); + + ::obj o = *obj; + o.num_mesh = index_buffer[1].buffer != 0 ? 2 : 1; + o.mesh_array = mesh; + o.bounding_sphere.center = center; + o.bounding_sphere.radius *= 2.0f; + + for (uint32_t i = 0; i < o.num_mesh; i++) { + obj_mesh& mesh = this->mesh[i]; + mesh.bounding_sphere.center = center; + for (uint32_t j = 0; j < mesh.num_submesh; j++) { + obj_sub_mesh& submesh = mesh.submesh_array[j]; + submesh.bounding_sphere.center = center; + } + } + + rctx->object_data.set_texture_pattern((int32_t)itm_eq_obj->texture_pattern.size(), itm_eq_obj->texture_pattern.data()); + draw_task_add_draw_object_by_obj(rctx, mat, &o, tex, vertex_buffer, index_buffer, 0, itm_eq_obj->alpha); + rctx->object_data.set_texture_pattern(); +} + +void RobCloth::InitData(size_t root_count, size_t nodes_count, obj_skin_block_cloth_root* root, + obj_skin_block_cloth_node* nodes, mat4u* mats, int32_t a7, + rob_chara_item_equip_object* itm_eq_obj, bone_database* bone_data) { + this->itm_eq_obj = itm_eq_obj; + obj* obj = object_storage_get_obj(itm_eq_obj->obj_info); + if (!obj) + return; + + obj_mesh_index_buffer* index_buffer = object_storage_get_obj_mesh_index_buffer(itm_eq_obj->obj_info); + uint32_t mesh_name_index = obj->get_obj_mesh_index(cls_data->mesh_name); + uint32_t backface_mesh_name_index = obj->get_obj_mesh_index(cls_data->backface_mesh_name); + + mesh[0] = obj->mesh_array[mesh_name_index]; + if (cls_data->backface_mesh_name && backface_mesh_name_index != -1) + mesh[1] = obj->mesh_array[backface_mesh_name_index]; + else + mesh[1] = {}; + + for (int32_t i = 0; i < 2; i++) { + RobClothSubMeshArray& submesh = this->submesh[i]; + for (uint32_t j = 0; j < mesh[i].num_submesh; j++) { + obj_sub_mesh& v27 = submesh.arr[j]; + v27 = mesh[i].submesh_array[j]; + mesh[i].submesh_array[j].attrib.m.cloth = 1; + v27.attrib.m.cloth = 0; + v27.bounding_sphere.radius = 1000.0f; + v27.axis_aligned_bounding_box.center = vec3_null; + v27.axis_aligned_bounding_box.size = { 1000.0f, 1000.0f, 1000.0f }; + } + mesh[i].submesh_array = submesh.arr; + mesh[i].bounding_sphere.radius = 1000.0f; + } + + this->index_buffer[0] = index_buffer[mesh_name_index]; + if (!vertex_buffer[0].load(mesh[0])) + return; + + this->index_buffer[1] = {}; + if (cls_data->backface_mesh_name && backface_mesh_name_index != -1) + this->index_buffer[1] = index_buffer[backface_mesh_name_index]; + + if (cls_data->backface_mesh_name && !vertex_buffer[1].load(mesh[1])) + return; + + field_8 = (((field_8 ^ (4 * a7)) & 0x04) ^ field_8) | 0x03; + + this->root_count = root_count; + this->nodes_count = nodes_count; + this->cls_root = root; + this->mats = mats; + + this->root.clear(); + this->root.reserve(root_count); + + for (size_t i = 0; i < root_count; i++) { + this->root.push_back({}); + RobClothRoot& v34 = this->root.back(); + v34.trans = root[i].trans; + v34.normal = root[i].normal; + for (int32_t j = 0; j < 4; j++) { + obj_skin_block_cloth_root_bone_weight& bone_weight = root[i].bone_weights[j]; + v34.node[j] = 0; + v34.node_mat[j] = 0; + v34.mat[j] = &mats[bone_weight.matrix_index]; + if (bone_weight.bone_name) { + v34.node[j] = itm_eq_obj->get_bone_node(bone_weight.bone_name, bone_data); + if (v34.node[j]) + v34.node_mat[j] = v34.node[j]->mat; + } + v34.weight[j] = bone_weight.weight; + } + } + + this->nodes.clear(); + this->nodes.reserve(root_count); + + for (size_t i = 0; i < root_count; i++) { + this->nodes.push_back({}); + CLOTHNode& v55 = this->nodes.back(); + v55.trans = root[i].trans; + v55.trans_orig = root[i].trans; + } + + uint16_t* mesh_indices = cls_data->mesh_indices; + + obj_mesh* mesh = object_storage_get_obj_mesh(itm_eq_obj->obj_info, cls_data->mesh_name); + if (mesh && mesh->vertex_format + & (OBJ_VERTEX_TEXCOORD0 | OBJ_VERTEX_TANGENT | OBJ_VERTEX_NORMAL | OBJ_VERTEX_POSITION)) { + obj_vertex_data* vertex = mesh->vertex; + for (size_t i = 0; i < root_count; ++i) + this->root.data()[i].tangent = vertex[mesh_indices[i]].tangent; + } + + for (size_t i = 1; i < nodes_count; i++) + for (size_t j = 0; j < root_count; j++) { + this->nodes.push_back({}); + obj_skin_block_cloth_node& node = nodes[(i - 1) * root_count + j]; + CLOTHNode& v72 = this->nodes.back(); + v72.trans = node.trans; + v72.trans_orig = node.trans; + v72.normal = { 0.0f, 0.0f, 1.0f }; + v72.tangent = { 1.0f, 0.0f, 0.0f }; + v72.trans_diff = node.trans_diff; + v72.field_64 = node.trans_diff; + vec3_normalize(v72.field_64, v72.field_64); + v72.length = node.length; + v72.field_74 = node.field_20; + v72.field_78 = node.field_24; + v72.field_7C = node.field_28; + v72.reset_data = {}; + + uint32_t flags = 0x00; + if (i) + flags |= 0x01; + if (i != nodes_count - 1) + flags |= 0x02; + if (j) + flags |= 0x04; + if (j != root_count - 1) + flags |= 0x08; + v72.flags = flags; + + if (mesh && mesh->vertex_format & OBJ_VERTEX_TEXCOORD0) + v72.texcoord = mesh->vertex[mesh_indices[i * root_count + j]].texcoord0; + } + + Init(); +} + +void RobCloth::InitDataParent(obj_skin_block_cloth* cls_data, + rob_chara_item_equip_object* itm_eq_obj, bone_database* bone_data) { + ResetData(); + this->cls_data = cls_data; + InitData(cls_data->root_count, cls_data->nodes_count, cls_data->root, + cls_data->nodes, cls_data->mats, cls_data->field_14, itm_eq_obj, bone_data); +} + +float_t* RobCloth::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { + CLOTHNode* i_begin = nodes.data() + root_count; + CLOTHNode* i_end = nodes.data() + nodes.size(); + for (CLOTHNode* i = i_begin; i != i_end; i++) { + if (node_index >= i->opd_data.size()) + i->opd_data.resize(node_index + 1); + + opd_vec3_data* opd = &i->opd_data[node_index]; + opd->x = opd_data; + opd_data += opd_count; + opd->y = opd_data; + opd_data += opd_count; + opd->z = opd_data; + opd_data += opd_count; + } + return opd_data; +} + +void RobCloth::LoadSkinParam(void* kv, const char* name, bone_database* bone_data) { + key_val* _kv = (key_val*)kv; + skin_param_osage_root root; + skin_param_osage_root_parse(_kv, name, root, bone_data); + SetSkinParamOsageRoot(root); +} + +void RobCloth::SetForceAirRes(float_t force, float_t force_gain, float_t air_res) { + skin_param_ptr->force = force; + skin_param_ptr->force_gain = force_gain; + skin_param_ptr->air_res = air_res; +} + +void RobCloth::SetMotionResetData(int32_t motion_id, float_t frame) { osage_reset = true; + auto v6 = motion_reset_data.find({ motion_id, (int32_t)roundf(frame * 1000.0f) }); + if (v6 != motion_reset_data.end() && v6->second.size() + 1 == nodes.size()) + reset_data_list = &v6->second; +} + +void RobCloth::SetOsagePlayData(std::vector& opd_blend_data) { + sub_140219940(this); + + size_t v7 = opd_blend_data.size() - 1; + for (auto i = opd_blend_data.end(); i != opd_blend_data.begin(); v7--) { + i--; + + float_t frame = i->frame; + if (frame >= i->frame_count) + frame = 0.0f; + + int32_t frame_int = (int32_t)frame; + if (frame != -0.0f && (float_t)frame_int != frame) + frame_int = (frame < 0.0f ? frame_int - 1 : frame_int); + + int32_t curr_key = frame_int; + int32_t next_key = frame_int + 1; + if ((float_t)next_key >= i->frame_count) + next_key = 0; + + float_t blend = frame - (float_t)frame_int; + float_t inv_blend = 1.0f - blend; + + for (size_t j = 0; j < root_count; j++) { + CLOTHNode& root_node = nodes.data()[j]; + vec3 v26 = root_node.trans; + mat4 mat = root.data()[j].field_98; + mat4_translate_mult(&mat, root_node.trans_orig.x, + root_node.trans_orig.y, root_node.trans_orig.z, &mat); + + CLOTHNode* v29 = &nodes.data()[j + root_count]; + + vec3 v78; + mat4_mult_vec3(&mat, &v29->field_64, &v78); + + int32_t yz_order = 0; + sub_140482FF0(mat, v78, 0, 0, yz_order); + + mat4 v32 = root.data()[j].field_D8; + for (size_t k = 1; k < nodes_count; k++, v29 += root_count) { + opd_vec3_data* opd = &v29->opd_data[v7]; + float_t* opd_x = opd->x; + float_t* opd_y = opd->y; + float_t* opd_z = opd->z; + + vec3 v61; + v61.x = opd_x[curr_key]; + v61.y = opd_y[curr_key]; + v61.z = opd_z[curr_key]; + + vec3 v62; + v62.x = opd_x[next_key]; + v62.y = opd_y[next_key]; + v62.z = opd_z[next_key]; + + mat4_mult_vec3_trans(&v32, &v61, &v61); + mat4_mult_vec3_trans(&v32, &v62, &v62); + + vec3 v57; + vec3_mult_scalar(v61, blend, v57); + + vec3 v58; + vec3_mult_scalar(v62, inv_blend, v58); + vec3_add(v57, v58, v57); + + vec3 v85; + mat4_mult_vec3_inv_trans(&mat, &v57, &v85); + + vec3 rotation = vec3_null; + int32_t yz_order = 0; + sub_140482FF0(mat, v85, 0, &rotation, yz_order); + + float_t v45; + vec3_distance(v57, v26, v45); + mat4_translate_mult(&mat, v45, 0.0f, 0.0f, &mat); + + struc_477 v83; + v83.rotation = rotation; + v83.length = v29->length; + sub_140482100(&v29->field_D0, &i[0], &v83); + + v26 = v61; + } + } + } + + for (size_t i = 0; i < root_count; i++) { + CLOTHNode& root_node = nodes.data()[i]; + mat4 mat = root.data()[0].field_98; + mat4_translate_mult(&mat, root_node.trans_orig.x, + root_node.trans_orig.y, root_node.trans_orig.z, &mat); + + CLOTHNode* v50 = &nodes.data()[i + root_count]; + + vec3 v78; + mat4_mult_vec3(&mat, &v50->field_64, &v78); + int32_t yz_order = 0; + sub_140482FF0(mat, v78, 0, 0, yz_order); + + for (size_t j = 1; j < nodes_count; j++, v50 += root_count) { + mat4_rotate_z_mult(&mat, v50->field_D0.field_0.rotation.z, &mat); + mat4_rotate_y_mult(&mat, v50->field_D0.field_0.rotation.y, &mat); + mat4_translate_mult(&mat, v50->field_D0.field_0.length, 0.0f, 0.0f, &mat); + mat4_get_translation(&mat, &v50->trans); + } + } +} + +void RobCloth::SetSkinParamOsageRoot(skin_param_osage_root& skp_root) { + SetForceAirRes(skp_root.force, skp_root.force_gain, skp_root.air_res); + SetSkinParamFriction(skp_root.friction); + SetSkinParamWindAfc(skp_root.wind_afc); + SetSkinParamColiR(skp_root.coli_r); + SetSkinParamHinge(skp_root.hinge_y, skp_root.hinge_z); + skin_param_ptr->coli = skp_root.coli; +} + +void RobCloth::UpdateDisp() { + if (pv_osage_manager_array_ptr_get_disp()) + return; + + if (rob_cloth_update_vertices_flags & 0x01) + UpdateNormals(); + + if (rob_cloth_update_vertices_flags & 0x02) { + obj_mesh* mesh = object_storage_get_obj_mesh(itm_eq_obj->obj_info, cls_data->mesh_name); + obj_mesh* backface_mesh = object_storage_get_obj_mesh(itm_eq_obj->obj_info, cls_data->backface_mesh_name); + if (cls_data->backface_mesh_name) { + UpdateVertexBuffer(mesh, &vertex_buffer[0], nodes.data(), + 1.0f, cls_data->mesh_indices_count, cls_data->mesh_indices, false); + UpdateVertexBuffer(backface_mesh, &vertex_buffer[1], nodes.data(), + -1.0f, cls_data->backface_mesh_indices_count, cls_data->backface_mesh_indices, false); + } + else + UpdateVertexBuffer(mesh, &vertex_buffer[0], nodes.data(), + 1.0, cls_data->backface_mesh_indices_count, cls_data->mesh_indices, true); + } +} + +void RobCloth::UpdateNormals() { + ssize_t root_count = this->root_count; + CLOTHNode* node = &nodes.data()[root_count]; + if (rob_cloth_update_normals_select) { + for (size_t i = 1; i < nodes_count - 1; i++) { + sub_14021A890(node, node, node + 1, &node[-root_count], &node[root_count]); + node++; + for (ssize_t j = 1; j < root_count - 1; j++, node++) + sub_14021A890(node, node - 1, node + 1, &node[-root_count], &node[root_count]); + sub_14021A890(node, node - 1, node, &node[-root_count], &node[root_count]); + node++; + } + + sub_14021A890(node, node, node + 1, &node[-root_count], node); + node++; + + for (ssize_t i = 1; i < root_count - 1; i++, node++) + sub_14021A890(node, node - 1, node + 1, &node[-root_count], node); + sub_14021A890(node, node - 1, node, &node[-root_count], node); + } + else + for (size_t i = 1; i < nodes_count; i++, node++) { + for (ssize_t j = 0; j < root_count - 1; j++, node++) { + node[0].tangent_sign = sub_14021A290( + node[0].trans, node[-root_count].trans, node[1].trans, + node[0].texcoord, node[-root_count].texcoord, node[1].texcoord, + node[0].tangent, node[0].binormal, node[0].normal); + } + node[0].normal = node[-1].normal; + node[0].tangent = node[-1].tangent; + node[0].binormal = node[-1].binormal; + node[0].tangent_sign = node[-1].tangent_sign; + } +} + +void RobCloth::UpdateVertexBuffer(obj_mesh* mesh, obj_mesh_vertex_buffer* vertex_buffer, + CLOTHNode* nodes, float_t facing, int32_t indices_count, uint16_t* indices, bool double_sided) { + if (!mesh || !vertex_buffer || (mesh->vertex_format + & (OBJ_VERTEX_NORMAL | OBJ_VERTEX_POSITION)) != (OBJ_VERTEX_NORMAL | OBJ_VERTEX_POSITION)) + return; + + vertex_buffer->cycle_index(); + glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer->get_buffer()); + size_t data = (size_t)glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); + if (!data) { + glBindBuffer(GL_ARRAY_BUFFER, 0); + return; + } + + if (double_sided) + indices_count /= 2; + + bool tangent = !!(mesh->vertex_format & OBJ_VERTEX_TANGENT); + + if (~mesh->attrib.m.compressed) { + if (tangent) + for (int32_t i = 2; i; i--, facing = -1.0f) { + for (int32_t j = indices_count; j; j--, indices++) { + CLOTHNode* node = &nodes[*indices]; + + *(vec3*)data = node->trans; + vec3_mult_scalar(node->normal, facing, *(vec3*)(data + 0x0C)); + *(vec3*)(data + 0x18) = node->tangent; + *(float_t*)(data + 0x24) = node->tangent_sign; + + data += mesh->size_vertex; + } + + if (!double_sided) + break; + } + else + for (int32_t i = 2; i; i--, facing = -1.0f) { + for (int32_t j = indices_count; j; j--, indices++) { + CLOTHNode* node = &nodes[*indices]; + + *(vec3*)data = node->trans; + vec3_mult_scalar(node->normal, facing, *(vec3*)(data + 0x0C)); + + data += mesh->size_vertex; + } + + if (!double_sided) + break; + } + } + else { + if (tangent) + for (int32_t i = 2; i; i--, facing = -1.0f) { + for (int32_t j = indices_count; j; j--, indices++) { + CLOTHNode* node = &nodes[*indices]; + + *(vec3*)data = node->trans; + + vec3 normal; + vec3_mult_scalar(node->normal, 32727.0f * facing, normal); + vec3_to_vec3i16(normal, *(vec3i16*)(data + 0x0C)); + *(int16_t*)(data + 0x12) = 0; + + vec4 tangent; + *(vec3*)&tangent = node->tangent; + tangent.w = node->tangent_sign; + vec4_mult_scalar(tangent, 32727.0f, tangent); + vec4_to_vec4i16(tangent, *(vec4i16*)(data + 0x14)); + + data += mesh->size_vertex; + } + + if (!double_sided) + break; + } + else + for (int32_t i = 2; i; i--, facing = -1.0f) { + for (int32_t j = indices_count; j; j--, indices++) { + CLOTHNode* node = &nodes[*indices]; + + *(vec3*)data = node->trans; + + vec3 normal; + vec3_mult_scalar(node->normal, 32727.0f * facing, normal); + vec3_to_vec3i16(normal, *(vec3i16*)(data + 0x0C)); + *(int16_t*)(data + 0x12) = 0; + + data += mesh->size_vertex; + } + + if (!double_sided) + break; + } + } + + glUnmapBuffer(GL_ARRAY_BUFFER); + glBindBuffer(GL_ARRAY_BUFFER, 0); +} + +ExClothBlock::ExClothBlock() { + Init(); +} + +ExClothBlock::~ExClothBlock() { + +} + +void ExClothBlock::Init() { + rob.Reset(); + cls_data = 0; + mats = 0; + index = 0; +} + +void ExClothBlock::Field_10() { + field_59 = false; +} + +void ExClothBlock::Field_18(int32_t stage, bool a3) { + +} + +void ExClothBlock::Field_20() { + rob.ColiSet(mats); + rob.SetWindDirection(task_wind.ptr->wind_direction); + + rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; + float_t step = get_delta_frame() * rob_itm_equip->step; + if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) + step = 1.0f; + sub_140218560(&rob, step, false); +} + +void ExClothBlock::SetOsagePlayData() { + rob.SetOsagePlayData(item_equip_object->item_equip->opd_blend_data); +} + +void ExClothBlock::Disp(mat4* mat, render_context* rctx) { + rob.UpdateDisp(); + rob.Disp(mat, rctx); +} + +void ExClothBlock::Reset() { + bone_node_ptr = 0; +} + +void ExClothBlock::Field_40() { + +} + +void ExClothBlock::Field_48() { + rob.ColiSet(mats); + rob.SetWindDirection(task_wind.ptr->wind_direction); + sub_14021D480(&rob); +} + +void ExClothBlock::Field_50() { + rob.ColiSet(mats); + rob.SetWindDirection(task_wind.ptr->wind_direction); + sub_14021D840(&rob); +} + +void ExClothBlock::AddMotionResetData(int32_t motion_id, float_t frame) { + rob.AddMotionResetData(motion_id, frame); +} + +void ExClothBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, + obj_skin_block_cloth* cls_data, skin_param_osage_root* skp_root, bone_database* bone_data) { + type = EX_CLOTH; + bone_node_ptr = 0; + this->cls_data = cls_data; + name = skp_root ? skp_root->name : 0; + item_equip_object = itm_eq_obj; + + mats = itm_eq_obj->get_bone_node(0)->mat; + rob.ResetData(); + rob.InitDataParent(cls_data, itm_eq_obj, bone_data); + SetSkinParamOsageRoot(skp_root); +} + +float_t* ExClothBlock::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { + return rob.LoadOpdData(node_index, opd_data, opd_count); +} + +void ExClothBlock::SetMotionResetData(int32_t motion_id, float_t frame) { + rob.SetMotionResetData(motion_id, frame); +} + +void ExClothBlock::SetOsageReset() { + rob.osage_reset = true; +} + +void ExClothBlock::SetSkinParam(struc_571* skp) { + rob.skin_param_ptr = &skp->skin_param; +} + +void ExClothBlock::SetSkinParamOsageRoot(skin_param_osage_root* skp_root) { + if (!skp_root) + return; + + rob.SetSkinParamOsageRoot(*skp_root); + + vec3 wind_direction; + vec3_mult_scalar(task_wind.ptr->wind_direction, + item_equip_object->item_equip->wind_strength, + wind_direction); + rob.SetWindDirection(wind_direction); +} + +struc_571::struc_571() : field_88() { + +} + +struc_571::~struc_571() { + +} + +osage_setting_osg_cat::osage_setting_osg_cat() : exf() { + parts = ROB_OSAGE_PARTS_NONE; +} + +RobOsage::RobOsage() : skin_param_ptr(), osage_setting(), field_2A0(), field_2A1(), field_2A4(), +wind_direction(), field_1EB4(), yz_order(), field_1EBC(), parent_mat_ptr(), parent_mat(), move_cancel(), +field_1F0C(), osage_reset(), field_1F0E(), field_1F0F(), set_external_force(), external_force(), reset_data_list() { + +} + +RobOsage::~RobOsage() { + +} + +void RobOsage::AddMotionResetData(int32_t motion_id, float_t frame) { + int32_t frame_int = (int32_t)roundf(frame * 1000.0f); + + auto elem = motion_reset_data.find({ motion_id, frame_int }); + if (elem != motion_reset_data.end()) + motion_reset_data.erase(elem); + + std::list v28; + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + v28.push_back(i->reset_data); + + motion_reset_data.insert({ { motion_id, frame_int }, v28 }); +} + +bool RobOsage::CheckPartsBits(rob_osage_parts_bit parts_bits) { + if (osage_setting.parts != ROB_OSAGE_PARTS_NONE) + return !!(parts_bits & (1 << osage_setting.parts)); + return false; +} + +void RobOsage::ColiSet(mat4* mats) { + if (skin_param_ptr->coli.size()) + osage_coli::set(coli, skin_param_ptr->coli.data(), mats); + osage_coli::ring_set(coli_ring, ring.skp_root_coli, mats); +} + +RobOsageNode* RobOsage::GetNode(size_t index) { + if (index < nodes.size()) + return &nodes.data()[index]; + else + return &node; +} + +void RobOsage::InitData(obj_skin_block_osage* osg_data, obj_skin_osage_node* osg_nodes, + bone_node* ex_data_bone_nodes, obj_skin* skin) { + Reset(); + exp_data.set_position_rotation(osg_data->base.position, osg_data->base.rotation); + nodes.clear(); + nodes.resize(osg_data->count + 1ULL); + + RobOsageNode* external = &nodes.data()[0]; + nodes.data()[0].Reset(); + external->child_length = osg_nodes->length; + bone_node* external_bone_node = &ex_data_bone_nodes[osg_data->external_name_index & 0x7FFF]; + external->bone_node_ptr = external_bone_node; + external->bone_node_mat = external_bone_node->mat; + *external_bone_node->ex_data_mat = mat4_identity; + external->sibling_node = 0; + + bone_node* parent_bone_node = external->bone_node_ptr; + for (uint32_t i = 0; i < osg_data->count; i++) { + obj_skin_osage_node* v14 = &osg_nodes[i]; + RobOsageNode* node = &nodes.data()[i + 1LL]; + node->Reset(); + node->length = v14[0].length; + if (i != osg_data->count - 1) + node->child_length = v14[1].length; + bone_node* node_bone_node = &ex_data_bone_nodes[v14->name_index & 0x7FFF]; + node->bone_node_ptr = node_bone_node; + node->bone_node_mat = node_bone_node->mat; + node_bone_node->parent = parent_bone_node; + parent_bone_node = node->bone_node_ptr; + } + + node.Reset(); + node.length = osg_nodes[osg_data->count - 1].length; + bone_node* v22 = &ex_data_bone_nodes[osg_data->name_index & 0x7FFF]; + node.bone_node_ptr = v22; + node.bone_node_mat = v22->mat; + v22->parent = parent_bone_node; + *node.bone_node_ptr->ex_data_mat = mat4_identity; + + if (osg_data->count) { + obj_skin_osage_node* v23 = osg_data->nodes; + size_t v24 = 0; + RobOsageNode* v26 = &nodes.data()[1]; + for (size_t i = 0; i < osg_data->count; i++) { + vec3 v27 = vec3_null; + if (v23) + v27 = v23[i].rotation; + + mat4 mat; + mat4_rotate(v27.x, v27.y, v27.z, &mat); + + vec3 v49; + v49 = vec3_null; + v49.x = v26[i].length; + mat4_mult_vec3(&mat, &v49, &v26[i].field_94); + } + } + + if (osg_data->count) { + obj_skin_osage_node* v23 = osg_data->nodes; + RobOsageNode* v26 = &nodes.data()[1]; + size_t v33 = 0; + for (uint32_t i = 0; i < osg_data->count; i++) { + v26[i].mat = mat4_null; + + obj_skin_bone* v36 = skin->bones; + for (uint32_t j = 0; j < skin->bones_count; j++, v36++) + if (v36->id == osg_nodes->name_index) { + mat4 mat = skin->bones[j].inv_bind_pose_mat; + mat4_inverse_normalized(&mat, &mat); + v26[i].mat = mat; + break; + } + + osg_nodes++; + } + } + + RobOsageNode* v38 = &nodes.back(); + if (memcmp(&v38->mat, &mat4_null, sizeof(mat4))) { + mat4 mat = v38->mat; + mat4_translate_mult(&mat, node.length, 0.0f, 0.0f, &mat); + node.mat = mat; + } +} + +float_t* RobOsage::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + if (node_index >= i->opd_data.size()) + i->opd_data.resize(node_index + 1); + + opd_vec3_data* opd = &i->opd_data[node_index]; + opd->x = opd_data; + opd_data += opd_count; + opd->y = opd_data; + opd_data += opd_count; + opd->z = opd_data; + opd_data += opd_count; + } + return opd_data; +} + +void RobOsage::LoadSkinParam(void* kv, const char* name, + skin_param_osage_root& skp_root, object_info* obj_info, bone_database* bone_data) { + key_val* _kv = (key_val*)kv; + skin_param_ptr = &skin_param; + for (RobOsageNode& i : nodes) + i.data_ptr = &i.data; + + skin_param_osage_root_parse(_kv, name, skp_root, bone_data); + SetSkinParamOsageRoot(skp_root); + + const osage_setting_osg_cat* osage_setting = osage_setting_data_get_cat_value(obj_info, name); + if (osage_setting) + this->osage_setting = *osage_setting; + + std::vector vec; + vec.resize(nodes.size() - 1); + skin_param_osage_node_parse(_kv, name, &vec, skp_root); + SetSkpOsgNodes(&vec); +} + +void RobOsage::Reset() { + nodes.clear(); + node.Reset(); + wind_direction = vec3_null; + field_1EB4 = 0.0f; + yz_order = 0; + field_2A0 = true; + motion_reset_data.clear(); + move_cancel = 0.0f; + field_1F0C = false; + osage_reset = false; + field_1F0E = false; + ring = osage_ring_data(); + field_1F0F = 0; + skin_param.reset(); + skin_param_ptr = &skin_param; + osage_setting = osage_setting_osg_cat(); + reset_data_list = 0; + field_2A4 = 0.0f; + field_2A1 = false; + set_external_force = false; + external_force = vec3_null; + parent_mat_ptr = 0; + parent_mat = mat4u_null; +} + +void RobOsage::SetAirRes(float_t air_res) { + skin_param_ptr->air_res = air_res; +} + +void RobOsage::SetColiR(float_t coli_r) { + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + i->data_ptr->skp_osg_node.coli_r = coli_r; +} + +void RobOsage::SetForce(float_t force, float_t force_gain) { + skin_param_ptr->force = force; + skin_param_ptr->force_gain = force_gain; + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + i->data_ptr->force = force; + force = force * force_gain; + } +} + +void RobOsage::SetHinge(float_t hinge_y, float_t hinge_z) { + hinge_y = min(hinge_y, 179.0f); + hinge_z = min(hinge_z, 179.0f); + hinge_y = hinge_y * DEG_TO_RAD_FLOAT; + hinge_z = hinge_z * DEG_TO_RAD_FLOAT; + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + RobOsageNodeData* data = i->data_ptr; + data->skp_osg_node.hinge.ymin = -hinge_y; + data->skp_osg_node.hinge.ymax = hinge_y; + data->skp_osg_node.hinge.zmin = -hinge_z; + data->skp_osg_node.hinge.zmax = hinge_z; + } +} + +void RobOsage::SetInitRot(float_t init_rot_y, float_t init_rot_z) { + skin_param_ptr->init_rot.y = init_rot_y * DEG_TO_RAD_FLOAT; + skin_param_ptr->init_rot.z = init_rot_z * DEG_TO_RAD_FLOAT; +} + +void RobOsage::SetMotionResetData(int32_t motion_id, float_t frame) { + osage_reset = true; + auto v6 = motion_reset_data.find({ motion_id, (int32_t)roundf(frame * 1000.0f) }); + if (v6 != motion_reset_data.end() && v6->second.size() + 1 == nodes.size()) + reset_data_list = &v6->second; +} + +void RobOsage::SetNodesExternalForce(vec3* external_force, float_t strength) { + vec3 v4; + if (external_force) + v4 = *external_force; + else + v4 = vec3_null; + + size_t exf = osage_setting.exf; + size_t v8 = 0; + if (exf >= 4) { + float_t strength4 = strength * strength * strength * strength; + v8 = ((exf - 4) / 4 + 1) * 4; + for (size_t v10 = v8 / 4; v10; v10--) + vec3_mult_scalar(v4, strength4, v4); + } + + if (v8 < exf) + for (size_t v12 = exf - v8; v12; v12--) + vec3_mult_scalar(v4, strength, v4); + + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + i->external_force = v4; + vec3_mult_scalar(v4, strength, v4); + } +} + +void RobOsage::SetNodesForce(float_t force) { + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + i->force = force; +} + +void RobOsage::SetOsagePlayData(mat4* parent_mat, + vec3& parent_scale, std::vector& opd_blend_data) { + if (!opd_blend_data.size()) + return; + + vec3 v63; + vec3_mult(exp_data.position, parent_scale, v63); + + mat4 v85; + mat4_mult_vec3_trans(&v85, &v63, &nodes.data()[0].trans); + + sub_14047F110(this, &v85, &parent_scale, 0); + *nodes.data()[0].bone_node_mat = v85; + *nodes.data()[0].bone_node_ptr->ex_data_mat = v85; + + size_t v17 = opd_blend_data.size() - 1; + for (auto i = opd_blend_data.end(); i != opd_blend_data.begin(); v17--) { + i--; + + mat4 v87 = v85; + vec3 v22 = nodes.data()[0].trans; + vec3 v25 = v22; + + float_t frame = i->frame; + if (frame >= i->frame_count) + frame = 0.0f; + + int32_t frame_int = (int32_t)frame; + if (frame != -0.0f && (float_t)frame_int != frame) + frame_int = (frame < 0.0f ? frame_int - 1 : frame_int); + + int32_t curr_key = frame_int; + int32_t next_key = frame_int + 1; + if ((float_t)next_key >= i->frame_count) + next_key = 0; + + float_t blend = frame - (float_t)frame_int; + float_t inv_blend = 1.0f - blend; + RobOsageNode* j_begin = nodes.data() + 1; + RobOsageNode* j_end = nodes.data() + nodes.size(); + for (RobOsageNode* j = j_begin; j != j_end; j++) { + opd_vec3_data* opd = &j->opd_data[v17]; + float_t* opd_x = opd->x; + float_t* opd_y = opd->y; + float_t* opd_z = opd->z; + + vec3 v62; + v62.x = opd_x[curr_key]; + v62.y = opd_y[curr_key]; + v62.z = opd_z[curr_key]; + + vec3 v77; + v77.x = opd_x[next_key]; + v77.y = opd_y[next_key]; + v77.z = opd_z[next_key]; + + mat4_mult_vec3_trans(parent_mat, &v62, &v62); + mat4_mult_vec3_trans(parent_mat, &v77, &v77); + + vec3 v82; + vec3_mult_scalar(v77, blend, v82); + + vec3 v81; + vec3_mult_scalar(v62, inv_blend, v81); + vec3_add(v82, v81, v82); + + vec3 v86; + mat4_mult_vec3_inv_trans(&v87, &v82, &v86); + + vec3 rotation = vec3_null; + sub_140482FF0(v87, v86, 0, &rotation, yz_order); + mat4_set_translation(&v87, &v82); + + float_t v50; + vec3_distance(v77, v25, v50); + + float_t v49; + vec3_distance(v62, v22, v49); + + struc_477 v72; + v72.rotation = rotation; + v72.length = v49 * inv_blend + v50 * blend; + sub_140482100(&j->field_1B0, &i[0], &v72); + + v22 = v62; + v25 = v77; + } + } + + RobOsageNode* i_begin = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + float_t rot_y = i->field_1B0.field_0.rotation.y; + float_t rot_z = i->field_1B0.field_0.rotation.z; + rot_y = clamp(rot_y, (float_t)-M_PI, (float_t)M_PI); + rot_z = clamp(rot_z, (float_t)-M_PI, (float_t)M_PI); + mat4_rotate_z_mult(&v85, rot_z, &v85); + mat4_rotate_y_mult(&v85, rot_y, &v85); + i->bone_node_ptr->exp_data.parent_scale = parent_scale; + *i->bone_node_ptr->ex_data_mat = v85; + if (i->bone_node_mat) { + mat4 mat = v85; + mat4_scale_rot(&mat, parent_scale.x, parent_scale.y, parent_scale.z, &mat); + *i->bone_node_mat = mat; + } + mat4_translate_mult(&v85, i->field_1B0.field_0.length, 0.0f, 0.0f, &v85); + i->trans_orig = i->trans; + mat4_get_translation(&v85, &i->trans); + } + + if (nodes.size() && node.bone_node_mat) { + mat4 v87 = *nodes.back().bone_node_ptr->ex_data_mat; + mat4_translate_mult(&v87, node.length * parent_scale.x, 0.0f, 0.0f, &v87); + *node.bone_node_ptr->ex_data_mat = v87; + + mat4_scale_rot(&v87, parent_scale.x, parent_scale.y, parent_scale.z, &v87); + *node.bone_node_mat = v87; + node.bone_node_ptr->exp_data.parent_scale = parent_scale; + } +} + +void RobOsage::SetRot(float_t rot_y, float_t rot_z) { + skin_param_ptr->rot.y = rot_y * DEG_TO_RAD_FLOAT; + skin_param_ptr->rot.z = rot_z * DEG_TO_RAD_FLOAT; +} + +void RobOsage::SetSkinParamOsageRoot(skin_param_osage_root& skp_root) { + skin_param_ptr->reset(); + SetForce(skp_root.force, skp_root.force_gain); + SetAirRes(skp_root.air_res); + SetRot(skp_root.rot_y, skp_root.rot_z); + SetInitRot(skp_root.init_rot_y, skp_root.init_rot_z); + SetYZOrder(skp_root.yz_order); + skin_param_ptr->friction = skp_root.friction; + skin_param_ptr->wind_afc = skp_root.wind_afc; + SetColiR(skp_root.coli_r); + SetHinge(skp_root.hinge_y, skp_root.hinge_z); + skin_param_ptr->coli = skp_root.coli; + skin_param_ptr->coli_type = skp_root.coli_type; + skin_param_ptr->stiffness = skp_root.stiffness; + skin_param_ptr->move_cancel = skp_root.move_cancel; +} + +void RobOsage::SetSkpOsgNodes(std::vector* skp_osg_nodes) { + if (!skp_osg_nodes) + return; + + if (nodes.size() - 1 != skp_osg_nodes->size()) + return; + + RobOsageNode* i = nodes.data() + 1; + RobOsageNode* i_end = nodes.data() + nodes.size(); + skin_param_osage_node* j = skp_osg_nodes->data(); + skin_param_osage_node* j_end = skp_osg_nodes->data() + skp_osg_nodes->size(); + while (i != i_end && j != j_end) { + i->data_ptr->skp_osg_node = *j++; + i->data_ptr->skp_osg_node.hinge.limit(); + i++; + } +} + +void RobOsage::SetYZOrder(int32_t yz_order) { + this->yz_order = yz_order; +} + +ExOsageBlock::ExOsageBlock() : rob(), mats(), step(1.0f) { + Reset(); +} + +ExOsageBlock::~ExOsageBlock() { + Reset(); +} + +void ExOsageBlock::Init() { + Reset(); +} + +void ExOsageBlock::Field_10() { + field_59 = false; +} + +void ExOsageBlock::Field_18(int32_t stage, bool a3) { + rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; + float_t step = get_delta_frame() * rob_itm_equip->step; + if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) + step = 1.0f; + + mat4* parent_node_mat = parent_bone_node->ex_data_mat; + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + switch (stage) { + case 0: + sub_1404803B0(&rob, parent_node_mat, &parent_scale, has_children_node); + break; + case 1: + case 2: + if ((stage == 1 && field_58) || (stage == 2 && rob.field_2A0)) { + SetWindDirection(); + sub_14047C800(&rob, parent_node_mat, &parent_scale, step, a3, true, has_children_node); + } + break; + case 3: + rob.ColiSet(mats); + sub_14047ECA0(&rob, step); + break; + case 4: + sub_14047D620(&rob, step); + break; + case 5: { + sub_14047D8C0(&rob, parent_node_mat, &parent_scale, step, false); + sub_140480260(&rob, parent_node_mat, &parent_scale, step, a3); + field_59 = true; + } break; + } +} + +void ExOsageBlock::Field_20() { + field_1FF8 &= ~2; + if (field_59) { + field_59 = false; + return; + } + + rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; + float_t step = get_delta_frame() * rob_itm_equip->step; + if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) + step = 1.0f; + + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + vec3 scale = parent_bone_node->exp_data.scale; + + mat4 mat = *parent_bone_node->ex_data_mat; + if (scale.x != 1.0f || scale.y != 1.0f || scale.z != 1.0f) { + vec3_div(vec3_identity, scale, scale); + mat4_scale_rot(&mat, scale.x, scale.y, scale.z, &mat); + } + SetWindDirection(); + rob.ColiSet(mats); + sub_14047C750(&rob, &mat, &parent_scale, step); +} + +void ExOsageBlock::SetOsagePlayData() { + rob.SetOsagePlayData(parent_bone_node->ex_data_mat, + parent_bone_node->exp_data.parent_scale, item_equip_object->item_equip->opd_blend_data); +} + +void ExOsageBlock::Disp(mat4* mat, render_context* rctx) { + +} + +void ExOsageBlock::Reset() { + index = 0; + rob.Reset(); + field_1FF8 &= ~3; + mats = 0; + step = 1.0f; + ExNodeBlock::Reset(); +} + +void ExOsageBlock::Field_40() { + +} + +void ExOsageBlock::Field_48() { + step = 4.0f; + SetWindDirection(); + rob.ColiSet(mats); + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + sub_14047F990(&rob, parent_bone_node->ex_data_mat, &parent_scale, 0); + field_1FF8 &= ~2; +} + +void ExOsageBlock::Field_50() { + if (field_59) { + field_59 = false; + return; + } + + SetWindDirection(); + + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + rob.ColiSet(mats); + sub_14047C770(&rob, parent_bone_node->ex_data_mat, &parent_scale, step, 1); + float_t step = 0.5f * this->step; + this->step = max(step, 1.0f); +} + +void ExOsageBlock::Field_58() { + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + sub_14047E1C0(&rob, &parent_scale); + field_59 = false; +} + +void ExOsageBlock::AddMotionResetData(int32_t motion_id, float_t frame) { + rob.AddMotionResetData(motion_id, frame); +} + +void ExOsageBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, + obj_skin_block_osage* osg_data, const char* osg_data_name, obj_skin_osage_node* osg_nodes, + bone_node* bone_nodes, bone_node* ex_data_bone_nodes, obj_skin* skin) { + ExNodeBlock::InitData(&ex_data_bone_nodes[osg_data->external_name_index & 0x7FFF], + EX_OSAGE, osg_data_name, itm_eq_obj); + rob.InitData(osg_data, osg_nodes, ex_data_bone_nodes, skin); + field_1FF8 &= ~2; + mats = bone_nodes->mat; +} + +float_t* ExOsageBlock::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { + return rob.LoadOpdData(node_index, opd_data, opd_count); +} + +void ExOsageBlock::SetMotionResetData(int32_t motion_id, float_t frame) { + rob.SetMotionResetData(motion_id, frame); +} + +void ExOsageBlock::SetOsageReset() { + rob.osage_reset = true; +} + +void ExOsageBlock::SetSkinParam(struc_571* skp) { + if (skp->nodes_data.size() == rob.nodes.size() - 1) { + size_t node_index = 0; + RobOsageNode* i_begin = rob.nodes.data() + 1; + RobOsageNode* i_end = rob.nodes.data() + rob.nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + i->data_ptr = &skp->nodes_data[node_index++]; + } + else { + rob.skin_param_ptr = &rob.skin_param; + for (RobOsageNode& i : rob.nodes) + i.data_ptr = &i.data; + } +} + +void ExOsageBlock::SetWindDirection() { + vec3_mult_scalar(task_wind.ptr->wind_direction, + item_equip_object->item_equip->wind_strength, + rob.wind_direction); +} + +void ExOsageBlock::sub_1405F3E10(obj_skin_block_osage* osg_data, + obj_skin_osage_node* osg_nodes, std::vector>* a4, + std::map* a5) { + RobOsageNode* node = rob.GetNode(0); + a4->push_back({ osg_data->external_name_index, node }); + + for (uint32_t i = 0; i < osg_data->count; i++) { + node = rob.GetNode(i); + a4->push_back({ osg_nodes[i].name_index, node }); + + if (node->bone_node_ptr && node->bone_node_ptr->name) + a5->insert({ node->bone_node_ptr->name, this }); + } + + node = rob.GetNode(osg_data->count + 1ULL); + a4->push_back({ osg_data->name_index, node }); + + if (node->bone_node_ptr && node->bone_node_ptr->name) + a5->insert({ node->bone_node_ptr->name, this }); +} + +ExConstraintBlock::ExConstraintBlock() : constraint_type(), +source_node_bone_node(), direction_up_vector_bone_node(), cns_data() { + Init(); +} + +ExConstraintBlock::~ExConstraintBlock() { + +} + +void ExConstraintBlock::Init() { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_NONE; + source_node_bone_node = 0; + direction_up_vector_bone_node = 0; + cns_data = 0; + field_80 = 0; +} + +void ExConstraintBlock::Field_10() { + if (bone_node_ptr) { + bone_node_expression_data* node_exp_data = &bone_node_ptr->exp_data; + node_exp_data->position = cns_data->base.position; + node_exp_data->rotation = cns_data->base.rotation; + node_exp_data->scale = cns_data->base.scale; + } + field_59 = false; +} + +void ExConstraintBlock::Field_18(int32_t stage, bool a3) { + if (field_59) + return; + + if (stage == 0) { + if (field_58) + Field_20(); + } + else if (stage == 2) { + if (has_children_node) + DataSet(); + } + else if (stage == 5) + Field_20(); +} + +void ExConstraintBlock::Field_20() { + if (!parent_bone_node) + return; + + if (field_59) { + field_59 = false; + return; + } + + Calc(); + DataSet(); + field_59 = true; +} + +void ExConstraintBlock::SetOsagePlayData() { + Field_20(); +} + +void ExConstraintBlock::Disp(mat4* mat, render_context* rctx) { + +} + +void ExConstraintBlock::Field_40() { + +} + +void ExConstraintBlock::Field_48() { + Field_20(); +} + +void ExConstraintBlock::Field_50() { + Field_20(); +} + +void ExConstraintBlock::Calc() { + bone_node* node = bone_node_ptr; + if (!node) + return; + + vec3 pos; + vec3_mult(parent_bone_node->exp_data.parent_scale, node->exp_data.position, pos); + + mat4 mat; + mat4_translate_mult(parent_bone_node->ex_data_mat, pos.x, pos.y, pos.z, &mat); + + switch (constraint_type) { + case OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION: { + vec3 trans; + mat4_get_translation(&mat, &trans); + + mat3 rot; + mat3_from_mat4(source_node_bone_node->mat, &rot); + mat3_normalize_rotation(&rot, &rot); + + vec3 offset = cns_data->orientation.offset; + mat3_rotate_mult(&rot, offset.x, offset.y, offset.z, &rot); + + mat4_from_mat3(&rot, node->mat); + mat4_set_translation(node->mat, &trans); + } break; + case OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION: { + vec3 align_axis = cns_data->direction.align_axis; + vec3 target_offset = cns_data->direction.target_offset; + mat4_mult_vec3_trans(source_node_bone_node->mat, &target_offset, &target_offset); + mat4_mult_vec3_inv_trans(&mat, &target_offset, &target_offset); + float_t target_offset_length; + vec3_length_squared(target_offset, target_offset_length); + if (target_offset_length <= 0.000001f) + break; + + mat4 v59; + sub_1401EB410(&v59, &align_axis, &target_offset); + if (direction_up_vector_bone_node) { + vec3 affected_axis = cns_data->direction.up_vector.affected_axis; + mat4 v56; + mat4_mult(&v59, &mat, &v56); + mat4_mult_vec3(&v56, &affected_axis, &affected_axis); + mat4* v20 = direction_up_vector_bone_node->mat; + + vec3 v23; + vec3 v24; + mat4_get_translation(v20, &v23); + mat4_get_translation(&v56, &v24); + vec3_sub(v23, v24, v23); + + vec3 v50; + mat4_mult_vec3(&mat, &target_offset, &v50); + + vec3 v25; + vec3 v29; + vec3_cross(v50, affected_axis, v25); + vec3_cross(v50, v23, v29); + vec3_normalize(v25, v25); + vec3_normalize(v29, v29); + + vec3 v35; + vec3_cross(v25, v29, v35); + + float_t v39; + float_t v36; + vec3_dot(v29, v25, v39); + vec3_dot(v35, v50, v36); + + float_t v40; + vec3_length(v35, v40); + if (v36 >= 0.0f) + v40 = -v40; + + sub_1405F10D0(&v56, &target_offset, v39, v40); + mat4_mult(&v59, &v56, &v59); + } + mat4_mult(&v59, &mat, node->mat); + } break; + case OBJ_SKIN_BLOCK_CONSTRAINT_POSITION: { + vec3 constraining_offset = cns_data->position.constraining_object.offset; + vec3 constrained_offset = cns_data->position.constrained_object.offset; + if (cns_data->position.constraining_object.affected_by_orientation) + mat4_mult_vec3(source_node_bone_node->mat, &constraining_offset, &constraining_offset); + + vec3 source_node_trans; + mat4_get_translation(source_node_bone_node->mat, &source_node_trans); + vec3_add(constraining_offset, source_node_trans, source_node_trans); + mat4_set_translation(&mat, &source_node_trans); + if (direction_up_vector_bone_node) { + vec3 up_vector_trans; + mat4_get_translation(direction_up_vector_bone_node->mat, &up_vector_trans); + mat4_mult_vec3_inv_trans(&mat, &up_vector_trans, &up_vector_trans); + + mat4 v26; + sub_1401EB410(&v26, &cns_data->position.up_vector.affected_axis, &up_vector_trans); + mat4_mult(&v26, &mat, &mat); + } + if (cns_data->position.constrained_object.affected_by_orientation) + mat4_mult_vec3(&mat, &constrained_offset, &constrained_offset); + + mat4 constrained_offset_mat; + mat4_translate(constrained_offset.x, constrained_offset.y, + constrained_offset.z, &constrained_offset_mat); + mat4_mult(&mat, &constrained_offset_mat, node->mat); + } break; + case OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE: + default: + *node->mat = mat; + break; + } +} + +void ExConstraintBlock::DataSet() { + if (!bone_node_ptr) + return; + + bone_node_expression_data* exp_data = &bone_node_ptr->exp_data; + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + + mat4 mat; + mat4_inverse_normalized(parent_bone_node->ex_data_mat, &mat); + mat4_mult(bone_node_ptr->mat, &mat, &mat); + mat4_get_rotation(&mat, &bone_node_ptr->exp_data.rotation); + mat4_get_translation(&mat, &exp_data->position); + if (fabsf(parent_scale.x) > 0.000001f) + exp_data->position.x /= parent_scale.x; + if (fabsf(parent_scale.y) > 0.000001f) + exp_data->position.y /= parent_scale.z; + if (fabsf(parent_scale.z) > 0.000001f) + exp_data->position.z /= parent_scale.z; + *bone_node_ptr->ex_data_mat = *bone_node_ptr->mat; + mat4_scale_rot(bone_node_ptr->mat, parent_scale.x, parent_scale.y, parent_scale.z, bone_node_ptr->mat); + vec3_mult(exp_data->scale, parent_scale, exp_data->parent_scale); +} + +void ExConstraintBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, + obj_skin_block_constraint* cns_data, const char* cns_data_name, bone_database* bone_data) { + bone_node* node = itm_eq_obj->get_bone_node(cns_data_name, bone_data); + type = EX_CONSTRAINT; + bone_node_ptr = node; + this->cns_data = cns_data; + name = node->name; + item_equip_object = itm_eq_obj; + + source_node_bone_node = itm_eq_obj->get_bone_node(cns_data->source_node_name, bone_data); + + obj_skin_block_constraint_type type = cns_data->type; + const char* up_vector_name; + if (type == OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION) { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION; + up_vector_name = cns_data->direction.up_vector.name; + } + else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_POSITION) { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_POSITION; + up_vector_name = cns_data->position.up_vector.name; + } + else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE) { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE; + up_vector_name = cns_data->distance.up_vector.name; + } + else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION) { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION; + return; + } + else { + constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_NONE; + return; + } + + if (up_vector_name) + direction_up_vector_bone_node = itm_eq_obj->get_bone_node(up_vector_name, bone_data); +} + +void ExConstraintBlock::sub_1405F10D0(mat4* mat, vec3* a2, float_t a3, float_t a4) { + vec3 v5; + vec3 v6; + vec3 v7; + vec3 v8; + vec3 v9; + vec3_normalize(*a2, v5); + vec3_mult_scalar(v5, 1.0f - a3, v9); + vec3_mult_scalar(v5, v9.x, v6); + vec3_mult_scalar(v5, v9.y, v7); + vec3_mult_scalar(v5, v9.z, v8); + mat->row0.x = v6.x + a3; + mat->row0.y = v6.y - v5.z * a4; + mat->row0.z = v6.z + v5.y * a4; + mat->row0.w = 0.0f; + mat->row1.x = v7.x + v5.z * a4; + mat->row1.y = v7.y + a3; + mat->row1.z = v7.z - v5.x * a4; + mat->row1.w = 0.0f; + mat->row2.x = v8.x - v5.y * a4; + mat->row2.y = v8.y + v5.x * a4; + mat->row2.z = v8.z + a3; + mat->row2.w = 0.0f; + mat->row3 = { 0.0f, 0.0f, 0.0f, 1.0f }; +} + +void ExConstraintBlock::sub_1401EB410(mat4* mat, vec3* a2, vec3* target_offset) { + vec3 v3; + vec3 v4; + vec3_normalize(*a2, v3); + vec3_normalize(*target_offset, v4); + vec3 v13; + vec3_cross(v4, v3, v13); + + float_t v18; + vec3_dot(v3, v4, v18); + v18 = clamp(v18, -1.0f, 1.0f); + float_t v19 = 1.0f - v18; + + float_t v20 = 1.0f - v18 * v18; + v20 = sqrtf(clamp(v20, 0.0f, 1.0f)); + + sub_1405F10D0(mat, &v13, v18, v20); +} + +ExExpressionBlock::ExExpressionBlock() : values(), types(), expressions(), +stack_data(), exp_data(), field_3D20(), field_3D28(), frame(), step(true) { + +} + +ExExpressionBlock::~ExExpressionBlock() { + +} + +void ExExpressionBlock::Init() { + frame = 0.0f; +} + +void ExExpressionBlock::Field_10() { + bone_node_expression_data* node_exp_data = &bone_node_ptr->exp_data; + node_exp_data->position = exp_data->base.position; + node_exp_data->rotation = exp_data->base.rotation; + node_exp_data->scale = exp_data->base.scale; + field_59 = false; +} + +void ExExpressionBlock::Field_18(int32_t stage, bool a3) { + if (field_59) + return; + + if (stage == 0) { + if (field_58) + Field_20(); + } + else if (stage == 2) { + if (has_children_node) + DataSet(); + } + else if (stage == 5) + Field_20(); +} + +void ExExpressionBlock::Field_20() { + if (!parent_bone_node) + return; + + if (field_59) { + field_59 = false; + return; + } + + Calc(); + DataSet(); + field_59 = true; +} + +void ExExpressionBlock::SetOsagePlayData() { + Field_20(); +} + +void ExExpressionBlock::Disp(mat4* mat, render_context* rctx) { + +} + +void ExExpressionBlock::Field_40() { + +} + +void ExExpressionBlock::Field_48() { + Field_20(); +} + +void ExExpressionBlock::Field_50() { + Field_20(); +} + +void ExExpressionBlock::Calc() { + float_t delta_frame = get_delta_frame(); + if (step) + delta_frame *= item_equip_object->item_equip->step; + float_t frame = this->frame + delta_frame; + this->frame = frame >= 65535.0f ? frame - 65535.0f : frame; + + if (field_3D28) { + field_3D28(&bone_node_ptr->exp_data); + return; + } + + for (int32_t i = 0; i < 9; i++) { + if (!expressions[i]) + break; + + float_t value = ex_expression_block_stack_get_value(expressions[i]); + if (types[i] == EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN) + value *= DEG_TO_RAD_FLOAT; + *values[i] = value; + } +} + +void ExExpressionBlock::DataSet() { + bone_node_expression_data* data = &bone_node_ptr->exp_data; + vec3 parent_scale = parent_bone_node->exp_data.parent_scale; + mat4 ex_data_mat = *parent_bone_node->ex_data_mat; + mat4 mat = mat4_identity; + data->mat_set(parent_scale, ex_data_mat, mat); + *bone_node_ptr->mat = mat; + *bone_node_ptr->ex_data_mat = ex_data_mat; +} + +void ExExpressionBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, + obj_skin_block_expression* exp_data, const char* exp_data_name, object_info a4, + size_t index, bone_database* bone_data) { + ex_expression_block_stack* stack_buf[28]; + ex_expression_block_stack** stack_buf_val = stack_buf; + + bone_node* node = itm_eq_obj->get_bone_node(exp_data_name, bone_data); + type = EX_EXPRESSION; + bone_node_ptr = node; + this->exp_data = exp_data; + name = node->name; + item_equip_object = itm_eq_obj; + + node->exp_data.position = exp_data->base.position; + node->exp_data.rotation = exp_data->base.rotation; + node->exp_data.scale = exp_data->base.scale; + field_3D28 = 0; + + ex_expression_block_stack* stack_val = stack_data; + for (int32_t i = 0; i < 9; i++) { + values[i] = 0; + expressions[i] = 0; + } + + for (int32_t i = 0; i < 9; i++) { + const char* expression = exp_data->expressions[i]; + if (!expression || str_utils_compare(expression, "= ")) + break; + + expression += 2; + + int32_t index = 0; + expression = str_utils_get_next_int32_t(expression, index, ' '); + values[i] = bone_node_ptr->get_exp_data_component(index, types[i]); + + while (expression) { + std::string value_type; + expression = str_utils_get_next_string(expression, value_type, ' '); + if (!value_type.size() || !memcmp(value_type.c_str(), "error", + min(value_type.size(), 5)) && value_type.size() == 5) + break; + + if (value_type[0] == 'n') { + stack_val->type = EX_EXPRESSION_BLOCK_STACK_NUMBER; + expression = str_utils_get_next_float_t(expression, stack_val->number.value, ' '); + *stack_buf_val++ = stack_val; + } + else if (value_type[0] == 'v') { + std::string func_str; + expression = str_utils_get_next_string(expression, func_str, ' '); + stack_val->type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + int32_t v40 = func_str[0] - '0'; + if (v40 < 9) { + bone_node* v42 = itm_eq_obj->get_bone_node(func_str.c_str() + 2, bone_data); + if (v42) + stack_val->var.value = v42->get_exp_data_component(v40, stack_val->type); + else { + stack_val->type = EX_EXPRESSION_BLOCK_STACK_NUMBER; + stack_val->number.value = 0.0f; + } + } + else + stack_val->var.value = &frame; + *stack_buf_val++ = stack_val; + } + else if (value_type[0] == 'f') { + std::string func_str; + expression = str_utils_get_next_string(expression, func_str, ' '); + stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP1; + stack_val->op1.v1 = stack_buf_val[-1]; + stack_val->op1.func = exp_func_op1_find_func(func_str, exp_func_op1_array)->func; + stack_buf_val[-1] = stack_val; + } + else if (value_type[0] == 'g') { + std::string func_str; + expression = str_utils_get_next_string(expression, func_str, ' '); + stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP2; + stack_val->op2.v1 = stack_buf_val[-2]; + stack_val->op2.v2 = stack_buf_val[-1]; + stack_val->op2.func = exp_func_op2_find_func(func_str, exp_func_op2_array)->func; + stack_buf_val[-2] = stack_val; + stack_buf_val--; + } + else if (value_type[0] == 'h') { + std::string func_str; + expression = str_utils_get_next_string(expression, func_str, ' '); + stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP3; + stack_val->op3.v1 = stack_buf_val[-3]; + stack_val->op3.v2 = stack_buf_val[-2]; + stack_val->op3.v3 = stack_buf_val[-1]; + stack_val->op3.func = exp_func_op3_find_func(func_str, exp_func_op3_array)->func; + stack_buf_val[-3] = stack_val; + stack_buf_val -= 2; + } + expressions[i] = stack_buf_val[-1]; + stack_val++; + } + } + + step = !((ssize_t)index - ITEM_TE_R <= 1); +} + +void osage_setting_data_init() { + osage_setting_data.cat = {}; + osage_setting_data.obj = {}; +} + +bool osage_setting_data_load_file(void* data, const char* path, const char* file, uint32_t hash) { + key_val kv; + if (key_val::load_file(&kv, path, file, hash)) { + osage_setting_data.parse(&kv); + return true; + } + return false; +} + +bool osage_setting_data_obj_has_key(object_info key) { + return osage_setting_data.obj.find(key) != osage_setting_data.obj.end(); +} + +void osage_setting_data_free() { + osage_setting_data.cat.clear(); + osage_setting_data.obj.clear(); +} + +void skin_param_osage_node_parse(void* kv, const char* name, + std::vector* vec, skin_param_osage_root& skp_root) { + key_val* _kv = (key_val*)kv; + if (!_kv->open_scope(name)) + return; + + if (!_kv->open_scope("node")) { + _kv->close_scope(); + return; + } + + int32_t count; + if (_kv->read("length", count)) { + size_t c = vec->size(); + if (c < count) + vec->resize(count); + } + else + vec->clear(); + + int32_t j = 0; + for (auto i = vec->begin(); i != vec->end(); i++, j++) { + if (!_kv->open_scope(j)) + continue; + + *i = skin_param_osage_node(); + + float_t coli_r = 0.0f; + if (_kv->read("coli_r", coli_r)) + i->coli_r = coli_r; + + float_t weight = 0.0f; + if (_kv->read("weight", weight)) + i->weight = weight; + + float_t inertial_cancel = 0.0f; + if (_kv->read("inertial_cancel", inertial_cancel)) + i->inertial_cancel = inertial_cancel; + + i->hinge.ymin = -skp_root.hinge_y; + i->hinge.ymax = skp_root.hinge_y; + i->hinge.zmin = -skp_root.hinge_z; + i->hinge.zmax = skp_root.hinge_z; + + float_t hinge_ymax = 0.0f; + if (_kv->read("hinge_ymax", hinge_ymax)) + i->hinge.ymax = hinge_ymax; + + float_t hinge_ymin = 0.0f; + if (_kv->read("hinge_ymin", hinge_ymin)) + i->hinge.ymin = hinge_ymin; + + float_t hinge_zmax = 0.0f; + if (_kv->read("hinge_zmax", hinge_zmax)) + i->hinge.zmax = hinge_zmax; + + float_t hinge_zmin = 0.0f; + if (_kv->read("hinge_zmin", hinge_zmin)) + i->hinge.zmin = hinge_zmin; + _kv->close_scope(); + } + + _kv->close_scope(); + _kv->close_scope(); +} + +void skin_param_osage_root_parse(void* kv, const char* name, + skin_param_osage_root& skp_root, bone_database* bone_data) { + key_val* _kv = (key_val*)kv; + if (!_kv->open_scope(name)) + return; + + int32_t node_length = 0; + _kv->read("node.length", node_length); + + if (!_kv->open_scope("root")) { + _kv->close_scope(); + return; + } + + float_t force = 0.0f; + float_t force_gain = 0.0f; + if (_kv->read("force", force) + && _kv->read("force_gain", force_gain)) { + skp_root.force = force; + skp_root.force_gain = force_gain; + } + + float_t air_res = 0.0f; + if (_kv->read("air_res", air_res)) + skp_root.air_res = min(air_res, 0.9f); + + float_t rot_y = 0.0f; + float_t rot_z = 0.0f; + if (_kv->read("rot_y", rot_y) + && _kv->read("rot_z", rot_z)) { + skp_root.rot_y = rot_y; + skp_root.rot_z = rot_z; + } + + float_t friction = 0.0f; + if (_kv->read("friction", friction)) + skp_root.friction = friction; + + float_t wind_afc = 0; + if (_kv->read("wind_afc", wind_afc)) { + skp_root.wind_afc = wind_afc; + if (!str_utils_compare_length(name, utf8_length(name), "c_opa", 5)) + skp_root.wind_afc = 0.0f; + } + + int32_t coli_type = 0; + if (_kv->read("coli_type", coli_type)) + skp_root.coli_type = coli_type; + + float_t init_rot_y = 0.0f; + float_t init_rot_z = 0.0f; + if (_kv->read("init_rot_y", init_rot_y) + && _kv->read("init_rot_z", init_rot_z)) { + skp_root.init_rot_y = init_rot_y; + skp_root.init_rot_z = init_rot_z; + } + + float_t hinge_y = 0.0f; + float_t hinge_z = 0.0f; + if (_kv->read("hinge_y", hinge_y) + && _kv->read("hinge_z", hinge_z)) { + skp_root.hinge_y = hinge_y; + skp_root.hinge_z = hinge_z; + } + + float_t coli_r = 0.0f; + if (_kv->read("coli_r", coli_r)) + skp_root.coli_r = coli_r; + + float_t stiffness = 0.0f; + if (_kv->read("stiffness", stiffness)) + skp_root.stiffness = stiffness; + + float_t move_cancel = 0.0f; + if (_kv->read("move_cancel", move_cancel)) + skp_root.move_cancel = move_cancel; + + int32_t count; + if (_kv->read("coli", "length", count)) { + std::vector& vc = skp_root.coli; + for (int32_t i = 0; i < count; i++) { + if (!_kv->open_scope(i)) + continue; + + skin_param_osage_root_coli* c = &vc[i]; + + int32_t type = 0; + if (!_kv->read("type", type)) { + _kv->close_scope(); + break; + } + c->type = (skin_param_osage_root_coli_type)type; + + float_t radius = 0; + if (!_kv->read("radius", radius)) { + _kv->close_scope(); + break; + } + c->radius = radius; + + const char* bone0_name; + if (!_kv->read("bone.0.name", bone0_name)) { + _kv->close_scope(); + break; + } + + c->bone0_index = bone_data->get_skeleton_object_bone_index( + bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone0_name); + + vec3 bone0_pos = vec3_null; + if (!_kv->read("bone.0.posx", bone0_pos.x) + || !_kv->read("bone.0.posy", bone0_pos.y) + || !_kv->read("bone.0.posz", bone0_pos.z)) { + _kv->close_scope(); + break; + } + + c->bone0_pos = bone0_pos; + + const char* bone1_name; + if (_kv->read("bone.1.name", bone1_name)) { + c->bone1_index = bone_data->get_skeleton_object_bone_index( + bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone1_name); + + vec3 bone1_pos = vec3_null; + if (!_kv->read("bone.1.posx", bone1_pos.x) + || !_kv->read("bone.1.posy", bone1_pos.y) + || !_kv->read("bone.1.posz", bone1_pos.z)) { + _kv->close_scope(); + break; + } + + c->bone1_pos = bone1_pos; + } + _kv->close_scope(); + } + _kv->close_scope(); + } + + if (_kv->read("boc", "length", count)) { + std::vector* vb = &skp_root.boc; + + vb->resize(count); + for (int32_t i = 0; i < count; i++) { + if (!_kv->open_scope(i)) + continue; + + int32_t st_node = 0; + std::string ed_root; + int32_t ed_node = 0; + if (_kv->read("st_node", st_node) + && st_node < node_length + && _kv->read("ed_root", ed_root) + && _kv->read("ed_node", ed_node) + && ed_node < node_length) { + skin_param_osage_root_boc b; + b.st_node = st_node; + b.ed_root = ed_root; + b.ed_node = ed_node; + vb->push_back(b); + } + _kv->close_scope(); + } + _kv->close_scope(); + } + + std::string colli_tgt_osg; + if (_kv->read("colli_tgt_osg", colli_tgt_osg)) + skp_root.colli_tgt_osg = colli_tgt_osg; + + if (_kv->read("normal_ref", "length", count)) { + std::vector* vnr = &skp_root.normal_ref; + + vnr->resize(count); + for (int32_t i = 0; i < count; i++) { + if (!_kv->open_scope(i)) + continue; + + std::string n; + if (_kv->read("N", n)) { + skin_param_osage_root_normal_ref nr; + nr.n = n; + _kv->read("U", nr.u); + _kv->read("D", nr.d); + _kv->read("L", nr.l); + _kv->read("R", nr.r); + vnr->push_back(nr); + } + _kv->close_scope(); + } + _kv->close_scope(); + } + + _kv->close_scope(); + _kv->close_scope(); +} + +osage_setting::osage_setting() { + +} + +osage_setting::~osage_setting() { + +} + +void osage_setting::parse(key_val* kv) { + int32_t count; + if (kv->read("cat", "length", count)) { + for (int32_t i = 0; i < count; i++) { + if (!kv->open_scope(i)) + continue; + + std::string name; + kv->read("name", name); + + int32_t count; + if (kv->read("osg", "length", count)) { + for (int32_t j = 0; j < count; j++) { + if (!kv->open_scope(j)) + continue; + + int32_t exf = 0; + kv->read("exf", exf); + + std::string parts; + kv->read("parts", parts); + + std::string root; + kv->read("root", root); + + std::pair key = { name, root }; + auto elem = cat.find(key); + if (elem == cat.end()) + elem = cat.insert({ key, {} }).first; + + elem->second.exf = exf; + elem->second.parts = parse_parts_string(&parts); + kv->close_scope(); + } + kv->close_scope(); + } + kv->close_scope(); + } + kv->close_scope(); + } + + data_struct* aft_data = &data_list[DATA_AFT]; + object_database* aft_obj_db = &aft_data->data_ft.obj_db; + + if (kv->read("obj", "length", count)) { + for (int32_t i = 0; i < count; i++) { + if (!kv->open_scope(i)) + continue; + + std::string cat; + kv->read("cat", cat); + + std::string name; + kv->read("name", name); + + obj.insert_or_assign(aft_obj_db->get_object_info(name.c_str()), cat); + kv->close_scope(); + } + kv->close_scope(); + } +} + +rob_osage_parts osage_setting::parse_parts_string(std::string* s) { + static const char* parts_string_array[] = { + "LEFT", "RIGHT", "CENTER", "LONG_C", "SHORT_L", "SHORT_R", + "APPEND_L", "APPEND_R", "MUFFLER", "WHITE_ONE_L", "PONY", "ANGEL_L", "ANGEL_R", + }; + + for (const char*& i : parts_string_array) + if (!s->compare(i)) + return (rob_osage_parts)(&i - parts_string_array); + return ROB_OSAGE_PARTS_NONE; +} + +static float_t ex_expression_block_stack_get_value(ex_expression_block_stack* stack) { + float_t value = 0.0f; + switch (stack->type) { + case EX_EXPRESSION_BLOCK_STACK_NUMBER: + value = stack->number.value; + break; + case EX_EXPRESSION_BLOCK_STACK_VARIABLE: + value = *stack->var.value; + break; + case EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN: + value = *stack->var_rad.value * RAD_TO_DEG_FLOAT; + break; + case EX_EXPRESSION_BLOCK_STACK_OP1: { + float_t v1 = ex_expression_block_stack_get_value(stack->op1.v1); + if (stack->op1.func) + value = stack->op1.func(v1); + } break; + case EX_EXPRESSION_BLOCK_STACK_OP2: { + float_t v1 = ex_expression_block_stack_get_value(stack->op2.v1); + float_t v2 = ex_expression_block_stack_get_value(stack->op2.v2); + if (stack->op2.func) + value = stack->op2.func(v1, v2); + } break; + case EX_EXPRESSION_BLOCK_STACK_OP3: { + float_t v1 = ex_expression_block_stack_get_value(stack->op1.v1); + float_t v2 = ex_expression_block_stack_get_value(stack->op2.v2); + float_t v3 = ex_expression_block_stack_get_value(stack->op3.v3); + if (stack->op3.func) + value = stack->op3.func(v1, v2, v3); + } break; + } + return value; +} + +static float_t exp_abs(float_t v1) { + return fabsf(v1); +} + +static float_t exp_acos(float_t v1) { + return acosf(v1) * RAD_TO_DEG_FLOAT; +} + +static float_t exp_add(float_t v1, float_t v2) { + return v1 + v2; +} + +static float_t exp_and(float_t v1, float_t v2) { + return v1 != 0.0f && v2 != 0.0f ? 1.0f : 0.0f; +} + +static float_t exp_asin(float_t v1) { + return asinf(v1) * RAD_TO_DEG_FLOAT; +} + +static float_t exp_atan(float_t v1) { + return atanf(v1) * RAD_TO_DEG_FLOAT; +} + +static float_t exp_av(float_t v1) { + return v1 * 0.1f; +} + +static float_t exp_ceil(float_t v1) { + return ceilf(v1); +} + +static float_t exp_cond(float_t v1, float_t v2, float_t v3) { + return v1 != 0.0f ? v2 : v3; +} + +static float_t exp_cos(float_t v1) { + return cosf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); +} + +static float_t exp_div(float_t v1, float_t v2) { + return v1 / v2; +} + +static float_t exp_eq(float_t v1, float_t v2) { + return v1 == v2 ? 1.0f : 0.0f; +} + +static float_t exp_exp(float_t v1) { + return expf(v1); +} + +static float_t exp_floor(float_t v1) { + return floorf(v1); +} + +static float_t exp_fmod(float_t v1, float_t v2) { + return fmodf(v1, v2); +} + +static const exp_func_op1* exp_func_op1_find_func(std::string& name, const exp_func_op1* array) { + const char* name_str = name.c_str(); + while (array->name) { + if (!str_utils_compare(name_str, array->name)) + return array; + array++; + } + return 0; +} + +static const exp_func_op2* exp_func_op2_find_func(std::string& name, const exp_func_op2* array) { + const char* name_str = name.c_str(); + while (array->name) { + if (!str_utils_compare(name_str, array->name)) + return array; + array++; + } + return 0; +} + +static const exp_func_op3* exp_func_op3_find_func(std::string& name, const exp_func_op3* array) { + const char* name_str = name.c_str(); + while (array->name) { + if (!str_utils_compare(name_str, array->name)) + return array; + array++; + } + return 0; +} + +static float_t exp_ge(float_t v1, float_t v2) { + return v1 >= v2 ? 1.0f : 0.0f; +} + +static float_t exp_gt(float_t v1, float_t v2) { + return v1 > v2 ? 1.0f : 0.0f; +} + +static float_t exp_le(float_t v1, float_t v2) { + return v1 <= v2 ? 1.0f : 0.0f; +} + +static float_t exp_log(float_t v1) { + return logf(v1); +} + +static float_t exp_lt(float_t v1, float_t v2) { + return v1 < v2 ? 1.0f : 0.0f; +} + +static float_t exp_max(float_t v1, float_t v2) { + return max(v1, v2); +} + +static float_t exp_min(float_t v1, float_t v2) { + return min(v1, v2); +} + +static float_t exp_mul(float_t v1, float_t v2) { + return v1 * v2; +} + +static float_t exp_ne(float_t v1, float_t v2) { + return v1 != v2 ? 1.0f : 0.0f; +} + +static float_t exp_neg(float_t v1) { + return -v1; +} + +static float_t exp_or(float_t v1, float_t v2) { + return v1 != 0.0f || v2 != 0.0f ? 1.0f : 0.0f; +} + +static float_t exp_pow(float_t v1, float_t v2) { + return powf(v1, v2); +} + +static float_t exp_rand(float_t v1, float_t v2, float_t v3) { + return v1 != 0.0f ? v2 : v3; +} + +static float_t exp_rand_0_1(float_t v1) { + return 0.0f; +} + +static float_t exp_round(float_t v1) { + return roundf(v1); +} + +static float_t exp_sin(float_t v1) { + return sinf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); +} + +static float_t exp_sqrt(float_t v1) { + return sqrtf(v1); +} + +static float_t exp_sub(float_t v1, float_t v2) { + return v1 - v2; +} + +static float_t exp_tan(float_t v1) { + return tanf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); +} + +static const osage_setting_osg_cat* osage_setting_data_get_cat_value( + object_info* obj_info, const char* root_node) { + auto elem_obj = osage_setting_data.obj.find(*obj_info); + if (elem_obj == osage_setting_data.obj.end()) + return 0; + + std::pair key = { elem_obj->second, root_node }; + auto elem_cat = osage_setting_data.cat.find(key); + if (elem_cat == osage_setting_data.cat.end()) + return 0; + + return &elem_cat->second; +} + +static void sub_140218560(RobCloth* rob_cls, float_t step, bool a3) { + sub_140219940(rob_cls); + if (rob_cls->osage_reset) { + sub_1402196D0(rob_cls); + rob_cls->osage_reset = false; + } + + if (rob_cls->move_cancel > 0.0f) { + size_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + + float_t move_cancel = rob_cls->move_cancel; + for (size_t i = 0; i < root_count; i++) { + mat4 mat = rob_cls->root.data()[i].field_D8; + CLOTHNode* node = &rob_cls->nodes.data()[i + root_count]; + for (size_t j = 1; j < nodes_count; j++, node += root_count) { + vec3 v19; + mat4_mult_vec3_trans(&mat, &node->reset_data.trans, &v19); + + vec3 v20; + vec3_sub(v19, node->trans, v20); + vec3_mult_scalar(v20, move_cancel, v20); + vec3_add(node->trans, v20, node->trans); + } + } + } + + if (step > 0.0f) { + sub_1402187D0(rob_cls, a3); + sub_140219D10(rob_cls); + sub_14021AA60(rob_cls, step, false); + if (!a3) { + rob_cls->set_external_force = false; + rob_cls->external_force = vec3_null; + } + } +} + +static void sub_1402187D0(RobCloth* rob_cls, bool a2) { + float_t v7 = (1.0f - rob_cls->field_44) * (1.0f - rob_cls->skin_param_ptr->air_res); + + float_t osage_gravity = get_osage_gravity_const(); + + vec3 external_force; + vec3_mult_scalar(rob_cls->wind_direction, rob_cls->skin_param_ptr->wind_afc, external_force); + if (rob_cls->set_external_force) { + vec3_add(external_force, rob_cls->external_force, external_force); + osage_gravity = 0.0f; + } + + size_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + + float_t force = rob_cls->skin_param_ptr->force; + CLOTHNode* node = &rob_cls->nodes.data()[root_count]; + for (size_t i = 1; i < nodes_count; i++) { + RobClothRoot* root = rob_cls->root.data(); + for (size_t j = 0; j < root_count; j++, root++, node++) { + mat4 mat = root->field_98; + + vec3 v37; + mat4_mult_vec3(&mat, &node->field_64, &v37); + + float_t v25; + if (!a2) + v25 = v7; + else if (node->trans_diff.y >= 0.0f) + v25 = 1.0f; + else + v25 = 0.0f; + + vec3_mult_scalar(v37, force, v37); + + vec3 v38; + vec3_mult_scalar(node->trans_diff, v25, v38); + + vec3_sub(v37, v38, v37); + vec3_add(v37, external_force, v37); + v37.y -= osage_gravity; + vec3_add(node->trans_diff, v37, node->trans_diff); + + node->field_1C = node->trans; + vec3_add(node->trans, node->trans_diff, node->trans); + } + force *= rob_cls->skin_param_ptr->force_gain; + } +} + +static void sub_1402196D0(RobCloth* rob_cls) { + size_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + + if (rob_cls->reset_data_list) { + std::list::iterator reset_data_list = rob_cls->reset_data_list->begin(); + CLOTHNode* i_begin = rob_cls->nodes.data() + root_count; + CLOTHNode* i_end = rob_cls->nodes.data() + rob_cls->nodes.size(); + for (CLOTHNode* i = i_begin; i != i_end; i++) + i->reset_data = *reset_data_list++; + rob_cls->reset_data_list = 0; + } + + + RobClothRoot* root = rob_cls->root.data(); + for (size_t i = 0; i < root_count; i++, root++) { + CLOTHNode* node = &rob_cls->nodes.data()[i + root_count]; + for (size_t j = 1; j < nodes_count; j++, node += root_count) { + mat4 mat = root->field_D8; + mat4_mult_vec3_trans(&mat, &node->reset_data.trans, &node->trans); + mat4_mult_vec3(&mat, &node->reset_data.trans_diff, &node->trans_diff); + } + } +} + +static void sub_140219940(RobCloth* rob_cls) { + size_t root_count = rob_cls->root_count; + + for (size_t i = 0; i < root_count; i++) { + RobClothRoot& root = rob_cls->root.data()[i]; + CLOTHNode& root_node = rob_cls->nodes.data()[i]; + + mat4 m = mat4_null; + for (int32_t j = 0; j < 4; j++) { + if (!root.mat[j] || !root.node_mat[j]) + continue; + + mat4 mat = *root.mat[j]; + mat4_mult(&mat, root.node_mat[j], &mat); + + float_t weight = root.weight[j]; + mat4_scale_mult(&mat, weight, weight, weight, weight, &mat); + + mat4_add(&m, &mat, &m); + } + root.field_98 = m; + + mat4_mult_vec3_trans(&m, &root_node.trans_orig, &root_node.trans); + mat4_mult_vec3(&m, &rob_cls->root.data()[i].normal, &root_node.normal); + mat4_mult_vec3(&m, (vec3*)&rob_cls->root.data()[i].tangent, &root_node.tangent); + root_node.tangent_sign = rob_cls->root.data()[i].tangent.w; + root_node.field_1C = root_node.trans; + + mat4_translate_mult(&m, root_node.trans_orig.x, root_node.trans_orig.y, root_node.trans_orig.z, &m); + root.field_D8 = m; + mat4_inverse(&m, &m); + root.field_118 = m; + } +} + +static void sub_140219D10(RobCloth* rob_cls) { + CLOTHNode* node = rob_cls->nodes.data(); + ssize_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + size_t v4 = nodes_count - 2; + + CLOTHNode* v7 = &node[root_count * (nodes_count - 2)]; + for (size_t i = nodes_count - 2; i; i--) { + CLOTHNode* v8 = &v7[root_count]; + for (ssize_t j = 0; j < root_count; j++, v8++) + sub_140482F30(&v8[-root_count].trans, &v8->trans, v8[-root_count].length); + v7 -= root_count; + } + + std::vector v52; + std::vector v53; + v52.resize(root_count); + v53.resize(root_count); + + vec3* v11 = v53.data(); + vec3* v12 = v52.data(); + CLOTHNode* v15 = &node[root_count]; + CLOTHNode* v16 = &node[2 * root_count - 1]; + + for (ssize_t i = nodes_count - 1; i >= 1; i--) { + vec3* v17 = v12; + vec3* v17a = v11; + if (root_count) { + CLOTHNode* v18 = v15; + for (ssize_t j = 0; j < root_count; j++, v17++, v17a++, v18++) { + *v17 = v18->trans; + *v17a = v18->trans; + } + } + + vec3* v20 = v11 + root_count - 2; + CLOTHNode* v22 = v16 - 1; + for (ssize_t j = root_count - 2; j; j--, v20--, v22--) + sub_140482F30(v20, v20 + 1, v22->field_7C); + + if (rob_cls->field_8 & 0x04) + sub_140482F30(&v11[root_count - 1], v11, v16->field_7C); + + vec3* v23 = v12 + 1; + CLOTHNode* v24 = v15 + 1; + for (ssize_t j = 1; j < root_count; j++, v23++, v24++) + sub_140482F30(v23, v23 - 1, v24->field_7C); + + if (rob_cls->field_8 & 0x04) + sub_140482F30(v12, &v12[root_count - 1], v15->field_7C); + + CLOTHNode* v26 = v15; + vec3* v27 = v11; + vec3* v28 = v12; + CLOTHNode* v36 = v26; + for (ssize_t i = 0; i < root_count; i++, v27++, v28++, v36++) { + vec3 v44; + vec3_add(*v27, *v28, v44); + vec3_mult_scalar(v44, 0.5f, v36->trans); + } + v16 += root_count; + v15 += root_count; + } +} + +static float_t sub_14021A290(vec3& a1, vec3& a2, vec3& a3, vec2& a4, vec2& a5, vec2& a6, + vec3& tangent, vec3& binormal, vec3& normal) { + vec3 v11; + vec3_sub(a2, a1, v11); + + vec3 v15; + vec3_sub(a2, a1, v15); + + vec3_cross(v15, v11, normal); + + float_t v12; + vec3_length(normal, v12); + if (v12 <= 0.000001) + return 1.0f; + + vec3_normalize(normal, normal); + + vec2 v37; + vec2 v38; + vec2_sub(a5, a4, v37); + vec2_sub(a6, a4, v38); + + float_t v19 = 1.0f / (v38.y * v37.x - v37.y * v38.x); + + vec3_mult_scalar(v15, v38.y, v15); + vec3_mult_scalar(v11, v37.y, v11); + + vec3 v20; + vec3_sub(v15, v11, v20); + vec3_mult_scalar(v20, v19, v20); + vec3_normalize(v20, v20); + + vec3_cross(normal, v20, binormal); + vec3_cross(normal, binormal, tangent); + + mat3 mat; + mat.row0 = tangent; + mat.row1 = binormal; + mat.row2 = normal; + mat3_transpose(&mat, &mat); + return mat3_determinant(&mat); +} + +static float_t sub_14021A5E0(vec3& a1, vec3& a2, float_t a3, float_t a4, vec3& tangent, vec3& binormal, vec3& normal) { + vec3_cross(a1, a2, normal); + vec3_normalize(normal, normal); + + vec3 v16; + vec3 v17; + vec3_mult_scalar(a1, a4, v16); + vec3_mult_scalar(a2, a3, v17); + + vec3 v18; + vec3_sub(v16, v17, v18); + + vec3_normalize(v18, v18); + + vec3_cross(normal, v18, binormal); + vec3_cross(normal, binormal, tangent); + + mat3 mat; + mat.row0 = tangent; + mat.row1 = binormal; + mat.row2 = normal; + mat3_transpose(&mat, &mat); + return mat3_determinant(&mat); +} + +static void sub_14021A890(CLOTHNode* a1, CLOTHNode* a2, CLOTHNode* a3, CLOTHNode* a4, CLOTHNode* a5) { + vec3 v18; + vec3_sub(a4->trans, a5->trans, v18); + + vec3 v17; + vec3_sub(a3->trans, a2->trans, v17); + + float_t v5; + float_t v7; + vec3_length(v18, v5); + vec3_length(v17, v7); + if (v5 <= 0.000001f || v7 <= 0.000001f) + return; + + vec2 v19; + vec2_sub(a4->texcoord, a5->texcoord, v19); + + vec2 v20; + vec2_sub(a3->texcoord, a2->texcoord, v20); + + float_t v14 = v19.x * v20.y - v19.y * v20.x; + if (fabsf(v14) > 0.000001f) { + v14 = 1.0f / v14; + a1->tangent_sign = sub_14021A5E0(v18, v17, v19.y * v14, v20.y * v14, + a1->tangent, a1->binormal, a1->normal); + } +} + +void sub_14021AA60(RobCloth* rob_cls, float_t step, bool a3) { + ssize_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + + float_t v10 = 1.0f / step; + + RobClothRoot* root = rob_cls->root.data(); + CLOTHNode* node = &rob_cls->nodes.data()[root_count]; + float_t coli_r = rob_cls->skin_param_ptr->coli_r; + float_t ring_height; + if (node->trans.x < rob_cls->ring.ring_rectangle_x - coli_r + || node->trans.z < rob_cls->ring.ring_rectangle_y - coli_r + || node->trans.x > rob_cls->ring.ring_rectangle_x + rob_cls->ring.ring_rectangle_width + || node->trans.z > rob_cls->ring.ring_rectangle_y + rob_cls->ring.ring_rectangle_height) + ring_height = rob_cls->ring.ring_out_height; + else + ring_height = rob_cls->ring.ring_height; + + float_t v19 = ring_height + coli_r; + + for (size_t i = 1; i < nodes_count; i++) { + for (ssize_t j = 0; j < root_count; j++, node++) { + float_t v71 = (1.0f - rob_cls->field_44) * rob_cls->skin_param_ptr->friction; + if (step != 1.0f) { + vec3 v60; + vec3_sub(node->trans, node->field_1C, v60); + + float_t v30; + vec3_length(v60, v30); + if (v30 * step > 0.0f && v30 != 0.0f) + vec3_mult_scalar(v60, 1.0f / v30, v60); + + vec3_mult_scalar(v60, v30 * step, v60); + vec3_add(node->field_1C, v60, node->trans); + } + sub_140482F30(&node[0].trans, &node[-root_count].trans, node[0].length); + + int32_t v39 = sub_1404851C0(&node->trans, rob_cls->skin_param_ptr->coli_r, &rob_cls->ring.coli, &v71); + v39 += sub_140485180(rob_cls->coli_ring, &node->trans, rob_cls->skin_param_ptr->coli_r); + v39 += sub_140485180(rob_cls->coli, &node->trans, rob_cls->skin_param_ptr->coli_r); + + if (v19 > node->trans.y && v19 < 1001.0) { + node->trans.y = v19; + node->trans_diff = vec3_null; + } + + mat4 mat = root->field_98; + mat4_set_translation(&mat, &node[-root_count].trans); + + int32_t yz_order = 1; + sub_140482FF0(mat, node->field_64, 0, 0, yz_order); + + vec3 v74; + mat4_mult_vec3_inv_trans(&mat, &node->trans, &v74); + + sub_140482FF0(mat, v74, &rob_cls->skin_param_ptr->hinge, + &node->reset_data.rotation, yz_order); + mat4_translate_mult(&mat, node->length, 0.0f, 0.0f, &mat); + mat4_get_translation(&mat, &node->trans); + + if (v39) + vec3_mult_scalar(node->trans_diff, v71, node->trans_diff); + + vec3 v44; + vec3_sub(node->trans, node->field_1C, v44); + vec3_mult_scalar(v44, v10, node->trans_diff); + + if (!a3) { + mat4 v49 = rob_cls->root.data()[j].field_118; + mat4_mult_vec3_trans(&v49, &node->trans, &node->reset_data.trans); + mat4_mult_vec3(&v49, &node->trans_diff, &node->reset_data.trans_diff); + } + } + } +} + +static void sub_14021D480(RobCloth* rob_cls) { + sub_140219940(rob_cls); + + const float_t osage_gravity_const = get_osage_gravity_const(); + + ssize_t root_count = rob_cls->root_count; + size_t nodes_count = rob_cls->nodes_count; + + CLOTHNode* node = &rob_cls->nodes.data()[root_count]; + float_t coli_r = rob_cls->skin_param_ptr->coli_r; + float_t ring_height; + if (node->trans.x < rob_cls->ring.ring_rectangle_x - coli_r + || node->trans.z < rob_cls->ring.ring_rectangle_y - coli_r + || node->trans.x > rob_cls->ring.ring_rectangle_x + rob_cls->ring.ring_rectangle_width + || node->trans.z > rob_cls->ring.ring_rectangle_y + rob_cls->ring.ring_rectangle_height) + ring_height = rob_cls->ring.ring_out_height; + else + ring_height = rob_cls->ring.ring_height; + + float_t v10 = ring_height + coli_r; + + for (size_t i = 1; i < nodes_count; i++) { + RobClothRoot* root = rob_cls->root.data(); + for (ssize_t j = 0; j < root_count; j++, root++, node++) { + mat4 mat = root->field_98; + + vec3 v38; + mat4_mult_vec3(&mat, &node->field_64, &v38); + v38.y -= osage_gravity_const; + + vec3_normalize(v38, v38); + vec3_mult_scalar(v38, node->length, v38); + vec3_add(node[-root_count].trans, v38, node[0].trans); + + sub_1404851C0(&node->trans, rob_cls->skin_param_ptr->coli_r, &rob_cls->ring.coli, 0); + sub_140485180(rob_cls->coli_ring, &node->trans, rob_cls->skin_param_ptr->coli_r); + sub_140485180(rob_cls->coli, &node->trans, rob_cls->skin_param_ptr->coli_r); + + if (v10 > node->trans.y && v10 < 1001.0f) + node->trans.y = v10; + + node->trans_diff = vec3_null; + node->field_1C = node->trans; + } + } + + for (size_t i = 0; i < qword_140FBDF88; ++i) + sub_14021DC60(rob_cls, 1.0f); + + node = &rob_cls->nodes.data()[root_count]; + for (size_t i = 1; i < nodes_count; i++) + for (ssize_t j = 0; j < root_count; j++, node++) + node->trans_diff = vec3_null; +} + +static void sub_14021DC60(RobCloth* rob_cls, float_t step) { + if (step <= 0.0f) + return; + + sub_140219940(rob_cls); + sub_1402187D0(rob_cls, true); + sub_140219D10(rob_cls); + sub_14021AA60(rob_cls, step, true); +} + +static void sub_14021D840(RobCloth* rob_cls) { + sub_140218560(rob_cls, 1.0f, true); +} + +static void sub_14047C800(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, + float_t step, bool disable_wind, bool ring_coli, bool has_children_node) { + if (!rob_osg->nodes.size()) + return; + + const float_t osage_gravity_const = get_osage_gravity_const(); + sub_1404803B0(rob_osg, mat, parent_scale, false); + + RobOsageNode* v17 = &rob_osg->nodes.data()[0]; + v17->trans_orig = v17->trans; + vec3 v113; + vec3_mult(rob_osg->exp_data.position, *parent_scale, v113); + + mat4 v130 = *mat; + mat4_mult_vec3_trans(&v130, &v113, &v17->trans); + vec3_sub(v17->trans, v17->trans_orig, v17->trans_diff); + sub_14047F110(rob_osg, &v130, parent_scale, 0); + *rob_osg->nodes.data()[0].bone_node_mat = v130; + *rob_osg->nodes.data()[0].bone_node_ptr->ex_data_mat = v130; + + v113 = { 1.0f, 0.0f, 0.0f }; + vec3 v128; + mat4_mult_vec3(&v130, &v113, &v128); + + float_t v25 = parent_scale->x; + if (!rob_osg->osage_reset && step <= 0.0f) + return; + + bool stiffness = rob_osg->skin_param_ptr->stiffness > 0.0f; + + RobOsageNode* v30 = rob_osg->nodes.data(); + RobOsageNode* v26_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v26_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v26 = v26_begin; v26 != v26_end; v26++, v30++) { + RobOsageNodeData* v31 = v26->data_ptr; + float_t weight = v31->skp_osg_node.weight; + vec3 v111; + if (!rob_osg->set_external_force) { + sub_140482300(&v111, &v26->trans, &v30->trans, osage_gravity_const, weight); + + if (v26 != v26_end - 1) { + vec3 v112; + sub_140482300(&v112, &v26->trans, &v26[1].trans, osage_gravity_const, weight); + vec3_add(v111, v112, v111); + vec3_mult_scalar(v111, 0.5f, v111); + } + } + else + vec3_mult_scalar(rob_osg->external_force, 1.0f / weight, v111); + + vec3 v127; + vec3_mult_scalar(v128, v31->force * v26->force, v127); + float_t v41 = (1.0f - rob_osg->field_1EB4) * (1.0f - rob_osg->skin_param_ptr->air_res); + + vec3 v126; + vec3_add(v111, v127, v126); + vec3_mult_scalar(v26->trans_diff, v41, v111); + vec3_sub(v126, v111, v126); + vec3_mult_scalar(v26->external_force, weight, v111); + vec3_add(v126, v111, v126); + + if (!disable_wind) { + vec3_mult_scalar(rob_osg->wind_direction, rob_osg->skin_param_ptr->wind_afc, v111); + vec3_add(v126, v111, v126); + } + + if (stiffness) { + vec3 v116; + vec3_sub(v26->trans_diff, v30->trans_diff, v116); + vec3_mult_scalar(v116, 1.0f - rob_osg->skin_param_ptr->air_res, v116); + vec3_sub(v126, v116, v126); + } + + float_t v49 = 1.0f / (weight - (weight - 1.0f) * v31->skp_osg_node.inertial_cancel); + vec3_mult_scalar(v126, v49, v26->field_28); + } + + if (stiffness) { + mat4 v131 = v130; + vec3 v111; + mat4_get_translation(&v131, &v111); + + RobOsageNode* v55_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v55_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v55 = v55_begin; v55 != v55_end; v55++) { + mat4_mult_vec3_trans(&v131, &v55->field_94, &v128); + + vec3 v123; + vec3_add(v55->trans_diff, v55->field_28, v123); + vec3 v126; + vec3_add(v55->trans, v123, v126); + sub_140482F30(&v126, &v111, v25 * v55->length); + vec3 v117; + vec3_sub(v128, v126, v117); + vec3_mult_scalar(v117, rob_osg->skin_param_ptr->stiffness, v117); + float_t weight = v55->data_ptr->skp_osg_node.weight; + float_t v74 = 1.0f / (weight - (weight - 1.0f) * v55->data_ptr->skp_osg_node.inertial_cancel); + vec3_mult_scalar(v117, v74, v117); + vec3_add(v55->field_28, v117, v55->field_28); + vec3_add(v55->trans, v117, v126); + vec3_add(v126, v123, v126); + + vec3 v129; + mat4_mult_vec3_inv_trans(&v131, &v126, &v129); + + sub_140482FF0(v131, v129, 0, 0, rob_osg->yz_order); + + float_t v58; + vec3_distance(v111, v126, v58); + mat4_translate_mult(&v131, v58, 0.0f, 0.0f, &v131); + + v111 = v126; + } + } + + RobOsageNode* v82_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v82_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v82 = v82_begin; v82 != v82_end; v82++) { + v82->trans_orig = v82->trans; + vec3_add(v82->field_28, v82->trans_diff, v82->trans_diff); + vec3_add(v82->trans_diff, v82->trans, v82->trans); + } + + if (rob_osg->nodes.size() > 1) { + RobOsageNode* v90_begin = rob_osg->nodes.data() + rob_osg->nodes.size() - 2; + RobOsageNode* v90_end = rob_osg->nodes.data(); + for (RobOsageNode* v90 = v90_begin; v90 != v90_end; v90--) + sub_140482F30(&v90[0].trans, &v90[1].trans, v25 * v90->child_length); + } + + if (ring_coli) { + RobOsageNode* v91 = &rob_osg->nodes.data()[0]; + float_t coli_r = v91->data_ptr->skp_osg_node.coli_r; + float_t ring_height; + if (v91->trans.x < rob_osg->ring.ring_rectangle_x - coli_r + || v91->trans.z < rob_osg->ring.ring_rectangle_y - coli_r + || v91->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width + || v91->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) + ring_height = rob_osg->ring.ring_out_height; + else + ring_height = rob_osg->ring.ring_height; + + float_t v96 = ring_height + coli_r; + RobOsageNode* v98_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v98_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (auto v98 = v98_begin; v98 != v98_end; v98++) { + sub_140482490(v98, step, v25); + sub_140482180(v98, v96); + } + } + + if (has_children_node) { + RobOsageNode* v100 = rob_osg->nodes.data(); + RobOsageNode* v99_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v99_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v99 = v99_begin; v99 != v99_end; v99++, v100++) { + vec3 v129; + mat4_mult_vec3_inv_trans(&v130, &v99->trans, &v129); + bool v102 = sub_140482FF0(v130, v129, + &v99->data_ptr->skp_osg_node.hinge, + &v99->reset_data.rotation, rob_osg->yz_order); + *v99->bone_node_ptr->ex_data_mat = v130; + + float_t v104; + vec3_distance_squared(v99->trans, v100->trans, v104); + float_t v105 = v25 * v99->length; + + bool v106; + if (v104 >= v105 * v105) { + v105 = sqrtf(v104); + v106 = false; + } + else + v106 = true; + + mat4_translate_mult(&v130, v105, 0.0f, 0.0f, &v130); + if (v102 || v106) + mat4_get_translation(&v130, &v99->trans); + } + + if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { + mat4 v131 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; + mat4_translate_mult(&v131, v25 * rob_osg->node.length, 0.0f, 0.0f, &v131); + *rob_osg->node.bone_node_ptr->ex_data_mat = v131; + } + } + rob_osg->field_2A0 = false; +} + +static void sub_14047E1C0(RobOsage* rob_osg, vec3* scale) { + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + if (i->data_ptr->normal_ref.field_0) { + sub_14053CE30(&i->data_ptr->normal_ref, i->bone_node_mat); + mat4_scale_rot(i->bone_node_mat, scale->x, scale->y, scale->z, i->bone_node_mat); + } +} + +static void sub_14047EE90(RobOsage* rob_osg, mat4* mat) { + if (rob_osg->reset_data_list) { + std::list::iterator reset_data_list = rob_osg->reset_data_list->begin(); + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + i->reset_data = *reset_data_list++; + rob_osg->reset_data_list = 0; + } + + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + mat4_mult_vec3(mat, &i->reset_data.trans_diff, &i->trans_diff); + mat4_mult_vec3_trans(mat, &i->reset_data.trans, &i->trans); + } + rob_osg->parent_mat = *rob_osg->parent_mat_ptr; +} + +static void sub_14047F110(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, bool init_rot) { + vec3 position; + vec3_mult(rob_osg->exp_data.position, *parent_scale, position); + mat4_translate_mult(mat, position.x, position.y, position.z, mat); + + vec3 rotation = rob_osg->exp_data.rotation; + mat4_rotate_mult(mat, rotation.x, rotation.y, rotation.z, mat); + + skin_param* skin_param = rob_osg->skin_param_ptr; + vec3 rot = skin_param->rot; + if (init_rot) + vec3_add(rot, skin_param->init_rot, rot); + mat4_rotate_mult(mat, rot.x, rot.y, rot.z, mat); +} + +static void sub_1404803B0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, bool has_children_node) { + mat4 v47 = *mat; + vec3 v45; + vec3_mult(rob_osg->exp_data.position, *parent_scale, v45); + mat4_mult_vec3_trans(&v47, &v45, &rob_osg->nodes.data()[0].trans); + if (rob_osg->osage_reset && !rob_osg->field_1F0E) { + rob_osg->field_1F0E = true; + sub_14047EE90(rob_osg, mat); + } + + if (!rob_osg->field_1F0C) { + rob_osg->field_1F0C = true; + + float_t move_cancel = rob_osg->skin_param_ptr->move_cancel; + if (rob_osg->move_cancel == 1.0f) + move_cancel = 1.0f; + if (move_cancel < 0.0f) + move_cancel = rob_osg->move_cancel; + + if (move_cancel > 0.0f) { + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + mat4 parent_mat; + vec3 v46; + parent_mat = rob_osg->parent_mat; + mat4_mult_vec3_inv_trans(&parent_mat, &i->trans, &v46); + parent_mat = *rob_osg->parent_mat_ptr; + mat4_mult_vec3_trans(&parent_mat, &v46, &v46); + vec3_sub(v46, i->trans, v46); + vec3_mult_scalar(v46, move_cancel, v46); + vec3_add(i->trans, v46, i->trans); + } + } + } + + if (has_children_node) { + sub_14047F110(rob_osg, &v47, parent_scale, 0); + *rob_osg->nodes.data()[0].bone_node_mat = v47; + RobOsageNode* v29 = rob_osg->nodes.data(); + RobOsageNode* v30_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v30_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v30 = v30_begin; v30 != v30_end; v29++, v30++) { + vec3 v46; + mat4_mult_vec3_inv_trans(&v47, &v30->trans, &v46); + bool v32 = sub_140482FF0(v47, v46, &v30->data_ptr->skp_osg_node.hinge, + &v30->reset_data.rotation, rob_osg->yz_order); + *v30->bone_node_ptr->ex_data_mat = v47; + float_t v34; + vec3_distance(v30->trans, v29->trans, v34); + float_t v35 = parent_scale->x * v30->length; + bool v36; + if (v34 >= fabsf(v35)) { + v35 = v34; + v36 = false; + } + else + v36 = true; + mat4_translate_mult(&v47, v35, 0.0f, 0.0f, &v47); + if (v32 || v36) + mat4_get_translation(&v47, &v30->trans); + } + + if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { + mat4 v48 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; + mat4_translate_mult(&v48, parent_scale->x * rob_osg->node.length, 0.0f, 0.0f, &v48); + *rob_osg->node.bone_node_ptr->ex_data_mat = v48; + } + } +} + +static void sub_140482180(RobOsageNode* node, float_t a2) { + float_t v2 = node->data_ptr->skp_osg_node.coli_r + a2; + if (v2 <= node->trans.y) + return; + + node->trans.y = v2; + vec3 v3; + vec3_sub(node->trans, node[-1].trans, v3); + vec3_normalize(v3, v3); + vec3_mult_scalar(v3, node->length, v3); + vec3_add(node[-1].trans, v3, node->trans); + node->trans_diff = vec3_null; + node->field_C8 += 1.0f; +} + +static void sub_140482300(vec3* a1, vec3* a2, vec3* a3, float_t osage_gravity_const, float_t weight) { + weight *= osage_gravity_const; + vec3 diff; + vec3_sub(*a2, *a3, diff); + float_t dist; + vec3_length(diff, dist); + if (dist <= fabsf(osage_gravity_const)) { + diff.y = osage_gravity_const; + vec3_length(diff, dist); + } + vec3_mult_scalar(diff, weight * diff.y * (1.0f / (dist * dist)), diff); + vec3_negate(diff, diff); + diff.y -= weight; + *a1 = diff; +} + +static void sub_140482490(RobOsageNode* node, float_t step, float_t a3) { + if (step != 1.0f) { + vec3 v4; + vec3_sub(node->trans, node->trans_orig, v4); + + float_t v9; + vec3_length(v4, v9); + if (v9 != 0.0f) + vec3_mult_scalar(v4, 1.0f / v9, v4); + vec3_mult_scalar(v4, step * v9, v4); + vec3_add(node->trans_orig, v4, node->trans); + } + + sub_140482F30(&node[0].trans, &node[-1].trans, node->length * a3); + if (node->sibling_node) + sub_140482F30(&node->trans, &node->sibling_node->trans, node->max_distance); +} + +static void sub_140482F30(vec3* pos1, vec3* pos2, float_t length) { + vec3 diff; + vec3_sub(*pos1, *pos2, diff); + float_t dist; + vec3_length_squared(diff, dist); + if (dist > length * length) { + vec3_mult_scalar(diff, length / sqrtf(dist), diff); + vec3_add(*pos2, diff, *pos1); + } +} + +static int32_t sub_140483B30(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { + vec3 bone_pos_diff; + vec3_add(a3->bone0_pos, a3->bone1_pos, bone_pos_diff); + + vec3 v29; + vec3 v30; + for (int32_t i = 0; i < 3; i++) { + float_t v13 = ((float_t*)a2)[i]; + float_t v14 = ((float_t*)&a3->bone0_pos)[i] - v13; + ((float_t*)&v30)[i] = v14; + if (v14 > radius) + return 0; + + v14 = v13 - ((float_t*)&bone_pos_diff)[i]; + ((float_t*)&v29)[i] = v14; + if (v14 > radius) + return 0; + } + + vec3 v28 = vec3_null; + vec3 v32 = vec3_null; + vec3 v27 = vec3_identity; + + float_t v16 = 0.0f; + for (int32_t i = 0; i < 3; i++) { + float_t v18 = ((float_t*)&v30)[i]; + float_t v19 = ((float_t*)&v29)[i]; + if (fabsf(v18) >= fabsf(v19)) { + ((float_t*)&v28)[i] = v19; + ((float_t*)&v27)[i] = 1.0f; + v18 = v19; + } + else { + ((float_t*)&v28)[i] = v18; + ((float_t*)&v27)[i] = -1.0f; + } + + if (v18 > 0.0f) { + float_t v20 = v18 * v18; + ((float_t*)&v32)[i] = v20; + v16 += v20; + } + } + + if (v16 > radius * radius) + return 0; + + if (v16 > 0.0f) { + vec3_mult(v27, v32, v32); + vec3_mult_scalar(v32, 1.0f / v16, v32); + vec3_mult_scalar(v32, radius - sqrtf(v16), *a1); + } + else { + float_t v25 = ((float_t*)&v28)[0]; + int32_t v26 = 0; + for (int32_t i = 0; i < 3; i++) { + if (((float_t*)&v28)[i] > v25) { + v25 = ((float_t*)&v28)[i]; + v26 = i; + } + } + ((float_t*)a1)[v26] -= ((float_t*)&v27)[v26] * (v25 - radius); + } + return 1; +} + +static int32_t sub_140483DE0(vec3* a1, vec3* a2, vec3* a3, float_t radius) { + vec3 v5; + float_t length; + vec3_sub(*a2, *a3, v5); + vec3_length_squared(v5, length); + if (length > 0.000001f && length < radius * radius) { + vec3_mult_scalar(v5, radius / sqrtf(length) - 1.0f, *a1); + return 1; + } + return 0; +} + +static int32_t sub_140483EA0(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { + if (a3->bone_pos_diff_length <= 0.000001f) + return sub_140483DE0(a1, a2, &a3->bone0_pos, radius); + + float_t v61 = a3->bone_pos_diff_length * 0.5f; + float_t v13 = sqrtf(radius * radius + v61 * v61); + + float_t v20; + vec3 v54; + vec3_sub(*a2, a3->bone0_pos, v54); + vec3_length(v54, v20); + + float_t v21; + vec3 v57; + vec3_sub(*a2, a3->bone1_pos, v57); + vec3_length(v57, v21); + + if (v20 <= 0.000001f || v21 <= 0.000001f) + return 0; + + float_t v22 = v20 + v21; + if (v21 + v20 >= v13 * 2.0f) + return 0; + + float_t v25 = 1.0f / a3->bone_pos_diff_length; + + vec3 v63; + vec3_add(a3->bone0_pos, a3->bone1_pos, v63); + vec3_mult_scalar(v63, 0.5f, v63); + vec3_sub(*a2, v63, v63); + + float_t v58; + vec3_length(v63, v58); + if (v58 != 0.0f) + vec3_mult_scalar(v63, 1.0f / v58, v63); + + float_t v36; + vec3_dot(v63, a3->bone_pos_diff, v36); + v36 *= v25; + float_t v37 = v36 * v36; + v37 = min(v37, 1.0f); + v22 *= 0.5f; + float_t v38 = v22 * v22 - v61; + if (v38 < 0.0f) + return 0; + + float_t v39 = sqrtf(v38); + if (v39 <= 0.000001f) + return 0; + + float_t v42 = sqrtf(1.0f - v37); + v22 = (v13 / v22 - 1.0f) * v36 * v58; + v42 = (radius / v39 - 1.0f) * v42 * v58; + float_t v43 = sqrtf(v42 * v42 + v22 * v22); + if (v20 != 0.0f) + vec3_mult_scalar(v54, 1.0f / v20, v54); + + if (v21 != 0.0f) + vec3_mult_scalar(v57, 1.0f / v21, v57); + + vec3 v48; + vec3_add(v54, v57, v48); + vec3_normalize(v48, v48); + vec3_mult_scalar(v48, v43, *a1); + return 1; +} + +static int32_t sub_140484540(vec3* a1, vec3* a2, osage_coli* coli, float_t radius) { + vec3 v11; + vec3_sub(*a2, coli->bone0_pos, v11); + + float_t v17; + vec3_dot(v11, coli->bone_pos_diff, v17); + if (v17 < 0.0f) + return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); + + float_t v19 = coli->bone_pos_diff_length_squared; + if (fabsf(v19) <= 0.000001f) + return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); + if (v17 > v19) + return sub_140483DE0(a1, a2, &coli->bone1_pos, radius); + + float_t v20; + vec3_length_squared(v11, v20); + float_t v22 = fabsf(v20 - v17 * v17 / v19); + if (v22 <= 0.000001f || v22 >= radius * radius) + return 0; + + vec3 v29; + vec3_mult_scalar(coli->bone_pos_diff, v17 / v19, v29); + vec3_sub(v11, v29, v29); + vec3_mult_scalar(v29, radius / sqrtf(v22) - 1.0f, *a1); + return 1; +} + +static int32_t sub_140484780(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { + float_t v3; + vec3_dot(*a2, *a4, v3); + float_t v4; + vec3_dot(*a3, *a4, v4); + float_t v5 = v3 - v4 - radius; + if (v5 >= 0.0f) + return 0; + + vec3_mult_scalar(*a4, -v5, *a1); + return 1; +} + +static int32_t sub_140485180(osage_coli* a1, vec3* a2, float_t& coli_r) { + return sub_140485220(a2, coli_r, a1, 0); +} + +static int32_t sub_1404851C0(vec3* a1, float_t& coli_r, std::vector* a3, float_t* a4) { + if (!a3->size() || a3->back().type) + return 0; + return sub_140485220(a1, coli_r, a3->data(), a4); +} + +static int32_t sub_140485220(vec3* a1, float_t& coli_r, osage_coli* a3, float_t* a4) { + if (!a3) + return 0; + + int32_t v8 = 0; + while (a3->type) { + int32_t v11 = 0; + vec3 v31 = vec3_null; + switch (a3->type) { + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: + v11 = sub_140483DE0(&v31, a1, &a3->bone0_pos, a3->radius + coli_r); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: + v11 = sub_140484540(&v31, a1, a3, a3->radius + coli_r); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE: + v11 = sub_140484780(&v31, a1, &a3->bone0_pos, &a3->bone1_pos, coli_r); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: + v11 = sub_140483EA0(&v31, a1, a3, a3->radius + coli_r); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_5: + v11 = sub_140483B30(&v31, a1, a3, coli_r); + break; + } + + if (a4 && v11 > 0) { + if (a3->field_34 < *a4) + *a4 = a3->field_34; + } + a3++; + v8 += v11; + vec3_add(*a1, v31, *a1); + } + return v8; +} + +static void sub_14047D8C0(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5) { + if (!rob_osg->osage_reset && step <= 0.0f) + return; + + osage_coli* coli = rob_osg->coli; + osage_coli* coli_ring = rob_osg->coli_ring; + std::vector* vec_ring_coli = &rob_osg->ring.coli; + + float_t v9 = 0.0f; + if (step > 0.0f) + v9 = 1.0f / step; + + mat4 v64; + if (a5) + v64 = *rob_osg->nodes.data()[0].bone_node_mat; + else { + v64 = *mat; + + vec3 trans; + vec3_mult(rob_osg->exp_data.position, *parent_scale, trans); + mat4_mult_vec3_trans(&v64, &trans, &rob_osg->nodes.data()[0].trans); + sub_14047F110(rob_osg, &v64, parent_scale, 0); + } + + float_t v60 = -1000.0f; + if (a5) { + RobOsageNode* v16 = &rob_osg->nodes.data()[0]; + float_t coli_r = v16->data_ptr->skp_osg_node.coli_r; + float_t ring_height; + if (v16->trans.x < rob_osg->ring.ring_rectangle_x - coli_r + || v16->trans.z < rob_osg->ring.ring_rectangle_y - coli_r + || v16->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width + || v16->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) + ring_height = rob_osg->ring.ring_out_height; + else + ring_height = rob_osg->ring.ring_height; + + v60 = ring_height + coli_r; + } + + float_t v23 = 0.2f; + if (step < 1.0f) + v23 = 0.2f / (2.0f - step); + + if (rob_osg->skin_param_ptr->colli_tgt_osg) { + std::vector* v24 = rob_osg->skin_param_ptr->colli_tgt_osg; + RobOsageNode* v27_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v27_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v27 = v27_begin; v27 != v27_end; v27++) { + vec3 v62 = vec3_null; + + RobOsageNode* v30_begin = v24->data() + 1; + RobOsageNode* v30_end = v24->data() + v24->size(); + for (RobOsageNode* v30 = v30_begin; v30 != v30_end; v30++) + sub_140483DE0(&v62, &v27->trans, &v30->trans, + v27->data_ptr->skp_osg_node.coli_r + v30->data_ptr->skp_osg_node.coli_r); + vec3_add(v27->trans, v62, v27->trans); + } + } + + RobOsageNode* v35_begin = rob_osg->nodes.data() + 1; + RobOsageNode* v35_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* v35 = v35_begin; v35 != v35_end; v35++) { + skin_param_osage_node* skp_osg_node = &v35->data_ptr->skp_osg_node; + float_t v37 = (1.0f - rob_osg->field_1EB4) * rob_osg->skin_param_ptr->friction; + if (a5) { + sub_140482490(&v35[0], step, parent_scale->x); + v35->field_C8 = (float_t)sub_1404851C0(&v35->trans, + skp_osg_node->coli_r, vec_ring_coli, &v35->field_CC); + if (!rob_osg->field_1F0F) { + v35->field_C8 += (float_t)sub_140485180(coli_ring, &v35->trans, skp_osg_node->coli_r); + v35->field_C8 += (float_t)sub_140485180(coli, &v35->trans, skp_osg_node->coli_r); + } + sub_140482180(&v35[0], v60); + } + else + sub_140482F30(&v35[0].trans, &v35[-1].trans, v35[0].length * parent_scale->x); + + vec3 v63; + mat4_mult_vec3_inv_trans(&v64, &v35->trans, &v63); + bool v40 = sub_140482FF0(v64, v63, &skp_osg_node->hinge, + &v35->reset_data.rotation, rob_osg->yz_order); + v35->bone_node_ptr->exp_data.parent_scale = *parent_scale; + *v35->bone_node_ptr->ex_data_mat = v64; + + if (v35->bone_node_mat) { + mat4* v41 = v35->bone_node_mat; + mat4_scale_rot(&v64, parent_scale->x, parent_scale->y, parent_scale->z, v41); + } + + float_t v42 = v35->length * parent_scale->x; + float_t v44; + bool v45; + vec3_distance_squared(v35[0].trans, v35[-1].trans, v44); + if (v44 >= v42 * v42) { + v42 = sqrtf(v44); + v45 = false; + } + else + v45 = true; + + mat4_translate_mult(&v64, v42, 0.0f, 0.0f, &v64); + v35->reset_data.length = v42; + if (v40 || v45) + mat4_get_translation(&v64, &v35->trans); + + vec3 v62; + vec3_sub(v35->trans, v35->trans_orig, v62); + vec3_mult_scalar(v62, v9, v35->trans_diff); + + if (v35->field_C8 > 0.0f) { + if (v35->field_CC < v37) + v37 = v35->field_CC; + vec3_mult_scalar(v35->trans_diff, v37, v35->trans_diff); + } + + float_t v55; + vec3_length_squared(v35->trans_diff, v55); + if (v55 > v23 * v23) + vec3_mult_scalar(v35->trans_diff, v23 / sqrtf(v55), v35->trans_diff); + + mat4_mult_vec3_inv_trans(mat, &v35->trans, &v35->reset_data.trans); + mat4_mult_vec3_inv(mat, &v35->trans_diff, &v35->reset_data.trans_diff); + } + + if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { + mat4 v65 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; + mat4_translate_mult(&v65, rob_osg->node.length * parent_scale->x, 0.0f, 0.0f, &v65); + *rob_osg->node.bone_node_ptr->ex_data_mat = v65; + mat4_scale_rot(&v65, parent_scale->x, parent_scale->y, parent_scale->z, &v65); + *rob_osg->node.bone_node_mat = v65; + rob_osg->node.bone_node_ptr->exp_data.parent_scale = *parent_scale; + } +} + +static void sub_14047C750(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step) { + sub_14047C770(rob_osg, mat, parent_scale, step, false); +} + +static void sub_14047C770(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5) { + sub_14047C800(rob_osg, mat, parent_scale, step, a5, false, false); + sub_14047D8C0(rob_osg, mat, parent_scale, step, true); + sub_140480260(rob_osg, mat, parent_scale, step, a5); +} + +static void sub_14047D620(RobOsage* rob_osg, float_t step) { + if (step < 0.0f && rob_osg->field_1F0F) + return; + + vec3 v7 = rob_osg->nodes.data()[0].trans; + osage_coli* coli = rob_osg->coli; + osage_coli* coli_ring = rob_osg->coli_ring; + int32_t coli_type = rob_osg->skin_param_ptr->coli_type; + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + RobOsageNodeData* data = i->data_ptr; + for (RobOsageNode*& j : data->boc) { + float_t v17 = (float_t)( + sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli) + + sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli_ring)); + i->field_C8 += v17; + j->field_C8 += v17; + } + + if (coli_type && (coli_type != 1 || i != i_begin)) { + float_t v20 = (float_t)( + sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli) + + sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli_ring)); + i[0].field_C8 += v20; + i[-1].field_C8 += v20; + } + } + rob_osg->nodes.data()[0].trans = v7; +} + +static void sub_14047ECA0(RobOsage* rob_osg, float_t step) { + if (step <= 0.0f) + return; + + std::vector* vec_coli = &rob_osg->ring.coli; + osage_coli* coli_ring = rob_osg->coli_ring; + osage_coli* coli = rob_osg->coli; + bool v11 = rob_osg->field_1F0F; + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) { + RobOsageNodeData* data = i->data_ptr; + i->field_C8 += (float_t)sub_1404851C0(&i->trans, data->skp_osg_node.coli_r, vec_coli, &i->field_CC); + if (v11) + continue; + + for (RobOsageNode*& j : data->boc) { + j->field_C8 += (float_t)sub_140485180(coli_ring, &j->trans, data->skp_osg_node.coli_r); + j->field_C8 += (float_t)sub_140485180(coli, &j->trans, data->skp_osg_node.coli_r); + } + + i->field_C8 += (float_t)sub_140485180(coli_ring, &i->trans, data->skp_osg_node.coli_r); + i->field_C8 += (float_t)sub_140485180(coli, &i->trans, data->skp_osg_node.coli_r); + } +} + +static void sub_14047F990(RobOsage* rob_osg, mat4* a2, vec3* a3, bool a4) { + if (!rob_osg->nodes.size()) + return; + + vec3 v76; + vec3_mult(rob_osg->exp_data.position, *a3, v76); + mat4_mult_vec3_trans(a2, &v76, &v76); + vec3 v74 = v76; + RobOsageNode* v12 = &rob_osg->nodes.data()[0]; + v12->trans = v76; + v12->trans_orig = v76; + v12->trans_diff = vec3_null; + + float_t ring_height; + RobOsageNode* v14 = &rob_osg->nodes.data()[0]; + float_t coli_r = v14->data_ptr->skp_osg_node.coli_r; + if (v14->trans.x < rob_osg->ring.ring_rectangle_x - coli_r + || v14->trans.z < rob_osg->ring.ring_rectangle_y - coli_r + || v14->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width + || v14->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) + ring_height = rob_osg->ring.ring_out_height; + else + ring_height = rob_osg->ring.ring_height; + + mat4 v78 = *a2; + sub_14047F110(rob_osg, &v78, a3, true); + vec3 v60 = { 1.0f, 0.0f, 0.0f }; + mat4_mult_vec3(&v78, &v60, &v60); + + osage_coli* coli_ring = rob_osg->coli_ring; + osage_coli* coli = rob_osg->coli; + float_t v25 = ring_height + coli_r; + float_t v16 = a3->x; + RobOsageNode* i = rob_osg->nodes.data(); + RobOsageNode* j_begin = rob_osg->nodes.data() + 1; + RobOsageNode* j_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* j = j_begin; j != j_end; i++, j++) { + vec3_normalize(v60, v60); + vec3_mult_scalar(v60, v16 * j->length, v60); + vec3_add(i->trans, v60, v74); + if (a4 && j->sibling_node) + sub_140482F30(&v74, &j->sibling_node->trans, j->max_distance); + + skin_param_osage_node* v38 = &j->data_ptr->skp_osg_node; + sub_140485180(coli_ring, &v74, v38->coli_r); + sub_140485180(coli, &v74, v38->coli_r); + + float_t v39 = v25 + v38->coli_r; + if (v74.y < v39 && v39 < 1001.0f) { + v74.y = v39; + vec3_sub(v74, i->trans, v74); + vec3_normalize(v74, v74); + vec3_mult_scalar(v74, v16 * j->length, v74); + vec3_add(v74, i->trans, v74); + } + j->trans = v74; + j->trans_diff = vec3_null; + vec3 v77; + mat4_mult_vec3_inv_trans(&v78, &j->trans, &v77); + sub_140482FF0(v78, v77, &j->data_ptr->skp_osg_node.hinge, + &j->reset_data.rotation, rob_osg->yz_order); + j->bone_node_ptr->exp_data.parent_scale = *a3; + *j->bone_node_ptr->ex_data_mat = v78; + if (j->bone_node_mat) + mat4_scale_rot(&v78, a3->x, a3->y, a3->z, j->bone_node_mat); + + float_t v55; + vec3_distance(j->trans, i->trans, v55); + float_t v56 = v16 * j->length; + if (v55 >= fabsf(v56)) + v56 = v55; + mat4_translate_mult(&v78, v56, 0.0f, 0.0f, &v78); + mat4_get_translation(&v78, &j->trans); + vec3_sub(j->trans, i->trans, v60); + } + + if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { + mat4 v79 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; + mat4_translate_mult(&v79, v16 * rob_osg->node.length, 0.0f, 0.0f, &v79); + *rob_osg->node.bone_node_ptr->ex_data_mat = v79; + mat4_scale_rot(&v79, a3->x, a3->y, a3->z, &v79); + *rob_osg->node.bone_node_mat = v79; + rob_osg->node.bone_node_ptr->exp_data.parent_scale = *a3; + } +} + +static void sub_140480260(RobOsage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool v5) { + if (!v5) { + rob_osg->SetNodesExternalForce(0, 1.0f); + rob_osg->SetNodesForce(1.0f); + rob_osg->set_external_force = false; + rob_osg->external_force = vec3_null; + } + + rob_osg->field_2A0 = true; + rob_osg->field_2A1 = false; + rob_osg->field_2A4 = -1.0f; + rob_osg->field_1F0C = false; + rob_osg->osage_reset = false; + rob_osg->field_1F0E = false; + + for (auto i = rob_osg->nodes.begin(); i != rob_osg->nodes.end(); i++) { + i->field_C8 = 0.0f; + i->field_CC = 1.0f; + } + + rob_osg->parent_mat = *rob_osg->parent_mat_ptr; +} + +static void sub_140482100(struc_476* a1, opd_blend_data* a2, struc_477* a3) { + if (!a2->field_C) + a1->field_0 = *a3; + else if (a2->type == MOTION_BLEND_FREEZE) { + if (a2->blend == 0.0f) + a1->field_10 = a1->field_0; + sub_140482DF0(&a1->field_0, &a1->field_10, a3, a2->blend); + } + else if (a2->type == MOTION_BLEND_CROSS) + sub_140482DF0(&a1->field_0, &a1->field_0, a3, a2->blend); +} + +static void sub_140482DF0(struc_477* dst, struc_477* src0, struc_477* src1, float_t blend) { + dst->length = lerp(src0->length, src1->length, blend); + vec3_lerp_scalar(src0->rotation, src1->rotation, dst->rotation, blend); +} + +static int32_t sub_140484450(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { + vec3 v8; + sub_140484E10(&v8, a2, a3, a4); + return sub_140483DE0(a1, &v8, a4, radius); +} + +static bool sub_140482FF0(mat4& mat, vec3& trans, skin_param_hinge* hinge, vec3* rot, int32_t& yz_order) { + bool clipped = false; + float_t z_rot; + float_t y_rot; + if (yz_order == 1) { + y_rot = atan2f(-trans.z, trans.x); + z_rot = atan2f(trans.y, sqrtf(trans.x * trans.x + trans.z * trans.z)); + if (hinge) { + if (y_rot > hinge->ymax) { + y_rot = hinge->ymax; + clipped = true; + } + + if (y_rot < hinge->ymin) { + y_rot = hinge->ymin; + clipped = true; + } + + if (z_rot > hinge->zmax) { + z_rot = hinge->zmax; + clipped = true; + } + + if (z_rot < hinge->zmin) { + z_rot = hinge->zmin; + clipped = true; + } + } + mat4_rotate_y_mult(&mat, y_rot, &mat); + mat4_rotate_z_mult(&mat, z_rot, &mat); + } + else { + z_rot = atan2f(trans.y, trans.x); + y_rot = atan2f(-trans.z, sqrtf(trans.x * trans.x + trans.y * trans.y)); + if (hinge) { + if (y_rot > hinge->ymax) { + y_rot = hinge->ymax; + clipped = true; + } + + if (y_rot < hinge->ymin) { + y_rot = hinge->ymin; + clipped = true; + } + + if (z_rot > hinge->zmax) { + z_rot = hinge->zmax; + clipped = true; + } + + if (z_rot < hinge->zmin) { + z_rot = hinge->zmin; + clipped = true; + } + } + mat4_rotate_z_mult(&mat, z_rot, &mat); + mat4_rotate_y_mult(&mat, y_rot, &mat); + } + + if (rot) { + rot->y = y_rot; + rot->z = z_rot; + } + return clipped; +} + +static int32_t sub_1404844A0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { + vec3 v8; + sub_140484850(&v8, a2, a3, a4); + return sub_140484540(a1, &v8, a4, radius); +} + +static int32_t sub_1404844F0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { + vec3 v8; + sub_140484850(&v8, a2, a3, a4); + return sub_140483EA0(a1, &v8, a4, radius); +} + +static void sub_140484850(vec3* a1, vec3* a2, vec3* a3, osage_coli* coli) { + vec3 v56; + vec3_sub(*a3, *a2, v56); + + vec3 v60; + vec3_cross(v56, coli->bone_pos_diff, v60); + + float_t v46; + vec3_length_squared(v60, v46); + if (v46 <= 0.000001f) { + vec3 v56; + vec3 v57; + vec3 v58; + vec3 v59; + sub_140484E10(&v59, &coli->bone0_pos, &coli->bone1_pos, a2); + sub_140484E10(&v58, &coli->bone0_pos, &coli->bone1_pos, a3); + sub_140484E10(&v57, a2, a3, &coli->bone0_pos); + sub_140484E10(&v56, a2, a3, &coli->bone1_pos); + + float_t v48; + float_t v51; + float_t v52; + float_t v55; + vec3_distance_squared(*a3, coli->bone0_pos, v48); + vec3_distance_squared(coli->bone0_pos, v57, v51); + vec3_distance_squared(coli->bone1_pos, v56, v52); + vec3_distance_squared(*a2, v59, v55); + *a1 = *a2; + + if (v55 > v48) { + *a1 = *a3; + v55 = v48; + } + + if (v55 > v51) { + *a1 = v57; + v55 = v51; + } + + if (v55 > v52) + *a1 = v56; + } + else { + float_t v25; + vec3_length(v56, v25); + if (v25 != 0.0f) + vec3_mult_scalar(v56, 1.0f / v25, v56); + + float_t v30 = 1.0f / coli->bone_pos_diff_length; + vec3 v61; + float_t v34; + vec3_mult_scalar(coli->bone_pos_diff, v30, v61); + vec3_dot(v61, v56, v34); + vec3_mult_scalar(v61, v34, v61); + vec3_sub(v61, v56, v61); + vec3_sub(coli->bone0_pos, *a2, v60); + float_t v35; + vec3_dot(v61, v60, v35); + v35 /= (v34 * v34 - 1.0f); + if (v35 < 0.0f) + *a1 = *a2; + else if (v35 <= v25) { + vec3_mult_scalar(v56, v35, v56); + vec3_add(*a2, v56, *a1); + } + else + *a1 = *a3; + + } +} + +static void sub_140484E10(vec3* a1, vec3* a2, vec3* a3, vec3* a4) { + vec3 v6; + vec3_sub(*a3, *a2, v6); + + vec3 v7; + vec3_sub(*a4, *a2, v7); + + float_t v8; + vec3_dot(v7, v6, v8); + if (v8 < 0.0f) { + *a1 = *a2; + return; + } + + float_t v9; + vec3_length_squared(v6, v9); + if (v9 <= 0.000001f) + *a1 = *a2; + else if (v8 <= v9) { + float_t v10 = v8 / v9; + vec3_mult_scalar(v6, v8 / v9, v6); + vec3_add(*a2, v6, *a1); + } + else + *a1 = *a3; +} + +static int32_t sub_140485000(vec3* a1, vec3* a2, skin_param_osage_node* a3, osage_coli* a4) { + if (!a4) + return 0; + + int32_t v8 = 0; + while (a4->type) { + int32_t type = a4->type; + vec3 v21 = vec3_null; + switch (a4->type) { + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: + v8 += sub_140484450(&v21, a1, a2, &a4->bone0_pos, a3->coli_r + a4->radius); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: + v8 += sub_1404844A0(&v21, a1, a2, a4, a3->coli_r + a4->radius); + break; + case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: + v8 += sub_1404844F0(&v21, a1, a2, a4, a3->coli_r + a4->radius); + break; + } + + if (v8 > 0) { + vec3_add(*a1, v21, *a1); + vec3_add(*a2, v21, *a2); + } + a4++; + } + return v8; +} + +static void sub_14053CE30(RobOsageNodeDataNormalRef* normal_ref, mat4* a2) { + if (!normal_ref->field_0) + return; + + vec3 n_trans; + vec3 u_trans; + vec3 d_trans; + vec3 l_trans; + vec3 r_trans; + mat4_get_translation(normal_ref->n->bone_node_ptr->ex_data_mat, &n_trans); + mat4_get_translation(normal_ref->u->bone_node_ptr->ex_data_mat, &u_trans); + mat4_get_translation(normal_ref->d->bone_node_ptr->ex_data_mat, &d_trans); + mat4_get_translation(normal_ref->l->bone_node_ptr->ex_data_mat, &l_trans); + mat4_get_translation(normal_ref->r->bone_node_ptr->ex_data_mat, &r_trans); + + vec3 v27; + vec3 v26; + vec3 v28; + if (sub_14053D1B0(&l_trans, &r_trans, &u_trans, &d_trans, &v27, &v26, &v28)) { + mat4 v34; + *(vec3*)&v34.row0 = v28; + *(vec3*)&v34.row1 = v26; + *(vec3*)&v34.row2 = v27; + *(vec3*)&v34.row3 = n_trans; + v34.row0.w = 0.0f; + v34.row1.w = 0.0f; + v34.row2.w = 0.0f; + v34.row3.w = 1.0f; + + mat4 v33 = normal_ref->mat; + mat4_mult(&v33, &v34, a2); + } +} + +static bool sub_14053D1B0(vec3* l_trans, vec3* r_trans, + vec3* u_trans, vec3* d_trans, vec3* a5, vec3* a6, vec3* a7) { + float_t length; + vec3_sub(*d_trans, *u_trans, *a5); + vec3_length_squared(*a5, length); + if (length <= 0.000001f) + return false; + vec3_mult_scalar(*a5, 1.0f / sqrtf(length), *a5); + + vec3 v9; + vec3_sub(*r_trans, *l_trans, v9); + vec3_cross(v9, *a5, *a6); + vec3_length_squared(*a6, length); + if (length <= 0.000001f) + return false; + vec3_mult_scalar(*a6, 1.0f / sqrtf(length), *a6); + + vec3_cross(*a5, *a6, *a7); + vec3_normalize(*a7, *a7); + return true; +} diff --git a/src/CRE/rob.cpp b/src/CRE/rob/rob.cpp similarity index 79% rename from src/CRE/rob.cpp rename to src/CRE/rob/rob.cpp index fd728663..28862b7f 100644 --- a/src/CRE/rob.cpp +++ b/src/CRE/rob/rob.cpp @@ -4,12 +4,12 @@ */ #include "rob.hpp" -#include "data.hpp" -#include "draw_task.h" -#include "../KKdLib/key_val.hpp" -#include "../KKdLib/str_utils.hpp" -#include "random.hpp" -#include "stage.hpp" +#include "../../KKdLib/key_val.hpp" +#include "../../KKdLib/str_utils.hpp" +#include "../data.hpp" +#include "../draw_task.hpp" +#include "../random.hpp" +#include "../stage.hpp" struct MotFile { motion_set_info* mot_set_info; @@ -50,38 +50,12 @@ struct MhdFile { static void ParseFileParent(void* data, const void* file_data, size_t size); }; -struct osage_setting { - std::map, osage_setting_osg_cat> cat; - std::map obj; - - osage_setting(); - ~osage_setting(); - - void parse(key_val* kv); - rob_osage_parts parse_parts_string(std::string* s); -}; - struct struc_380 { rob_chara* rob_chara; rob_chara_data* rob_chara_data; struc_223* field_10; }; -struct exp_func_op1 { - const char* name; - float_t(*func)(float_t v1); -}; - -struct exp_func_op2 { - const char* name; - float_t(*func)(float_t v1, float_t v2); -}; - -struct exp_func_op3 { - const char* name; - float_t(*func)(float_t v1, float_t v2, float_t v3); -}; - struct mothead_func_data { rob_chara* rob_chr; rob_chara_data* rob_chr_data; @@ -487,68 +461,14 @@ static void bone_data_mult_1_ik_legs(bone_data* a1, vec3* a2); static bool bone_data_mult_1_exp_data(bone_data* a1, bone_node_expression_data* a2, bone_data* a3); static void bone_data_mult_ik(bone_data* a1, int32_t skeleton_select); -static float_t* bone_node_get_exp_data_component(bone_node* a1, - size_t index, ex_expression_block_stack_type* type); - static void bone_data_parent_data_init(bone_data_parent* bone, rob_chara_bone_data* rob_bone_data, bone_database* bone_data); static void bone_data_parent_load_bone_database(bone_data_parent* bone, std::vector* bones, vec3* common_translation, vec3* translation); static void bone_data_parent_load_rob_chara(bone_data_parent* bone); -static void bone_node_expression_data_mat_set(bone_node_expression_data* data, - vec3* parent_scale, mat4* ex_data_mat, mat4* mat); -static void bone_node_expression_data_reset_scale(bone_node_expression_data* data); -static void bone_node_expression_data_set_position_rotation(bone_node_expression_data* data, - float_t position_x, float_t position_y, float_t position_z, - float_t rotation_x, float_t rotation_y, float_t rotation_z); -static void bone_node_expression_data_set_position_rotation(bone_node_expression_data* data, - vec3* position, vec3* rotation); - static bool check_module_index_is_501(int32_t module_index); -static float_t ex_expression_block_stack_get_value(ex_expression_block_stack* stack); - -static float_t exp_abs(float_t v1); -static float_t exp_acos(float_t v1); -static float_t exp_add(float_t v1, float_t v2); -static float_t exp_and(float_t v1, float_t v2); -static float_t exp_asin(float_t v1); -static float_t exp_atan(float_t v1); -static float_t exp_av(float_t v1); -static float_t exp_ceil(float_t v1); -static float_t exp_cond(float_t v1, float_t v2, float_t v3); -static float_t exp_cos(float_t v1); -static float_t exp_div(float_t v1, float_t v2); -static float_t exp_eq(float_t v1, float_t v2); -static float_t exp_exp(float_t v1); -static float_t exp_floor(float_t v1); -static float_t exp_fmod(float_t v1, float_t v2); -static const exp_func_op1* exp_func_op1_find_func(std::string& name, const exp_func_op1* array); -static const exp_func_op2* exp_func_op2_find_func(std::string& name, const exp_func_op2* array); -static const exp_func_op3* exp_func_op3_find_func(std::string& name, const exp_func_op3* array); -static float_t exp_ge(float_t v1, float_t v2); -static float_t exp_gt(float_t v1, float_t v2); -static float_t exp_le(float_t v1, float_t v2); -static float_t exp_log(float_t v1); -static float_t exp_lt(float_t v1, float_t v2); -static float_t exp_max(float_t v1, float_t v2); -static float_t exp_min(float_t v1, float_t v2); -static float_t exp_mul(float_t v1, float_t v2); -static float_t exp_ne(float_t v1, float_t v2); -static float_t exp_neg(float_t v1); -static float_t exp_or(float_t v1, float_t v2); -static float_t exp_pow(float_t v1, float_t v2); -static float_t exp_rand(float_t v1, float_t v2, float_t v3); -static float_t exp_rand_0_1(float_t v1); -static float_t exp_round(float_t v1); -static float_t exp_sin(float_t v1); -static float_t exp_sqrt(float_t v1); -static float_t exp_sub(float_t v1, float_t v2); -static float_t exp_tan(float_t v1); - -static const float_t get_osage_gravity_const(); - static void mot_blend_interpolate(mot_blend* a1, std::vector* bones, std::vector* bone_indices, bone_database_skeleton_type skeleton_type); static void mot_blend_load_motion(mot_blend* a1, int32_t motion_id, motion_database* mot_db); @@ -747,18 +667,9 @@ static void motion_blend_mot_set_blend(motion_blend_mot* a1, static void motion_blend_mot_set_duration(motion_blend_mot* mot, float_t duration, float_t step, float_t offset); -static void osage_coli_set(osage_coli* osg_coli, - skin_param_osage_root_coli* skp_root_coli, mat4* mats); -static void osage_coli_ring_set(osage_coli* osg_coli, - std::vector* vec_skp_root_coli, mat4* mats); - static void osage_play_data_manager_get_opd_file_data(object_info obj_info, int32_t motion_id, float_t** data, uint32_t* count); -static const osage_setting_osg_cat* osage_setting_data_get_cat_value( - object_info* obj_info, const char* root_node); -static bool osage_setting_data_obj_has_key(object_info key); - static bool pv_osage_manager_array_get_disp(int32_t* chara_id); static PvOsageManager* pv_osage_manager_array_ptr_get(int32_t chara_id); static void pv_osage_manager_array_ptr_set_not_reset_true(); @@ -863,10 +774,10 @@ static void rob_chara_item_cos_data_set_chara_index( rob_chara_item_cos_data* item_cos_data, chara_index chara_index); static void rob_chara_item_cos_data_set_chara_index_item_nos( rob_chara_item_cos_data* item_cos_data, chara_index chara_index, int32_t* items); -static void rob_chara_item_cos_data_set_customize_item(rob_chara_item_cos_data* item_cos_data, int32_t item_no); -static void rob_chara_item_cos_data_set_customize_items(rob_chara_item_cos_data* item_cos_data, - rob_chara_pv_data_customize_items* customize_items); -static void rob_chara_item_cos_data_set_item( +static void rob_chara_item_cos_data_set_item(rob_chara_item_cos_data* item_cos_data, int32_t item_no); +static void rob_chara_item_cos_data_set_item_array(rob_chara_item_cos_data* item_cos_data, + rob_chara_pv_data_item* item); +static void rob_chara_item_cos_data_set_item_no( rob_chara_item_cos_data* item_cos_data, item_sub_id sub_id, int32_t item_no); static void rob_chara_item_cos_data_set_item_nos( rob_chara_item_cos_data* item_cos_data, int32_t* item_nos); @@ -884,51 +795,6 @@ static void rob_chara_item_equip_get_parent_bone_nodes( static void rob_chara_item_equip_load_object_info( rob_chara_item_equip* rob_itm_equip, object_info object_info, item_id id, bool osage_reset, bone_database* bone_data, void* data, object_database* obj_db); -static void rob_chara_item_equip_object_add_motion_reset_data(rob_chara_item_equip_object* itm_eq_obj, - int32_t motion_id, float_t frame, int32_t osage_iterations); -static void rob_chara_item_equip_object_check_no_opd( - rob_chara_item_equip_object* itm_eq_obj, std::vector* opd_blend_data); -static void rob_chara_item_equip_object_clear_ex_data(rob_chara_item_equip_object* itm_eq_obj); -static void rob_chara_item_equip_object_disp( - rob_chara_item_equip_object* itm_eq_obj, mat4* mat, render_context* rctx); -static int32_t rob_chara_item_equip_object_get_bone_index( - rob_chara_item_equip_object* itm_eq_obj, const char* name, bone_database* bone_data); -static bone_node* rob_chara_item_equip_object_get_bone_node( - rob_chara_item_equip_object* itm_eq_obj, int32_t bone_index); -static bone_node* rob_chara_item_equip_object_get_bone_node_by_name( - rob_chara_item_equip_object* itm_eq_obj, const char* name, bone_database* bone_data); -static void rob_chara_item_equip_object_get_parent_bone_nodes( - rob_chara_item_equip_object* itm_eq_obj, bone_node* bone_nodes, bone_database* bone_data); -static void rob_chara_item_equip_object_init_ex_data_bone_nodes( - rob_chara_item_equip_object* itm_eq_obj, obj_skin_ex_data* ex_data); -static void rob_chara_item_equip_object_init_members(rob_chara_item_equip_object* itm_eq_obj, size_t index = 0xDEADBEEF); -static void rob_chara_item_equip_object_load_ex_data(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_ex_data* ex_data, bone_database* bone_data, void* data, object_database* obj_db); -static void rob_chara_item_equip_object_load_object_info_ex_data( - rob_chara_item_equip_object* itm_eq_obj, object_info object_info, bone_node* bone_nodes, - bool osage_reset, bone_database* bone_data, void* data, object_database* obj_db); -static void rob_chara_item_equip_object_set_alpha_draw_task_flags( - rob_chara_item_equip_object* itm_eq_obj, float_t alpha, draw_task_flags flags); -static bool rob_chara_item_equip_object_set_boc(rob_chara_item_equip_object* itm_eq_obj, - skin_param_osage_root* skp_root, ExOsageBlock* osg); -static void rob_chara_item_equip_object_set_collision_target_osage( - rob_chara_item_equip_object* itm_eq_obj, skin_param_osage_root* skp_root, skin_param* skp); -static void rob_chara_item_equip_object_set_motion_reset_data( - rob_chara_item_equip_object* itm_eq_obj, int32_t motion_id, float_t frame); -static void rob_chara_item_equip_object_set_motion_skin_param( - rob_chara_item_equip_object* itm_eq_obj, int8_t chara_id, int32_t motion_id, int32_t frame); -static void rob_chara_item_equip_object_set_null_blocks_expression_data( - rob_chara_item_equip_object* rob_itm_equip, vec3* position, vec3* rotation, vec3* scale); -static void rob_chara_item_equip_object_set_osage_reset( - rob_chara_item_equip_object* itm_eq_obj); -static void rob_chara_item_equip_object_set_osage_move_cancel( - rob_chara_item_equip_object* itm_eq_obj, float_t value); -static void rob_chara_item_equip_object_set_texture_pattern( - rob_chara_item_equip_object* itm_eq_obj, texture_pattern_struct* tex_pat, size_t count); -static void rob_chara_item_equip_object_skp_load( - rob_chara_item_equip_object* itm_eq_obj, key_val* kv, bone_database* bone_data); -static void rob_chara_item_equip_object_skp_load_file( - rob_chara_item_equip_object* itm_eq_obj, void* data, bone_database* bone_data, object_database* obj_db); static void rob_chara_item_equip_reset_init_data(rob_chara_item_equip* rob_itm_equip, bone_node* bone_nodes); static void rob_chara_item_equip_set_alpha_draw_task_flags( @@ -970,39 +836,10 @@ static void rob_cmn_mottbl_read(void* a1, const void* data, size_t size); static rob_manager_rob_impl* rob_manager_rob_impls1_get(TaskRobManager* rob_mgr); static rob_manager_rob_impl* rob_manager_rob_impls2_get(TaskRobManager* rob_mgr); -static void rob_osage_init_data(rob_osage* rob_osg, - obj_skin_block_osage* osg_data, obj_skin_osage_node* osg_nodes, - bone_node* ex_data_bone_nodes, obj_skin* skin); -static rob_osage_node* rob_osage_get_node(rob_osage* rob_osg, size_t index); -static float_t* rob_osage_load_opd_data(rob_osage* rob_osg, - size_t node_index, float_t* opd_data, size_t opd_count); -static void rob_osage_load_skin_param(rob_osage* rob_osg, key_val* kv, const char* name, - skin_param_osage_root* skp_root, object_info* obj_info, bone_database* bone_data); -static void rob_osage_set_air_res(rob_osage* rob_osg, float_t air_res); -static void rob_osage_coli_set(rob_osage* rob_osg, mat4* mats); -static void rob_osage_set_coli_r(rob_osage* rob_osg, float_t coli_r); -static void rob_osage_set_force(rob_osage* rob_osg, float_t force, float_t force_gain); -static void rob_osage_set_hinge(rob_osage* rob_osg, float_t hinge_y, float_t hinge_z); -static void rob_osage_set_init_rot(rob_osage* rob_osg, float_t init_rot_y, float_t init_rot_z); -static void rob_osage_set_motion_reset_data(rob_osage* rob_osg, int32_t motion_id, float_t frame); -static void rob_osage_set_rot(rob_osage* rob_osg, float_t rot_y, float_t rot_z); -static void rob_osage_set_skin_param_osage_root(rob_osage* rob_osg, skin_param_osage_root* skp_root); -static void rob_osage_set_skp_osg_nodes(rob_osage* rob_osg, - std::vector* skp_osg_nodes); -static void rob_osage_set_yz_order(rob_osage* rob_osg, int32_t yz_order); -static void rob_osage_free(rob_osage* rob_osg); - -static void skin_param_osage_node_parse(key_val* kv, const char* name, - std::vector* a3, skin_param_osage_root* skp_root); - -static void skin_param_osage_root_parse(key_val* kv, const char* name, - skin_param_osage_root* skp_root, bone_database* bone_data); - static bool task_rob_load_check_load_req_data(); std::map motion_storage_data; std::map mothead_storage_data; -osage_setting osage_setting_data; rob_chara* rob_chara_array; rob_chara_pv_data* rob_chara_pv_data_array; @@ -1020,53 +857,6 @@ static TaskRobLoad task_rob_load; static const mothead_mot mothead_mot_null; -static const exp_func_op1 exp_func_op1_array[] = { - { "neg" , exp_neg }, - { "sin" , exp_sin }, - { "cos" , exp_cos }, - { "tan" , exp_tan }, - { "abs" , exp_abs }, - { "sqrt" , exp_sqrt }, - { "av" , exp_av }, - { "floor" , exp_floor }, - { "ceil" , exp_ceil }, - { "round" , exp_round }, - { "asin" , exp_asin }, - { "acos" , exp_acos }, - { "atan" , exp_atan }, - { "log" , exp_log }, - { "exp" , exp_exp }, - { "rand_0_1", exp_rand_0_1 }, - { 0 , 0 }, -}; - -static const exp_func_op2 exp_func_op2_array[] = { - { "+" , exp_add }, - { "-" , exp_sub }, - { "*" , exp_mul }, - { "/" , exp_div }, - { "%" , exp_fmod }, - { "==" , exp_eq }, - { ">" , exp_gt }, - { ">=" , exp_ge }, - { "<" , exp_lt }, - { "<=" , exp_le }, - { "!=" , exp_ne }, - { "&&" , exp_and }, - { "||" , exp_or }, - { "min" , exp_min }, - { "max" , exp_max }, - { "fmod", exp_fmod }, - { "pow" , exp_pow }, - { 0 , 0 }, -}; - -static const exp_func_op3 exp_func_op3_array[] = { - { "rand", exp_rand }, - { "cond", exp_cond }, - { 0 , 0 }, -}; - static const mothead_func_struct mothead_func_array[] = { { mothead_func_0 , 1 }, { mothead_func_1 , 1 }, @@ -2145,6 +1935,10 @@ float_t chara_pos_adjust_y_table_get_value(uint32_t index) { return 0.0f; } +const float_t get_osage_gravity_const() { + return 0.00299444468691945f; +} + void motion_set_load_mothead(uint32_t set, std::string* mdata_dir, motion_database* mot_db) { motion_set_info* set_info = mot_db->get_motion_set_by_id(set); if (!set_info) @@ -2248,10 +2042,6 @@ void rob_free() { } } -static void sub_1405EE878(ExNodeBlock* node) { - -} - static void rob_chara_item_equip_object_ctrl_iterate_nodes(rob_chara_item_equip_object* itm_eq_obj, int32_t osage_iterations) { if (!itm_eq_obj->node_blocks.size()) return; @@ -2452,24 +2242,15 @@ static void rob_chara_bone_data_set_disable_eye_motion(rob_chara_bone_data* rob_ rob_bone_data->disable_eye_motion = value; } -static bool rob_osage_check_osage_setting_parts_bit(rob_osage* rob_osg, int32_t parts_bits) { - if (rob_osg->osage_setting.parts == -1) - return 0; - return _bittest((const LONG*)&parts_bits, rob_osg->osage_setting.parts); +static void sub_1405F9520(rob_chara_item_equip_object* itm_eq_obj, rob_osage_parts_bit a2, bool a3) { + for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) + if (i->rob.CheckPartsBits(a2)) + i->rob.field_1F0F = a3; } -static void sub_1405F9510(ExOsageBlock* a1, bool a2) { - a1->rob.field_1F0F = a2; -} - -static void sub_1405F9520(rob_chara_item_equip_object* a1, int32_t parts_bits, bool a3) { - for (ExOsageBlock*& i : a1->osage_blocks) - if (rob_osage_check_osage_setting_parts_bit(&i->rob, parts_bits)) - sub_1405F9510(i, a3); -} - -static void sub_140513EE0(rob_chara_item_equip* rob_itm_equip, int32_t a2, bool a3) { - sub_1405F9520(&rob_itm_equip->item_equip_object[a2 == 8 ? ITEM_OUTER : ITEM_KAMI], 1 << a2, a3); +static void sub_140513EE0(rob_chara_item_equip* rob_itm_eq, rob_osage_parts a2, bool a3) { + sub_1405F9520(&rob_itm_eq->item_equip_object[a2 == ROB_OSAGE_PARTS_MUFFLER ? ITEM_OUTER : ITEM_KAMI], + (rob_osage_parts_bit)(1 << a2), a3); } static void sub_140419D30(rob_chara_bone_data* rob_bone_data, @@ -2984,8 +2765,8 @@ void rob_chara::load_motion(int32_t motion_id, bool a3, float_t frame, rob_chara_bone_data_set_disable_eye_motion(this->bone_data, false); rob_chara_item_equip_set_osage_move_cancel(item_equip, 0, 0.0f); - for (int32_t i = 0; i < 13; i++) - sub_140513EE0(item_equip, i, false); + for (int32_t i = 0; i < ROB_OSAGE_PARTS_MAX; i++) + sub_140513EE0(item_equip, (rob_osage_parts)i, false); data.field_1588.field_0.field_30 = data.field_1588.field_0.field_10; data.field_1588.field_0.field_40 = data.field_1588.field_0.field_20; data.field_1588.field_0.field_276 = data.field_1588.field_0.field_274; @@ -3704,10 +3485,10 @@ void rob_chara::set_parts_disp(item_id id, bool disp) { if (id < ITEM_BODY) return; else if (id < ITEM_ITEM16) - item_equip->item_equip_object[id].disp = disp; + item_equip->item_equip_object[id].can_disp = disp; else if (id == ITEM_MAX) for (int32_t i = ITEM_ATAMA; i <= ITEM_ITEM16; i++) { - item_equip->item_equip_object[i].disp = disp; + item_equip->item_equip_object[i].can_disp = disp; /*if (index == ITEM_ATAMA && rob_chara_check_for_ageageagain_module(chara_index, module_index)) { sub_140543780(chara_id, 1, disp); @@ -3846,7 +3627,7 @@ static void bone_data_mult_1(bone_data* a1, mat4* parent_mat, bone_data* a3, boo *a1->node[0].mat = mat; if (solve_ik) { a1->node[0].exp_data.position = a1->trans; - bone_node_expression_data_reset_scale(&a1->node[0].exp_data); + a1->node[0].exp_data.reset_scale(); } if (a1->type < BONE_DATABASE_BONE_HEAD_IK_ROTATION) @@ -3864,8 +3645,8 @@ static void bone_data_mult_1(bone_data* a1, mat4* parent_mat, bone_data* a3, boo a1->node[1].exp_data.position = vec3_null; mat4_get_rotation(&a1->rot_mat[1], &a1->node[1].exp_data.rotation); - bone_node_expression_data_reset_scale(&a1->node[1].exp_data); - bone_node_expression_data_set_position_rotation(&a1->node[2].exp_data, + a1->node[1].exp_data.reset_scale(); + a1->node[2].exp_data.set_position_rotation( a1->ik_segment_length[1], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); } else { @@ -3881,11 +3662,11 @@ static void bone_data_mult_1(bone_data* a1, mat4* parent_mat, bone_data* a3, boo a1->node[1].exp_data.position = vec3_null; mat4_get_rotation(&a1->rot_mat[1], &a1->node[1].exp_data.rotation); - bone_node_expression_data_reset_scale(&a1->node[1].exp_data); + a1->node[1].exp_data.reset_scale(); a1->node[2].exp_data.position = { a1->ik_segment_length[1], 0.0f, 0.0f }; mat4_get_rotation(&a1->rot_mat[2], &a1->node[2].exp_data.rotation); - bone_node_expression_data_reset_scale(&a1->node[2].exp_data); - bone_node_expression_data_set_position_rotation(&a1->node[3].exp_data, + a1->node[2].exp_data.reset_scale(); + a1->node[3].exp_data.set_position_rotation( a1->ik_2nd_segment_length[1], 0.0f, 0.0f, 0.0f, 0.0f, 0.0f); } } @@ -4432,1743 +4213,12 @@ static void bone_data_parent_load_rob_chara(bone_data_parent* bone) { bone->bone_key_set_count = (uint32_t)((bone->motion_bone_count + bone->ik_bone_count) * 3); } -static float_t* bone_node_get_exp_data_component(bone_node* a1, - size_t index, ex_expression_block_stack_type* type) { - switch (index) { - case 0: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.position.x; - case 1: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.position.y; - case 2: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.position.z; - case 3: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; - return &a1->exp_data.rotation.x; - case 4: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; - return &a1->exp_data.rotation.y; - case 5: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; - return &a1->exp_data.rotation.z; - case 6: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.scale.x; - case 7: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.scale.y; - case 8: - *type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - return &a1->exp_data.scale.z; - default: - return 0; - } -} - -static void bone_node_expression_data_mat_set(bone_node_expression_data* data, - vec3* parent_scale, mat4* ex_data_mat, mat4* mat) { - vec3 position; - vec3_mult(data->position, *parent_scale, position); - mat4_translate_mult(ex_data_mat, position.x, position.y, position.z, ex_data_mat); - vec3 rotation = data->rotation; - mat4_rotate_mult(ex_data_mat, rotation.x, rotation.y, rotation.z, ex_data_mat); - vec3_mult(data->scale, *parent_scale, data->parent_scale); - *mat = *ex_data_mat; - mat4_scale_rot(mat, data->parent_scale.x, data->parent_scale.y, data->parent_scale.z, mat); -} - -static void bone_node_expression_data_reset_scale(bone_node_expression_data* data) { - data->scale = vec3_identity; - data->parent_scale = vec3_identity; -} - -static void bone_node_expression_data_set_position_rotation(bone_node_expression_data* data, - float_t position_x, float_t position_y, float_t position_z, - float_t rotation_x, float_t rotation_y, float_t rotation_z) { - data->position.x = position_x; - data->position.y = position_y; - data->position.z = position_z; - data->rotation.x = rotation_x; - data->rotation.z = rotation_z; - data->rotation.y = rotation_y; - data->scale = vec3_identity; - data->parent_scale = vec3_identity; -} - -static void bone_node_expression_data_set_position_rotation(bone_node_expression_data* data, - vec3* position, vec3* rotation) { - data->position = *position; - data->rotation = *rotation; - data->scale = vec3_identity; - data->parent_scale = vec3_identity; -} - -static void sub_14047EE90(rob_osage* rob_osg, mat4* mat) { - if (rob_osg->reset_data_list) { - std::list::iterator reset_data_list = rob_osg->reset_data_list->begin(); - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - i->reset_data = *reset_data_list++; - rob_osg->reset_data_list = 0; - } - - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - mat4_mult_vec3(mat, &i->reset_data.trans_diff, &i->trans_diff); - mat4_mult_vec3_trans(mat, &i->reset_data.trans, &i->trans); - } - rob_osg->parent_mat = *rob_osg->parent_mat_ptr; -} - -static void sub_14047F110(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, bool init_rot) { - vec3 position; - vec3_mult(rob_osg->exp_data.position, *parent_scale, position); - mat4_translate_mult(mat, position.x, position.y, position.z, mat); - - vec3 rotation = rob_osg->exp_data.rotation; - mat4_rotate_mult(mat, rotation.x, rotation.y, rotation.z, mat); - - skin_param* skin_param = rob_osg->skin_param_ptr; - vec3 rot = skin_param->rot; - if (init_rot) - vec3_add(rot, skin_param->init_rot, rot); - mat4_rotate_mult(mat, rot.x, rot.y, rot.z, mat); -} - -static bool sub_140482FF0(mat4* mat, vec3* trans, skin_param_hinge* hinge, vec3* rot, int32_t* yz_order) { - bool clipped = false; - float_t z_rot; - float_t y_rot; - if (*yz_order == 1) { - y_rot = atan2f(-trans->z, trans->x); - z_rot = atan2f(trans->y, sqrtf(trans->x * trans->x + trans->z * trans->z)); - if (hinge) { - if (y_rot > hinge->ymax) { - y_rot = hinge->ymax; - clipped = true; - } - - if (y_rot < hinge->ymin) { - y_rot = hinge->ymin; - clipped = true; - } - - if (z_rot > hinge->zmax) { - z_rot = hinge->zmax; - clipped = true; - } - - if (z_rot < hinge->zmin) { - z_rot = hinge->zmin; - clipped = true; - } - } - mat4_rotate_y_mult(mat, y_rot, mat); - mat4_rotate_z_mult(mat, z_rot, mat); - } - else { - z_rot = atan2f(trans->y, trans->x); - y_rot = atan2f(-trans->z, sqrtf(trans->x * trans->x + trans->y * trans->y)); - if (hinge) { - if (y_rot > hinge->ymax) { - y_rot = hinge->ymax; - clipped = true; - } - - if (y_rot < hinge->ymin) { - y_rot = hinge->ymin; - clipped = true; - } - - if (z_rot > hinge->zmax) { - z_rot = hinge->zmax; - clipped = true; - } - - if (z_rot < hinge->zmin) { - z_rot = hinge->zmin; - clipped = true; - } - } - mat4_rotate_z_mult(mat, z_rot, mat); - mat4_rotate_y_mult(mat, y_rot, mat); - } - - if (rot) { - rot->y = y_rot; - rot->z = z_rot; - } - return clipped; -} - -static void sub_1404803B0(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, bool has_children_node) { - mat4 v47 = *mat; - vec3 v45; - vec3_mult(rob_osg->exp_data.position, *parent_scale, v45); - mat4_mult_vec3_trans(&v47, &v45, &rob_osg->nodes[0].trans); - if (rob_osg->osage_reset && !rob_osg->field_1F0E) { - rob_osg->field_1F0E = true; - sub_14047EE90(rob_osg, mat); - } - - if (!rob_osg->field_1F0C) { - rob_osg->field_1F0C = true; - - float_t move_cancel = rob_osg->skin_param_ptr->move_cancel; - if (rob_osg->move_cancel == 1.0f) - move_cancel = 1.0f; - if (move_cancel < 0.0f) - move_cancel = rob_osg->move_cancel; - - if (move_cancel > 0.0f) { - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - mat4 parent_mat; - vec3 v46; - parent_mat = rob_osg->parent_mat; - mat4_mult_vec3_inv_trans(&parent_mat, &i->trans, &v46); - parent_mat = *rob_osg->parent_mat_ptr; - mat4_mult_vec3_trans(&parent_mat, &v46, &v46); - vec3_sub(v46, i->trans, v46); - vec3_mult_scalar(v46, move_cancel, v46); - vec3_add(i->trans, v46, i->trans); - } - } - } - - if (has_children_node) { - sub_14047F110(rob_osg, &v47, parent_scale, 0); - *rob_osg->nodes[0].bone_node_mat = v47; - rob_osage_node* v29 = rob_osg->nodes.data(); - rob_osage_node* v30_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v30_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v30 = v30_begin; v30 != v30_end; v29++, v30++) { - vec3 v46; - mat4_mult_vec3_inv_trans(&v47, &v30->trans, &v46); - bool v32 = sub_140482FF0(&v47, &v46, &v30->data_ptr->skp_osg_node.hinge, - &v30->reset_data.rotation, &rob_osg->yz_order); - *v30->bone_node_ptr->ex_data_mat = v47; - float_t v34; - vec3_distance(v30->trans, v29->trans, v34); - float_t v35 = parent_scale->x * v30->length; - bool v36; - if (v34 >= fabsf(v35)) { - v35 = v34; - v36 = false; - } - else - v36 = true; - mat4_translate_mult(&v47, v35, 0.0f, 0.0f, &v47); - if (v32 || v36) - mat4_get_translation(&v47, &v30->trans); - } - - if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { - mat4 v48 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; - mat4_translate_mult(&v48, parent_scale->x * rob_osg->node.length, 0.0f, 0.0f, &v48); - *rob_osg->node.bone_node_ptr->ex_data_mat = v48; - } - } -} - -static void sub_140482300(vec3* a1, vec3* a2, vec3* a3, float_t osage_gravity_const, float_t weight) { - weight *= osage_gravity_const; - vec3 diff; - vec3_sub(*a2, *a3, diff); - float_t dist; - vec3_length(diff, dist); - if (dist <= fabsf(osage_gravity_const)) { - diff.y = osage_gravity_const; - vec3_length(diff, dist); - } - vec3_mult_scalar(diff, weight * diff.y * (1.0f / (dist * dist)), diff); - vec3_negate(diff, diff); - diff.y -= weight; - *a1 = diff; -} - -static void sub_140482F30(vec3* pos1, vec3* pos2, float_t length) { - vec3 diff; - vec3_sub(*pos1, *pos2, diff); - float_t dist; - vec3_length_squared(diff, dist); - if (dist > length * length) { - vec3_mult_scalar(diff, length / sqrtf(dist), diff); - vec3_add(*pos2, diff, *pos1); - } -} - -static void sub_140482490(rob_osage_node* node, float_t step, float_t a3) { - if (step != 1.0f) { - vec3 v4; - vec3_sub(node->trans, node->trans_orig, v4); - - float_t v9; - vec3_length(v4, v9); - if (v9 != 0.0f) - vec3_mult_scalar(v4, 1.0f / v9, v4); - vec3_mult_scalar(v4, step * v9, v4); - vec3_add(node->trans_orig, v4, node->trans); - } - - sub_140482F30(&node[0].trans, &node[-1].trans, node->length * a3); - if (node->sibling_node) - sub_140482F30(&node->trans, &node->sibling_node->trans, node->max_distance); -} - -static void sub_140482180(rob_osage_node* node, float_t a2) { - float_t v2 = node->data_ptr->skp_osg_node.coli_r + a2; - if (v2 <= node->trans.y) - return; - - node->trans.y = v2; - vec3 v3; - vec3_sub(node->trans, node[-1].trans, v3); - vec3_normalize(v3, v3); - vec3_mult_scalar(v3, node->length, v3); - vec3_add(node[-1].trans, v3, node->trans); - node->trans_diff = vec3_null; - node->field_C8 += 1.0f; -} - -static void sub_14047C800(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, - float_t step, bool disable_wind, bool ring_coli, bool has_children_node) { - if (!rob_osg->nodes.size()) - return; - - const float_t osage_gravity_const = get_osage_gravity_const(); - sub_1404803B0(rob_osg, mat, parent_scale, false); - - rob_osage_node* v17 = &rob_osg->nodes[0]; - v17->trans_orig = v17->trans; - vec3 v113; - vec3_mult(rob_osg->exp_data.position, *parent_scale, v113); - - mat4 v130 = *mat; - mat4_mult_vec3_trans(&v130, &v113, &v17->trans); - vec3_sub(v17->trans, v17->trans_orig, v17->trans_diff); - sub_14047F110(rob_osg, &v130, parent_scale, 0); - *rob_osg->nodes[0].bone_node_mat = v130; - *rob_osg->nodes[0].bone_node_ptr->ex_data_mat = v130; - - v113 = { 1.0f, 0.0f, 0.0f }; - vec3 v128; - mat4_mult_vec3(&v130, &v113, &v128); - - float_t v25 = parent_scale->x; - if (!rob_osg->osage_reset && step <= 0.0f) - return; - - bool stiffness = rob_osg->skin_param_ptr->stiffness > 0.0f; - - rob_osage_node* v30 = rob_osg->nodes.data(); - rob_osage_node* v26_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v26_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v26 = v26_begin; v26 != v26_end; v26++, v30++) { - rob_osage_node_data* v31 = v26->data_ptr; - float_t weight = v31->skp_osg_node.weight; - vec3 v111; - if (!rob_osg->set_external_force) { - sub_140482300(&v111, &v26->trans, &v30->trans, osage_gravity_const, weight); - - if (v26 != v26_end - 1) { - vec3 v112; - sub_140482300(&v112, &v26->trans, &v26[1].trans, osage_gravity_const, weight); - vec3_add(v111, v112, v111); - vec3_mult_scalar(v111, 0.5f, v111); - } - } - else - vec3_mult_scalar(rob_osg->external_force, 1.0f / weight, v111); - - vec3 v127; - vec3_mult_scalar(v128, v31->force * v26->force, v127); - float_t v41 = (1.0f - rob_osg->field_1EB4) * (1.0f - rob_osg->skin_param_ptr->air_res); - - vec3 v126; - vec3_add(v111, v127, v126); - vec3_mult_scalar(v26->trans_diff, v41, v111); - vec3_sub(v126, v111, v126); - vec3_mult_scalar(v26->external_force, weight, v111); - vec3_add(v126, v111, v126); - - if (!disable_wind) { - vec3_mult_scalar(rob_osg->wind_direction, rob_osg->skin_param_ptr->wind_afc, v111); - vec3_add(v126, v111, v126); - } - - if (stiffness) { - vec3 v116; - vec3_sub(v26->trans_diff, v30->trans_diff, v116); - vec3_mult_scalar(v116, 1.0f - rob_osg->skin_param_ptr->air_res, v116); - vec3_sub(v126, v116, v126); - } - - float_t v49 = 1.0f / (weight - (weight - 1.0f) * v31->skp_osg_node.inertial_cancel); - vec3_mult_scalar(v126, v49, v26->field_28); - } - - if (stiffness) { - mat4 v131 = v130; - vec3 v111; - mat4_get_translation(&v131, &v111); - - rob_osage_node* v55_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v55_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v55 = v55_begin; v55 != v55_end; v55++) { - mat4_mult_vec3_trans(&v131, &v55->field_94, &v128); - - vec3 v123; - vec3_add(v55->trans_diff, v55->field_28, v123); - vec3 v126; - vec3_add(v55->trans, v123, v126); - sub_140482F30(&v126, &v111, v25 * v55->length); - vec3 v117; - vec3_sub(v128, v126, v117); - vec3_mult_scalar(v117, rob_osg->skin_param_ptr->stiffness, v117); - float_t weight = v55->data_ptr->skp_osg_node.weight; - float_t v74 = 1.0f / (weight - (weight - 1.0f) * v55->data_ptr->skp_osg_node.inertial_cancel); - vec3_mult_scalar(v117, v74, v117); - vec3_add(v55->field_28, v117, v55->field_28); - vec3_add(v55->trans, v117, v126); - vec3_add(v126, v123, v126); - - vec3 v129; - mat4_mult_vec3_inv_trans(&v131, &v126, &v129); - - sub_140482FF0(&v131, &v129, 0, 0, &rob_osg->yz_order); - - float_t v58; - vec3_distance(v111, v126, v58); - mat4_translate_mult(&v131, v58, 0.0f, 0.0f, &v131); - - v111 = v126; - } - } - - rob_osage_node* v82_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v82_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v82 = v82_begin; v82 != v82_end; v82++) { - v82->trans_orig = v82->trans; - vec3_add(v82->field_28, v82->trans_diff, v82->trans_diff); - vec3_add(v82->trans_diff, v82->trans, v82->trans); - } - - if (rob_osg->nodes.size() > 1) { - rob_osage_node* v90_begin = rob_osg->nodes.data() + rob_osg->nodes.size() - 2; - rob_osage_node* v90_end = rob_osg->nodes.data(); - for (rob_osage_node* v90 = v90_begin; v90 != v90_end; v90--) - sub_140482F30(&v90[0].trans, &v90[1].trans, v25 * v90->child_length); - } - - if (ring_coli) { - rob_osage_node* v91 = &rob_osg->nodes.data()[0]; - float_t v93 = v91->data_ptr->skp_osg_node.coli_r; - float_t v97; - if (v91->trans.x < rob_osg->ring.ring_rectangle_x - v93 - || v91->trans.z < rob_osg->ring.ring_rectangle_y - v93 - || v91->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width - || v91->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) - v97 = rob_osg->ring.ring_out_height; - else - v97 = rob_osg->ring.ring_height; - - float_t v96 = v97 + v93; - rob_osage_node* v98_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v98_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (auto v98 = v98_begin; v98 != v98_end; v98++) { - sub_140482490(v98, step, v25); - sub_140482180(v98, v96); - } - } - - if (has_children_node) { - rob_osage_node* v100 = rob_osg->nodes.data(); - rob_osage_node* v99_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v99_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v99 = v99_begin; v99 != v99_end; v99++, v100++) { - vec3 v129; - mat4_mult_vec3_inv_trans(&v130, &v99->trans, &v129); - bool v102 = sub_140482FF0(&v130, &v129, - &v99->data_ptr->skp_osg_node.hinge, - &v99->reset_data.rotation, &rob_osg->yz_order); - *v99->bone_node_ptr->ex_data_mat = v130; - - float_t v104; - vec3_distance_squared(v99->trans, v100->trans, v104); - float_t v105 = v25 * v99->length; - - bool v106; - if (v104 >= v105 * v105) { - v105 = sqrtf(v104); - v106 = false; - } - else - v106 = true; - - mat4_translate_mult(&v130, v105, 0.0f, 0.0f, &v130); - if (v102 || v106) - mat4_get_translation(&v130, &v99->trans); - } - - if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { - mat4 v131 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; - mat4_translate_mult(&v131, v25 * rob_osg->node.length, 0.0f, 0.0f, &v131); - *rob_osg->node.bone_node_ptr->ex_data_mat = v131; - } - } - rob_osg->field_2A0 = false; -} - -static int32_t sub_140483DE0(vec3* a1, vec3* a2, vec3* a3, float_t radius) { - vec3 v5; - float_t length; - vec3_sub(*a2, *a3, v5); - vec3_length_squared(v5, length); - if (length > 0.000001f && length < radius * radius) { - vec3_mult_scalar(v5, radius / sqrtf(length) - 1.0f, *a1); - return 1; - } - return 0; -} - -static int32_t sub_140484540(vec3* a1, vec3* a2, osage_coli* coli, float_t radius) { - vec3 v11; - vec3_sub(*a2, coli->bone0_pos, v11); - - float_t v17; - vec3_dot(v11, coli->bone_pos_diff, v17); - if (v17 < 0.0f) - return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); - - float_t v19 = coli->bone_pos_diff_length_squared; - if (fabsf(v19) <= 0.000001f) - return sub_140483DE0(a1, a2, &coli->bone0_pos, radius); - if (v17 > v19) - return sub_140483DE0(a1, a2, &coli->bone1_pos, radius); - - float_t v20; - vec3_length_squared(v11, v20); - float_t v22 = fabsf(v20 - v17 * v17 / v19); - if (v22 <= 0.000001f || v22 >= radius * radius) - return 0; - - vec3 v29; - vec3_mult_scalar(coli->bone_pos_diff, v17 / v19, v29); - vec3_sub(v11, v29, v29); - vec3_mult_scalar(v29, radius / sqrtf(v22) - 1.0f, *a1); - return 1; -} - -static int32_t sub_140484780(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { - float_t v3; - vec3_dot(*a2, *a4, v3); - float_t v4; - vec3_dot(*a3, *a4, v4); - float_t v5 = v3 - v4 - radius; - if (v5 >= 0.0f) - return 0; - - vec3_mult_scalar(*a4, -v5, *a1); - return 1; -} - -static int32_t sub_140483EA0(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { - if (a3->bone_pos_diff_length <= 0.000001f) - return sub_140483DE0(a1, a2, &a3->bone0_pos, radius); - - float_t v61 = a3->bone_pos_diff_length * 0.5f; - float_t v13 = sqrtf(radius * radius + v61 * v61); - - float_t v20; - vec3 v54; - vec3_sub(*a2, a3->bone0_pos, v54); - vec3_length(v54, v20); - - float_t v21; - vec3 v57; - vec3_sub(*a2, a3->bone1_pos, v57); - vec3_length(v57, v21); - - if (v20 <= 0.000001f || v21 <= 0.000001f) - return 0; - - float_t v22 = v20 + v21; - if (v21 + v20 >= v13 * 2.0f) - return 0; - - float_t v25 = 1.0f / a3->bone_pos_diff_length; - - vec3 v63; - vec3_add(a3->bone0_pos, a3->bone1_pos, v63); - vec3_mult_scalar(v63, 0.5f, v63); - vec3_sub(*a2, v63, v63); - - float_t v58; - vec3_length(v63, v58); - if (v58 != 0.0f) - vec3_mult_scalar(v63, 1.0f / v58, v63); - - float_t v36; - vec3_dot(v63, a3->bone_pos_diff, v36); - v36 *= v25; - float_t v37 = v36 * v36; - v37 = min(v37, 1.0f); - v22 *= 0.5f; - float_t v38 = v22 * v22 - v61; - if (v38 < 0.0f) - return 0; - - float_t v39 = sqrtf(v38); - if (v39 <= 0.000001f) - return 0; - - float_t v42 = sqrtf(1.0f - v37); - v22 = (v13 / v22 - 1.0f) * v36 * v58; - v42 = (radius / v39 - 1.0f) * v42 * v58; - float_t v43 = sqrtf(v42 * v42 + v22 * v22); - if (v20 != 0.0f) - vec3_mult_scalar(v54, 1.0f / v20, v54); - - if (v21 != 0.0f) - vec3_mult_scalar(v57, 1.0f / v21, v57); - - vec3 v48; - vec3_add(v54, v57, v48); - vec3_normalize(v48, v48); - vec3_mult_scalar(v48, v43, *a1); - return 1; -} - -static int32_t sub_140483B30(vec3* a1, vec3* a2, osage_coli* a3, float_t radius) { - vec3 bone_pos_diff; - vec3_add(a3->bone0_pos, a3->bone1_pos, bone_pos_diff); - - vec3 v29; - vec3 v30; - for (int32_t i = 0; i < 3; i++) { - float_t v13 = ((float_t*)a2)[i]; - float_t v14 = ((float_t*)&a3->bone0_pos)[i] - v13; - ((float_t*)&v30)[i] = v14; - if (v14 > radius) - return 0; - - v14 = v13 - ((float_t*)&bone_pos_diff)[i]; - ((float_t*)&v29)[i] = v14; - if (v14 > radius) - return 0; - } - - vec3 v28 = vec3_null; - vec3 v32 = vec3_null; - vec3 v27 = vec3_identity; - - float_t v16 = 0.0f; - for (int32_t i = 0; i < 3; i++) { - float_t v18 = ((float_t*)&v30)[i]; - float_t v19 = ((float_t*)&v29)[i]; - if (fabsf(v18) >= fabsf(v19)) { - ((float_t*)&v28)[i] = v19; - ((float_t*)&v27)[i] = 1.0f; - v18 = v19; - } - else { - ((float_t*)&v28)[i] = v18; - ((float_t*)&v27)[i] = -1.0f; - } - - if (v18 > 0.0f) { - float_t v20 = v18 * v18; - ((float_t*)&v32)[i] = v20; - v16 += v20; - } - } - - if (v16 > radius * radius) - return 0; - - if (v16 > 0.0f) { - vec3_mult(v27, v32, v32); - vec3_mult_scalar(v32, 1.0f / v16, v32); - vec3_mult_scalar(v32, radius - sqrtf(v16), *a1); - } - else { - float_t v25 = ((float_t*)&v28)[0]; - int32_t v26 = 0; - for (int32_t i = 0; i < 3; i++) { - if (((float_t*)&v28)[i] > v25) { - v25 = ((float_t*)&v28)[i]; - v26 = i; - } - } - ((float_t*)a1)[v26] -= ((float_t*)&v27)[v26] * (v25 - radius); - } - return 1; -} - -static int32_t sub_140485220(vec3* a1, skin_param_osage_node* a2, osage_coli* a3, float_t* a4) { - if (!a3) - return 0; - - int32_t v8 = 0; - while (a3->type) { - int32_t v11 = 0; - vec3 v31 = vec3_null; - switch (a3->type) { - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: - v11 = sub_140483DE0(&v31, a1, &a3->bone0_pos, a3->radius + a2->coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: - v11 = sub_140484540(&v31, a1, a3, a3->radius + a2->coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE: - v11 = sub_140484780(&v31, a1, &a3->bone0_pos, &a3->bone1_pos, a2->coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: - v11 = sub_140483EA0(&v31, a1, a3, a3->radius + a2->coli_r); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_5: - v11 = sub_140483B30(&v31, a1, a3, a2->coli_r); - break; - } - - if (a4 && v11 > 0) { - if (a3->field_34 < *a4) - *a4 = a3->field_34; - } - a3++; - v8 += v11; - vec3_add(*a1, v31, *a1); - } - return v8; -} - -static int32_t sub_1404851C0(vec3* a1, skin_param_osage_node* a2, std::vector* a3, float_t* a4) { - if (!a3->size() || a3->back().type) - return 0; - return sub_140485220(a1, a2, a3->data(), a4); -} - -static int32_t sub_140485180(osage_coli* a1, vec3* a2, skin_param_osage_node* a3) { - return sub_140485220(a2, a3, a1, 0); -} - -static void sub_14047D8C0(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5) { - if (!rob_osg->osage_reset && step <= 0.0f) - return; - - osage_coli* coli = rob_osg->coli; - osage_coli* coli_ring = rob_osg->coli_ring; - std::vector* vec_ring_coli = &rob_osg->ring.coli; - - float_t v9 = 0.0f; - if (step > 0.0f) - v9 = 1.0f / step; - - mat4 v64; - if (a5) - v64 = *rob_osg->nodes.data()[0].bone_node_mat; - else { - v64 = *mat; - - vec3 trans; - vec3_mult(rob_osg->exp_data.position, *parent_scale, trans); - mat4_mult_vec3_trans(&v64, &trans, &rob_osg->nodes.data()[0].trans); - sub_14047F110(rob_osg, &v64, parent_scale, 0); - } - - float_t v60 = -1000.0f; - if (a5) { - float_t v22; - rob_osage_node* v16 = &rob_osg->nodes.data()[0]; - float_t v18 = v16->data_ptr->skp_osg_node.coli_r; - if (v16->trans.x < rob_osg->ring.ring_rectangle_x - v18 - || v16->trans.z < rob_osg->ring.ring_rectangle_y - v18 - || v16->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width - || v16->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) - v22 = rob_osg->ring.ring_out_height; - else - v22 = rob_osg->ring.ring_height; - v60 = v22 + v18; - } - - float_t v23 = 0.2f; - if (step < 1.0f) - v23 = 0.2f / (2.0f - step); - - if (rob_osg->skin_param_ptr->colli_tgt_osg) { - std::vector* v24 = rob_osg->skin_param_ptr->colli_tgt_osg; - rob_osage_node* v27_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v27_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v27 = v27_begin; v27 != v27_end; v27++) { - vec3 v62 = vec3_null; - - rob_osage_node* v30_begin = v24->data() + 1; - rob_osage_node* v30_end = v24->data() + v24->size(); - for (rob_osage_node* v30 = v30_begin; v30 != v30_end; v30++) - sub_140483DE0(&v62, &v27->trans, &v30->trans, - v27->data_ptr->skp_osg_node.coli_r + v30->data_ptr->skp_osg_node.coli_r); - vec3_add(v27->trans, v62, v27->trans); - } - } - - rob_osage_node* v35_begin = rob_osg->nodes.data() + 1; - rob_osage_node* v35_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* v35 = v35_begin; v35 != v35_end; v35++) { - skin_param_osage_node* skp_osg_node = &v35->data_ptr->skp_osg_node; - float_t v37 = (1.0f - rob_osg->field_1EB4) * rob_osg->skin_param_ptr->friction; - if (a5) { - sub_140482490(&v35[0], step, parent_scale->x); - v35->field_C8 = (float_t)sub_1404851C0(&v35->trans, - skp_osg_node, vec_ring_coli, &v35->field_CC); - if (!rob_osg->field_1F0F) { - v35->field_C8 += (float_t)sub_140485180(coli_ring, &v35->trans, skp_osg_node); - v35->field_C8 += (float_t)sub_140485180(coli, &v35->trans, skp_osg_node); - } - sub_140482180(&v35[0], v60); - } - else - sub_140482F30(&v35[0].trans, &v35[-1].trans, v35[0].length * parent_scale->x); - - vec3 v63; - mat4_mult_vec3_inv_trans(&v64, &v35->trans, &v63); - bool v40 = sub_140482FF0(&v64, &v63, &skp_osg_node->hinge, - &v35->reset_data.rotation, &rob_osg->yz_order); - v35->bone_node_ptr->exp_data.parent_scale = *parent_scale; - *v35->bone_node_ptr->ex_data_mat = v64; - - if (v35->bone_node_mat) { - mat4* v41 = v35->bone_node_mat; - mat4_scale_rot(&v64, parent_scale->x, parent_scale->y, parent_scale->z, v41); - } - - float_t v42 = v35->length * parent_scale->x; - float_t v44; - bool v45; - vec3_distance_squared(v35[0].trans, v35[-1].trans, v44); - if (v44 >= v42 * v42) { - v42 = sqrtf(v44); - v45 = false; - } - else - v45 = true; - - mat4_translate_mult(&v64, v42, 0.0f, 0.0f, &v64); - v35->reset_data.length = v42; - if (v40 || v45) - mat4_get_translation(&v64, &v35->trans); - - vec3 v62; - vec3_sub(v35->trans, v35->trans_orig, v62); - vec3_mult_scalar(v62, v9, v35->trans_diff); - - if (v35->field_C8 > 0.0f) { - if (v35->field_CC < v37) - v37 = v35->field_CC; - vec3_mult_scalar(v35->trans_diff, v37, v35->trans_diff); - } - - float_t v55; - vec3_length_squared(v35->trans_diff, v55); - if (v55 > v23 * v23) - vec3_mult_scalar(v35->trans_diff, v23 / sqrtf(v55), v35->trans_diff); - - mat4_mult_vec3_inv_trans(mat, &v35->trans, &v35->reset_data.trans); - mat4_mult_vec3_inv(mat, &v35->trans_diff, &v35->reset_data.trans_diff); - } - - if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { - mat4 v65 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; - mat4_translate_mult(&v65, rob_osg->node.length * parent_scale->x, 0.0f, 0.0f, &v65); - *rob_osg->node.bone_node_ptr->ex_data_mat = v65; - mat4_scale_rot(&v65, parent_scale->x, parent_scale->y, parent_scale->z, &v65); - *rob_osg->node.bone_node_mat = v65; - rob_osg->node.bone_node_ptr->exp_data.parent_scale = *parent_scale; - } -} - -static void rob_osage_set_nodes_external_force(rob_osage* rob_osg, vec3* external_force, float_t strength) { - vec3 v4 ; - if (external_force) - v4 = *external_force; - else - v4 = vec3_null; - - size_t exf = rob_osg->osage_setting.exf; - size_t v8 = 0; - if (exf >= 4) { - float_t strength4 = strength * strength * strength * strength; - v8 = ((exf - 4) / 4 + 1) * 4; - for (size_t v10 = v8 / 4; v10; v10--) - vec3_mult_scalar(v4, strength4, v4); - } - - if (v8 < exf) - for (size_t v12 = exf - v8; v12; v12--) - vec3_mult_scalar(v4, strength, v4); - - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - i->external_force = v4; - vec3_mult_scalar(v4, strength, v4); - } -} - -static void rob_osage_set_nodes_force(rob_osage* rob_osg, float_t force) { - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - i->force = force; -} - -static void sub_140480260(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool v5) { - if (!v5) { - rob_osage_set_nodes_external_force(rob_osg, 0, 1.0f); - rob_osage_set_nodes_force(rob_osg, 1.0f); - rob_osg->set_external_force = false; - rob_osg->external_force = vec3_null; - } - - rob_osg->field_2A0 = true; - rob_osg->field_2A1 = false; - rob_osg->field_2A4 = -1.0f; - rob_osg->field_1F0C = false; - rob_osg->osage_reset = false; - rob_osg->field_1F0E = false; - - for (auto i = rob_osg->nodes.begin(); i != rob_osg->nodes.end(); i++) { - i->field_C8 = 0.0f; - i->field_CC = 1.0f; - } - - rob_osg->parent_mat = *rob_osg->parent_mat_ptr; -} - -static void sub_14047C770(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, float_t step, bool a5) { - sub_14047C800(rob_osg, mat, parent_scale, step, a5, false, false); - sub_14047D8C0(rob_osg, mat, parent_scale, step, true); - sub_140480260(rob_osg, mat, parent_scale, step, a5); -} - -static void sub_14047C750(rob_osage* rob_osg, mat4* mat, vec3* parent_scale, float_t step) { - sub_14047C770(rob_osg, mat, parent_scale, step, false); -} - -static void sub_14047ECA0(rob_osage* rob_osg, float_t step) { - if (step <= 0.0f) - return; - - std::vector* vec_coli = &rob_osg->ring.coli; - osage_coli* coli_ring = rob_osg->coli_ring; - osage_coli* coli = rob_osg->coli; - bool v11 = rob_osg->field_1F0F; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - rob_osage_node_data* data = i->data_ptr; - i->field_C8 += (float_t)sub_1404851C0(&i->trans, &data->skp_osg_node, vec_coli, &i->field_CC); - if (v11) - continue; - - for (rob_osage_node*& j : data->boc) { - j->field_C8 += (float_t)sub_140485180(coli_ring, &j->trans, &data->skp_osg_node); - j->field_C8 += (float_t)sub_140485180(coli, &j->trans, &data->skp_osg_node); - } - - i->field_C8 += (float_t)sub_140485180(coli_ring, &i->trans, &data->skp_osg_node); - i->field_C8 += (float_t)sub_140485180(coli, &i->trans, &data->skp_osg_node); - } -} - -void sub_140484E10(vec3* a1, vec3* a2, vec3* a3, vec3* a4) { - vec3 v6; - vec3_sub(*a3, *a2, v6); - - vec3 v7; - vec3_sub(*a4, *a2, v7); - - float_t v8; - vec3_dot(v7, v6, v8); - if (v8 < 0.0f) { - *a1 = *a2; - return; - } - - float_t v9; - vec3_length_squared(v6, v9); - if (v9 <= 0.000001f) - *a1 = *a2; - else if (v8 <= v9) { - float_t v10 = v8 / v9; - vec3_mult_scalar(v6, v8 / v9, v6); - vec3_add(*a2, v6, *a1); - } - else - *a1 = *a3; -} - -static int32_t sub_140484450(vec3* a1, vec3* a2, vec3* a3, vec3* a4, float_t radius) { - vec3 v8; - sub_140484E10(&v8, a2, a3, a4); - return sub_140483DE0(a1, &v8, a4, radius); -} - -static void sub_140484850(vec3* a1, vec3* a2, vec3* a3, osage_coli* coli) { - vec3 v56; - vec3_sub(*a3, *a2, v56); - - vec3 v60; - vec3_cross(v56, coli->bone_pos_diff, v60); - - float_t v46; - vec3_length_squared(v60, v46); - if (v46 <= 0.000001f) { - vec3 v56; - vec3 v57; - vec3 v58; - vec3 v59; - sub_140484E10(&v59, &coli->bone0_pos, &coli->bone1_pos, a2); - sub_140484E10(&v58, &coli->bone0_pos, &coli->bone1_pos, a3); - sub_140484E10(&v57, a2, a3, &coli->bone0_pos); - sub_140484E10(&v56, a2, a3, &coli->bone1_pos); - - float_t v48; - float_t v51; - float_t v52; - float_t v55; - vec3_distance_squared(*a3, coli->bone0_pos, v48); - vec3_distance_squared(coli->bone0_pos, v57, v51); - vec3_distance_squared(coli->bone1_pos, v56, v52); - vec3_distance_squared(*a2, v59, v55); - *a1 = *a2; - - if (v55 > v48) { - *a1 = *a3; - v55 = v48; - } - - if (v55 > v51) { - *a1 = v57; - v55 = v51; - } - - if (v55 > v52) - *a1 = v56; - } - else { - float_t v25; - vec3_length(v56, v25); - if (v25 != 0.0f) - vec3_mult_scalar(v56, 1.0f / v25, v56); - - float_t v30 = 1.0f / coli->bone_pos_diff_length; - vec3 v61; - float_t v34; - vec3_mult_scalar(coli->bone_pos_diff, v30, v61); - vec3_dot(v61, v56, v34); - vec3_mult_scalar(v61, v34, v61); - vec3_sub(v61, v56, v61); - vec3_sub(coli->bone0_pos, *a2, v60); - float_t v35; - vec3_dot(v61, v60, v35); - v35 /= (v34 * v34 - 1.0f); - if (v35 < 0.0f) - *a1 = *a2; - else if (v35 <= v25) { - vec3_mult_scalar(v56, v35, v56); - vec3_add(*a2, v56, *a1); - } - else - *a1 = *a3; - - } -} - -static int32_t sub_1404844A0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { - vec3 v8; - sub_140484850(&v8, a2, a3, a4); - return sub_140484540(a1, &v8, a4, radius); -} - -static int32_t sub_1404844F0(vec3* a1, vec3* a2, vec3* a3, osage_coli* a4, float_t radius) { - vec3 v8; - sub_140484850(&v8, a2, a3, a4); - return sub_140483EA0(a1, &v8, a4, radius); -} - -static int32_t sub_140485000(vec3* a1, vec3* a2, skin_param_osage_node* a3, osage_coli* a4) { - if (!a4) - return 0; - - int32_t v8 = 0; - while (a4->type) { - int32_t type = a4->type; - vec3 v21 = vec3_null; - switch (a4->type) { - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL: - v8 += sub_140484450(&v21, a1, a2, &a4->bone0_pos, a3->coli_r + a4->radius); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER: - v8 += sub_1404844A0(&v21, a1, a2, a4, a3->coli_r + a4->radius); - break; - case SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE: - v8 += sub_1404844F0(&v21, a1, a2, a4, a3->coli_r + a4->radius); - break; - } - - if (v8 > 0) { - vec3_add(*a1, v21, *a1); - vec3_add(*a2, v21, *a2); - } - a4++; - } - return v8; -} - -static void sub_14047D620(rob_osage* rob_osg, float_t step) { - if (step < 0.0f && rob_osg->field_1F0F) - return; - - vec3 v7 = rob_osg->nodes.data()[0].trans; - osage_coli* coli = rob_osg->coli; - osage_coli* coli_ring = rob_osg->coli_ring; - int32_t coli_type = rob_osg->skin_param_ptr->coli_type; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - rob_osage_node_data* data = i->data_ptr; - for (rob_osage_node*& j : data->boc) { - float_t v17 = (float_t)( - sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli) - + sub_140485000(&i->trans, &j->trans, &data->skp_osg_node, coli_ring)); - i->field_C8 += v17; - j->field_C8 += v17; - } - - if (coli_type && (coli_type != 1 || i != i_begin)) { - float_t v20 = (float_t)( - sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli) - + sub_140485000(&i[0].trans, &i[-1].trans, &data->skp_osg_node, coli_ring)); - i[0].field_C8 += v20; - i[-1].field_C8 += v20; - } - } - rob_osg->nodes.data()[0].trans = v7; -} - -static void sub_14047F990(rob_osage* rob_osg, mat4* a2, vec3* a3, bool a4) { - if (!rob_osg->nodes.size()) - return; - - vec3 v76; - vec3_mult(rob_osg->exp_data.position, *a3, v76); - mat4_mult_vec3_trans(a2, &v76, &v76); - vec3 v74 = v76; - rob_osage_node* v12 = &rob_osg->nodes[0]; - v12->trans = v76; - v12->trans_orig = v76; - v12->trans_diff = vec3_null; - - float_t ring_height; - rob_osage_node* v14 = &rob_osg->nodes[0]; - float_t coli_r = v14->data_ptr->skp_osg_node.coli_r; - if (v14->trans.x < rob_osg->ring.ring_rectangle_x - coli_r - || v14->trans.z < rob_osg->ring.ring_rectangle_y - coli_r - || v14->trans.x > rob_osg->ring.ring_rectangle_x + rob_osg->ring.ring_rectangle_width - || v14->trans.z > rob_osg->ring.ring_rectangle_y + rob_osg->ring.ring_rectangle_height) - ring_height = rob_osg->ring.ring_out_height; - else - ring_height = rob_osg->ring.ring_height; - - mat4 v78 = *a2; - sub_14047F110(rob_osg, &v78, a3, true); - vec3 v60 = { 1.0f, 0.0f, 0.0f }; - mat4_mult_vec3(&v78, &v60, &v60); - - osage_coli* coli_ring = rob_osg->coli_ring; - osage_coli* coli = rob_osg->coli; - float_t v25 = ring_height + coli_r; - float_t v16 = a3->x; - rob_osage_node* i = rob_osg->nodes.data(); - rob_osage_node* j_begin = rob_osg->nodes.data() + 1; - rob_osage_node* j_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* j = j_begin; j != j_end; i++, j++) { - vec3_normalize(v60, v60); - vec3_mult_scalar(v60, v16 * j->length, v60); - vec3_add(i->trans, v60, v74); - if (a4 && j->sibling_node) - sub_140482F30(&v74, &j->sibling_node->trans, j->max_distance); - - skin_param_osage_node* v38 = &j->data_ptr->skp_osg_node; - sub_140485180(coli_ring, &v74, v38); - sub_140485180(coli, &v74, v38); - - float_t v39 = v25 + v38->coli_r; - if (v74.y < v39 && v39 < 1001.0f) { - v74.y = v39; - vec3_sub(v74, i->trans, v74); - vec3_normalize(v74, v74); - vec3_mult_scalar(v74, v16 * j->length, v74); - vec3_add(v74, i->trans, v74); - } - j->trans = v74; - j->trans_diff = vec3_null; - vec3 v77; - mat4_mult_vec3_inv_trans(&v78, &j->trans, &v77); - sub_140482FF0(&v78, &v77, &j->data_ptr->skp_osg_node.hinge, - &j->reset_data.rotation, &rob_osg->yz_order); - j->bone_node_ptr->exp_data.parent_scale = *a3; - *j->bone_node_ptr->ex_data_mat = v78; - if (j->bone_node_mat) - mat4_scale_rot(&v78, a3->x, a3->y, a3->z, j->bone_node_mat); - - float_t v55; - vec3_distance(j->trans, i->trans, v55); - float_t v56 = v16 * j->length; - if (v55 >= fabsf(v56)) - v56 = v55; - mat4_translate_mult(&v78, v56, 0.0f, 0.0f, &v78); - mat4_get_translation(&v78, &j->trans); - vec3_sub(j->trans, i->trans, v60); - } - - if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { - mat4 v79 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; - mat4_translate_mult(&v79, v16 * rob_osg->node.length, 0.0f, 0.0f, &v79); - *rob_osg->node.bone_node_ptr->ex_data_mat = v79; - mat4_scale_rot(&v79, a3->x, a3->y, a3->z, &v79); - *rob_osg->node.bone_node_mat = v79; - rob_osg->node.bone_node_ptr->exp_data.parent_scale = *a3; - } -} - -static bool sub_14053D1B0(vec3* l_trans, vec3* r_trans, - vec3* u_trans, vec3* d_trans, vec3* a5, vec3* a6, vec3* a7) { - float_t length; - vec3_sub(*d_trans, *u_trans, *a5); - vec3_length_squared(*a5, length); - if (length <= 0.000001f) - return false; - vec3_mult_scalar(*a5, 1.0f / sqrtf(length), *a5); - - vec3 v9; - vec3_sub(*r_trans, *l_trans, v9); - vec3_cross(v9, *a5, *a6); - vec3_length_squared(*a6, length); - if (length <= 0.000001f) - return false; - vec3_mult_scalar(*a6, 1.0f / sqrtf(length), *a6); - - vec3_cross(*a5, *a6, *a7); - vec3_normalize(*a7, *a7); - return true; -} - -static void sub_14053CE30(rob_osage_node_data_normal_ref* normal_ref, mat4* a2) { - if (!normal_ref->field_0) - return; - - vec3 n_trans; - vec3 u_trans; - vec3 d_trans; - vec3 l_trans; - vec3 r_trans; - mat4_get_translation(normal_ref->n->bone_node_ptr->ex_data_mat, &n_trans); - mat4_get_translation(normal_ref->u->bone_node_ptr->ex_data_mat, &u_trans); - mat4_get_translation(normal_ref->d->bone_node_ptr->ex_data_mat, &d_trans); - mat4_get_translation(normal_ref->l->bone_node_ptr->ex_data_mat, &l_trans); - mat4_get_translation(normal_ref->r->bone_node_ptr->ex_data_mat, &r_trans); - - vec3 v27; - vec3 v26; - vec3 v28; - if (sub_14053D1B0(&l_trans, &r_trans, &u_trans, &d_trans, &v27, &v26, &v28)) { - mat4 v34; - *(vec3*)&v34.row0 = v28; - *(vec3*)&v34.row1 = v26; - *(vec3*)&v34.row2 = v27; - *(vec3*)&v34.row3 = n_trans; - v34.row0.w = 0.0f; - v34.row1.w = 0.0f; - v34.row2.w = 0.0f; - v34.row3.w = 1.0f; - - mat4 v33 = normal_ref->mat; - mat4_mult(&v33, &v34, a2); - } -} - -static void sub_14047E1C0(rob_osage* rob_osg, vec3* scale) { - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - if (i->data_ptr->normal_ref.field_0) { - sub_14053CE30(&i->data_ptr->normal_ref, i->bone_node_mat); - mat4_scale_rot(i->bone_node_mat, scale->x, scale->y, scale->z, i->bone_node_mat); - } -} - -static void sub_140482DF0(struc_477* dst, struc_477* src0, struc_477* src1, float_t blend) { - dst->length = lerp(src0->length, src1->length, blend); - vec3_lerp_scalar(src0->angle, src1->angle, dst->angle, blend); -} - -static void sub_140482100(struc_476* a1, opd_blend_data* a2, struc_477* a3) { - if (!a2->field_C) - a1->field_0 = *a3; - else if (a2->type == MOTION_BLEND_FREEZE) { - if (a2->blend == 0.0f) - a1->field_10 = a1->field_0; - sub_140482DF0(&a1->field_0, &a1->field_10, a3, a2->blend); - } - else if (a2->type == MOTION_BLEND_CROSS) - sub_140482DF0(&a1->field_0, &a1->field_0, a3, a2->blend); -} - -static void sub_14047E240(rob_osage* rob_osg, mat4* a2, vec3* a3, std::vector* a4) { - if (!a4->size()) - return; - - vec3 v63; - vec3_mult(rob_osg->exp_data.position, *a3, v63); - - mat4 v85; - mat4_mult_vec3_trans(&v85, &v63, &rob_osg->nodes[0].trans); - - sub_14047F110(rob_osg, &v85, a3, 0); - *rob_osg->nodes[0].bone_node_mat = v85; - *rob_osg->nodes[0].bone_node_ptr->ex_data_mat = v85; - - size_t v17 = a4->size() - 1; - for (auto i = a4->end(); i != a4->begin(); v17--) { - i--; - mat4 v87 = v85; - float_t frame = i->frame; - vec3 v22 = rob_osg->nodes[0].trans; - vec3 v25 = v22; - if (frame >= i->frame_count) - frame = 0.0f; - - int32_t frame_int = (int32_t)frame; - if (frame != -0.0f && (float_t)frame_int != frame) - frame_int = (frame < 0.0f ? frame_int - 1 : frame_int); - - int32_t curr_key = frame_int; - int32_t next_key = frame_int + 1; - if ((float_t)next_key >= i->frame_count) - next_key = 0; - - float_t blend = frame - (float_t)frame_int; - float_t inv_blend = 1.0f - blend; - rob_osage_node* j_begin = rob_osg->nodes.data() + 1; - rob_osage_node* j_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* j = j_begin; j != j_end; j++) { - opd_vec3_data* opd = &j->opd_data[v17]; - float_t* opd_x = opd->x; - float_t* opd_y = opd->y; - float_t* opd_z = opd->z; - - vec3 v62; - v62.x = opd_x[curr_key]; - v62.y = opd_y[curr_key]; - v62.z = opd_z[curr_key]; - - vec3 v77; - v77.x = opd_x[next_key]; - v77.y = opd_y[next_key]; - v77.z = opd_z[next_key]; - - vec3 v84; - mat4_mult_vec3_trans(a2, &v62, &v84); - - vec3 v83; - mat4_mult_vec3_trans(a2, &v77, &v83); - - vec3 v82; - vec3_mult_scalar(v83, blend, v82); - - vec3 v81; - vec3_mult_scalar(v84, inv_blend, v81); - vec3_add(v82, v81, v82); - - vec3 v86; - mat4_mult_vec3_inv_trans(&v87, &v82, &v86); - - vec3 v64 = vec3_null; - sub_140482FF0(&v87, &v86, 0, &v64, &rob_osg->yz_order); - mat4_set_translation(&v87, &v82); - - float_t v50; - vec3_distance(v83, v25, v50); - - float_t v49; - vec3_distance(v84, v22, v49); - - struc_477 v72; - v72.angle = v64; - v72.length = v49 * inv_blend + v50 * blend; - sub_140482100(&j->field_1B0, &i[0], &v72); - - v22 = v84; - v25 = v83; - } - } - - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - float_t v54 = i->field_1B0.field_0.angle.y; - float_t v55 = i->field_1B0.field_0.angle.z; - v54 = clamp(v54, (float_t)-M_PI, (float_t)M_PI); - v55 = clamp(v55, (float_t)-M_PI, (float_t)M_PI); - mat4_rotate_z_mult(&v85, v55, &v85); - mat4_rotate_y_mult(&v85, v54, &v85); - i->bone_node_ptr->exp_data.parent_scale = *a3; - *i->bone_node_ptr->ex_data_mat = v85; - if (i->bone_node_mat) { - mat4 mat = v85; - mat4_scale_rot(&mat, a3->x, a3->y, a3->z, &mat); - *i->bone_node_mat = mat; - } - mat4_translate_mult(&v85, i->field_1B0.field_0.length, 0.0f, 0.0f, &v85); - i->trans_orig = i->trans; - mat4_get_translation(&v85, &i->trans); - } - - if (rob_osg->nodes.size() && rob_osg->node.bone_node_mat) { - mat4 v87 = *rob_osg->nodes.back().bone_node_ptr->ex_data_mat; - mat4_translate_mult(&v87, rob_osg->node.length * a3->x, 0.0f, 0.0f, &v87); - *rob_osg->node.bone_node_ptr->ex_data_mat = v87; - - mat4_scale_rot(&v87, a3->x, a3->y, a3->z, &v87); - *rob_osg->node.bone_node_mat = v87; - rob_osg->node.bone_node_ptr->exp_data.parent_scale = *a3; - } -} - -static void rob_osage_add_motion_reset_data(rob_osage* rob_osg, int32_t motion_id, float_t frame) { - int32_t frame_int = (int32_t)roundf(frame * 1000.0f); - - auto elem = rob_osg->motion_reset_data.find({ motion_id, frame_int }); - if (elem != rob_osg->motion_reset_data.end()) - rob_osg->motion_reset_data.erase(elem); - - std::list v28; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - v28.push_back(i->reset_data); - - rob_osg->motion_reset_data.insert({ { motion_id, frame_int }, v28 }); -} - -static void rob_osage_init_data(rob_osage* rob_osg, - obj_skin_block_osage* osg_data, obj_skin_osage_node* osg_nodes, - bone_node* ex_data_bone_nodes, obj_skin* skin) { - rob_osg->reset(); - bone_node_expression_data_set_position_rotation( - &rob_osg->exp_data, - &osg_data->base.position, - &osg_data->base.rotation); - std::vector& nodes = rob_osg->nodes; - rob_osg->nodes.clear(); - rob_osg->nodes.resize(osg_data->count + 1ULL); - - rob_osage_node* external = &nodes[0]; - nodes[0].reset(); - external->child_length = osg_nodes->length; - bone_node* external_bone_node = &ex_data_bone_nodes[osg_data->external_name_index & 0x7FFF]; - external->bone_node_ptr = external_bone_node; - external->bone_node_mat = external_bone_node->mat; - *external_bone_node->ex_data_mat = mat4_identity; - external->sibling_node = 0; - - bone_node* parent_bone_node = external->bone_node_ptr; - for (uint32_t i = 0; i < osg_data->count; i++) { - obj_skin_osage_node* v14 = &osg_nodes[i]; - rob_osage_node* node = &nodes[i + 1LL]; - node->reset(); - node->length = v14[0].length; - if (i != osg_data->count - 1) - node->child_length = v14[1].length; - bone_node* node_bone_node = &ex_data_bone_nodes[v14->name_index & 0x7FFF]; - node->bone_node_ptr = node_bone_node; - node->bone_node_mat = node_bone_node->mat; - node_bone_node->parent = parent_bone_node; - parent_bone_node = node->bone_node_ptr; - } - - rob_osg->node.reset(); - rob_osg->node.length = osg_nodes[osg_data->count - 1].length; - bone_node* v22 = &ex_data_bone_nodes[osg_data->name_index & 0x7FFF]; - rob_osg->node.bone_node_ptr = v22; - rob_osg->node.bone_node_mat = v22->mat; - v22->parent = parent_bone_node; - *rob_osg->node.bone_node_ptr->ex_data_mat = mat4_identity; - - if (osg_data->count) { - obj_skin_osage_node* v23 = osg_data->nodes; - size_t v24 = 0; - rob_osage_node* v26 = &nodes[1]; - for (size_t i = 0; i < osg_data->count; i++) { - vec3 v27 = vec3_null; - if (v23) - v27 = v23[i].rotation; - - mat4 mat; - mat4_rotate(v27.x, v27.y, v27.z, &mat); - - vec3 v49; - v49 = vec3_null; - v49.x = v26[i].length; - mat4_mult_vec3(&mat, &v49, &v26[i].field_94); - } - } - - if (osg_data->count) { - obj_skin_osage_node* v23 = osg_data->nodes; - rob_osage_node* v26 = &nodes[1]; - size_t v33 = 0; - for (uint32_t i = 0; i < osg_data->count; i++) { - v26[i].mat = mat4_null; - - obj_skin_bone* v36 = skin->bones; - for (uint32_t j = 0; j < skin->bones_count; j++, v36++) - if (v36->id == osg_nodes->name_index) { - mat4 mat = skin->bones[j].inv_bind_pose_mat; - mat4_inverse_normalized(&mat, &mat); - v26[i].mat = mat; - break; - } - - osg_nodes++; - } - } - - rob_osage_node* v38 = &rob_osg->nodes.back(); - if (memcmp(&v38->mat, &mat4_null, sizeof(mat4))) { - mat4 mat = v38->mat; - mat4_translate_mult(&mat, rob_osg->node.length, 0.0f, 0.0f, &mat); - rob_osg->node.mat = mat; - } -} - static bool check_module_index_is_501(int32_t module_index) { if (module_index == -1 || module_index >= 502) return false; return module_index == 501; } -static float_t ex_expression_block_stack_get_value(ex_expression_block_stack* stack) { - float_t value = 0.0f; - switch (stack->type) { - case EX_EXPRESSION_BLOCK_STACK_NUMBER: - value = stack->number.value; - break; - case EX_EXPRESSION_BLOCK_STACK_VARIABLE: - value = *stack->var.value; - break; - case EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN: - value = *stack->var_rad.value * RAD_TO_DEG_FLOAT; - break; - case EX_EXPRESSION_BLOCK_STACK_OP1: { - float_t v1 = ex_expression_block_stack_get_value(stack->op1.v1); - if (stack->op1.func) - value = stack->op1.func(v1); - } break; - case EX_EXPRESSION_BLOCK_STACK_OP2: { - float_t v1 = ex_expression_block_stack_get_value(stack->op2.v1); - float_t v2 = ex_expression_block_stack_get_value(stack->op2.v2); - if (stack->op2.func) - value = stack->op2.func(v1, v2); - } break; - case EX_EXPRESSION_BLOCK_STACK_OP3: { - float_t v1 = ex_expression_block_stack_get_value(stack->op1.v1); - float_t v2 = ex_expression_block_stack_get_value(stack->op2.v2); - float_t v3 = ex_expression_block_stack_get_value(stack->op3.v3); - if (stack->op3.func) - value = stack->op3.func(v1, v2, v3); - } break; - } - return value; -} - -static float_t exp_abs(float_t v1) { - return fabsf(v1); -} - -static float_t exp_acos(float_t v1) { - return acosf(v1) * RAD_TO_DEG_FLOAT; -} - -static float_t exp_add(float_t v1, float_t v2) { - return v1 + v2; -} - -static float_t exp_and(float_t v1, float_t v2) { - return v1 != 0.0f && v2 != 0.0f ? 1.0f : 0.0f; -} - -static float_t exp_asin(float_t v1) { - return asinf(v1) * RAD_TO_DEG_FLOAT; -} - -static float_t exp_atan(float_t v1) { - return atanf(v1) * RAD_TO_DEG_FLOAT; -} - -static float_t exp_av(float_t v1) { - return v1 * 0.1f; -} - -static float_t exp_ceil(float_t v1) { - return ceilf(v1); -} - -static float_t exp_cond(float_t v1, float_t v2, float_t v3) { - return v1 != 0.0f ? v2 : v3; -} - -static float_t exp_cos(float_t v1) { - return cosf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); -} - -static float_t exp_div(float_t v1, float_t v2) { - return v1 / v2; -} - -static float_t exp_eq(float_t v1, float_t v2) { - return v1 == v2 ? 1.0f : 0.0f; -} - -static float_t exp_exp(float_t v1) { - return expf(v1); -} - -static float_t exp_floor(float_t v1) { - return floorf(v1); -} - -static float_t exp_fmod(float_t v1, float_t v2) { - return fmodf(v1, v2); -} - -static const exp_func_op1* exp_func_op1_find_func(std::string& name, const exp_func_op1* array) { - const char* name_str = name.c_str(); - while (array->name) { - if (!str_utils_compare(name_str, array->name)) - return array; - array++; - } - return 0; -} - -static const exp_func_op2* exp_func_op2_find_func(std::string& name, const exp_func_op2* array) { - const char* name_str = name.c_str(); - while (array->name) { - if (!str_utils_compare(name_str, array->name)) - return array; - array++; - } - return 0; -} - -static const exp_func_op3* exp_func_op3_find_func(std::string& name, const exp_func_op3* array) { - const char* name_str = name.c_str(); - while (array->name) { - if (!str_utils_compare(name_str, array->name)) - return array; - array++; - } - return 0; -} - -static float_t exp_ge(float_t v1, float_t v2) { - return v1 >= v2 ? 1.0f : 0.0f; -} - -static float_t exp_gt(float_t v1, float_t v2) { - return v1 > v2 ? 1.0f : 0.0f; -} - -static float_t exp_le(float_t v1, float_t v2) { - return v1 <= v2 ? 1.0f : 0.0f; -} - -static float_t exp_log(float_t v1) { - return logf(v1); -} - -static float_t exp_lt(float_t v1, float_t v2) { - return v1 < v2 ? 1.0f : 0.0f; -} - -static float_t exp_max(float_t v1, float_t v2) { - return max(v1, v2); -} - -static float_t exp_min(float_t v1, float_t v2) { - return min(v1, v2); -} - -static float_t exp_mul(float_t v1, float_t v2) { - return v1 * v2; -} - -static float_t exp_ne(float_t v1, float_t v2) { - return v1 != v2 ? 1.0f : 0.0f; -} - -static float_t exp_neg(float_t v1) { - return -v1; -} - -static float_t exp_or(float_t v1, float_t v2) { - return v1 != 0.0f || v2 != 0.0f ? 1.0f : 0.0f; -} - -static float_t exp_pow(float_t v1, float_t v2) { - return powf(v1, v2); -} - -static float_t exp_rand(float_t v1, float_t v2, float_t v3) { - return v1 != 0.0f ? v2 : v3; -} - -static float_t exp_rand_0_1(float_t v1) { - return 0.0f; -} - -static float_t exp_round(float_t v1) { - return roundf(v1); -} - -static float_t exp_sin(float_t v1) { - return sinf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); -} - -static float_t exp_sqrt(float_t v1) { - return sqrtf(v1); -} - -static float_t exp_sub(float_t v1, float_t v2) { - return v1 - v2; -} - -static float_t exp_tan(float_t v1) { - return tanf(fmodf(v1, 360.0f) * DEG_TO_RAD_FLOAT); -} - -static const float_t get_osage_gravity_const() { - return 0.00299444468691945f; -} - static bool sub_140410250(struc_313* a1, size_t a2) { return !!(a1->bitfield.data()[a2 >> 5] & (1 << (a2 & 0x1F))); } @@ -7456,23 +5506,6 @@ static void mothead_func_73_rob_hand_adjust(mothead_func_data* func_data, } } -static bool rob_osage_check_parts_bits(rob_osage* rob_osg, rob_osage_parts_bit parts_bits) { - if (rob_osg->osage_setting.parts != ROB_OSAGE_PARTS_NONE) - return !!(parts_bits & (1 << rob_osg->osage_setting.parts)); - return false; -} - -static void sub_1405F9520(rob_chara_item_equip_object* itm_eq_obj, rob_osage_parts_bit a2, bool a3) { - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - if (rob_osage_check_parts_bits(&i->rob, a2)) - i->rob.field_1F0F = a3; -} - -static void sub_140513EE0(rob_chara_item_equip* rob_itm_eq, rob_osage_parts a2, bool a3) { - sub_1405F9520(&rob_itm_eq->item_equip_object[a2 == ROB_OSAGE_PARTS_MUFFLER ? ITEM_OUTER : ITEM_KAMI], - (rob_osage_parts_bit)(1 << a2), a3); -} - static void sub_140555120(rob_chara* rob_chr, rob_osage_parts a2, bool a3) { sub_140513EE0(rob_chr->item_equip, a2, a3); } @@ -7970,72 +6003,11 @@ static void opd_data_decode(int16_t* src_data, size_t count, uint8_t shift, floa } } -static void osage_coli_set(osage_coli* osg_coli, - skin_param_osage_root_coli* skp_root_coli, mat4* mats) { - osg_coli->type = (skin_param_osage_root_coli_type)0; - if (!skp_root_coli || !mats) - return; - - for (; skp_root_coli->type; osg_coli++, skp_root_coli++) { - osg_coli->type = skp_root_coli->type; - osg_coli->radius = skp_root_coli->radius; - mat4 mat = mats[skp_root_coli->bone0_index]; - mat4_mult_vec3_trans(&mat, &skp_root_coli->bone0_pos, &osg_coli->bone0_pos); - if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_CYLINDER - || skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_ELLIPSE) { - mat = mats[skp_root_coli->bone1_index]; - mat4_mult_vec3_trans(&mat, &skp_root_coli->bone1_pos, &osg_coli->bone1_pos); - vec3_sub(osg_coli->bone1_pos, osg_coli->bone0_pos, osg_coli->bone_pos_diff); - vec3_length_squared(osg_coli->bone_pos_diff, osg_coli->bone_pos_diff_length_squared); - osg_coli->bone_pos_diff_length = sqrtf(osg_coli->bone_pos_diff_length_squared); - if (osg_coli->bone_pos_diff_length < 0.01f) - osg_coli->type = SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_BALL; - } - else if (skp_root_coli->type == SKIN_PARAM_OSAGE_ROOT_COLI_TYPE_PLANE) - mat4_mult_vec3(&mat, &skp_root_coli->bone1_pos, &osg_coli->bone1_pos); - } - osg_coli->type = (skin_param_osage_root_coli_type)0; -} - -static void osage_coli_ring_set(osage_coli* osg_coli, - std::vector* vec_skp_root_coli, mat4* mats) { - if (!vec_skp_root_coli->size()) { - osg_coli->type = (skin_param_osage_root_coli_type)0; - osg_coli->radius = 0.0f; - osg_coli->bone0_pos = vec3_null; - osg_coli->bone1_pos = vec3_null; - osg_coli->bone_pos_diff = vec3_null; - osg_coli->bone_pos_diff_length = 0.0f; - osg_coli->bone_pos_diff_length_squared = 0.0f; - osg_coli->field_34 = 1.0f; - } - else - osage_coli_set(osg_coli, vec_skp_root_coli->data(), mats); -} - static void osage_play_data_manager_get_opd_file_data(object_info obj_info, int32_t motion_id, float_t** data, uint32_t* count) { //osage_play_data_manager_get()->GetOpdFileData(v8, obj_info, motion_id, data, count); } -static const osage_setting_osg_cat* osage_setting_data_get_cat_value( - object_info* obj_info, const char* root_node) { - auto elem_obj = osage_setting_data.obj.find(*obj_info); - if (elem_obj == osage_setting_data.obj.end()) - return 0; - - std::pair key = { elem_obj->second, root_node }; - auto elem_cat = osage_setting_data.cat.find(key); - if (elem_cat == osage_setting_data.cat.end()) - return 0; - - return &elem_cat->second; -} - -static bool osage_setting_data_obj_has_key(object_info key) { - return osage_setting_data.obj.find(key) != osage_setting_data.obj.end(); -} - static bool pv_osage_manager_array_get_disp(int32_t* chara_id) { return pv_osage_manager_array_ptr_get(*chara_id)->GetDisp(); } @@ -8179,13 +6151,13 @@ void rob_chara_data_adjust_ctrl(rob_chara* rob_chr, rob_chara_data_adjust* adjus } static void rob_chara_item_equip_object_set_parts_external_force( - rob_chara_item_equip_object* itm_eq_obj, int32_t parts_bits, + rob_chara_item_equip_object* itm_eq_obj, rob_osage_parts_bit parts_bits, vec3* weight, float_t force, float_t strength) { for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) { - rob_osage* rob_osg = &i->rob; - if (rob_osage_check_osage_setting_parts_bit(rob_osg, parts_bits)) { - rob_osage_set_nodes_external_force(rob_osg, weight, strength); - rob_osage_set_nodes_force(rob_osg, force); + RobOsage* rob_osg = &i->rob; + if (rob_osg->CheckPartsBits(parts_bits)) { + rob_osg->SetNodesExternalForce(weight, strength); + rob_osg->SetNodesForce(force); } } } @@ -8210,23 +6182,23 @@ static void rob_chara_item_equip_set_parts_external_force(rob_chara_item_equip* break; } - int32_t parts_bits = 1 << parts; + rob_osage_parts_bit parts_bits = (rob_osage_parts_bit)(1 << parts); if (!rob_itm_eq->parts_short) { if (parts == ROB_OSAGE_PARTS_LEFT) - parts_bits |= ROB_OSAGE_PARTS_SHORT_L_BIT; + enum_or(parts_bits, ROB_OSAGE_PARTS_SHORT_L_BIT); else if (parts == ROB_OSAGE_PARTS_RIGHT) - parts_bits |= ROB_OSAGE_PARTS_SHORT_R_BIT; + enum_or(parts_bits, ROB_OSAGE_PARTS_SHORT_R_BIT); } if (!rob_itm_eq->parts_append) { if (parts == ROB_OSAGE_PARTS_LEFT) - parts_bits |= ROB_OSAGE_PARTS_APPEND_L_BIT; + enum_or(parts_bits, ROB_OSAGE_PARTS_APPEND_L_BIT); else if (parts == ROB_OSAGE_PARTS_RIGHT) - parts_bits |= ROB_OSAGE_PARTS_APPEND_R_BIT; + enum_or(parts_bits, ROB_OSAGE_PARTS_APPEND_R_BIT); } if (!rob_itm_eq->parts_white_one_l && parts == ROB_OSAGE_PARTS_LONG_C) - parts_bits |= ROB_OSAGE_PARTS_WHITE_ONE_L_BIT; + enum_or(parts_bits, ROB_OSAGE_PARTS_WHITE_ONE_L_BIT); rob_chara_item_equip_object_set_parts_external_force( &rob_itm_eq->item_equip_object[id], parts_bits, external_force, force, strength); @@ -8239,10 +6211,10 @@ static void rob_chara_item_equip_object_set_external_force( i->rob.external_force = *external_force; } - /*for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) { - i->set_external_force = true; - i->external_force = *external_force; - }*/ + for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) { + i->rob.set_external_force = true; + i->rob.external_force = *external_force; + } } static void rob_chara_item_equip_set_external_force( @@ -9592,11 +7564,8 @@ static void sub_14053BEE0(rob_chara* rob_chr) { rob_chara_bone_data* rob_bone_data = rob_chr->bone_data; vec3* v3 = 0; if (sub_14041A010(rob_bone_data) || rob_bone_data->field_788.field_14C) { - if (rob_bone_data->field_788.field_8C) { - vec3 view_point; - camera_get_view_point(rctx_ptr->camera, &view_point); - rob_bone_data->field_788.field_B4 = view_point; - } + if (rob_bone_data->field_788.field_8C) + rctx_ptr->camera->get_view_point(rob_bone_data->field_788.field_B4); if (sub_140419F90(rob_chr->bone_data) || sub_140419F00(rob_bone_data)) v3 = &rob_bone_data->field_788.field_B4; @@ -10044,6 +8013,8 @@ static bool sub_14040AC40(vec3* a1, vec3* a2, float_t a3, vec3* a4) { static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t a4, float_t a5, float_t a6, float_t a7, vec3* a8, float_t a9) { vec3 v16; + vec3 v52; + vec3 v53; mat4_mult_vec3_inv(a3, a1, &v16); v16.x = 0.0f; @@ -10054,8 +8025,6 @@ static void sub_1403FA040(vec3* a1, float_t a2, mat4* a3, float_t a4, vec3_normalize(v16, v16); - vec3 v52; - vec3 v53; float_t v23; if (a7 - a6 >= a5 - a4) { v23 = (a5 - a4) * 0.5f; @@ -12382,7 +10351,7 @@ static void sub_140513B90(rob_chara_item_equip* rob_itm_equip, item_id id, objec rob_itm_equip->field_D4 = id; rob_chara_item_equip_load_object_info(rob_itm_equip, a3, id, false, bone_data, data, obj_db); if (id >= ITEM_BODY && id < ITEM_MAX) - rob_itm_equip->item_equip_object[id].disp = false; + rob_itm_equip->item_equip_object[id].can_disp = false; } static void sub_14052C560(rob_chara_item_cos_data* item_sub_data, @@ -12712,7 +10681,7 @@ static void rob_chara_item_cos_data_set_chara_index_item_nos( rob_chara_item_cos_data_set_item_nos(item_cos_data, items); } -static void rob_chara_item_cos_data_set_customize_item(rob_chara_item_cos_data* item_cos_data, int32_t item_no) { +static void rob_chara_item_cos_data_set_item(rob_chara_item_cos_data* item_cos_data, int32_t item_no) { if (!item_no) return; @@ -12721,13 +10690,13 @@ static void rob_chara_item_cos_data_set_customize_item(rob_chara_item_cos_data* item_cos_data->cos.arr[item->sub_id] = item_no; } -static void rob_chara_item_cos_data_set_customize_items(rob_chara_item_cos_data* item_cos_data, - rob_chara_pv_data_customize_items* customize_items) { +static void rob_chara_item_cos_data_set_item_array(rob_chara_item_cos_data* item_cos_data, + rob_chara_pv_data_item* item) { for (int32_t i = 0; i < 4; i++) - rob_chara_item_cos_data_set_customize_item(item_cos_data, customize_items->arr[i]); + rob_chara_item_cos_data_set_item(item_cos_data, item->arr[i]); } -static void rob_chara_item_cos_data_set_item( +static void rob_chara_item_cos_data_set_item_no( rob_chara_item_cos_data* item_cos_data, item_sub_id sub_id, int32_t item_no) { item_cos_data->cos.arr[sub_id] = item_no; } @@ -12735,7 +10704,7 @@ static void rob_chara_item_cos_data_set_item( static void rob_chara_item_cos_data_set_item_nos( rob_chara_item_cos_data* item_cos_data, int32_t* item_nos) { for (int32_t i = ITEM_SUB_ZUJO; i < ITEM_SUB_MAX; i++) - rob_chara_item_cos_data_set_item(item_cos_data, (item_sub_id)i, item_nos[i]); + rob_chara_item_cos_data_set_item_no(item_cos_data, (item_sub_id)i, item_nos[i]); } static void rob_chara_item_cos_data_texture_change_clear(rob_chara_item_cos_data* item_cos_data) { @@ -12834,8 +10803,7 @@ static void sub_140512C20(rob_chara_item_equip* rob_itm_equip, render_context* r name = "j_1_hyoutan_000wj"; bone_database* bone_data = &rctx->data->data_ft.bone_data; - bone_node* node = rob_chara_item_equip_object_get_bone_node_by_name( - &rob_itm_equip->item_equip_object[rob_itm_equip->field_D4], name, bone_data); + bone_node* node = rob_itm_equip->item_equip_object[rob_itm_equip->field_D4].get_bone_node(name, bone_data); if (!node || !node->mat) return; @@ -12854,8 +10822,7 @@ static void sub_140512C20(rob_chara_item_equip* rob_itm_equip, render_context* r static void rob_chara_item_equip_add_motion_reset_data(rob_chara_item_equip* rob_item_equip, int32_t motion_id, float_t frame, int32_t iterations) { for (int32_t i = rob_item_equip->first_item_equip_object; i < rob_item_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_add_motion_reset_data( - &rob_item_equip->item_equip_object[i], motion_id, frame, iterations); + rob_item_equip->item_equip_object[i].add_motion_reset_data(motion_id, frame, iterations); } static void rob_chara_item_equip_disp( @@ -12905,7 +10872,7 @@ static void rob_chara_item_equip_disp( if (rob_itm_equip->item_equip_range) for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_disp(&rob_itm_equip->item_equip_object[i], &mat, rctx); + rob_itm_equip->item_equip_object[i].disp(&mat, rctx); else { for (int32_t i = ITEM_ATAMA; i < ITEM_MAX; i++) { draw_task_flags v18 = (draw_task_flags)0; @@ -12924,7 +10891,7 @@ static void rob_chara_item_equip_disp( enum_and(v19, ~DRAW_TASK_SHADOW); object_data->set_draw_task_flags( (draw_task_flags)(v18 | v19 | DRAW_TASK_SSS)); - rob_chara_item_equip_object_disp(&rob_itm_equip->item_equip_object[i], &mat, rctx); + rob_itm_equip->item_equip_object[i].disp(&mat, rctx); } } object_data->set_texture_color_coeff(&v23); @@ -12947,8 +10914,7 @@ static void rob_chara_item_equip_get_parent_bone_nodes( rob_itm_equip->matrices = bone_nodes->mat; for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_get_parent_bone_nodes( - &rob_itm_equip->item_equip_object[i], rob_itm_equip->bone_nodes, bone_data); + rob_itm_equip->item_equip_object[i].get_parent_bone_nodes(rob_itm_equip->bone_nodes, bone_data); } static void rob_chara_item_equip_load_object_info( @@ -12957,539 +10923,12 @@ static void rob_chara_item_equip_load_object_info( if (id < ITEM_BODY || id > ITEM_ITEM16 || !rob_itm_equip->bone_nodes) return; - rob_chara_item_equip_object_load_object_info_ex_data( - &rob_itm_equip->item_equip_object[id], object_info, + rob_itm_equip->item_equip_object[id].load_object_info_ex_data(object_info, rob_itm_equip->bone_nodes, osage_reset, bone_data, data, obj_db); - rob_itm_equip->item_equip_object[id].disp = true; + rob_itm_equip->item_equip_object[id].can_disp = true; } -static void rob_chara_item_equip_object_add_motion_reset_data(rob_chara_item_equip_object* itm_eq_obj, - int32_t motion_id, float_t frame, int32_t osage_iterations) { - if (osage_iterations > 0) - rob_chara_item_equip_object_ctrl_iterate_nodes(itm_eq_obj, osage_iterations); - - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - i->AddMotionResetData(motion_id, frame); - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) - i->AddMotionResetData(motion_id, frame); -} - -static void rob_chara_item_equip_object_check_no_opd( - rob_chara_item_equip_object* itm_eq_obj, std::vector* opd_blend_data) { - itm_eq_obj->use_opd = true; - if (!itm_eq_obj->osage_blocks.size() && !itm_eq_obj->cloth_blocks.size() || !opd_blend_data->size()) - return; - - for (::opd_blend_data& i : *opd_blend_data) { - float_t* opd_data = 0; - uint32_t opd_count = 0; - osage_play_data_manager_get_opd_file_data(itm_eq_obj->obj_info, - i.motion_id, &opd_data, &opd_count); - if (!opd_data) { - itm_eq_obj->use_opd = false; - break; - } - } -} - -static void rob_chara_item_equip_object_clear_ex_data(rob_chara_item_equip_object* itm_eq_obj) { - for (ExNullBlock*& i : itm_eq_obj->null_blocks) { - i->Reset(); - delete i; - } - itm_eq_obj->null_blocks.clear(); - - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) { - i->Reset(); - delete i; - } - itm_eq_obj->osage_blocks.clear(); - - for (ExConstraintBlock*& i : itm_eq_obj->constraint_blocks) { - i->Reset(); - delete i; - } - itm_eq_obj->constraint_blocks.clear(); - - for (ExExpressionBlock*& i : itm_eq_obj->expression_blocks) { - i->Reset(); - delete i; - } - itm_eq_obj->expression_blocks.clear(); - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) { - i->Reset(); - delete i; - } - itm_eq_obj->cloth_blocks.clear(); - - itm_eq_obj->node_blocks.clear(); -} - -static void rob_chara_item_equip_object_disp( - rob_chara_item_equip_object* itm_eq_obj, mat4* mat, render_context* rctx) { - if (itm_eq_obj->obj_info.is_null()) - return; - - draw_task_flags v2 = rctx->object_data.get_draw_task_flags(); - draw_task_flags v4 = v2; - if (fabsf(itm_eq_obj->alpha - 1.0f) > 0.000001f) - enum_or(v4, itm_eq_obj->draw_task_flags); - else - enum_and(v4, ~(DRAW_TASK_40000 | DRAW_TASK_20000 | DRAW_TASK_10000)); - rctx->object_data.set_draw_task_flags(v4); - if (itm_eq_obj->disp) { - draw_task_add_draw_object_by_object_info_object_skin(rctx, - itm_eq_obj->obj_info, - &itm_eq_obj->texture_pattern, - &itm_eq_obj->texture_data, - itm_eq_obj->alpha, - itm_eq_obj->mats, - itm_eq_obj->ex_data_block_mats.data(), - itm_eq_obj->mat, - mat); - - for (ExNodeBlock*& i : itm_eq_obj->node_blocks) - i->Disp(); - } - rctx->object_data.set_draw_task_flags(v2); -} - -static int32_t rob_chara_item_equip_object_get_bone_index( - rob_chara_item_equip_object* itm_eq_obj, const char* name, bone_database* bone_data) { - int32_t bone_index = bone_data->get_skeleton_motion_bone_index( - bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), name); - if (bone_index == -1) - for (ex_data_name_bone_index& i : itm_eq_obj->ex_bones) - if (!str_utils_compare(name, i.name)) - return 0x8000 | i.bone_index; - return bone_index; -} - -static bone_node* rob_chara_item_equip_object_get_bone_node( - rob_chara_item_equip_object* itm_eq_obj, int32_t bone_index) { - if (~bone_index & 0x8000) - return &itm_eq_obj->bone_nodes[bone_index & 0x7FFF]; - else if ((bone_index & 0x7FFF) < itm_eq_obj->ex_data_bone_nodes.size()) - return &itm_eq_obj->ex_data_bone_nodes[bone_index & 0x7FFF]; - return 0; -} - -static bone_node* rob_chara_item_equip_object_get_bone_node_by_name( - rob_chara_item_equip_object* itm_eq_obj, const char* name, bone_database* bone_data) { - return rob_chara_item_equip_object_get_bone_node(itm_eq_obj, - rob_chara_item_equip_object_get_bone_index(itm_eq_obj, name, bone_data)); -} - -static void rob_chara_item_equip_object_get_parent_bone_nodes( - rob_chara_item_equip_object* itm_eq_obj, bone_node* bone_nodes, bone_database* bone_data) { - itm_eq_obj->bone_nodes = bone_nodes; - itm_eq_obj->mats = bone_nodes->mat; - for (ExNodeBlock*& i : itm_eq_obj->node_blocks) - i->parent_bone_node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, i->parent_name.c_str(), bone_data); -} - -static void rob_chara_item_equip_object_init_ex_data_bone_nodes( - rob_chara_item_equip_object* itm_eq_obj, obj_skin_ex_data* ex_data) { - itm_eq_obj->ex_data_bone_nodes.clear(); - itm_eq_obj->ex_data_mats.clear(); - itm_eq_obj->ex_data_block_mats.clear(); - - int32_t count = ex_data->bone_names_count; - itm_eq_obj->ex_data_bone_nodes.resize(count); - itm_eq_obj->ex_data_mats.resize(count); - itm_eq_obj->ex_data_block_mats.resize(count); - - bone_node* v4 = itm_eq_obj->ex_data_bone_nodes.data(); - mat4* v5 = itm_eq_obj->ex_data_mats.data(); - mat4* v8 = itm_eq_obj->ex_data_block_mats.data(); - for (int32_t v10 = 0; v10 < count; v10++) - v4[v10].mat = &v5[v10]; - - if (ex_data->bone_names) { - itm_eq_obj->ex_bones.clear(); - for (int32_t i = 0; i < count; i++) { - bone_node* node = &v4[i]; - node->name = ex_data->bone_names[i]; - node->mat = &v5[i]; - *node->mat = mat4_identity; - node->ex_data_mat = &v8[i]; - *node->ex_data_mat = mat4_identity; - - itm_eq_obj->ex_bones.push_back({ ex_data->bone_names[i], i}); - } - } -} - -static void rob_chara_item_equip_object_init_members(rob_chara_item_equip_object* itm_eq_obj, size_t index) { - itm_eq_obj->index = index; - itm_eq_obj->obj_info = object_info(); - itm_eq_obj->field_14 = -1; - itm_eq_obj->mats = 0; - itm_eq_obj->texture_pattern.clear(); - itm_eq_obj->texture_data.field_0 = -1; - itm_eq_obj->texture_data.texture_color_coeff = vec3_identity; - itm_eq_obj->texture_data.texture_color_offset = vec3_null; - itm_eq_obj->texture_data.texture_specular_coeff = vec3_identity; - itm_eq_obj->texture_data.texture_specular_offset = vec3_null; - itm_eq_obj->alpha = 1.0f; - itm_eq_obj->draw_task_flags = DRAW_TASK_10000; - itm_eq_obj->null_blocks_data_set = 0; - itm_eq_obj->disp = true; - itm_eq_obj->field_A4 = 0; - itm_eq_obj->mat = 0; - itm_eq_obj->bone_nodes = 0; - rob_chara_item_equip_object_clear_ex_data(itm_eq_obj); - itm_eq_obj->ex_data_bone_nodes.clear(); - itm_eq_obj->ex_data_mats.clear(); - itm_eq_obj->ex_data_block_mats.clear(); - itm_eq_obj->ex_bones.clear(); - itm_eq_obj->field_1B8 = 0; - itm_eq_obj->use_opd = false; - itm_eq_obj->field_1C0 = 0; -} - -static void rob_chara_item_equip_object_load_ex_data(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_ex_data* ex_data, bone_database* bone_data, void* data, object_database* obj_db) { - if (!ex_data->blocks) - return; - - std::vector> v129; - std::map v138; - rob_chara_item_equip_object_clear_ex_data(itm_eq_obj); - - size_t constraint_count = 0; - size_t expression_count = 0; - size_t osage_count = 0; - size_t cloth_count = 0; - size_t null_count = 0; - char** bone_names_ptr = ex_data->bone_names; - obj_skin_block* v4 = ex_data->blocks; - for (uint32_t i = 0; i < ex_data->blocks_count; i++, v4++) { - ExNodeBlock* node; - if (v4->type == OBJ_SKIN_BLOCK_CLOTH) { - if (cloth_count >= 0x08) - continue; - - ExClothBlock* cls = new ExClothBlock; - node = cls; - itm_eq_obj->cloth_blocks.push_back(cls); - cls->index = cloth_count + osage_count; - cloth_count++; - continue; - } - else if (v4->type == OBJ_SKIN_BLOCK_CONSTRAINT) { - if (constraint_count >= 0x40) - continue; - - ExConstraintBlock* cns = new ExConstraintBlock; - node = cns; - itm_eq_obj->constraint_blocks.push_back(cns); - cns->InitData(itm_eq_obj, &v4->constraint, - bone_names_ptr[v4->constraint.name_index & 0x7FFF], bone_data); - constraint_count++; - } - else if (v4->type == OBJ_SKIN_BLOCK_EXPRESSION) { - if (expression_count >= 0x50) - continue; - - ExExpressionBlock* exp = new ExExpressionBlock; - node = exp; - itm_eq_obj->expression_blocks.push_back(exp); - exp->InitData(itm_eq_obj, &v4->expression, - bone_names_ptr[v4->expression.name_index & 0x7FFF], - itm_eq_obj->obj_info, itm_eq_obj->index, bone_data); - expression_count++; - } - else if (v4->type == OBJ_SKIN_BLOCK_OSAGE) { - if (osage_count >= 0x100) - continue; - - ExOsageBlock* osg = new ExOsageBlock; - node = osg; - itm_eq_obj->osage_blocks.push_back(osg); - osg->InitData(itm_eq_obj, &v4->osage, - bone_names_ptr[v4->osage.external_name_index & 0x7FFF], - &itm_eq_obj->skin_ex_data->osage_nodes[v4->osage.start_index], - itm_eq_obj->bone_nodes, itm_eq_obj->ex_data_bone_nodes.data(), itm_eq_obj->skin); - osg->sub_1405F3E10(&v4->osage, - &itm_eq_obj->skin_ex_data->osage_nodes[v4->osage.start_index], &v129, &v138); - osg->index = osage_count; - osage_count++; - } - else { - if (null_count >= 0x4) - continue; - - ExNullBlock* null = new ExNullBlock; - node = null; - itm_eq_obj->null_blocks.push_back(null); - null->InitData(itm_eq_obj, &v4->constraint, - bone_names_ptr[v4->constraint.name_index & 0x7FFF], bone_data); - null_count++; - } - - obj_skin_block_node* v54 = &v4->base; - bone_node_expression_data exp_data; - exp_data.position = v54->position; - exp_data.rotation = v54->rotation; - exp_data.scale = v54->scale; - exp_data.parent_scale = vec3_identity; - node->parent_name = std::string(v54->parent_name); - - bone_node* parent_bone_node = rob_chara_item_equip_object_get_bone_node_by_name(itm_eq_obj, - v54->parent_name, bone_data); - node->parent_bone_node = parent_bone_node; - if (node->bone_node_ptr) { - node->bone_node_ptr->exp_data = exp_data; - node->bone_node_ptr->parent = parent_bone_node; - } - - auto v75 = v138.find(parent_bone_node->name); - if (v75 != v138.end()) - node->parent_node = v75->second; - - v138.insert({ node->name, node }); - itm_eq_obj->node_blocks.push_back(node); - } - - for (ExNodeBlock*& i : itm_eq_obj->node_blocks) { - ExNodeBlock* v86 = i->parent_node; - if (v86) { - v86->has_children_node = true; - if ((v86->type & ~3u) || v86->type == EX_OSAGE || !v86->field_58) - continue; - } - i->field_58 = true; - } - - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) { - ExOsageBlock* osg = i; - ExNodeBlock* parent_node = osg->parent_node; - bone_node* parent_bone_node = 0; - if (!parent_node || osg->field_58) - parent_bone_node = osg->parent_bone_node; - else { - while (!parent_node->field_58) { - parent_node = parent_node->parent_node; - if (!parent_node) - break; - } - - if (parent_node) - parent_bone_node = parent_node->parent_bone_node; - } - - if (parent_bone_node && parent_bone_node->ex_data_mat) { - osg->rob.parent_mat_ptr = parent_bone_node->ex_data_mat; - osg->rob.parent_mat = *parent_bone_node->ex_data_mat; - } - } - - if (ex_data->osage_sibling_infos) - for (uint32_t i = 0; i < ex_data->osage_sibling_infos_count; i++) { - obj_skin_osage_sibling_info* sibling_info = &ex_data->osage_sibling_infos[i]; - uint32_t name_index = sibling_info->name_index; - uint32_t sibling_name_index = sibling_info->sibling_name_index; - - auto node = v129.begin(); - for (; node != v129.end(); node++) - if (node->first == name_index) - break; - - auto sibling_node = v129.begin(); - for (; sibling_node != v129.end(); sibling_node++) - if (sibling_node->first == sibling_name_index) - break; - - if (node != v129.end() && sibling_node != v129.end()) { - rob_osage_node* v102 = node->second; - v102->sibling_node = sibling_node->second; - v102->max_distance = sibling_info->max_distance; - } - } - - if (osage_count || cloth_count) - rob_chara_item_equip_object_skp_load_file(itm_eq_obj, data, bone_data, obj_db); - - size_t v103 = 0; - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - v103 += i->rob.nodes.size() - 1; - //for (ExClothBlock*& i : itm_eq_obj->cloth_blocks.begin) - // v103 += i->rob.base.field_20.size() - i->rob.base.field_10; - itm_eq_obj->field_1C0 = v103; -} - -static void rob_chara_item_equip_object_load_object_info_ex_data( - rob_chara_item_equip_object* itm_eq_obj, object_info object_info, bone_node* bone_nodes, - bool osage_reset, bone_database* bone_data, void* data, object_database* obj_db) { - itm_eq_obj->obj_info = object_info; - itm_eq_obj->bone_nodes = bone_nodes; - itm_eq_obj->mats = bone_nodes->mat; - itm_eq_obj->ex_data_bone_nodes.clear(); - itm_eq_obj->ex_bones.clear(); - itm_eq_obj->ex_data_mats.clear(); - rob_chara_item_equip_object_clear_ex_data(itm_eq_obj); - obj_skin* skin = object_storage_get_obj_skin(itm_eq_obj->obj_info); - if (!skin || !skin->ex_data_init) - return; - - itm_eq_obj->skin = skin; - itm_eq_obj->skin_ex_data = &skin->ex_data; - rob_chara_item_equip_object_init_ex_data_bone_nodes(itm_eq_obj, &skin->ex_data); - rob_chara_item_equip_object_load_ex_data(itm_eq_obj, &skin->ex_data, bone_data, data, obj_db); - - if (osage_reset && itm_eq_obj->osage_blocks.size()) - itm_eq_obj->osage_iterations = 60; -} - -static void rob_chara_item_equip_object_set_alpha_draw_task_flags( - rob_chara_item_equip_object* itm_eq_obj, float_t alpha, draw_task_flags flags) { - itm_eq_obj->draw_task_flags = flags; - itm_eq_obj->alpha = clamp(alpha, 0.0f, 1.0f); -} - -static bool rob_chara_item_equip_object_set_boc(rob_chara_item_equip_object* itm_eq_obj, - skin_param_osage_root* skp_root, ExOsageBlock* osg) { - rob_osage* rob_osg = &osg->rob; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - i->data_ptr->boc.clear(); - - bool v6 = false; - for (skin_param_osage_root_boc& i : skp_root->boc) { - for (ExOsageBlock*& j : itm_eq_obj->osage_blocks) { - if (str_utils_compare(j->name, i.ed_root.c_str()) - || i.ed_node + 1ULL >= rob_osg->nodes.size() - || i.st_node + 1ULL >= j->rob.nodes.size()) - continue; - - rob_osage_node* v17 = rob_osage_get_node(rob_osg, i.ed_node + 1LL); - rob_osage_node* v18 = rob_osage_get_node(&j->rob, i.st_node + 1LL); - v17->data_ptr->boc.push_back(v18); - v6 = true; - break; - } - } - return v6; -} - -static void rob_chara_item_equip_object_set_collision_target_osage( - rob_chara_item_equip_object* itm_eq_obj, skin_param_osage_root* skp_root, skin_param* skp) { - if (!skp_root->colli_tgt_osg.size()) - return; - - const char* colli_tgt_osg = skp_root->colli_tgt_osg.c_str(); - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - if (!str_utils_compare(colli_tgt_osg, i->name)) { - skp->colli_tgt_osg = &i->rob.nodes; - break; - } -} - -static void rob_chara_item_equip_object_set_motion_reset_data( - rob_chara_item_equip_object* itm_eq_obj, int32_t motion_id, float_t frame) { - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - i->SetMotionResetData(motion_id, frame); - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) - i->SetMotionResetData(motion_id, frame); -} - -static void rob_chara_item_equip_object_set_motion_skin_param( - rob_chara_item_equip_object* itm_eq_obj, int8_t chara_id, int32_t motion_id, int32_t frame) { - if (itm_eq_obj->obj_info.is_null()) - return; - - struc_571** v7 = 0;//sub_14060B470(chara_id, itm_eq_obj->obj_info, motion_id, frame); - if (!v7) - return; - - struc_571* v9 = *v7; - itm_eq_obj->field_1B8 = 0; - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) { - itm_eq_obj->field_1B8 |= v9->field_88; - i->SetSkinParam(v9++); - } - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) { - itm_eq_obj->field_1B8 |= v9->field_88; - i->SetSkinParam(v9++); - } -} - -static void rob_chara_item_equip_object_set_null_blocks_expression_data( - rob_chara_item_equip_object* rob_itm_equip, vec3* position, vec3* rotation, vec3* scale) { - vec3 pos = *position; - vec3 rot; - vec3_mult_scalar(*rotation, DEG_TO_RAD_FLOAT, rot); - vec3 sc = *scale; - - rob_itm_equip->null_blocks_data_set = true; - for (ExNullBlock*& i : rob_itm_equip->null_blocks) { - if (!i || !i->bone_node_ptr) - continue; - - bone_node_expression_data* node_exp_data = &i->bone_node_ptr->exp_data; - node_exp_data->position = pos; - node_exp_data->rotation = rot; - node_exp_data->scale = sc; - } -} - -static void rob_chara_item_equip_object_set_osage_reset( - rob_chara_item_equip_object* itm_eq_obj) { - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - i->SetOsageReset(); - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) - i->SetOsageReset(); -} - -static void rob_chara_item_equip_object_set_osage_move_cancel( - rob_chara_item_equip_object* itm_eq_obj, float_t value) { - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) - i->rob.move_cancel = value; - //for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) - // i->rob.move_cancel = value; -} - -static void rob_chara_item_equip_object_set_texture_pattern( - rob_chara_item_equip_object* itm_eq_obj, texture_pattern_struct* tex_pat, size_t count) { - itm_eq_obj->texture_pattern.clear(); - if (count && tex_pat) - for (size_t i = 0; i < count; i++) - itm_eq_obj->texture_pattern.push_back(tex_pat[i]); -} - -static rob_osage_node* sub_1405FAB90(rob_chara_item_equip_object* a1, std::string* a2, size_t* a3) { - if (!a2->size()) - return 0; - - size_t v8 = a2->find(',', 0); - if (v8 == -1) - return 0; - - std::string v22 = a2->substr(0, v8); - std::string v23 = a2->substr(v8 + 1); - size_t v11 = atoi(v23.c_str()); - if (a3) - *a3 = v11; - - rob_osage_node* node = 0; - for (ExOsageBlock*& i : a1->osage_blocks) - if (!v22.compare(i->name)) { - if (v11 + 1 < i->rob.nodes.size()) - node = rob_osage_get_node(&i->rob, v11 + 1); - break; - } - return node; -} - -static bool sub_14053E690(rob_osage_node_data_normal_ref* normal_ref) { +static bool sub_14053E690(RobOsageNodeDataNormalRef* normal_ref) { normal_ref->field_0 = false; if (normal_ref->n == 0) return normal_ref->field_0; @@ -13520,121 +10959,6 @@ static bool sub_14053E690(rob_osage_node_data_normal_ref* normal_ref) { return normal_ref->field_0; } -static void sub_14053CAC0(rob_osage_node_data_normal_ref* normal_ref) { - if (!normal_ref->field_0) - return; - - vec3 n_trans; - vec3 u_trans; - vec3 d_trans; - vec3 l_trans; - vec3 r_trans; - mat4_get_translation(&normal_ref->n->mat, &n_trans); - mat4_get_translation(&normal_ref->u->mat, &u_trans); - mat4_get_translation(&normal_ref->d->mat, &d_trans); - mat4_get_translation(&normal_ref->l->mat, &l_trans); - mat4_get_translation(&normal_ref->r->mat, &r_trans); - - vec3 v21; - vec3 v22; - vec3 v23; - if (sub_14053D1B0(&l_trans, &r_trans, &u_trans, &d_trans, &v22, &v21, &v23)) { - mat4u mat; - mat.row0.x = v23.x; - mat.row0.y = v21.x; - mat.row0.z = v22.x; - mat.row0.w = 0.0f; - mat.row1.x = v23.y; - mat.row1.y = v21.y; - mat.row1.z = v22.y; - mat.row1.w = 0.0f; - mat.row2.x = v23.z; - mat.row2.y = v21.z; - mat.row2.z = v22.z; - mat.row2.w = 0.0f; - vec3_dot(n_trans, v23, mat.row3.x); - vec3_dot(n_trans, v21, mat.row3.y); - vec3_dot(n_trans, v22, mat.row3.z); - vec3_negate(*(vec3*)&mat.row3, *(vec3*)&mat.row3); - mat.row3.w = 1.0f; - mat4_mult(&normal_ref->n->mat, &mat, &normal_ref->mat); - } -} - -static bool sub_1405FAA30(rob_chara_item_equip_object* a1, - skin_param_osage_root* a2, std::vector* a3) { - if (!a2->normal_ref.size()) - return true; - - for (skin_param_osage_root_normal_ref& i : a2->normal_ref) { - size_t v12 = 0; - rob_osage_node* v8 = sub_1405FAB90(a1, &i.n, &v12); - if (!v8) - continue; - - rob_osage_node_data* v10; - if (a3) - v10 = &(*a3)[v12]; - else - v10 = v8->data_ptr; - - v10->normal_ref.n = v8; - v10->normal_ref.u = sub_1405FAB90(a1, &i.u, 0); - v10->normal_ref.d = sub_1405FAB90(a1, &i.d, 0); - v10->normal_ref.l = sub_1405FAB90(a1, &i.l, 0); - v10->normal_ref.r = sub_1405FAB90(a1, &i.r, 0); - sub_14053CAC0(&v10->normal_ref); - } - return true; -} - -static void rob_chara_item_equip_object_skp_load( - rob_chara_item_equip_object* itm_eq_obj, key_val* kv, bone_database* bone_data) { - if (kv->key.size() < 1) - return; - - itm_eq_obj->field_1B8 = 0; - for (ExOsageBlock*& i : itm_eq_obj->osage_blocks) { - ExOsageBlock* osg = i; - skin_param_osage_root root; - rob_osage_load_skin_param(&osg->rob, kv, osg->name, - &root, &itm_eq_obj->obj_info, bone_data); - rob_chara_item_equip_object_set_collision_target_osage(itm_eq_obj, &root, osg->rob.skin_param_ptr); - itm_eq_obj->field_1B8 |= rob_chara_item_equip_object_set_boc(itm_eq_obj, &root, osg); - itm_eq_obj->field_1B8 |= root.coli_type != 0; - itm_eq_obj->field_1B8 |= sub_1405FAA30(itm_eq_obj, &root, 0); - } - - for (ExClothBlock*& i : itm_eq_obj->cloth_blocks) { - ExClothBlock* cls = i; - skin_param_osage_root root; - skin_param_osage_root_parse(kv, cls->name, &root, bone_data); - //rob_cloth_load_skin_param(&cls->rob, &root); - } -} - -static void rob_chara_item_equip_object_skp_load_file( - rob_chara_item_equip_object* itm_eq_obj, void* data, - bone_database* bone_data, object_database* obj_db) { - key_val* kv_ptr = 0;//sub_14060B4B0(itm_eq_obj->object_info); - if (kv_ptr) { - rob_chara_item_equip_object_skp_load(itm_eq_obj, kv_ptr, bone_data); - return; - } - - char buf[0x200]; - const char* name = obj_db->get_object_name(itm_eq_obj->obj_info); - sprintf_s(buf, sizeof(buf), "ext_skp_%s.txt", name); - - for (int32_t i = 0; buf[i]; i++) - if (buf[i] > 0x40 && buf[i] < 0x5B) - buf[i] += 0x20; - - key_val kv; - ((data_struct*)data)->load_file(&kv, "rom/skin_param/", buf, key_val::load_file); - rob_chara_item_equip_object_skp_load(itm_eq_obj, &kv, bone_data); -} - static void rob_chara_item_equip_reset_init_data(rob_chara_item_equip* rob_itm_equip, bone_node* bone_nodes) { rob_itm_equip->reset(); @@ -13644,7 +10968,7 @@ static void rob_chara_item_equip_reset_init_data(rob_chara_item_equip* rob_itm_e mat4u* v7 = rob_itm_equip->field_13C; int32_t* v8 = rob_itm_equip->field_18; for (int32_t v6 = ITEM_BODY; v6 < ITEM_MAX; v6++) { - rob_chara_item_equip_object_init_members(&rob_itm_equip->item_equip_object[v6], v6); + rob_itm_equip->item_equip_object[v6].init_members(v6); *v8++ = 0; *v7++ = mat4u_identity; } @@ -13662,12 +10986,10 @@ static void rob_chara_item_equip_set_alpha_draw_task_flags( if (rob_itm_equip->item_equip_range) for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_set_alpha_draw_task_flags( - &rob_itm_equip->item_equip_object[i], alpha, flags); + rob_itm_equip->item_equip_object[i].set_alpha_draw_task_flags(alpha, flags); else for (int32_t i = ITEM_ATAMA; i < ITEM_MAX; i++) - rob_chara_item_equip_object_set_alpha_draw_task_flags( - &rob_itm_equip->item_equip_object[i], alpha, flags); + rob_itm_equip->item_equip_object[i].set_alpha_draw_task_flags(alpha, flags); } static void rob_chara_item_equip_set_item_equip_range(rob_chara_item_equip* rob_itm_equip, bool value) { @@ -13685,7 +11007,7 @@ static void rob_chara_item_equip_set_item_equip_range(rob_chara_item_equip* rob_ static void rob_chara_item_equip_set_motion_reset_data( rob_chara_item_equip* rob_itm_equip, int32_t motion_id, float_t frame) { for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_set_motion_reset_data(&rob_itm_equip->item_equip_object[i], motion_id, frame); + rob_itm_equip->item_equip_object[i].set_motion_reset_data(motion_id, frame); task_wind.ptr->reset(); } @@ -13693,22 +11015,18 @@ static void rob_chara_item_equip_set_motion_reset_data( static void rob_chara_item_equip_set_motion_skin_param( rob_chara_item_equip* rob_itm_equip, int8_t chara_id, int32_t motion_id, int32_t frame) { for (int32_t i = ITEM_KAMI; i < ITEM_ITEM16; i++) - rob_chara_item_equip_object_set_motion_skin_param(&rob_itm_equip->item_equip_object[i], chara_id, motion_id, frame); + rob_itm_equip->item_equip_object[i].set_motion_skin_param(chara_id, motion_id, frame); } static void rob_chara_item_equip_set_null_blocks_expression_data( rob_chara_item_equip* rob_itm_equip, item_id id, vec3* position, vec3* rotation, vec3* scale) { - rob_chara_item_equip_object_set_null_blocks_expression_data( - &rob_itm_equip->item_equip_object[id], - position, - rotation, - scale); + rob_itm_equip->item_equip_object[id].set_null_blocks_expression_data( + position, rotation, scale); } static void rob_chara_item_equip_set_object_texture_pattern(rob_chara_item_equip* rob_itm_equip, item_id id, texture_pattern_struct* tex_pat, size_t count) { - rob_chara_item_equip_object_set_texture_pattern( - &rob_itm_equip->item_equip_object[id], tex_pat, count); + rob_itm_equip->item_equip_object[id].set_texture_pattern(tex_pat, count); } static void rob_chara_item_equip_set_opd_blend_data( @@ -13742,12 +11060,12 @@ static void rob_chara_item_equip_set_opd_blend_data( if (rob_itm_equip->use_opd) for (int32_t i = ITEM_KAMI; i < ITEM_MAX; i++) - rob_chara_item_equip_object_check_no_opd(&rob_itm_equip->item_equip_object[i], &rob_itm_equip->opd_blend_data); + rob_itm_equip->item_equip_object[i].check_no_opd(rob_itm_equip->opd_blend_data); } static void rob_chara_item_equip_set_osage_reset(rob_chara_item_equip* rob_itm_equip) { for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; i++) - rob_chara_item_equip_object_set_osage_reset(&rob_itm_equip->item_equip_object[i]); + rob_itm_equip->item_equip_object[i].set_osage_reset(); task_wind.ptr->reset(); } @@ -13756,11 +11074,11 @@ static void rob_chara_item_equip_set_osage_move_cancel(rob_chara_item_equip* rob uint8_t id, float_t value) { if (id == 0) for (int32_t i = rob_itm_equip->first_item_equip_object; i < rob_itm_equip->max_item_equip_object; ++i) - rob_chara_item_equip_object_set_osage_move_cancel(&rob_itm_equip->item_equip_object[i], value); + rob_itm_equip->item_equip_object[i].set_osage_move_cancel(value); else if (id == 1) - rob_chara_item_equip_object_set_osage_move_cancel(&rob_itm_equip->item_equip_object[ITEM_KAMI], value); + rob_itm_equip->item_equip_object[ITEM_KAMI].set_osage_move_cancel(value); else if (id == 2) - rob_chara_item_equip_object_set_osage_move_cancel(&rob_itm_equip->item_equip_object[ITEM_OUTER], value); + rob_itm_equip->item_equip_object[ITEM_OUTER].set_osage_move_cancel(value); } static void rob_chara_item_equip_set_osage_step(rob_chara_item_equip* rob_itm_equip, float_t value) { @@ -13922,7 +11240,7 @@ static void rob_chara_set_pv_data(rob_chara* rob_chr, int8_t chara_id, if (cos_data) rob_chara_item_cos_data_set_chara_index_item_nos(&rob_chr->item_cos_data, chara_index, cos_data->arr); } - rob_chara_item_cos_data_set_customize_items(&rob_chr->item_cos_data, &pv_data->customize_items); + rob_chara_item_cos_data_set_item_array(&rob_chr->item_cos_data, &pv_data->item); } static void rob_cmn_mottbl_read(void* a1, const void* data, size_t size) { @@ -13971,418 +11289,6 @@ static rob_manager_rob_impl* rob_manager_rob_impls2_get(TaskRobManager* rob_mgr) return rob_manager_rob_impls2; } -static rob_osage_node* rob_osage_get_node(rob_osage* rob_osg, - size_t index) { - if (index < rob_osg->nodes.size()) - return &rob_osg->nodes[index]; - else - return &rob_osg->node; -} - -static float_t* rob_osage_load_opd_data(rob_osage* rob_osg, - size_t node_index, float_t* opd_data, size_t opd_count) { - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - if (node_index >= i->opd_data.size()) - i->opd_data.resize(node_index + 1); - - opd_vec3_data* opd = &i->opd_data[node_index]; - opd->x = opd_data; - opd_data += opd_count; - opd->y = opd_data; - opd_data += opd_count; - opd->z = opd_data; - opd_data += opd_count; - } - return opd_data; -} - -static void rob_osage_load_skin_param(rob_osage* rob_osg, key_val* kv, const char* name, - skin_param_osage_root* skp_root, object_info* obj_info, bone_database* bone_data) { - rob_osg->skin_param_ptr = &rob_osg->skin_param; - for (rob_osage_node& i : rob_osg->nodes) - i.data_ptr = &i.data; - - skin_param_osage_root_parse(kv, name, skp_root, bone_data); - rob_osage_set_skin_param_osage_root(rob_osg, skp_root); - - const osage_setting_osg_cat* osage_setting = osage_setting_data_get_cat_value(obj_info, name); - if (osage_setting) - rob_osg->osage_setting = *osage_setting; - - std::vector vec; - vec.resize(rob_osg->nodes.size() - 1); - skin_param_osage_node_parse(kv, name, &vec, skp_root); - rob_osage_set_skp_osg_nodes(rob_osg, &vec); -} - -static void rob_osage_set_air_res(rob_osage* rob_osg, float_t air_res) { - rob_osg->skin_param_ptr->air_res = air_res; -} - -static void rob_osage_coli_set(rob_osage* rob_osg, mat4* mats) { - if (rob_osg->skin_param_ptr->coli.size()) - osage_coli_set(rob_osg->coli, rob_osg->skin_param_ptr->coli.data(), mats); - osage_coli_ring_set(rob_osg->coli_ring, &rob_osg->ring.skp_root_coli, mats); -} - -static void rob_osage_set_coli_r(rob_osage* rob_osg, float_t coli_r) { - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - i->data_ptr->skp_osg_node.coli_r = coli_r; -} - -static void rob_osage_set_force(rob_osage* rob_osg, float_t force, float_t force_gain) { - rob_osg->skin_param_ptr->force = force; - rob_osg->skin_param_ptr->force_gain = force_gain; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - i->data_ptr->force = force; - force = force * force_gain; - } -} - -static void rob_osage_set_hinge(rob_osage* rob_osg, float_t hinge_y, float_t hinge_z) { - hinge_y = min(hinge_y, 179.0f); - hinge_z = min(hinge_z, 179.0f); - hinge_y = hinge_y * DEG_TO_RAD_FLOAT; - hinge_z = hinge_z * DEG_TO_RAD_FLOAT; - rob_osage_node* i_begin = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) { - rob_osage_node_data* data = i->data_ptr; - data->skp_osg_node.hinge.ymin = -hinge_y; - data->skp_osg_node.hinge.ymax = hinge_y; - data->skp_osg_node.hinge.zmin = -hinge_z; - data->skp_osg_node.hinge.zmax = hinge_z; - } -} - -static void rob_osage_set_init_rot(rob_osage* rob_osg, float_t init_rot_y, float_t init_rot_z) { - rob_osg->skin_param_ptr->init_rot.y = init_rot_y * DEG_TO_RAD_FLOAT; - rob_osg->skin_param_ptr->init_rot.z = init_rot_z * DEG_TO_RAD_FLOAT; -} - -static void rob_osage_set_motion_reset_data(rob_osage* rob_osg, int32_t motion_id, float_t frame) { - rob_osg->osage_reset = true; - auto v6 = rob_osg->motion_reset_data.find({ motion_id, (int32_t)roundf(frame * 1000.0f) }); - if (v6 != rob_osg->motion_reset_data.end() && v6->second.size() + 1 == rob_osg->nodes.size()) - rob_osg->reset_data_list = &v6->second; -} - -static void rob_osage_set_rot(rob_osage* rob_osg, float_t rot_y, float_t rot_z) { - rob_osg->skin_param_ptr->rot.y = rot_y * DEG_TO_RAD_FLOAT; - rob_osg->skin_param_ptr->rot.z = rot_z * DEG_TO_RAD_FLOAT; -} - -static void rob_osage_set_skin_param_osage_root(rob_osage* rob_osg, skin_param_osage_root* skp_root) { - rob_osg->skin_param_ptr->reset(); - rob_osage_set_force(rob_osg, skp_root->force, skp_root->force_gain); - rob_osage_set_air_res(rob_osg, skp_root->air_res); - rob_osage_set_rot(rob_osg, skp_root->rot_y, skp_root->rot_z); - rob_osage_set_init_rot(rob_osg, skp_root->init_rot_y, skp_root->init_rot_z); - rob_osage_set_yz_order(rob_osg, skp_root->yz_order); - rob_osg->skin_param_ptr->friction = skp_root->friction; - rob_osg->skin_param_ptr->wind_afc = skp_root->wind_afc; - rob_osage_set_coli_r(rob_osg, skp_root->coli_r); - rob_osage_set_hinge(rob_osg, skp_root->hinge_y, skp_root->hinge_z); - rob_osg->skin_param_ptr->coli = skp_root->coli; - rob_osg->skin_param_ptr->coli_type = skp_root->coli_type; - rob_osg->skin_param_ptr->stiffness = skp_root->stiffness; - rob_osg->skin_param_ptr->move_cancel = skp_root->move_cancel; -} - -static void rob_osage_set_skp_osg_nodes(rob_osage* rob_osg, - std::vector* skp_osg_nodes) { - if (!skp_osg_nodes) - return; - - if (rob_osg->nodes.size() - 1 != skp_osg_nodes->size()) - return; - - rob_osage_node* i = rob_osg->nodes.data() + 1; - rob_osage_node* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); - skin_param_osage_node* j = skp_osg_nodes->data(); - skin_param_osage_node* j_end = skp_osg_nodes->data() + skp_osg_nodes->size(); - while (i != i_end && j != j_end) { - i->data_ptr->skp_osg_node = *j++; - i->data_ptr->skp_osg_node.hinge.limit(); - i++; - } -} - -static void rob_osage_set_yz_order(rob_osage* rob_osg, int32_t yz_order) { - rob_osg->yz_order = yz_order; -} - -static void rob_osage_free(rob_osage* rob_osg) { - rob_osg->reset(); -} - -static void skin_param_osage_node_parse(key_val* kv, const char* name, - std::vector* vec, skin_param_osage_root* skp_root) { - if (!kv->open_scope(name)) - return; - - if (!kv->open_scope("node")) { - kv->close_scope(); - return; - } - - int32_t count; - if (kv->read("length", count)) { - size_t c = vec->size(); - if (c < count) - vec->resize(count); - } - else - vec->clear(); - - int32_t j = 0; - for (auto i = vec->begin(); i != vec->end(); i++, j++) { - if (!kv->open_scope(j)) - continue; - - *i = skin_param_osage_node(); - - float_t coli_r = 0.0f; - if (kv->read("coli_r", coli_r)) - i->coli_r = coli_r; - - float_t weight = 0.0f; - if (kv->read("weight", weight)) - i->weight = weight; - - float_t inertial_cancel = 0.0f; - if (kv->read("inertial_cancel", inertial_cancel)) - i->inertial_cancel = inertial_cancel; - - i->hinge.ymin = -skp_root->hinge_y; - i->hinge.ymax = skp_root->hinge_y; - i->hinge.zmin = -skp_root->hinge_z; - i->hinge.zmax = skp_root->hinge_z; - - float_t hinge_ymax = 0.0f; - if (kv->read("hinge_ymax", hinge_ymax)) - i->hinge.ymax = hinge_ymax; - - float_t hinge_ymin = 0.0f; - if (kv->read("hinge_ymin", hinge_ymin)) - i->hinge.ymin = hinge_ymin; - - float_t hinge_zmax = 0.0f; - if (kv->read("hinge_zmax", hinge_zmax)) - i->hinge.zmax = hinge_zmax; - - float_t hinge_zmin = 0.0f; - if (kv->read("hinge_zmin", hinge_zmin)) - i->hinge.zmin = hinge_zmin; - kv->close_scope(); - } - - kv->close_scope(); - kv->close_scope(); -} - -static void skin_param_osage_root_parse(key_val* kv, const char* name, - skin_param_osage_root* skp_root, bone_database* bone_data) { - if (!kv->open_scope(name)) - return; - - int32_t node_length = 0; - kv->read("node.length", node_length); - - if (!kv->open_scope("root")) { - kv->close_scope(); - return; - } - - float_t force = 0.0f; - float_t force_gain = 0.0f; - if (kv->read("force", force) - && kv->read("force_gain", force_gain)) { - skp_root->force = force; - skp_root->force_gain = force_gain; - } - - float_t air_res = 0.0f; - if (kv->read("air_res", air_res)) - skp_root->air_res = min(air_res, 0.9f); - - float_t rot_y = 0.0f; - float_t rot_z = 0.0f; - if (kv->read("rot_y", rot_y) - && kv->read("rot_z", rot_z)) { - skp_root->rot_y = rot_y; - skp_root->rot_z = rot_z; - } - - float_t friction = 0.0f; - if (kv->read("friction", friction)) - skp_root->friction = friction; - - float_t wind_afc = 0; - if (kv->read("wind_afc", wind_afc)) { - skp_root->wind_afc = wind_afc; - if (!str_utils_compare_length(name, utf8_length(name), "c_opa", 5)) - skp_root->wind_afc = 0.0f; - } - - int32_t coli_type = 0; - if (kv->read("coli_type", coli_type)) - skp_root->coli_type = coli_type; - - float_t init_rot_y = 0.0f; - float_t init_rot_z = 0.0f; - if (kv->read("init_rot_y", init_rot_y) - && kv->read("init_rot_z", init_rot_z)) { - skp_root->init_rot_y = init_rot_y; - skp_root->init_rot_z = init_rot_z; - } - - float_t hinge_y = 0.0f; - float_t hinge_z = 0.0f; - if (kv->read("hinge_y", hinge_y) - && kv->read("hinge_z", hinge_z)) { - skp_root->hinge_y = hinge_y; - skp_root->hinge_z = hinge_z; - } - - float_t coli_r = 0.0f; - if (kv->read("coli_r", coli_r)) - skp_root->coli_r = coli_r; - - float_t stiffness = 0.0f; - if (kv->read("stiffness", stiffness)) - skp_root->stiffness = stiffness; - - float_t move_cancel = 0.0f; - if (kv->read("move_cancel", move_cancel)) - skp_root->move_cancel = move_cancel; - - int32_t count; - if (kv->read("coli", "length", count)) { - std::vector& vc = skp_root->coli; - for (int32_t i = 0; i < count; i++) { - if (!kv->open_scope(i)) - continue; - - skin_param_osage_root_coli* c = &vc[i]; - - int32_t type = 0; - if (!kv->read("type", type)) { - kv->close_scope(); - break; - } - c->type = (skin_param_osage_root_coli_type)type; - - float_t radius = 0; - if (!kv->read("radius", radius)) { - kv->close_scope(); - break; - } - c->radius = radius; - - const char* bone0_name; - if (!kv->read("bone.0.name", bone0_name)) { - kv->close_scope(); - break; - } - - c->bone0_index = bone_data->get_skeleton_object_bone_index( - bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone0_name); - - vec3 bone0_pos = vec3_null; - if (!kv->read("bone.0.posx", bone0_pos.x) - || !kv->read("bone.0.posy", bone0_pos.y) - || !kv->read("bone.0.posz", bone0_pos.z)) { - kv->close_scope(); - break; - } - - c->bone0_pos = bone0_pos; - - const char* bone1_name; - if (kv->read("bone.1.name", bone1_name)) { - c->bone1_index = bone_data->get_skeleton_object_bone_index( - bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), bone1_name); - - vec3 bone1_pos = vec3_null; - if (!kv->read("bone.1.posx", bone1_pos.x) - || !kv->read("bone.1.posy", bone1_pos.y) - || !kv->read("bone.1.posz", bone1_pos.z)) { - kv->close_scope(); - break; - } - - c->bone1_pos = bone1_pos; - } - kv->close_scope(); - } - kv->close_scope(); - } - - if (kv->read("boc", "length", count)) { - std::vector* vb = &skp_root->boc; - - vb->resize(count); - for (int32_t i = 0; i < count; i++) { - if (!kv->open_scope(i)) - continue; - - int32_t st_node = 0; - std::string ed_root; - int32_t ed_node = 0; - if (kv->read("st_node", st_node) - && st_node < node_length - && kv->read("ed_root", ed_root) - && kv->read("ed_node", ed_node) - && ed_node < node_length) { - skin_param_osage_root_boc b; - b.st_node = st_node; - b.ed_root = ed_root; - b.ed_node = ed_node; - vb->push_back(b); - } - kv->close_scope(); - } - kv->close_scope(); - } - - std::string colli_tgt_osg; - if (kv->read("colli_tgt_osg", colli_tgt_osg)) - skp_root->colli_tgt_osg = colli_tgt_osg; - - if (kv->read("normal_ref", "length", count)) { - std::vector* vnr = &skp_root->normal_ref; - - vnr->resize(count); - for (int32_t i = 0; i < count; i++) { - if (!kv->open_scope(i)) - continue; - - std::string n; - if (kv->read("N", n)) { - skin_param_osage_root_normal_ref nr; - nr.n = n; - kv->read("U", nr.u); - kv->read("D", nr.d); - kv->read("L", nr.l); - kv->read("R", nr.r); - vnr->push_back(nr); - } - kv->close_scope(); - } - kv->close_scope(); - } - - kv->close_scope(); - kv->close_scope(); -} - static bool task_rob_load_check_load_req_data() { if (task_rob_load.field_F0 == 2 && !task_rob_load.load_req_data_obj.size()) return !!task_rob_load.load_req_data.size(); @@ -14506,10 +11412,79 @@ bone_node_expression_data::bone_node_expression_data() { parent_scale = vec3_identity; } +void bone_node_expression_data::mat_set(vec3& parent_scale, mat4& ex_data_mat, mat4& mat) { + vec3 position; + vec3_mult(this->position, parent_scale, position); + mat4_translate_mult(&ex_data_mat, position.x, position.y, position.z, &ex_data_mat); + mat4_rotate_mult(&ex_data_mat, rotation.x, rotation.y, rotation.z, &ex_data_mat); + vec3_mult(scale, parent_scale, this->parent_scale); + mat = ex_data_mat; + mat4_scale_rot(&mat, this->parent_scale.x, this->parent_scale.y, this->parent_scale.z, &mat); +} + +void bone_node_expression_data::reset_scale() { + scale = vec3_identity; + parent_scale = vec3_identity; +} + +void bone_node_expression_data::set_position_rotation( + float_t position_x, float_t position_y, float_t position_z, + float_t rotation_x, float_t rotation_y, float_t rotation_z) { + position.x = position_x; + position.y = position_y; + position.z = position_z; + rotation.x = rotation_x; + rotation.z = rotation_z; + rotation.y = rotation_y; + scale = vec3_identity; + parent_scale = vec3_identity; +} + +void bone_node_expression_data::set_position_rotation(vec3& position, vec3& rotation) { + this->position = position; + this->rotation = rotation; + scale = vec3_identity; + parent_scale = vec3_identity; +} + bone_node::bone_node() : name(), mat(), parent(), ex_data_mat() { } +float_t* bone_node::get_exp_data_component(size_t index, ex_expression_block_stack_type& type) { + switch (index) { + case 0: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.position.x; + case 1: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.position.y; + case 2: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.position.z; + case 3: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; + return &exp_data.rotation.x; + case 4: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; + return &exp_data.rotation.y; + case 5: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN; + return &exp_data.rotation.z; + case 6: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.scale.x; + case 7: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.scale.y; + case 8: + type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; + return &exp_data.scale.z; + default: + return 0; + } +} + mot_key_data::mot_key_data() : key_sets_ready(), key_set_count(), key_set(), mot(), key_set_data(), mot_data(), skeleton_type(), skeleton_select(), field_68() { motion_id = -1; @@ -15099,7 +12074,7 @@ rob_chara_pv_data::rob_chara_pv_data() { motion_face_ids[9] = -1; chara_size_index = 1; height_adjust = false; - customize_items = {}; + item = {}; eyes_adjust.base_adjust = EYES_BASE_ADJUST_DIRECTION; eyes_adjust.neg = -1.0f; eyes_adjust.pos = -1.0f; @@ -15109,1146 +12084,588 @@ rob_chara_pv_data::~rob_chara_pv_data() { } -ExNodeBlock::ExNodeBlock() : bone_node_ptr(), type(), name(), parent_bone_node(), -parent_name(), parent_node(), item_equip_object(), field_58(), field_59(), has_children_node() { - -} - -ExNodeBlock::~ExNodeBlock() { - -} - -void ExNodeBlock::Field_10() { - field_59 = false; -} - -void ExNodeBlock::Reset() { - bone_node_ptr = 0; -} - -void ExNodeBlock::Field_58() { - field_59 = false; -} - -void ExNodeBlock::InitData(bone_node* bone_node, ex_node_type type, - const char* name, rob_chara_item_equip_object* itm_eq_obj) { - bone_node_ptr = bone_node; - this->type = type; - if (name) - this->name = name; - else - this->name = "(null)"; - parent_bone_node = 0; - item_equip_object = itm_eq_obj; -} - -ExNullBlock::ExNullBlock() { - Init(); -} - -ExNullBlock::~ExNullBlock() { - -} - -void ExNullBlock::Init() { - bone_node_ptr = 0; - type = EX_NONE; - name = 0; - parent_bone_node = 0; - item_equip_object = 0; - cns_data = 0; -} - -void ExNullBlock::Field_10() { - field_59 = false; -} - -void ExNullBlock::Field_18(int32_t stage, bool a3) { - -} - -void ExNullBlock::Field_20() { - if (!bone_node_ptr) - return; - - mat4 mat; - mat4 ex_data_mat = *parent_bone_node->ex_data_mat; - bone_node_expression_data_mat_set(&bone_node_ptr->exp_data, - &parent_bone_node->exp_data.parent_scale, &ex_data_mat, &mat); - *bone_node_ptr->ex_data_mat = ex_data_mat; - *bone_node_ptr->mat = mat; -} - -void ExNullBlock::SetOsagePlayData() { - Field_20(); -} - -void ExNullBlock::Disp() { - -} - -void ExNullBlock::Reset() { - bone_node_ptr = 0; -} - -void ExNullBlock::Field_40() { - -} - -void ExNullBlock::Field_48() { - Field_20(); -} - -void ExNullBlock::Field_50() { - -} - -void ExNullBlock::Field_58() { - field_59 = false; -} - -void ExNullBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_block_constraint* cns_data, const char* cns_data_name, bone_database* bone_data) { - bone_node* node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, cns_data_name, bone_data); - type = EX_NONE; - bone_node_ptr = node; - this->cns_data = cns_data; - name = node->name; - item_equip_object = itm_eq_obj; -} - -ExConstraintBlock::ExConstraintBlock() : constraint_type(), -source_node_bone_node(), direction_up_vector_bone_node(), cns_data() { - Init(); -} - -ExConstraintBlock::~ExConstraintBlock() { - -} - -void ExConstraintBlock::Init() { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_NONE; - source_node_bone_node = 0; - direction_up_vector_bone_node = 0; - cns_data = 0; - field_80 = 0; -} - -void ExConstraintBlock::Field_10() { - if (bone_node_ptr) { - bone_node_expression_data* node_exp_data = &bone_node_ptr->exp_data; - node_exp_data->position = cns_data->base.position; - node_exp_data->rotation = cns_data->base.rotation; - node_exp_data->scale = cns_data->base.scale; - } - field_59 = false; -} - -void ExConstraintBlock::Field_18(int32_t stage, bool a3) { - if (field_59) - return; - - if (stage == 0) { - if (field_58) - Field_20(); - } - else if (stage == 2) { - if (has_children_node) - DataSet(); - } - else if (stage == 5) - Field_20(); -} - -void ExConstraintBlock::Field_20() { - if (!parent_bone_node) - return; - - if (field_59) { - field_59 = false; - return; - } - - Calc(); - DataSet(); - field_59 = true; -} - -void ExConstraintBlock::SetOsagePlayData() { - Field_20(); -} - -void ExConstraintBlock::Disp() { - -} - -void ExConstraintBlock::Reset() { - bone_node_ptr = 0; -} - -void ExConstraintBlock::Field_40() { - -} - -void ExConstraintBlock::Field_48() { - Field_20(); -} - -void ExConstraintBlock::Field_50() { - Field_20(); -} - -void ExConstraintBlock::Field_58() { - field_59 = false; -} - -void ExConstraintBlock::Calc() { - bone_node* node = bone_node_ptr; - if (!node) - return; - - vec3 pos; - vec3_mult(parent_bone_node->exp_data.parent_scale, node->exp_data.position, pos); - - mat4 mat; - mat4_translate_mult(parent_bone_node->ex_data_mat, pos.x, pos.y, pos.z, &mat); - - switch (constraint_type) { - case OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION: { - vec3 trans; - mat4_get_translation(&mat, &trans); - - mat3 rot; - mat3_from_mat4(source_node_bone_node->mat, &rot); - mat3_normalize_rotation(&rot, &rot); - - vec3 offset = cns_data->orientation.offset; - mat3_rotate_mult(&rot, offset.x, offset.y, offset.z, &rot); - - mat4_from_mat3(&rot, node->mat); - mat4_set_translation(node->mat, &trans); - } break; - case OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION: { - vec3 align_axis = cns_data->direction.align_axis; - vec3 target_offset = cns_data->direction.target_offset; - mat4_mult_vec3_trans(source_node_bone_node->mat, &target_offset, &target_offset); - mat4_mult_vec3_inv_trans(&mat, &target_offset, &target_offset); - float_t target_offset_length; - vec3_length_squared(target_offset, target_offset_length); - if (target_offset_length <= 0.000001f) - break; - - mat4 v59; - sub_1401EB410(&v59, &align_axis, &target_offset); - if (direction_up_vector_bone_node) { - vec3 affected_axis = cns_data->direction.up_vector.affected_axis; - mat4 v56; - mat4_mult(&v59, &mat, &v56); - mat4_mult_vec3(&v56, &affected_axis, &affected_axis); - mat4* v20 = direction_up_vector_bone_node->mat; - - vec3 v23; - vec3 v24; - mat4_get_translation(v20, &v23); - mat4_get_translation(&v56, &v24); - vec3_sub(v23, v24, v23); - - vec3 v50; - mat4_mult_vec3(&mat, &target_offset, &v50); - - vec3 v25; - vec3 v29; - vec3_cross(v50, affected_axis, v25); - vec3_cross(v50, v23, v29); - vec3_normalize(v25, v25); - vec3_normalize(v29, v29); - - vec3 v35; - vec3_cross(v25, v29, v35); - - float_t v39; - float_t v36; - vec3_dot(v29, v25, v39); - vec3_dot(v35, v50, v36); - - float_t v40; - vec3_length(v35, v40); - if (v36 >= 0.0f) - v40 = -v40; - - sub_1405F10D0(&v56, &target_offset, v39, v40); - mat4_mult(&v59, &v56, &v59); - } - mat4_mult(&v59, &mat, node->mat); - } break; - case OBJ_SKIN_BLOCK_CONSTRAINT_POSITION: { - vec3 constraining_offset = cns_data->position.constraining_object.offset; - vec3 constrained_offset = cns_data->position.constrained_object.offset; - if (cns_data->position.constraining_object.affected_by_orientation) - mat4_mult_vec3(source_node_bone_node->mat, &constraining_offset, &constraining_offset); - - vec3 source_node_trans; - mat4_get_translation(source_node_bone_node->mat, &source_node_trans); - vec3_add(constraining_offset, source_node_trans, source_node_trans); - mat4_set_translation(&mat, &source_node_trans); - if (direction_up_vector_bone_node) { - vec3 up_vector_trans; - mat4_get_translation(direction_up_vector_bone_node->mat, &up_vector_trans); - mat4_mult_vec3_inv_trans(&mat, &up_vector_trans, &up_vector_trans); - - mat4 v26; - sub_1401EB410(&v26, &cns_data->position.up_vector.affected_axis, &up_vector_trans); - mat4_mult(&v26, &mat, &mat); - } - if (cns_data->position.constrained_object.affected_by_orientation) - mat4_mult_vec3(&mat, &constrained_offset, &constrained_offset); - - mat4 constrained_offset_mat; - mat4_translate(constrained_offset.x, constrained_offset.y, - constrained_offset.z, &constrained_offset_mat); - mat4_mult(&mat, &constrained_offset_mat, node->mat); - } break; - case OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE: - default: - *node->mat = mat; - break; - } -} - -void ExConstraintBlock::DataSet() { - if (!bone_node_ptr) - return; - - bone_node_expression_data* exp_data = &bone_node_ptr->exp_data; - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - - mat4 mat; - mat4_inverse_normalized(parent_bone_node->ex_data_mat, &mat); - mat4_mult(bone_node_ptr->mat, &mat, &mat); - mat4_get_rotation(&mat, &bone_node_ptr->exp_data.rotation); - mat4_get_translation(&mat, &exp_data->position); - if (fabsf(parent_scale.x) > 0.000001f) - exp_data->position.x /= parent_scale.x; - if (fabsf(parent_scale.y) > 0.000001f) - exp_data->position.y /= parent_scale.z; - if (fabsf(parent_scale.z) > 0.000001f) - exp_data->position.z /= parent_scale.z; - *bone_node_ptr->ex_data_mat = *bone_node_ptr->mat; - mat4_scale_rot(bone_node_ptr->mat, parent_scale.x, parent_scale.y, parent_scale.z, bone_node_ptr->mat); - vec3_mult(exp_data->scale, parent_scale, exp_data->parent_scale); -} - -void ExConstraintBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_block_constraint* cns_data, const char* cns_data_name, bone_database* bone_data) { - bone_node* node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, cns_data_name, bone_data); - type = EX_CONSTRAINT; - bone_node_ptr = node; - this->cns_data = cns_data; - name = node->name; - item_equip_object = itm_eq_obj; - - source_node_bone_node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, cns_data->source_node_name, bone_data); - - obj_skin_block_constraint_type type = cns_data->type; - const char* up_vector_name; - if (type == OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION) { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_DIRECTION; - up_vector_name = cns_data->direction.up_vector.name; - } - else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_POSITION) { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_POSITION; - up_vector_name = cns_data->position.up_vector.name; - } - else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE) { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_DISTANCE; - up_vector_name = cns_data->distance.up_vector.name; - } - else if (type == OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION) { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION; - return; - } - else { - constraint_type = OBJ_SKIN_BLOCK_CONSTRAINT_NONE; - return; - } - - if (up_vector_name) - direction_up_vector_bone_node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, up_vector_name, bone_data); -} - -void ExConstraintBlock::sub_1405F10D0(mat4* mat, vec3* a2, float_t a3, float_t a4) { - vec3 v5; - vec3 v6; - vec3 v7; - vec3 v8; - vec3 v9; - vec3_normalize(*a2, v5); - vec3_mult_scalar(v5, 1.0f - a3, v9); - vec3_mult_scalar(v5, v9.x, v6); - vec3_mult_scalar(v5, v9.y, v7); - vec3_mult_scalar(v5, v9.z, v8); - mat->row0.x = v6.x + a3; - mat->row0.y = v6.y - v5.z * a4; - mat->row0.z = v6.z + v5.y * a4; - mat->row0.w = 0.0f; - mat->row1.x = v7.x + v5.z * a4; - mat->row1.y = v7.y + a3; - mat->row1.z = v7.z - v5.x * a4; - mat->row1.w = 0.0f; - mat->row2.x = v8.x - v5.y * a4; - mat->row2.y = v8.y + v5.x * a4; - mat->row2.z = v8.z + a3; - mat->row2.w = 0.0f; - mat->row3 = { 0.0f, 0.0f, 0.0f, 1.0f }; -} - -void ExConstraintBlock::sub_1401EB410(mat4* mat, vec3* a2, vec3* target_offset) { - vec3 v3; - vec3 v4; - vec3_normalize(*a2, v3); - vec3_normalize(*target_offset, v4); - vec3 v13; - vec3_cross(v4, v3, v13); - - float_t v18; - vec3_dot(v3, v4, v18); - v18 = clamp(v18, -1.0f, 1.0f); - float_t v19 = 1.0f - v18; - - float_t v20 = 1.0f - v18 * v18; - v20 = sqrtf(clamp(v20, 0.0f, 1.0f)); - - sub_1405F10D0(mat, &v13, v18, v20); -} - -ExExpressionBlock::ExExpressionBlock() : values(), types(), expressions(), -stack_data(), exp_data(), field_3D20(), field_3D28(), frame(), step(true) { - -} - -ExExpressionBlock::~ExExpressionBlock() { - -} - -void ExExpressionBlock::Init() { - frame = 0.0f; -} - -void ExExpressionBlock::Field_10() { - bone_node_expression_data* node_exp_data = &bone_node_ptr->exp_data; - node_exp_data->position = exp_data->base.position; - node_exp_data->rotation = exp_data->base.rotation; - node_exp_data->scale = exp_data->base.scale; - field_59 = false; -} - -void ExExpressionBlock::Field_18(int32_t stage, bool a3) { - if (field_59) - return; - - if (stage == 0) { - if (field_58) - Field_20(); - } - else if (stage == 2) { - if (has_children_node) - DataSet(); - } - else if (stage == 5) - Field_20(); -} - -void ExExpressionBlock::Field_20() { - if (!parent_bone_node) - return; - - if (field_59) { - field_59 = false; - return; - } - - Calc(); - DataSet(); - field_59 = true; -} - -void ExExpressionBlock::SetOsagePlayData() { - Field_20(); -} - -void ExExpressionBlock::Disp() { - -} - -void ExExpressionBlock::Reset() { - bone_node_ptr = 0; -} - -void ExExpressionBlock::Field_40() { - -} - -void ExExpressionBlock::Field_48() { - Field_20(); -} - -void ExExpressionBlock::Field_50() { - Field_20(); -} - -void ExExpressionBlock::Field_58() { - field_59 = false; -} - -void ExExpressionBlock::Calc() { - float_t delta_frame = get_delta_frame(); - if (step) - delta_frame *= item_equip_object->item_equip->step; - float_t frame = this->frame + delta_frame; - this->frame = frame >= 65535.0f ? frame - 65535.0f : frame; - - if (field_3D28) { - field_3D28(&bone_node_ptr->exp_data); - return; - } - - for (int32_t i = 0; i < 9; i++) { - if (!expressions[i]) - break; - - float_t value = ex_expression_block_stack_get_value(expressions[i]); - if (types[i] == EX_EXPRESSION_BLOCK_STACK_VARIABLE_RADIAN) - value *= DEG_TO_RAD_FLOAT; - *values[i] = value; - } -} - -void ExExpressionBlock::DataSet() { - bone_node_expression_data* data = &bone_node_ptr->exp_data; - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - mat4 ex_data_mat = *parent_bone_node->ex_data_mat; - mat4 mat = mat4_identity; - bone_node_expression_data_mat_set(data, &parent_scale, &ex_data_mat, &mat); - *bone_node_ptr->mat = mat; - *bone_node_ptr->ex_data_mat = ex_data_mat; -} - -void ExExpressionBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_block_expression* exp_data, const char* exp_data_name, object_info a4, - size_t index, bone_database* bone_data) { - ex_expression_block_stack* stack_buf[28]; - ex_expression_block_stack** stack_buf_val = stack_buf; - - bone_node* node = rob_chara_item_equip_object_get_bone_node_by_name( - itm_eq_obj, exp_data_name, bone_data); - type = EX_EXPRESSION; - bone_node_ptr = node; - this->exp_data = exp_data; - name = node->name; - item_equip_object = itm_eq_obj; - - node->exp_data.position = exp_data->base.position; - node->exp_data.rotation = exp_data->base.rotation; - node->exp_data.scale = exp_data->base.scale; - field_3D28 = 0; - - ex_expression_block_stack* stack_val = stack_data; - for (int32_t i = 0; i < 9; i++) { - values[i] = 0; - expressions[i] = 0; - } - - for (int32_t i = 0; i < 9; i++) { - const char* expression = exp_data->expressions[i]; - if (!expression || str_utils_compare(expression, "= ")) - break; - - expression += 2; - - int32_t index = 0; - expression = str_utils_get_next_int32_t(expression, index, ' '); - values[i] = bone_node_get_exp_data_component(bone_node_ptr, index, &types[i]); - - while (expression) { - std::string value_type; - expression = str_utils_get_next_string(expression, value_type, ' '); - if (!value_type.size() || !memcmp(value_type.c_str(), "error", - min(value_type.size(), 5)) && value_type.size() == 5) - break; - - if (value_type[0] == 'n') { - stack_val->type = EX_EXPRESSION_BLOCK_STACK_NUMBER; - expression = str_utils_get_next_float_t(expression, stack_val->number.value, ' '); - *stack_buf_val++ = stack_val; - } - else if (value_type[0] == 'v') { - std::string func_str; - expression = str_utils_get_next_string(expression, func_str, ' '); - stack_val->type = EX_EXPRESSION_BLOCK_STACK_VARIABLE; - int32_t v40 = func_str[0] - '0'; - if (v40 < 9) { - bone_node* v42 = rob_chara_item_equip_object_get_bone_node_by_name(itm_eq_obj, - func_str.c_str() + 2, bone_data); - if (v42) - stack_val->var.value = bone_node_get_exp_data_component(v42, v40, &stack_val->type); - else { - stack_val->type = EX_EXPRESSION_BLOCK_STACK_NUMBER; - stack_val->number.value = 0.0f; - } - } - else - stack_val->var.value = &frame; - *stack_buf_val++ = stack_val; - } - else if (value_type[0] == 'f') { - std::string func_str; - expression = str_utils_get_next_string(expression, func_str, ' '); - stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP1; - stack_val->op1.v1 = stack_buf_val[-1]; - stack_val->op1.func = exp_func_op1_find_func(func_str, exp_func_op1_array)->func; - stack_buf_val[-1] = stack_val; - } - else if (value_type[0] == 'g') { - std::string func_str; - expression = str_utils_get_next_string(expression, func_str, ' '); - stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP2; - stack_val->op2.v1 = stack_buf_val[-2]; - stack_val->op2.v2 = stack_buf_val[-1]; - stack_val->op2.func = exp_func_op2_find_func(func_str, exp_func_op2_array)->func; - stack_buf_val[-2] = stack_val; - stack_buf_val--; - } - else if (value_type[0] == 'h') { - std::string func_str; - expression = str_utils_get_next_string(expression, func_str, ' '); - stack_val->type = EX_EXPRESSION_BLOCK_STACK_OP3; - stack_val->op3.v1 = stack_buf_val[-3]; - stack_val->op3.v2 = stack_buf_val[-2]; - stack_val->op3.v3 = stack_buf_val[-1]; - stack_val->op3.func = exp_func_op3_find_func(func_str, exp_func_op3_array)->func; - stack_buf_val[-3] = stack_val; - stack_buf_val -= 2; - } - expressions[i] = stack_buf_val[-1]; - stack_val++; - } - } - - step = !((ssize_t)index - ITEM_TE_R <= 1); -} - -ExOsageBlock::ExOsageBlock() : rob(), mats(), step(1.0f) { - Reset(); -} - -ExOsageBlock::~ExOsageBlock() { - Reset(); - rob_osage_free(&rob); -} - -void ExOsageBlock::Init() { - Reset(); -} - -void ExOsageBlock::Field_10() { - field_59 = false; -} - -void ExOsageBlock::Field_18(int32_t stage, bool a3) { - rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; - float_t step = get_delta_frame() * rob_itm_equip->step; - if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) - step = 1.0f; - - mat4* parent_node_mat = parent_bone_node->ex_data_mat; - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - switch (stage) { - case 0: - sub_1404803B0(&rob, parent_node_mat, &parent_scale, has_children_node); - break; - case 1: - case 2: - if ((stage == 1 && field_58) || (stage == 2 && rob.field_2A0)) { - SetWindDirection(); - sub_14047C800(&rob, parent_node_mat, &parent_scale, step, a3, true, has_children_node); - } - break; - case 3: - rob_osage_coli_set(&rob, mats); - sub_14047ECA0(&rob, step); - break; - case 4: - sub_14047D620(&rob, step); - break; - case 5: { - sub_14047D8C0(&rob, parent_node_mat, &parent_scale, step, false); - sub_140480260(&rob, parent_node_mat, &parent_scale, step, a3); - field_59 = true; - } break; - } -} - -void ExOsageBlock::Field_20() { - field_1FF8 &= ~2; - if (field_59) { - field_59 = false; - return; - } - - rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; - float_t step = get_delta_frame() * rob_itm_equip->step; - if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) - step = 1.0f; - - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - vec3 scale = parent_bone_node->exp_data.scale; - - mat4 mat = *parent_bone_node->ex_data_mat; - if (scale.x != 1.0f || scale.y != 1.0f || scale.z != 1.0f) { - vec3_div(vec3_identity, scale, scale); - mat4_scale_rot(&mat, scale.x, scale.y, scale.z, &mat); - } - SetWindDirection(); - rob_osage_coli_set(&rob, mats); - sub_14047C750(&rob, &mat, &parent_scale, step); -} - -void ExOsageBlock::SetOsagePlayData() { - rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - sub_14047E240(&rob, parent_bone_node->ex_data_mat, &parent_scale, &rob_itm_equip->opd_blend_data); -} - -void ExOsageBlock::Disp() { - -} - -void ExOsageBlock::Reset() { - index = 0; - rob.reset(); - field_1FF8 &= ~3; - mats = 0; - step = 1.0f; - ExNodeBlock::Reset(); -} - -void ExOsageBlock::Field_40() { - -} - -void ExOsageBlock::Field_48() { - step = 4.0f; - SetWindDirection(); - rob_osage_coli_set(&rob, mats); - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - sub_14047F990(&rob, parent_bone_node->ex_data_mat, &parent_scale, 0); - field_1FF8 &= ~2; -} - -void ExOsageBlock::Field_50() { - if (field_59) { - field_59 = false; - return; - } - - SetWindDirection(); - - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - rob_osage_coli_set(&rob, mats); - sub_14047C770(&rob, parent_bone_node->ex_data_mat, &parent_scale, step, 1); - float_t step = 0.5f * this->step; - this->step = max(step, 1.0f); -} - -void ExOsageBlock::Field_58() { - vec3 parent_scale = parent_bone_node->exp_data.parent_scale; - sub_14047E1C0(&rob, &parent_scale); - field_59 = false; -} - -void ExOsageBlock::AddMotionResetData(int32_t motion_id, float_t frame) { - rob_osage_add_motion_reset_data(&rob, motion_id, frame); -} - -void ExOsageBlock::InitData(rob_chara_item_equip_object* itm_eq_obj, - obj_skin_block_osage* osg_data, const char* osg_data_name, obj_skin_osage_node* osg_nodes, - bone_node* bone_nodes, bone_node* ex_data_bone_nodes, obj_skin* skin) { - ExNodeBlock::InitData(&ex_data_bone_nodes[osg_data->external_name_index & 0x7FFF], - EX_OSAGE, osg_data_name, itm_eq_obj); - rob_osage_init_data(&rob, osg_data, osg_nodes, ex_data_bone_nodes, skin); - field_1FF8 &= ~2; - mats = bone_nodes->mat; -} - -float_t* ExOsageBlock::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { - return rob_osage_load_opd_data(&rob, node_index, opd_data, opd_count); -} - -void ExOsageBlock::SetMotionResetData(int32_t motion_id, float_t frame) { - rob_osage_set_motion_reset_data(&rob, motion_id, frame); -} - -void ExOsageBlock::SetOsageReset() { - rob.osage_reset = true; -} - -void ExOsageBlock::SetSkinParam(struc_571* skp) { - if (skp->nodes_data.size() == rob.nodes.size() - 1) { - size_t node_index = 0; - rob_osage_node* i_begin = rob.nodes.data() + 1; - rob_osage_node* i_end = rob.nodes.data() + rob.nodes.size(); - for (rob_osage_node* i = i_begin; i != i_end; i++) - i->data_ptr = &skp->nodes_data[node_index++]; - } - else { - rob.skin_param_ptr = &rob.skin_param; - for (rob_osage_node& i : rob.nodes) - i.data_ptr = &i.data; - } -} - -void ExOsageBlock::SetWindDirection() { - vec3_mult_scalar(task_wind.ptr->wind_direction, - item_equip_object->item_equip->wind_strength, - rob.wind_direction); -} - -void ExOsageBlock::sub_1405F3E10(obj_skin_block_osage* osg_data, - obj_skin_osage_node* osg_nodes, std::vector>* a4, - std::map* a5) { - rob_osage_node* v9 = rob_osage_get_node(&rob, 0); - a4->push_back({ osg_data->external_name_index, v9 }); - - for (uint32_t i = 0; i < osg_data->count; i++) { - v9 = rob_osage_get_node(&rob, i); - a4->push_back({ osg_nodes[i].name_index, v9 }); - - if (v9->bone_node_ptr && v9->bone_node_ptr->name) - a5->insert({ v9->bone_node_ptr->name, this }); - } - - v9 = rob_osage_get_node(&rob, osg_data->count + 1ULL); - a4->push_back({ osg_data->name_index, v9 }); - - if (v9->bone_node_ptr && v9->bone_node_ptr->name) - a5->insert({ v9->bone_node_ptr->name, this }); -} - -ExClothBlock::ExClothBlock() { - Init(); -} - -ExClothBlock::~ExClothBlock() { - -} - -void ExClothBlock::Init() { - //rob.base.field_48(&cls->rob); - cls_data = 0; - field_2428 = 0; - index = 0; -} - -void ExClothBlock::Field_10() { - field_59 = false; -} - -void ExClothBlock::Field_18(int32_t stage, bool a3) { - -} - -void ExClothBlock::Field_20() { - //sub_14021FD00(&rob, field_2428); - //rob.__vftable->set_wind_direction(&rob, wind_task_struct_get_wind_direction()); - rob_chara_item_equip* rob_itm_equip = item_equip_object->item_equip; - float_t step = get_delta_frame() * rob_itm_equip->step; - if (rob_itm_equip->opd_blend_data.size() && rob_itm_equip->opd_blend_data[0].field_C) - step = 1.0f; - //sub_140218560(&rob, step, 0); -} - -void ExClothBlock::SetOsagePlayData() { - //sub_140218E40(&cls->rob, &cls->base.item_equip_object->item_equip->opd_blend_data); -} - -void ExClothBlock::Disp() { - -} - -void ExClothBlock::Reset() { - bone_node_ptr = 0; -} - -void ExClothBlock::Field_40() { - -} - -void ExClothBlock::Field_48() { - //sub_14021FD00(&rob, field_2428); - //rob.__vftable->set_wind_direction(&rob, wind_task_struct_get_wind_direction()); - //sub_14021D480(&rob); -} - -void ExClothBlock::Field_50() { - //sub_14021FD00(&rob, field_2428); - //rob.__vftable->set_wind_direction(&rob, wind_task_struct_get_wind_direction()); - //sub_14021D840(&rob); -} - -void ExClothBlock::Field_58() { - field_59 = false; -} - -void ExClothBlock::AddMotionResetData(int32_t motion_id, float_t frame) { - //rob_cloth_add_motion_reset_data(&rob, motion_id, frame); -} - -float_t* ExClothBlock::LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count) { - return opd_data;//rob_cloth_load_opd_data(&rob, node_index, opd_data, opd_count); -} - -void ExClothBlock::SetMotionResetData(int32_t motion_id, float_t frame) { - //rob_cloth::set_motion_reset_data(&rob, motion_id, frame); -} - -void ExClothBlock::SetOsageReset() { - //rob.osage_reset = true; -} - -void ExClothBlock::SetSkinParam(struc_571* skp) { - //rob.skin_param_ptr = &skp->skin_param; -} - -skin_param_hinge::skin_param_hinge() { - ymin = -90.0f; - ymax = 90.0f; - zmin = -90.0f; - zmax = 90.0f; -} - -skin_param_hinge::~skin_param_hinge() { - -} - -void skin_param_hinge::limit() { - ymin = max(ymin, -179.0f) * DEG_TO_RAD_FLOAT; - ymax = min(ymax, 179.0f) * DEG_TO_RAD_FLOAT; - zmin = max(zmin, -179.0f) * DEG_TO_RAD_FLOAT; - zmax = min(zmax, 179.0f) * DEG_TO_RAD_FLOAT; -} - -skin_param_osage_node::skin_param_osage_node() : coli_r(0.0f), weight(1.0f), inertial_cancel(0.0f) { - hinge.limit(); -} - -skin_param_osage_node::~skin_param_osage_node() { - -} - -rob_osage_node_data::rob_osage_node_data() : force(), normal_ref() { - -} - -rob_osage_node_data::~rob_osage_node_data() { - -} - -void rob_osage_node_data::reset() { - force = 0.0f; - boc.clear(); - normal_ref.field_0 = 0; - normal_ref.n = 0; - normal_ref.u = 0; - normal_ref.d = 0; - normal_ref.l = 0; - normal_ref.r = 0; - normal_ref.mat = mat4u_identity; - skp_osg_node.weight = 1.0f; - skp_osg_node.inertial_cancel = 0.0f; - skp_osg_node.coli_r = 0.0f; - skp_osg_node.hinge = skin_param_hinge(); - skp_osg_node.hinge.limit(); -} - -rob_osage_node::rob_osage_node() : length(), trans(), trans_orig(), trans_diff(), field_28(), -child_length(), bone_node_ptr(), bone_node_mat(), sibling_node(), max_distance(), field_94(), -reset_data(), field_C8(), field_CC(1.0f), external_force(), force(1.0f), mat(), field_1B0() { - data_ptr = &data; - opd_data.resize(3); -} - -rob_osage_node::~rob_osage_node() { - -} - -void rob_osage_node::reset() { - length = 0.0f; - trans = vec3_null; - trans_orig = vec3_null; - trans_diff = vec3_null; - field_28 = vec3_null; - child_length = 0.0f; - bone_node_ptr = 0; - bone_node_mat = 0; - sibling_node = 0; - max_distance = 0.0f; - field_94 = vec3_null; - reset_data.trans = vec3_null; - reset_data.trans_diff = vec3_null; - reset_data.rotation = vec3_null; - reset_data.length = 0.0f; - field_C8 = 0.0f; - field_CC = 1.0f; - external_force = vec3_null; - force = 1.0f; - data.reset(); - data_ptr = &data; - opd_data.clear(); - opd_data.resize(3); - mat = mat4u_null; -} - -skin_param_osage_root_coli::skin_param_osage_root_coli() : type(), -bone0_index(), bone1_index(), radius(0.2f), bone0_pos(), bone1_pos() { - -} - -skin_param_osage_root_coli::~skin_param_osage_root_coli() { - -} - -skin_param_osage_root_normal_ref::skin_param_osage_root_normal_ref() { - -} - -skin_param_osage_root_normal_ref::~skin_param_osage_root_normal_ref() { - -} - -skin_param_osage_root_boc::skin_param_osage_root_boc() : ed_node(), st_node() { - -} - -skin_param_osage_root_boc::~skin_param_osage_root_boc() { - -} - -skin_param_osage_root::skin_param_osage_root() : field_0(), force(), force_gain(), air_res(0.5f), -rot_y(), rot_z(), init_rot_y(), init_rot_z(), hinge_y(90.0f), hinge_z(90.0f), name("NO-PARAM"), -coli_r(), friction(1.0f), wind_afc(0.5f), yz_order(), coli_type(), stiffness(), move_cancel(-0.01f) { - coli.resize(13); -} - -skin_param_osage_root::~skin_param_osage_root() { - -} - -skin_param::skin_param() : friction(1.0f), wind_afc(), air_res(1.0f), rot(), init_rot(), -coli_type(), stiffness(), move_cancel(-0.01f), coli_r(), force(), force_gain(), colli_tgt_osg() { - hinge.limit(); -} - -skin_param::~skin_param() { - -} - -void skin_param::reset() { - coli.clear(); - friction = 1.0f; - wind_afc = 0.0f; - air_res = 1.0f; - rot = vec3_null; - init_rot = vec3_null; - coli_type = 0; - stiffness = 0.0f; - move_cancel = -0.01f; - coli_r = 0.0f; - hinge = skin_param_hinge(); - hinge.limit(); - force = 0.0f; - force_gain = 0.0f; - colli_tgt_osg = 0; -} - -struc_571::struc_571() : field_88() { - -} - -struc_571::~struc_571() { - -} - -osage_coli::osage_coli() : type(), radius(), bone0_pos(), bone1_pos(), -bone_pos_diff(), bone_pos_diff_length(), bone_pos_diff_length_squared(), field_34() { - -} - -osage_coli::~osage_coli() { - -} - -osage_ring_data::osage_ring_data() : ring_rectangle_x(0.0f), ring_rectangle_y(0.0f), ring_rectangle_width(0.0f), -ring_rectangle_height(0.0f), ring_height(-1000.0f), ring_out_height(-1000.0f), field_18() { - -} - -osage_ring_data::~osage_ring_data() { - -} - -osage_setting_osg_cat::osage_setting_osg_cat() : exf() { - parts = ROB_OSAGE_PARTS_NONE; -} - -rob_osage::rob_osage() : skin_param_ptr(), osage_setting(), field_2A0(), field_2A1(), field_2A4(), -wind_direction(), field_1EB4(), yz_order(), field_1EBC(), parent_mat_ptr(), parent_mat(), move_cancel(), -field_1F0C(), osage_reset(), field_1F0E(), field_1F0F(), set_external_force(), external_force(), reset_data_list() { - -} - -rob_osage::~rob_osage() { - -} - -void rob_osage::reset() { - nodes.clear(); - node.reset(); - wind_direction = vec3_null; - field_1EB4 = 0.0f; - yz_order = 0; - field_2A0 = true; - motion_reset_data.clear(); - move_cancel = 0.0f; - field_1F0C = false; - osage_reset = false; - field_1F0E = false; - ring = osage_ring_data(); - field_1F0F = 0; - skin_param.reset(); - skin_param_ptr = &skin_param; - osage_setting = osage_setting_osg_cat(); - reset_data_list = 0; - field_2A4 = 0.0f; - field_2A1 = false; - set_external_force = false; - external_force = vec3_null; - parent_mat_ptr = 0; - parent_mat = mat4u_null; -} - rob_chara_item_equip_object::rob_chara_item_equip_object() : index(), mats(), obj_info(), field_14(), texture_data(), null_blocks_data_set(), alpha(), -draw_task_flags(), disp(), field_A4(), mat(), osage_iterations(), bone_nodes(), +draw_task_flags(), can_disp(), field_A4(), mat(), osage_iterations(), bone_nodes(), field_138(), field_1B8(), field_1C0(), use_opd(), skin_ex_data(), skin(), item_equip() { - rob_chara_item_equip_object_init_members(this, 0x12345678); + init_members(0x12345678); } rob_chara_item_equip_object::~rob_chara_item_equip_object() { - rob_chara_item_equip_object_init_members(this, 0xDDDDDDDD); + init_members(0xDDDDDDDD); +} + +void rob_chara_item_equip_object::add_motion_reset_data( + int32_t motion_id, float_t frame, int32_t osage_iterations) { + if (osage_iterations > 0) + rob_chara_item_equip_object_ctrl_iterate_nodes(this, osage_iterations); + + for (ExOsageBlock*& i : osage_blocks) + i->AddMotionResetData(motion_id, frame); + + for (ExClothBlock*& i : cloth_blocks) + i->AddMotionResetData(motion_id, frame); +} + +void rob_chara_item_equip_object::check_no_opd(std::vector& opd_blend_data) { + use_opd = true; + if (!osage_blocks.size() && !cloth_blocks.size() || !opd_blend_data.size()) + return; + + for (::opd_blend_data& i : opd_blend_data) { + float_t* opd_data = 0; + uint32_t opd_count = 0; + osage_play_data_manager_get_opd_file_data(obj_info, + i.motion_id, &opd_data, &opd_count); + if (!opd_data) { + use_opd = false; + break; + } + } +} + +void rob_chara_item_equip_object::clear_ex_data() { + for (ExNullBlock*& i : null_blocks) { + i->Reset(); + delete i; + } + null_blocks.clear(); + + for (ExOsageBlock*& i : osage_blocks) { + i->Reset(); + delete i; + } + osage_blocks.clear(); + + for (ExConstraintBlock*& i : constraint_blocks) { + i->Reset(); + delete i; + } + constraint_blocks.clear(); + + for (ExExpressionBlock*& i : expression_blocks) { + i->Reset(); + delete i; + } + expression_blocks.clear(); + + for (ExClothBlock*& i : cloth_blocks) { + i->Reset(); + delete i; + } + cloth_blocks.clear(); + + node_blocks.clear(); +} + +void rob_chara_item_equip_object::disp(mat4* mat, render_context* rctx) { + if (obj_info.is_null()) + return; + + ::draw_task_flags v2 = rctx->object_data.get_draw_task_flags(); + ::draw_task_flags v4 = v2; + if (fabsf(alpha - 1.0f) > 0.000001f) + enum_or(v4, draw_task_flags); + else + enum_and(v4, ~(DRAW_TASK_40000 | DRAW_TASK_20000 | DRAW_TASK_10000)); + rctx->object_data.set_draw_task_flags(v4); + if (can_disp) { + draw_task_add_draw_object_by_object_info_object_skin(rctx, obj_info, + &texture_pattern, &texture_data, alpha, mats, ex_data_block_mats.data(), 0, mat); + + for (ExNodeBlock*& i : node_blocks) + i->Disp(mat, rctx); + } + rctx->object_data.set_draw_task_flags(v2); +} + +int32_t rob_chara_item_equip_object::get_bone_index(const char* name, bone_database* bone_data) { + int32_t bone_index = bone_data->get_skeleton_motion_bone_index( + bone_database_skeleton_type_to_string(BONE_DATABASE_SKELETON_COMMON), name); + if (bone_index == -1) + for (ex_data_name_bone_index& i : ex_bones) + if (!str_utils_compare(name, i.name)) + return 0x8000 | i.bone_index; + return bone_index; +} + +bone_node* rob_chara_item_equip_object::get_bone_node( + int32_t bone_index) { + if (~bone_index & 0x8000) + return &bone_nodes[bone_index & 0x7FFF]; + else if ((bone_index & 0x7FFF) < ex_data_bone_nodes.size()) + return &ex_data_bone_nodes[bone_index & 0x7FFF]; + return 0; +} + +bone_node* rob_chara_item_equip_object::get_bone_node(const char* name, bone_database* bone_data) { + return get_bone_node(get_bone_index(name, bone_data)); +} + +RobOsageNode* rob_chara_item_equip_object::get_normal_ref_osage_node(std::string& name, size_t* index) { + if (!name.size()) + return 0; + + size_t v8 = name.find(',', 0); + if (v8 == -1) + return 0; + + std::string v22 = name.substr(0, v8); + std::string v23 = name.substr(v8 + 1); + size_t v11 = atoi(v23.c_str()); + if (index) + *index = v11; + + RobOsageNode* node = 0; + for (ExOsageBlock*& i : osage_blocks) + if (!v22.compare(i->name)) { + if (v11 + 1 < i->rob.nodes.size()) + node = i->rob.GetNode(v11 + 1); + break; + } + return node; +} + +void rob_chara_item_equip_object::get_parent_bone_nodes(bone_node* bone_nodes, bone_database* bone_data) { + this->bone_nodes = bone_nodes; + mats = bone_nodes->mat; + for (ExNodeBlock*& i : node_blocks) + i->parent_bone_node = get_bone_node(i->parent_name.c_str(), bone_data); +} + +void rob_chara_item_equip_object::init_ex_data_bone_nodes(obj_skin_ex_data* ex_data) { + ex_data_bone_nodes.clear(); + ex_data_mats.clear(); + ex_data_block_mats.clear(); + + int32_t count = ex_data->bone_names_count; + ex_data_bone_nodes.resize(count); + ex_data_mats.resize(count); + ex_data_block_mats.resize(count); + + bone_node* v4 = ex_data_bone_nodes.data(); + mat4* v5 = ex_data_mats.data(); + mat4* v8 = ex_data_block_mats.data(); + for (int32_t v10 = 0; v10 < count; v10++) + v4[v10].mat = &v5[v10]; + + if (ex_data->bone_names) { + ex_bones.clear(); + for (int32_t i = 0; i < count; i++) { + bone_node* node = &v4[i]; + node->name = ex_data->bone_names[i]; + node->mat = &v5[i]; + *node->mat = mat4_identity; + node->ex_data_mat = &v8[i]; + *node->ex_data_mat = mat4_identity; + + ex_bones.push_back({ ex_data->bone_names[i], i }); + } + } +} + +void rob_chara_item_equip_object::init_members(size_t index) { + this->index = index; + obj_info = {}; + field_14 = -1; + mats = 0; + texture_pattern.clear(); + texture_data.field_0 = -1; + texture_data.texture_color_coeff = vec3_identity; + texture_data.texture_color_offset = vec3_null; + texture_data.texture_specular_coeff = vec3_identity; + texture_data.texture_specular_offset = vec3_null; + alpha = 1.0f; + draw_task_flags = DRAW_TASK_10000; + null_blocks_data_set = 0; + can_disp = true; + field_A4 = 0; + mat = 0; + bone_nodes = 0; + clear_ex_data(); + ex_data_bone_nodes.clear(); + ex_data_mats.clear(); + ex_data_block_mats.clear(); + ex_bones.clear(); + field_1B8 = 0; + use_opd = false; + field_1C0 = 0; +} + +void rob_chara_item_equip_object::load_ex_data(obj_skin_ex_data* ex_data, + bone_database* bone_data, void* data, object_database* obj_db) { + if (!ex_data->blocks) + return; + + std::vector> v129; + std::map v138; + clear_ex_data(); + + size_t constraint_count = 0; + size_t expression_count = 0; + size_t osage_count = 0; + size_t cloth_count = 0; + size_t null_count = 0; + char** bone_names_ptr = ex_data->bone_names; + obj_skin_block* v4 = ex_data->blocks; + for (uint32_t i = 0; i < ex_data->blocks_count; i++, v4++) { + ExNodeBlock* node; + if (v4->type == OBJ_SKIN_BLOCK_CLOTH) { + if (cloth_count >= 0x08) + continue; + + ExClothBlock* cls = new ExClothBlock; + node = cls; + cloth_blocks.push_back(cls); + cls->InitData(this, &v4->cloth, 0, bone_data); + cls->index = cloth_count + osage_count; + cls->name = v4->cloth.mesh_name; + cloth_count++; + } + else if (v4->type == OBJ_SKIN_BLOCK_CONSTRAINT) { + if (constraint_count >= 0x40) + continue; + + ExConstraintBlock* cns = new ExConstraintBlock; + node = cns; + constraint_blocks.push_back(cns); + cns->InitData(this, &v4->constraint, + bone_names_ptr[v4->constraint.name_index & 0x7FFF], bone_data); + constraint_count++; + } + else if (v4->type == OBJ_SKIN_BLOCK_EXPRESSION) { + if (expression_count >= 0x50) + continue; + + ExExpressionBlock* exp = new ExExpressionBlock; + node = exp; + expression_blocks.push_back(exp); + exp->InitData(this, &v4->expression, + bone_names_ptr[v4->expression.name_index & 0x7FFF], obj_info, index, bone_data); + expression_count++; + } + else if (v4->type == OBJ_SKIN_BLOCK_OSAGE) { + if (osage_count >= 0x100) + continue; + + ExOsageBlock* osg = new ExOsageBlock; + node = osg; + osage_blocks.push_back(osg); + osg->InitData(this, &v4->osage, + bone_names_ptr[v4->osage.external_name_index & 0x7FFF], + &skin_ex_data->osage_nodes[v4->osage.start_index], + bone_nodes, ex_data_bone_nodes.data(), skin); + osg->sub_1405F3E10(&v4->osage, + &skin_ex_data->osage_nodes[v4->osage.start_index], &v129, &v138); + osg->index = osage_count; + osage_count++; + } + else { + if (null_count >= 0x4) + continue; + + ExNullBlock* null = new ExNullBlock; + node = null; + null_blocks.push_back(null); + null->InitData(this, &v4->constraint, + bone_names_ptr[v4->constraint.name_index & 0x7FFF], bone_data); + null_count++; + } + + obj_skin_block_node* v54 = &v4->base; + bone_node_expression_data exp_data; + exp_data.position = v54->position; + exp_data.rotation = v54->rotation; + exp_data.scale = v54->scale; + exp_data.parent_scale = vec3_identity; + node->parent_name = v54->parent_name; + + bone_node* parent_bone_node = get_bone_node(v54->parent_name, bone_data); + node->parent_bone_node = parent_bone_node; + if (node->bone_node_ptr) { + node->bone_node_ptr->exp_data = exp_data; + node->bone_node_ptr->parent = parent_bone_node; + } + + if (parent_bone_node) { + auto elem = v138.find(parent_bone_node->name); + if (elem != v138.end()) + node->parent_node = elem->second; + } + + v138.insert({ node->name, node }); + node_blocks.push_back(node); + } + + for (ExNodeBlock*& i : node_blocks) { + ExNodeBlock* v86 = i->parent_node; + if (v86) { + v86->has_children_node = true; + if ((v86->type & ~3u) || v86->type == EX_OSAGE || !v86->field_58) + continue; + } + i->field_58 = true; + } + + for (ExOsageBlock*& i : osage_blocks) { + ExOsageBlock* osg = i; + ExNodeBlock* parent_node = osg->parent_node; + bone_node* parent_bone_node = 0; + if (!parent_node || osg->field_58) + parent_bone_node = osg->parent_bone_node; + else { + while (!parent_node->field_58) { + parent_node = parent_node->parent_node; + if (!parent_node) + break; + } + + if (parent_node) + parent_bone_node = parent_node->parent_bone_node; + } + + if (parent_bone_node && parent_bone_node->ex_data_mat) { + osg->rob.parent_mat_ptr = parent_bone_node->ex_data_mat; + osg->rob.parent_mat = *parent_bone_node->ex_data_mat; + } + } + + if (ex_data->osage_sibling_infos) + for (uint32_t i = 0; i < ex_data->osage_sibling_infos_count; i++) { + obj_skin_osage_sibling_info* sibling_info = &ex_data->osage_sibling_infos[i]; + uint32_t name_index = sibling_info->name_index; + uint32_t sibling_name_index = sibling_info->sibling_name_index; + + auto node = v129.begin(); + for (; node != v129.end(); node++) + if (node->first == name_index) + break; + + auto sibling_node = v129.begin(); + for (; sibling_node != v129.end(); sibling_node++) + if (sibling_node->first == sibling_name_index) + break; + + if (node != v129.end() && sibling_node != v129.end()) { + RobOsageNode* v102 = node->second; + v102->sibling_node = sibling_node->second; + v102->max_distance = sibling_info->max_distance; + } + } + + if (osage_count || cloth_count) + skp_load_file(data, bone_data, obj_db); + + size_t v103 = 0; + for (ExOsageBlock*& i : osage_blocks) + v103 += i->rob.nodes.size() - 1; + for (ExClothBlock*& i : cloth_blocks) + v103 += i->rob.nodes.size() - i->rob.root_count; + field_1C0 = v103; +} + +void rob_chara_item_equip_object::load_object_info_ex_data(object_info object_info, bone_node* bone_nodes, + bool osage_reset, bone_database* bone_data, void* data, object_database* obj_db) { + this->obj_info = object_info; + this->bone_nodes = bone_nodes; + mats = bone_nodes->mat; + ex_data_bone_nodes.clear(); + ex_bones.clear(); + ex_data_mats.clear(); + clear_ex_data(); + obj_skin* skin = object_storage_get_obj_skin(this->obj_info); + if (!skin || !skin->ex_data_init) + return; + + this->skin = skin; + this->skin_ex_data = &skin->ex_data; + init_ex_data_bone_nodes(&skin->ex_data); + load_ex_data(&skin->ex_data, bone_data, data, obj_db); + + if (osage_reset && osage_blocks.size()) + osage_iterations = 60; +} + +void rob_chara_item_equip_object::set_alpha_draw_task_flags(float_t alpha, int32_t flags) { + draw_task_flags = (::draw_task_flags)flags; + alpha = clamp(alpha, 0.0f, 1.0f); +} + +bool rob_chara_item_equip_object::set_boc( + skin_param_osage_root& skp_root, ExOsageBlock* osg) { + RobOsage* rob_osg = &osg->rob; + RobOsageNode* i_begin = rob_osg->nodes.data() + 1; + RobOsageNode* i_end = rob_osg->nodes.data() + rob_osg->nodes.size(); + for (RobOsageNode* i = i_begin; i != i_end; i++) + i->data_ptr->boc.clear(); + + bool v6 = false; + for (skin_param_osage_root_boc& i : skp_root.boc) { + for (ExOsageBlock*& j : osage_blocks) { + if (str_utils_compare(j->name, i.ed_root.c_str()) + || i.ed_node + 1ULL >= rob_osg->nodes.size() + || i.st_node + 1ULL >= j->rob.nodes.size()) + continue; + + RobOsageNode* v17 = rob_osg->GetNode(i.ed_node + 1LL); + RobOsageNode* v18 = j->rob.GetNode(i.st_node + 1LL); + v17->data_ptr->boc.push_back(v18); + v6 = true; + break; + } + } + return v6; +} + +void rob_chara_item_equip_object::set_collision_target_osage(skin_param_osage_root& skp_root, skin_param* skp) { + if (!skp_root.colli_tgt_osg.size()) + return; + + const char* colli_tgt_osg = skp_root.colli_tgt_osg.c_str(); + for (ExOsageBlock*& i : osage_blocks) + if (!str_utils_compare(colli_tgt_osg, i->name)) { + skp->colli_tgt_osg = &i->rob.nodes; + break; + } +} + +void rob_chara_item_equip_object::set_motion_reset_data(int32_t motion_id, float_t frame) { + for (ExOsageBlock*& i : osage_blocks) + i->SetMotionResetData(motion_id, frame); + + for (ExClothBlock*& i : cloth_blocks) + i->SetMotionResetData(motion_id, frame); +} + +void rob_chara_item_equip_object::set_motion_skin_param(int8_t chara_id, int32_t motion_id, int32_t frame) { + if (obj_info.is_null()) + return; + + struc_571** v7 = 0;//sub_14060B470(chara_id, obj_info, motion_id, frame); + if (!v7) + return; + + struc_571* v9 = *v7; + field_1B8 = 0; + for (ExOsageBlock*& i : osage_blocks) { + field_1B8 |= v9->field_88; + i->SetSkinParam(v9++); + } + + for (ExClothBlock*& i : cloth_blocks) { + field_1B8 |= v9->field_88; + i->SetSkinParam(v9++); + } +} + +void rob_chara_item_equip_object::set_null_blocks_expression_data(vec3* position, vec3* rotation, vec3* scale) { + vec3 pos = *position; + vec3 rot; + vec3_mult_scalar(*rotation, DEG_TO_RAD_FLOAT, rot); + vec3 sc = *scale; + + null_blocks_data_set = true; + for (ExNullBlock*& i : null_blocks) { + if (!i || !i->bone_node_ptr) + continue; + + bone_node_expression_data* node_exp_data = &i->bone_node_ptr->exp_data; + node_exp_data->position = pos; + node_exp_data->rotation = rot; + node_exp_data->scale = sc; + } +} + +void rob_chara_item_equip_object::set_osage_reset() { + for (ExOsageBlock*& i : osage_blocks) + i->SetOsageReset(); + + for (ExClothBlock*& i : cloth_blocks) + i->SetOsageReset(); +} + +void rob_chara_item_equip_object::set_osage_move_cancel(float_t value) { + for (ExOsageBlock*& i : osage_blocks) + i->rob.move_cancel = value; + for (ExClothBlock*& i : cloth_blocks) + i->rob.move_cancel = value; +} + +void rob_chara_item_equip_object::set_texture_pattern(texture_pattern_struct* tex_pat, size_t count) { + texture_pattern.clear(); + if (count && tex_pat) + for (size_t i = 0; i < count; i++) + texture_pattern.push_back(tex_pat[i]); +} + +void rob_chara_item_equip_object::skp_load(void* kv, bone_database* bone_data) { + key_val* _kv = (key_val*)kv; + if (_kv->key.size() < 1) + return; + + field_1B8 = 0; + for (ExOsageBlock*& i : osage_blocks) { + ExOsageBlock* osg = i; + skin_param_osage_root root; + osg->rob.LoadSkinParam(_kv, osg->name, root, &obj_info, bone_data); + set_collision_target_osage(root, osg->rob.skin_param_ptr); + field_1B8 |= set_boc(root, osg); + field_1B8 |= root.coli_type != 0; + field_1B8 |= skp_load_normal_ref(root, 0); + } + + for (ExClothBlock*& i : cloth_blocks) { + ExClothBlock* cls = i; + cls->rob.LoadSkinParam(_kv, cls->name, bone_data); + } +} + +void rob_chara_item_equip_object::skp_load_file(void* data, + bone_database* bone_data, object_database* obj_db) { + key_val* kv_ptr = 0;//sub_14060B4B0(itm_eq_obj->object_info); + if (kv_ptr) { + skp_load(kv_ptr, bone_data); + return; + } + + char buf[0x200]; + const char* name = obj_db->get_object_name(obj_info); + sprintf_s(buf, sizeof(buf), "ext_skp_%s.txt", name); + + for (int32_t i = 0; buf[i]; i++) + if (buf[i] > 0x40 && buf[i] < 0x5B) + buf[i] += 0x20; + + key_val kv; + ((data_struct*)data)->load_file(&kv, "rom/skin_param/", buf, key_val::load_file); + skp_load(&kv, bone_data); +} + +bool rob_chara_item_equip_object::skp_load_normal_ref( + skin_param_osage_root& skp_root, std::vector* node_data) { + if (!skp_root.normal_ref.size()) + return true; + + for (skin_param_osage_root_normal_ref& i : skp_root.normal_ref) { + size_t v12 = 0; + RobOsageNode* v8 = get_normal_ref_osage_node(i.n, &v12); + if (!v8) + continue; + + RobOsageNodeData* v10; + if (node_data) + v10 = &(*node_data)[v12]; + else + v10 = v8->data_ptr; + + v10->normal_ref.n = v8; + v10->normal_ref.u = get_normal_ref_osage_node(i.u, 0); + v10->normal_ref.d = get_normal_ref_osage_node(i.d, 0); + v10->normal_ref.l = get_normal_ref_osage_node(i.l, 0); + v10->normal_ref.r = get_normal_ref_osage_node(i.r, 0); + v10->normal_ref.GetMat(); + } + return true; } rob_chara_item_equip::rob_chara_item_equip() : bone_nodes(), matrices(), item_equip_object(), field_18(), @@ -16278,7 +12695,7 @@ void rob_chara_item_equip::reset() { bone_nodes = 0; matrices = 0; for (int32_t i = ITEM_BODY; i < ITEM_MAX; i++) - rob_chara_item_equip_object_init_members(&item_equip_object[i]); + item_equip_object[i].init_members(); item_equip_range = false; shadow_type = (shadow_type_enum)-1; field_A0 = 5; @@ -17136,25 +13553,6 @@ inline void mothead_storage_free() { mothead_storage_data.clear(); } -inline void osage_setting_data_init() { - osage_setting_data.cat = {}; - osage_setting_data.obj = {}; -} - -inline bool osage_setting_data_load_file(void* data, const char* path, const char* file, uint32_t hash) { - key_val kv; - if (key_val::load_file(&kv, path, file, hash)) { - osage_setting_data.parse(&kv); - return true; - } - return false; -} - -inline void osage_setting_data_free() { - osage_setting_data.cat.clear(); - osage_setting_data.obj.clear(); -} - MotFile::MotFile() : mot_set_info(), mot_set(), load_count() { FreeData(); } @@ -17372,88 +13770,6 @@ void MhdFile::ParseFileParent(void* data, const void* file_data, size_t size) { ((MhdFile*)data)->ParseFile(file_data); } -osage_setting::osage_setting() { - -} - -osage_setting::~osage_setting() { - -} - -void osage_setting::parse(key_val* kv) { - int32_t count; - if (kv->read("cat", "length", count)) { - for (int32_t i = 0; i < count; i++) { - if (!kv->open_scope(i)) - continue; - - std::string name; - kv->read("name", name); - - int32_t count; - if (kv->read("osg", "length", count)) { - for (int32_t j = 0; j < count; j++) { - if (!kv->open_scope(j)) - continue; - - int32_t exf = 0; - kv->read("exf", exf); - - std::string parts; - kv->read("parts", parts); - - std::string root; - kv->read("root", root); - - std::pair key = { name, root }; - auto elem = cat.find(key); - if (elem == cat.end()) - elem = cat.insert({ key, {} }).first; - - elem->second.exf = exf; - elem->second.parts = parse_parts_string(&parts); - kv->close_scope(); - } - kv->close_scope(); - } - kv->close_scope(); - } - kv->close_scope(); - } - - data_struct* aft_data = &data_list[DATA_AFT]; - object_database* aft_obj_db = &aft_data->data_ft.obj_db; - - if (kv->read("obj", "length", count)) { - for (int32_t i = 0; i < count; i++) { - if (!kv->open_scope(i)) - continue; - - std::string cat; - kv->read("cat", cat); - - std::string name; - kv->read("name", name); - - obj.insert_or_assign(aft_obj_db->get_object_info(name.c_str()), cat); - kv->close_scope(); - } - kv->close_scope(); - } -} - -rob_osage_parts osage_setting::parse_parts_string(std::string* s) { - static const char* parts_string_array[] = { - "LEFT", "RIGHT", "CENTER", "LONG_C", "SHORT_L", "SHORT_R", - "APPEND_L", "APPEND_R", "MUFFLER", "WHITE_ONE_L", "PONY", "ANGEL_L", "ANGEL_R", - }; - - for (const char*& i : parts_string_array) - if (!s->compare(i)) - return (rob_osage_parts)(&i - parts_string_array); - return ROB_OSAGE_PARTS_NONE; -} - ReqData::ReqData() : chara_index(), count() { } diff --git a/src/CRE/rob.hpp b/src/CRE/rob/rob.hpp similarity index 89% rename from src/CRE/rob.hpp rename to src/CRE/rob/rob.hpp index b4152659..5b0d0f27 100644 --- a/src/CRE/rob.hpp +++ b/src/CRE/rob/rob.hpp @@ -5,16 +5,16 @@ #pragma once -#include "../KKdLib/default.hpp" -#include "../KKdLib/database/bone.hpp" -#include "../KKdLib/database/motion.hpp" -#include "../KKdLib/mat.hpp" -#include "../KKdLib/mot.hpp" -#include "../KKdLib/vec.hpp" -#include "draw_object.h" -#include "item_table.hpp" -#include "object.hpp" -#include "static_var.h" +#include "../../KKdLib/default.hpp" +#include "../../KKdLib/database/bone.hpp" +#include "../../KKdLib/database/motion.hpp" +#include "../../KKdLib/mat.hpp" +#include "../../KKdLib/mot.hpp" +#include "../../KKdLib/vec.hpp" +#include "../draw_object.hpp" +#include "../item_table.hpp" +#include "../object.hpp" +#include "../static_var.hpp" enum ex_expression_block_stack_type { EX_EXPRESSION_BLOCK_STACK_NUMBER = 0x00, @@ -823,6 +823,13 @@ struct bone_node_expression_data { vec3 parent_scale; bone_node_expression_data(); + + void mat_set(vec3& parent_scale, mat4& ex_data_mat, mat4& mat); + void reset_scale(); + void set_position_rotation(float_t position_x, float_t position_y, float_t position_z, + float_t rotation_x, float_t rotation_y, float_t rotation_z); + void set_position_rotation(vec3& position, vec3& rotation); + }; struct bone_node { @@ -833,6 +840,9 @@ struct bone_node { mat4* ex_data_mat; bone_node(); + + float_t* get_exp_data_component(size_t index, ex_expression_block_stack_type& type); + }; struct struc_314 { @@ -1273,7 +1283,7 @@ struct rob_chara_bone_data { void reset(); }; -union rob_chara_pv_data_customize_items { +union rob_chara_pv_data_item { struct { int32_t head; int32_t face; @@ -1297,7 +1307,7 @@ struct rob_chara_pv_data { int32_t motion_face_ids[10]; int32_t chara_size_index; bool height_adjust; - rob_chara_pv_data_customize_items customize_items; + rob_chara_pv_data_item item; eyes_adjust eyes_adjust; rob_chara_pv_data(); @@ -1354,7 +1364,7 @@ public: virtual void Field_18(int32_t stage, bool a3) = 0; virtual void Field_20() = 0; virtual void SetOsagePlayData() = 0; - virtual void Disp() = 0; + virtual void Disp(mat4* mat, render_context* rctx) = 0; virtual void Reset(); virtual void Field_40() = 0; virtual void Field_48() = 0; @@ -1376,63 +1386,27 @@ public: virtual void Field_18(int32_t stage, bool a3) override; virtual void Field_20() override; virtual void SetOsagePlayData() override; - virtual void Disp() override; - virtual void Reset(); + virtual void Disp(mat4* mat, render_context* rctx) override; virtual void Field_40() override; virtual void Field_48() override; virtual void Field_50() override; - virtual void Field_58(); void InitData(rob_chara_item_equip_object* itm_eq_obj, obj_skin_block_constraint* cns_data, const char* cns_data_name, bone_database* bone_data); }; -struct struc_571; +struct RobOsageNode; -struct ExClothBlock : public ExNodeBlock { -public: - //rob_cloth rob; - obj_skin_block_cloth* cls_data; - mat4* field_2428; - size_t index; - - ExClothBlock(); - virtual ~ExClothBlock() override; - virtual void Init() override; - virtual void Field_10(); - virtual void Field_18(int32_t stage, bool a3) override; - virtual void Field_20() override; - virtual void SetOsagePlayData() override; - virtual void Disp() override; - virtual void Reset() override; - virtual void Field_40() override; - virtual void Field_48() override; - virtual void Field_50() override; - virtual void Field_58(); - - void AddMotionResetData(int32_t motion_id, float_t frame); - float_t* LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count); - void SetMotionResetData(int32_t motion_id, float_t frame); - void SetOsageReset(); - void SetSkinParam(struc_571* skp); -}; - -struct opd_vec3_data { - float_t* x; - float_t* y; - float_t* z; -}; - -struct rob_osage_node; - -struct rob_osage_node_data_normal_ref { +struct RobOsageNodeDataNormalRef { bool field_0; - rob_osage_node* n; - rob_osage_node* u; - rob_osage_node* d; - rob_osage_node* l; - rob_osage_node* r; + RobOsageNode* n; + RobOsageNode* u; + RobOsageNode* d; + RobOsageNode* l; + RobOsageNode* r; mat4u mat; + + void GetMat(); }; struct skin_param_hinge { @@ -1457,21 +1431,34 @@ struct skin_param_osage_node { ~skin_param_osage_node(); }; -struct rob_osage_node_data { +struct RobOsageNodeResetData { + vec3 trans; + vec3 trans_diff; + vec3 rotation; + float_t length; +}; + +struct RobOsageNodeData { float_t force; - std::vector boc; - rob_osage_node_data_normal_ref normal_ref; + std::vector boc; + RobOsageNodeDataNormalRef normal_ref; skin_param_osage_node skp_osg_node; - rob_osage_node_data(); - ~rob_osage_node_data(); + RobOsageNodeData(); + ~RobOsageNodeData(); - void reset(); + void Reset(); +}; + +struct opd_vec3_data { + float_t* x; + float_t* y; + float_t* z; }; struct struc_477 { float_t length; - vec3 angle; + vec3 rotation; }; struct struc_476 { @@ -1479,14 +1466,7 @@ struct struc_476 { struc_477 field_10; }; -struct rob_osage_node_reset_data { - vec3 trans; - vec3 trans_diff; - vec3 rotation; - float_t length; -}; - -struct rob_osage_node { +struct RobOsageNode { float_t length; vec3 trans; vec3 trans_orig; @@ -1496,23 +1476,23 @@ struct rob_osage_node { bone_node* bone_node_ptr; mat4* bone_node_mat; mat4u mat; - rob_osage_node* sibling_node; + RobOsageNode* sibling_node; float_t max_distance; vec3 field_94; - rob_osage_node_reset_data reset_data; + RobOsageNodeResetData reset_data; float_t field_C8; float_t field_CC; vec3 external_force; float_t force; - rob_osage_node_data* data_ptr; - rob_osage_node_data data; + RobOsageNodeData* data_ptr; + RobOsageNodeData data; std::vector opd_data; struc_476 field_1B0; - rob_osage_node(); - ~rob_osage_node(); + RobOsageNode(); + ~RobOsageNode(); - void reset(); + void Reset(); }; struct skin_param_osage_root_coli { @@ -1589,7 +1569,7 @@ struct skin_param { skin_param_hinge hinge; float_t force; float_t force_gain; - std::vector* colli_tgt_osg; + std::vector* colli_tgt_osg; skin_param(); ~skin_param(); @@ -1597,15 +1577,6 @@ struct skin_param { void reset(); }; -struct struc_571 { - skin_param skin_param; - std::vector nodes_data; - bool field_88; - - struc_571(); - ~struc_571(); -}; - struct osage_coli { skin_param_osage_root_coli_type type; float_t radius; @@ -1618,6 +1589,10 @@ struct osage_coli { osage_coli(); ~osage_coli(); + + static void set(osage_coli* coli, skin_param_osage_root_coli* skp_root_coli, mat4* mats); + static void ring_set(osage_coli* coli, + std::vector& vec_skp_root_coli, mat4* mats); }; struct osage_ring_data { @@ -1635,6 +1610,181 @@ struct osage_ring_data { ~osage_ring_data(); }; +struct struc_571; + +struct CLOTHNode { + uint32_t flags; + vec3 trans; + vec3 trans_orig; + vec3 field_1C; + vec3 trans_diff; + vec3 normal; + vec3 tangent; + vec3 binormal; + float_t tangent_sign; + vec2 texcoord; + vec3 field_64; + float_t length; + float_t field_74; + float_t field_78; + float_t field_7C; + int64_t field_80; + int32_t field_88; + RobOsageNodeResetData reset_data; + int32_t field_B4; + std::vector opd_data; + struc_476 field_D0; + + CLOTHNode(); + ~CLOTHNode(); +}; + +struct struc_341 { + size_t field_0; + size_t field_8; + float_t length; +}; + +struct CLOTH { + int32_t field_8; + size_t root_count; + size_t nodes_count; + std::vector nodes; + vec3 wind_direction; + float_t field_44; + bool set_external_force; + vec3 external_force; + std::vector field_58; + skin_param* skin_param_ptr; + skin_param skin_param; + osage_coli coli[64]; + osage_coli coli_ring[64]; + osage_ring_data ring; + mat4u* mats; + + CLOTH(); + virtual ~CLOTH(); + + virtual void Init(); + virtual void SetSkinParamColiR(float_t coli_r); + virtual void SetSkinParamFriction(float_t friction); + virtual void SetSkinParamWindAfc(float_t wind_afc); + virtual void SetWindDirection(vec3& wind_direction); + virtual void Field_30(float_t a2); + virtual void SetSkinParamHinge(float_t hinge_y, float_t hinge_z); + virtual CLOTHNode* GetNodes(); + virtual void Reset(); + virtual void ResetData(); +}; + +struct RobClothRoot { + vec3 trans; + vec3 normal; + vec4u tangent; + bone_node* node[4]; + mat4* node_mat[4]; + mat4u* mat[4]; + float_t weight[4]; + mat4u field_98; + mat4u field_D8; + mat4u field_118; +}; + +struct RobClothSubMeshArray { + obj_sub_mesh arr[4]; + + RobClothSubMeshArray(); +}; + +struct opd_blend_data { + int32_t motion_id; + float_t frame; + float_t frame_count; + bool field_C; + MotionBlendType type; + float_t blend; +}; + +struct RobCloth : public CLOTH { + std::vector root; + rob_chara_item_equip_object* itm_eq_obj; + obj_skin_block_cloth_root* cls_root; + obj_skin_block_cloth* cls_data; + float_t move_cancel; + bool osage_reset; + obj_mesh mesh[2]; + RobClothSubMeshArray submesh[2]; + obj_mesh_vertex_buffer vertex_buffer[2]; + obj_mesh_index_buffer index_buffer[2]; + std::map, std::list> motion_reset_data; + std::list* reset_data_list; + + RobCloth(); + virtual ~RobCloth() override; + + virtual void ResetData() override; + + void AddMotionResetData(int32_t motion_id, float_t frame); + void ColiSet(mat4* mats); + void Disp(mat4* mat, render_context* rctx); + void InitData(size_t root_count, size_t nodes_count, obj_skin_block_cloth_root* root, + obj_skin_block_cloth_node* nodes, mat4u* mats, int32_t a7, + rob_chara_item_equip_object* itm_eq_obj, bone_database* bone_data); + void InitDataParent(obj_skin_block_cloth* cls_data, + rob_chara_item_equip_object* itm_eq_obj, bone_database* bone_data); + float_t* LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count); + void LoadSkinParam(void* kv, const char* name, bone_database* bone_data); + void SetForceAirRes(float_t force, float_t force_gain, float_t air_res); + void SetMotionResetData(int32_t motion_id, float_t frame); + void SetOsagePlayData(std::vector& opd_blend_data); + void SetSkinParamOsageRoot(skin_param_osage_root& skp_root); + void UpdateDisp(); + void UpdateNormals(); + + static void UpdateVertexBuffer(obj_mesh* mesh, obj_mesh_vertex_buffer* vertex_buffer, + CLOTHNode* node, float_t facing, int32_t indices_count, uint16_t* indices, bool double_faced); +}; + +struct ExClothBlock : public ExNodeBlock { +public: + RobCloth rob; + obj_skin_block_cloth* cls_data; + mat4* mats; + size_t index; + + ExClothBlock(); + virtual ~ExClothBlock() override; + + virtual void Init() override; + virtual void Field_10(); + virtual void Field_18(int32_t stage, bool a3) override; + virtual void Field_20() override; + virtual void SetOsagePlayData() override; + virtual void Disp(mat4* mat, render_context* rctx) override; + virtual void Reset() override; + virtual void Field_40() override; + virtual void Field_48() override; + virtual void Field_50() override; + + void AddMotionResetData(int32_t motion_id, float_t frame); + void InitData(rob_chara_item_equip_object* itm_eq_obj, obj_skin_block_cloth* cls_data, + skin_param_osage_root* skp_root, bone_database* bone_data); + float_t* LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count); + void SetMotionResetData(int32_t motion_id, float_t frame); + void SetOsageReset(); + void SetSkinParam(struc_571* skp); + void SetSkinParamOsageRoot(skin_param_osage_root* skp_root); +}; + +struct struc_571 { + skin_param skin_param; + std::vector nodes_data; + bool field_88; + + struc_571(); + ~struc_571(); +}; + struct osage_setting_osg_cat { rob_osage_parts parts; size_t exf; @@ -1642,11 +1792,11 @@ struct osage_setting_osg_cat { osage_setting_osg_cat(); }; -struct rob_osage { +struct RobOsage { skin_param* skin_param_ptr; bone_node_expression_data exp_data; - std::vector nodes; - rob_osage_node node; + std::vector nodes; + RobOsageNode node; skin_param skin_param; osage_setting_osg_cat osage_setting; bool field_2A0; @@ -1666,21 +1816,44 @@ struct rob_osage { bool field_1F0E; bool field_1F0F; osage_ring_data ring; - std::map, std::list> motion_reset_data; - std::list* reset_data_list; + std::map, std::list> motion_reset_data; + std::list* reset_data_list; bool set_external_force; vec3 external_force; - rob_osage(); - ~rob_osage(); + RobOsage(); + ~RobOsage(); - void reset(); + void AddMotionResetData(int32_t motion_id, float_t frame); + bool CheckPartsBits(rob_osage_parts_bit parts_bits); + void ColiSet(mat4* mats); + RobOsageNode* GetNode(size_t index); + void InitData(obj_skin_block_osage* osg_data, obj_skin_osage_node* osg_nodes, + bone_node* ex_data_bone_nodes, obj_skin* skin); + float_t* LoadOpdData(size_t node_index, float_t* opd_data, size_t opd_count); + void LoadSkinParam(void* kv, const char* name, + skin_param_osage_root& skp_root, object_info* obj_info, bone_database* bone_data); + void Reset(); + void SetAirRes(float_t air_res); + void SetColiR(float_t coli_r); + void SetForce(float_t force, float_t force_gain); + void SetHinge(float_t hinge_y, float_t hinge_z); + void SetInitRot(float_t init_rot_y, float_t init_rot_z); + void SetMotionResetData(int32_t motion_id, float_t frame); + void SetNodesExternalForce(vec3* external_force, float_t strength); + void SetNodesForce(float_t force); + void SetOsagePlayData(mat4* parent_mat, + vec3& parent_scale, std::vector& opd_blend_data); + void SetRot(float_t rot_y, float_t rot_z); + void SetSkinParamOsageRoot(skin_param_osage_root& skp_root); + void SetSkpOsgNodes(std::vector* skp_osg_nodes); + void SetYZOrder(int32_t yz_order); }; class ExOsageBlock : public ExNodeBlock { public: size_t index; - rob_osage rob; + RobOsage rob; mat4* mats; int32_t field_1FF8; float_t step; @@ -1692,7 +1865,7 @@ public: virtual void Field_18(int32_t stage, bool a3) override; virtual void Field_20() override; virtual void SetOsagePlayData() override; - virtual void Disp() override; + virtual void Disp(mat4* mat, render_context* rctx) override; virtual void Reset() override; virtual void Field_40() override; virtual void Field_48() override; @@ -1709,7 +1882,7 @@ public: void SetSkinParam(struc_571* skp); void SetWindDirection(); void sub_1405F3E10(obj_skin_block_osage* osg_data, obj_skin_osage_node* osg_nodes, - std::vector>* a4, + std::vector>* a4, std::map* a5); }; @@ -1728,12 +1901,10 @@ public: virtual void Field_18(int32_t stage, bool a3) override; virtual void Field_20() override; virtual void SetOsagePlayData() override; - virtual void Disp() override; - virtual void Reset(); + virtual void Disp(mat4* mat, render_context* rctx) override; virtual void Field_40() override; virtual void Field_48() override; virtual void Field_50() override; - virtual void Field_58(); void Calc(); void DataSet(); @@ -1807,12 +1978,10 @@ public: virtual void Field_18(int32_t stage, bool a3) override; virtual void Field_20() override; virtual void SetOsagePlayData() override; - virtual void Disp() override; - virtual void Reset(); + virtual void Disp(mat4* mat, render_context* rctx) override; virtual void Field_40() override; virtual void Field_48() override; virtual void Field_50() override; - virtual void Field_58(); void Calc(); void DataSet(); @@ -1838,7 +2007,7 @@ struct rob_chara_item_equip_object { bone_node_expression_data exp_data; float_t alpha; draw_task_flags draw_task_flags; - bool disp; + bool can_disp; int32_t field_A4; mat4* mat; int32_t osage_iterations; @@ -1863,15 +2032,34 @@ struct rob_chara_item_equip_object { rob_chara_item_equip_object(); virtual ~rob_chara_item_equip_object(); -}; -struct opd_blend_data { - int32_t motion_id; - float_t frame; - float_t frame_count; - bool field_C; - MotionBlendType type; - float_t blend; + void add_motion_reset_data(int32_t motion_id, float_t frame, int32_t osage_iterations); + void check_no_opd(std::vector& opd_blend_data); + void clear_ex_data(); + void disp(mat4* mat, render_context* rctx); + int32_t get_bone_index(const char* name, bone_database* bone_data); + bone_node* get_bone_node(int32_t bone_index); + bone_node* get_bone_node(const char* name, bone_database* bone_data); + RobOsageNode* get_normal_ref_osage_node(std::string& name, size_t* index); + void get_parent_bone_nodes(bone_node* bone_nodes, bone_database* bone_data); + void init_ex_data_bone_nodes(obj_skin_ex_data* ex_data); + void init_members(size_t index = 0xDEADBEEF); + void load_ex_data(obj_skin_ex_data* ex_data, + bone_database* bone_data, void* data, object_database* obj_db); + void load_object_info_ex_data(object_info object_info, bone_node* bone_nodes, + bool osage_reset, bone_database* bone_data, void* data, object_database* obj_db); + void set_alpha_draw_task_flags(float_t alpha, int32_t flags); + bool set_boc(skin_param_osage_root& skp_root, ExOsageBlock* osg); + void set_collision_target_osage(skin_param_osage_root& skp_root, skin_param* skp); + void set_motion_reset_data(int32_t motion_id, float_t frame); + void set_motion_skin_param(int8_t chara_id, int32_t motion_id, int32_t frame); + void set_null_blocks_expression_data(vec3* position, vec3* rotation, vec3* scale); + void set_osage_reset(); + void set_osage_move_cancel(float_t value); + void set_texture_pattern(texture_pattern_struct* tex_pat, size_t count); + void skp_load(void* kv, bone_database* bone_data); + void skp_load_file(void* data, bone_database* bone_data, object_database* obj_db); + bool skp_load_normal_ref(skin_param_osage_root& skp_root, std::vector* node_data); }; struct rob_chara_item_equip { @@ -3005,6 +3193,8 @@ extern int32_t chara_init_data_get_chara_size_index(chara_index chara_index); extern float_t chara_pos_adjust_y_table_get_value(uint32_t index); extern float_t chara_size_table_get_value(uint32_t index); +extern const float_t get_osage_gravity_const(); + extern void motion_set_load_mothead(uint32_t set, std::string* mdata_dir, motion_database* mot_db); extern void motion_set_load_motion(uint32_t set, std::string* mdata_dir, motion_database* mot_db); extern void motion_set_unload_mothead(uint32_t set); @@ -3046,4 +3236,11 @@ extern void mothead_storage_free(); extern void osage_setting_data_init(); extern bool osage_setting_data_load_file(void* data, const char* path, const char* file, uint32_t hash); +extern bool osage_setting_data_obj_has_key(object_info key); extern void osage_setting_data_free(); + +extern void skin_param_osage_node_parse(void* kv, const char* name, + std::vector* a3, skin_param_osage_root& skp_root); + +extern void skin_param_osage_root_parse(void* kv, const char* name, + skin_param_osage_root& skp_root, bone_database* bone_data); diff --git a/src/CRE/shader.c b/src/CRE/shader.cpp similarity index 98% rename from src/CRE/shader.c rename to src/CRE/shader.cpp index dfab66b0..fbe90255 100644 --- a/src/CRE/shader.c +++ b/src/CRE/shader.cpp @@ -3,11 +3,11 @@ GitHub/GitLab: korenkonder */ -#include "shader.h" +#include "shader.hpp" #include "../KKdLib/io/path.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" -#include "gl_state.h" +#include "gl_state.hpp" #include struct program_binary { @@ -27,6 +27,71 @@ static bool shader_parse_define(const char* data, int32_t num_uniform, static char* shader_parse_include(char* data, farc* f); static void shader_update_data(shader_set_data* set); +shader_state_clip::shader_state_clip() { + +} + +shader_state_depth::shader_state_depth() { + +} + +shader_state_fog::shader_state_fog() { + +} + +shader_state_light::shader_state_light() { + +} + +shader_state_lightmodel::shader_state_lightmodel() { + +} + +shader_state_lightprod::shader_state_lightprod() { + +} + +shader_state_material::shader_state_material() { + +} + +shader_state_matrix_data::shader_state_matrix_data() { + +} + +shader_state_matrix::shader_state_matrix() { + +} + +shader_state_point::shader_state_point() { + +} + +shader_state_texgen::shader_state_texgen() { + +} + +shader_state_texenv::shader_state_texenv() { + +} + +shader_buffer::shader_buffer() { + +} + +shader_env::shader_env() { + +} + +shader_state::shader_state() { + +} + +shader_data::shader_data() : state_update_data(), state_matrix_update_data(), +env_update_data(), buffer_update_data(), state_ubo(), state_matrix_ubo(), env_ubo(), buffer_ubo() { + +} + int32_t shader::bind(uint32_t sub_index) { int32_t sub_shader_index = 0; if (num_sub < 1) @@ -77,6 +142,10 @@ void shader::unbind() { gl_state_bind_uniform_buffer_base(3, 0); } +shader_set_data::shader_set_data() : shaders(), size(), data() { + +} + void shader_set_data::draw_arrays(GLenum mode, GLint first, GLsizei count) { shader_update_data(this); glDrawArrays(mode, first, count); @@ -438,10 +507,10 @@ void shader_set_data::set(uint32_t index) { shader->bind_func(this, shader); else shader->bind(shader->sub[0].sub_index); - gl_state_bind_uniform_buffer_base(0, data.state_ubo); - gl_state_bind_uniform_buffer_base(1, data.state_matrix_ubo); - gl_state_bind_uniform_buffer_base(2, data.env_ubo); - gl_state_bind_uniform_buffer_base(3, data.buffer_ubo); + gl_state_bind_uniform_buffer_range(0, data.state_ubo, 0, sizeof(data.state)); + gl_state_bind_uniform_buffer_range(1, data.state_matrix_ubo, 0, sizeof(data.state_matrix)); + gl_state_bind_uniform_buffer_range(2, data.env_ubo, 0, sizeof(data.env)); + gl_state_bind_uniform_buffer_range(3, data.buffer_ubo, 0, sizeof(data.buffer)); } else shader::unbind(); diff --git a/src/CRE/shader.h b/src/CRE/shader.hpp similarity index 96% rename from src/CRE/shader.h rename to src/CRE/shader.hpp index aaa4f603..2e71c727 100644 --- a/src/CRE/shader.h +++ b/src/CRE/shader.hpp @@ -11,7 +11,7 @@ #include "../KKdLib/farc.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/vec.hpp" -#include "static_var.h" +#include "static_var.hpp" #define SHADER_MAX_CLIP_PLANES 8 #define SHADER_MAX_LIGHTS 8 @@ -29,15 +29,21 @@ struct shader_state_clip { vec4 plane; + + shader_state_clip(); }; struct shader_state_depth { vec4 range; + + shader_state_depth(); }; struct shader_state_fog { vec4 color; vec4 params; + + shader_state_fog(); }; struct shader_state_light { @@ -48,17 +54,23 @@ struct shader_state_light { vec4 attenuation; vec4 spot_direction; vec4 half; + + shader_state_light(); }; struct shader_state_lightmodel { vec4 ambient; vec4 scene_color; + shader_state_lightmodel(); + }; struct shader_state_lightprod { vec4 ambient; vec4 diffuse; vec4 specular; + + shader_state_lightprod(); }; struct shader_state_material { @@ -67,6 +79,8 @@ struct shader_state_material { vec4 specular; vec4 emission; vec4 shininess; + + shader_state_material(); }; struct shader_state_matrix_data { @@ -74,6 +88,8 @@ struct shader_state_matrix_data { mat4 inv; mat4 trans; mat4 invtrans; + + shader_state_matrix_data(); }; struct shader_state_matrix { @@ -83,11 +99,15 @@ struct shader_state_matrix { shader_state_matrix_data texture[SHADER_MAX_TEXTURE_COORDS]; shader_state_matrix_data palette[SHADER_MAX_PALETTE_MATRICES]; shader_state_matrix_data program[SHADER_MAX_PROGRAM_MATRICES]; + + shader_state_matrix(); }; struct shader_state_point { vec4 size; vec4 attenuation; + + shader_state_point(); }; struct shader_state_texgen { @@ -110,19 +130,27 @@ struct shader_state_texgen { vec4 object_q; }; }; + + shader_state_texgen(); }; struct shader_state_texenv { vec4 color; + + shader_state_texenv(); }; struct shader_buffer { vec4 buffer[SHADER_MAX_PROGRAM_PARAMETER_BUFFER_SIZE / sizeof(vec4)]; + + shader_buffer(); }; struct shader_env { vec4 frag[SHADER_MAX_PROGRAM_ENV_PARAMETERS]; vec4 vert[SHADER_MAX_PROGRAM_ENV_PARAMETERS]; + + shader_env(); }; struct shader_state { @@ -137,6 +165,8 @@ struct shader_state { shader_state_clip clip[SHADER_MAX_CLIP_PLANES]; shader_state_point point; shader_state_depth depth; + + shader_state(); }; struct shader_data { @@ -152,6 +182,8 @@ struct shader_data { GLuint state_matrix_ubo; GLuint env_ubo; GLuint buffer_ubo; + + shader_data(); }; struct shader; @@ -208,6 +240,8 @@ struct shader_set_data { size_t size; shader_data data; + shader_set_data(); + void draw_arrays(GLenum mode, GLint first, GLsizei count); void draw_elements(GLenum mode, GLsizei count, GLenum type, const void* indices); diff --git a/src/CRE/shader_ft.c b/src/CRE/shader_ft.cpp similarity index 99% rename from src/CRE/shader_ft.c rename to src/CRE/shader_ft.cpp index 3d9b1776..337cfef2 100644 --- a/src/CRE/shader_ft.c +++ b/src/CRE/shader_ft.cpp @@ -3,8 +3,8 @@ GitHub/GitLab: korenkonder */ -#include "shader_ft.h" -#include "gl_state.h" +#include "shader_ft.hpp" +#include "gl_state.hpp" enum shader_ft_sub_enum { SHADER_FT_SUB_SHADER_FFP = 0x00, @@ -2337,7 +2337,7 @@ glass_eye_struct glass_eye = { 0.0, { 0.0f, 0.0f, 0.0f }, 0, - { 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f, 0.0f }, 0, 0, 0, diff --git a/src/CRE/shader_ft.h b/src/CRE/shader_ft.hpp similarity index 99% rename from src/CRE/shader_ft.h rename to src/CRE/shader_ft.hpp index ea05ec60..e7343239 100644 --- a/src/CRE/shader_ft.h +++ b/src/CRE/shader_ft.hpp @@ -6,7 +6,7 @@ #pragma once #include "../KKdLib/default.hpp" -#include "shader.h" +#include "shader.hpp" enum shader_ft_enum { SHADER_FT_FFP = 0x00, diff --git a/src/CRE/shader_glsl.cpp b/src/CRE/shader_glsl.cpp index 2f3090e6..7ee5355b 100644 --- a/src/CRE/shader_glsl.cpp +++ b/src/CRE/shader_glsl.cpp @@ -6,8 +6,8 @@ #include "shader_glsl.hpp" #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" -#include "gl_state.h" -#include "static_var.h" +#include "gl_state.hpp" +#include "static_var.hpp" static const char* common_data_string = "layout (binding = 0, std140) uniform common_data {\n" @@ -39,7 +39,7 @@ shader_glsl::shader_glsl() : program() { } shader_glsl::~shader_glsl() { - + unload(); } GLint shader_glsl::get_uniform_location(const char* name) { diff --git a/src/CRE/shader_glsl.hpp b/src/CRE/shader_glsl.hpp index 908acf30..bd12d3a8 100644 --- a/src/CRE/shader_glsl.hpp +++ b/src/CRE/shader_glsl.hpp @@ -29,7 +29,7 @@ struct shader_glsl { std::vector> uniform_block; shader_glsl(); - ~shader_glsl(); + virtual ~shader_glsl(); GLint get_uniform_location(const char* name); void load(const char* vert_data, const char* frag_data, diff --git a/src/CRE/shared.c b/src/CRE/shared.cpp similarity index 72% rename from src/CRE/shared.c rename to src/CRE/shared.cpp index 9c91201e..030c087f 100644 --- a/src/CRE/shared.c +++ b/src/CRE/shared.cpp @@ -3,4 +3,4 @@ GitHub/GitLab: korenkonder */ -#include "shared.h" +#include "shared.hpp" diff --git a/src/CRE/shared.h b/src/CRE/shared.hpp similarity index 86% rename from src/CRE/shared.h rename to src/CRE/shared.hpp index 64d29567..79b5235e 100644 --- a/src/CRE/shared.h +++ b/src/CRE/shared.hpp @@ -8,4 +8,4 @@ #include "../KKdLib/default.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/vec.hpp" -#include "static_var.h" +#include "static_var.hpp" diff --git a/src/CRE/stage.cpp b/src/CRE/stage.cpp index 1b782ff1..1b534ef7 100644 --- a/src/CRE/stage.cpp +++ b/src/CRE/stage.cpp @@ -7,10 +7,10 @@ #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" #include "../KKdLib/vec.hpp" -#include "draw_task.h" +#include "rob/rob.hpp" +#include "draw_task.hpp" #include "light_param.hpp" #include "render_context.hpp" -#include "rob.hpp" namespace stage_detail { static void TaskStage_CtrlInner(stage_detail::TaskStage* a1); @@ -50,33 +50,46 @@ static void task_stage_set_ring(task_stage_info* stg_info, bool value); static void task_stage_set_sky(task_stage_info* stg_info, bool value); static void task_stage_set_stage_display(task_stage_info* stg_info, bool value); -stage_detail::TaskStage task_stage; -DtmStg dtm_stg; +stage_detail::TaskStage* task_stage; +DtmStg* dtm_stg; extern render_context* rctx_ptr; +extern bool task_stage_is_modern; extern bool light_chara_ambient; extern vec4 npr_spec_color; static uint16_t stage_counter; +void dtm_stg_init() { + dtm_stg = new DtmStg; +} + void dtm_stg_load(int32_t stage_index) { - if (app::TaskWork::CheckTaskReady(&dtm_stg)) + if (app::TaskWork::CheckTaskReady(dtm_stg)) return; - if (app::TaskWork::CheckTaskReady(&dtm_stg)) { - dtm_stg.stage_index = stage_index; - dtm_stg.load_stage_index = stage_index; + if (app::TaskWork::CheckTaskReady(dtm_stg)) { + dtm_stg->stage_index = stage_index; + dtm_stg->load_stage_index = stage_index; } - app::TaskWork::AppendTask(&dtm_stg, "DATA_TEST_STAGE"); + app::TaskWork::AppendTask(dtm_stg, "DATA_TEST_STAGE"); } bool dtm_stg_unload() { - return dtm_stg.SetDest(); + return dtm_stg->SetDest(); +} + +void dtm_stg_free() { + delete dtm_stg; +} + +void task_stage_init() { + task_stage = new stage_detail::TaskStage; } bool task_stage_check_not_loaded() { - return task_stage.load_stage_indices.size() || task_stage.state != 6; + return task_stage->load_stage_indices.size() || task_stage->state != 6; } void task_stage_current_set_effect_display(bool value) { @@ -115,23 +128,38 @@ void task_stage_current_set_stage_display(bool value) { } void task_stage_disp_shadow() { - stage_detail::TaskStage_DispShadow(&task_stage); + stage_detail::TaskStage_DispShadow(task_stage); } stage* task_stage_get_current_stage() { - return stage_detail::TaskStage_GetCurrentStage(&task_stage); + return stage_detail::TaskStage_GetCurrentStage(task_stage); +} + +int32_t task_stage_get_current_stage_index() { + task_stage_info stg_info; + task_stage_get_current_stage_info(&stg_info); + if (task_stage_has_stage_info(&stg_info)) + return task_stage_get_stage_index(&stg_info); + return -1; } void task_stage_get_current_stage_info(task_stage_info* stg_info) { - stage_detail::TaskStage_GetCurrentStageInfo(&task_stage, stg_info); + stage_detail::TaskStage_GetCurrentStageInfo(task_stage, stg_info); } void task_stage_get_loaded_stage_infos(std::vector* vec) { - stage_detail::TaskStage_GetLoadedStageInfos(&task_stage, vec); + stage_detail::TaskStage_GetLoadedStageInfos(task_stage, vec); } stage* task_stage_get_stage(task_stage_info stg_info) { - return stage_detail::TaskStage_GetStage(&task_stage, stg_info); + return stage_detail::TaskStage_GetStage(task_stage, stg_info); +} + +int32_t task_stage_get_stage_index(task_stage_info* stg_info) { + stage* stg = task_stage_get_stage(*stg_info); + if (stg) + return stg->index; + return -1; } bool task_stage_has_stage_info(task_stage_info* stg_info) { @@ -139,19 +167,20 @@ bool task_stage_has_stage_info(task_stage_info* stg_info) { } bool task_stage_load(const char* name) { - return stage_detail::TaskStage_Load(&task_stage, name); + task_stage_is_modern = false; + return stage_detail::TaskStage_Load(task_stage, name); } void task_stage_set_mat(mat4* mat) { - task_stage.mat = *mat; + task_stage->mat = *mat; } void task_stage_set_mat(mat4u* mat) { - task_stage.mat = *mat; + task_stage->mat = *mat; } void task_stage_set_stage(task_stage_info* stg_info) { - stage_detail::TaskStage_SetStage(&task_stage, *stg_info); + stage_detail::TaskStage_SetStage(task_stage, *stg_info); } void task_stage_set_stage_index(int32_t stage_index) { @@ -163,17 +192,21 @@ void task_stage_set_stage_index(int32_t stage_index) { std::vector stage_indices; stage_indices.push_back(stage_index); - task_stage.load_stage_indices.insert(task_stage.load_stage_indices.end(), + task_stage->load_stage_indices.insert(task_stage->load_stage_indices.end(), stage_indices.begin(), stage_indices.end()); } void task_stage_set_stage_indices(std::vector* stage_indices) { - task_stage.load_stage_indices.insert(task_stage.load_stage_indices.end(), + task_stage->load_stage_indices.insert(task_stage->load_stage_indices.end(), stage_indices->begin(), stage_indices->end()); } bool task_stage_unload() { - return task_stage.SetDest(); + return task_stage->SetDest(); +} + +void task_stage_free() { + delete task_stage; } static void stage_detail::TaskStage_CtrlInner(stage_detail::TaskStage* a1) { @@ -412,8 +445,9 @@ static bool stage_ctrl(stage* s) { } for (int32_t& i : s->auth_3d_ids) { - auth_3d_data_set_enable(&i, true); + auth_3d_data_set_repeat(&i, true); auth_3d_data_set_paused(&i, false); + auth_3d_data_set_enable(&i, true); auth_3d_data_set_visibility(&i, s->effect_display); auth_3d_data_set_frame_rate(&i, 0); } diff --git a/src/CRE/stage.hpp b/src/CRE/stage.hpp index c1d3bfc6..b3635e0b 100644 --- a/src/CRE/stage.hpp +++ b/src/CRE/stage.hpp @@ -82,11 +82,14 @@ public: virtual bool Dest() override; }; -extern DtmStg dtm_stg; +extern DtmStg* dtm_stg; +extern void dtm_stg_init(); extern void dtm_stg_load(int32_t stage_index); extern bool dtm_stg_unload(); +extern void dtm_stg_free(); +extern void task_stage_init(); extern bool task_stage_check_not_loaded(); extern void task_stage_current_set_effect_display(bool value); extern void task_stage_current_set_ground(bool value); @@ -95,9 +98,11 @@ extern void task_stage_current_set_sky(bool value); extern void task_stage_current_set_stage_display(bool value); extern void task_stage_disp_shadow(); extern stage* task_stage_get_current_stage(); +int32_t task_stage_get_current_stage_index(); extern void task_stage_get_current_stage_info(task_stage_info* stg_info); extern void task_stage_get_loaded_stage_infos(std::vector* vec); extern stage* task_stage_get_stage(task_stage_info stg_info); +int32_t task_stage_get_stage_index(task_stage_info* stg_info); extern bool task_stage_has_stage_info(task_stage_info* stg_info); extern bool task_stage_load(const char* name); extern void task_stage_set_mat(mat4* mat); @@ -106,3 +111,4 @@ extern void task_stage_set_stage(task_stage_info* stg_info); extern void task_stage_set_stage_index(int32_t stage_index); extern void task_stage_set_stage_indices(std::vector* stage_indices); extern bool task_stage_unload(); +extern void task_stage_free(); diff --git a/src/CRE/stage_modern.cpp b/src/CRE/stage_modern.cpp index bdab0dae..a06bf4a9 100644 --- a/src/CRE/stage_modern.cpp +++ b/src/CRE/stage_modern.cpp @@ -7,10 +7,10 @@ #include "../KKdLib/hash.hpp" #include "../KKdLib/str_utils.hpp" #include "../KKdLib/vec.hpp" -#include "draw_task.h" +#include "rob/rob.hpp" +#include "draw_task.hpp" #include "light_param.hpp" #include "render_context.hpp" -#include "rob.hpp" namespace stage_detail { static void TaskStageModern_CtrlInner(stage_detail::TaskStageModern* a1); @@ -50,17 +50,22 @@ static void task_stage_modern_set_ground(task_stage_modern_info* stg_info, bool static void task_stage_modern_set_sky(task_stage_modern_info* stg_info, bool value); static void task_stage_modern_set_stage_display(task_stage_modern_info* stg_info, bool value); -stage_detail::TaskStageModern task_stage_modern; +stage_detail::TaskStageModern* task_stage_modern; extern render_context* rctx_ptr; +extern bool task_stage_is_modern; extern bool light_chara_ambient; extern vec4 npr_spec_color; static uint16_t stage_counter; +void task_stage_modern_init() { + task_stage_modern = new stage_detail::TaskStageModern; +} + bool task_stage_modern_check_not_loaded() { - return task_stage_modern.load_stage_hashes.size() || task_stage_modern.state != 6; + return task_stage_modern->load_stage_hashes.size() || task_stage_modern->state != 6; } void task_stage_modern_current_set_effect_display(bool value) { @@ -92,23 +97,38 @@ void task_stage_modern_current_set_stage_display(bool value) { } void task_stage_modern_disp_shadow() { - stage_detail::TaskStageModern_DispShadow(&task_stage_modern); + stage_detail::TaskStageModern_DispShadow(task_stage_modern); } stage_modern* task_stage_modern_get_current_stage() { - return stage_detail::TaskStageModern_GetCurrentStage(&task_stage_modern); + return stage_detail::TaskStageModern_GetCurrentStage(task_stage_modern); +} + +uint32_t task_stage_modern_get_current_stage_hash() { + task_stage_modern_info stg_info; + task_stage_modern_get_current_stage_info(&stg_info); + if (task_stage_modern_has_stage_info(&stg_info)) + return task_stage_modern_get_stage_hash(&stg_info); + return hash_murmurhash_empty; } void task_stage_modern_get_current_stage_info(task_stage_modern_info* stg_info) { - stage_detail::TaskStageModern_GetCurrentStageInfo(&task_stage_modern, stg_info); + stage_detail::TaskStageModern_GetCurrentStageInfo(task_stage_modern, stg_info); } void task_stage_modern_get_loaded_stage_infos(std::vector* vec) { - stage_detail::TaskStageModern_GetLoadedStageInfos(&task_stage_modern, vec); + stage_detail::TaskStageModern_GetLoadedStageInfos(task_stage_modern, vec); } stage_modern* task_stage_modern_get_stage(task_stage_modern_info stg_info) { - return stage_detail::TaskStageModern_GetStage(&task_stage_modern, stg_info); + return stage_detail::TaskStageModern_GetStage(task_stage_modern, stg_info); +} + +uint32_t task_stage_modern_get_stage_hash(task_stage_modern_info* stg_info) { + stage_modern* stg = task_stage_modern_get_stage(*stg_info); + if (stg) + return stg->hash; + return -1; } bool task_stage_modern_has_stage_info(task_stage_modern_info* stg_info) { @@ -116,51 +136,56 @@ bool task_stage_modern_has_stage_info(task_stage_modern_info* stg_info) { } bool task_stage_modern_load(const char* name) { - return stage_detail::TaskStageModern_Load(&task_stage_modern, name); + task_stage_is_modern = true; + return stage_detail::TaskStageModern_Load(task_stage_modern, name); } void task_stage_modern_set_data(void* data, object_database* obj_db, texture_database* tex_db, stage_database* stage_data) { - task_stage_modern.data = data; - task_stage_modern.obj_db = obj_db; - task_stage_modern.tex_db = tex_db; - task_stage_modern.stage_data = stage_data; + task_stage_modern->data = data; + task_stage_modern->obj_db = obj_db; + task_stage_modern->tex_db = tex_db; + task_stage_modern->stage_data = stage_data; } void task_stage_modern_set_mat(mat4* mat) { - task_stage_modern.mat = *mat; + task_stage_modern->mat = *mat; } void task_stage_modern_set_mat(mat4u* mat) { - task_stage_modern.mat = *mat; + task_stage_modern->mat = *mat; } void task_stage_modern_set_stage(task_stage_modern_info* stg_info) { - stage_detail::TaskStageModern_SetStage(&task_stage_modern, *stg_info); + stage_detail::TaskStageModern_SetStage(task_stage_modern, *stg_info); } void task_stage_modern_set_stage_hash(uint32_t stage_hash, stage_data_modern* stg_data) { std::vector stage_hashes; stage_hashes.push_back(stage_hash); - task_stage_modern.load_stage_hashes.insert(task_stage_modern.load_stage_hashes.end(), + task_stage_modern->load_stage_hashes.insert(task_stage_modern->load_stage_hashes.end(), stage_hashes.begin(), stage_hashes.end()); std::vector stages_data; stages_data.push_back(stg_data); - task_stage_modern.load_stages_data.insert(task_stage_modern.load_stages_data.end(), + task_stage_modern->load_stages_data.insert(task_stage_modern->load_stages_data.end(), stages_data.begin(), stages_data.end()); } void task_stage_modern_set_stage_hashes(std::vector* stage_hashes, std::vector* load_stage_data) { - task_stage_modern.load_stage_hashes.insert(task_stage_modern.load_stage_hashes.end(), + task_stage_modern->load_stage_hashes.insert(task_stage_modern->load_stage_hashes.end(), stage_hashes->begin(), stage_hashes->end()); - task_stage_modern.load_stages_data.insert(task_stage_modern.load_stages_data.end(), + task_stage_modern->load_stages_data.insert(task_stage_modern->load_stages_data.end(), load_stage_data->begin(), load_stage_data->end()); } bool task_stage_modern_unload() { - return task_stage_modern.SetDest(); + return task_stage_modern->SetDest(); +} + +void task_stage_modern_free() { + delete task_stage_modern; } static void stage_detail::TaskStageModern_CtrlInner(stage_detail::TaskStageModern* a1) { diff --git a/src/CRE/stage_modern.hpp b/src/CRE/stage_modern.hpp index a5230a62..d6b862ef 100644 --- a/src/CRE/stage_modern.hpp +++ b/src/CRE/stage_modern.hpp @@ -73,6 +73,7 @@ struct task_stage_modern_info { task_stage_modern_info(); }; +extern void task_stage_modern_init(); extern bool task_stage_modern_check_not_loaded(); extern void task_stage_modern_current_set_effect_display(bool value); extern void task_stage_modern_current_set_ground(bool value); @@ -80,9 +81,11 @@ extern void task_stage_modern_current_set_sky(bool value); extern void task_stage_modern_current_set_stage_display(bool value); extern void task_stage_modern_disp_shadow(); extern stage_modern* task_stage_modern_get_current_stage(); +extern uint32_t task_stage_modern_get_current_stage_hash(); extern void task_stage_modern_get_current_stage_info(task_stage_modern_info* stg_info); extern void task_stage_modern_get_loaded_stage_infos(std::vector* vec); extern stage_modern* task_stage_modern_get_stage(task_stage_modern_info stg_info); +extern uint32_t task_stage_modern_get_stage_hash(task_stage_modern_info* stg_info); extern bool task_stage_modern_has_stage_info(task_stage_modern_info* stg_info); extern bool task_stage_modern_load(const char* name); extern void task_stage_modern_set_data(void* data, @@ -94,3 +97,4 @@ extern void task_stage_modern_set_stage_hash(uint32_t stage_hash, stage_data_mod extern void task_stage_modern_set_stage_hashes(std::vector* stage_hashes, std::vector* load_stage_data); extern bool task_stage_modern_unload(); +extern void task_stage_modern_free(); diff --git a/src/CRE/static_var.c b/src/CRE/static_var.cpp similarity index 93% rename from src/CRE/static_var.c rename to src/CRE/static_var.cpp index 9b7d7f3e..0209577c 100644 --- a/src/CRE/static_var.c +++ b/src/CRE/static_var.cpp @@ -3,10 +3,10 @@ GitHub/GitLab: korenkonder */ -#include "static_var.h" -#include "timer.h" +#include "static_var.hpp" +#include "timer.hpp" -extern timer render_timer; +extern timer* render_timer; int32_t sv_max_texture_buffer_size = 0x100000; int32_t sv_max_texture_size = 2048; @@ -57,7 +57,7 @@ float_t get_delta_frame() { if (!select_frame_speed) return frame_speed; - double_t freq_ratio = timer_get_freq_ratio(&render_timer); + double_t freq_ratio = render_timer->get_freq_ratio(); return (float_t)(freq_ratio * frame_speed); } diff --git a/src/CRE/static_var.h b/src/CRE/static_var.hpp similarity index 100% rename from src/CRE/static_var.h rename to src/CRE/static_var.hpp diff --git a/src/CRE/task.cpp b/src/CRE/task.cpp index 46b53bf8..415bdb25 100644 --- a/src/CRE/task.cpp +++ b/src/CRE/task.cpp @@ -4,7 +4,7 @@ */ #include "task.hpp" -#include "time.h" +#include "time.hpp" extern float_t get_delta_frame(); extern uint32_t get_frame_counter(); @@ -133,8 +133,10 @@ namespace app { for (Task* i : tasks) i->SetDest(); - while (tasks.size()) + while (tasks.size()) { Ctrl(); + Basic(); + } } bool TaskWork::AppendTask(Task* t, const char* name, int32_t priority) { @@ -186,11 +188,10 @@ namespace app { continue; time_struct t; - time_struct_init(&t); task_work->current = tsk; Task_do_ctrl(tsk); task_work->current = 0; - Task_add_base_calc_time(tsk, (uint32_t)(time_struct_calc_time(&t) * 1000.0)); + Task_add_base_calc_time(tsk, (uint32_t)(t.calc_time() * 1000.0)); } for (std::list::iterator i = task_work->tasks.begin(); i != task_work->tasks.end(); ) { @@ -222,9 +223,8 @@ namespace app { continue; time_struct t; - time_struct_init(&t); Task_do_disp(tsk); - Task_set_disp_time(tsk, (uint32_t)(time_struct_calc_time(&t) * 1000.0)); + Task_set_disp_time(tsk, (uint32_t)(t.calc_time() * 1000.0)); } task_work->disp = false; } @@ -322,11 +322,10 @@ namespace app { continue; time_struct t; - time_struct_init(&t); task_work->current = tsk; Task_do_ctrl(tsk); task_work->current = 0; - Task_add_base_calc_time(tsk, (uint32_t)(time_struct_calc_time(&t) * 1000.0)); + Task_add_base_calc_time(tsk, (uint32_t)(t.calc_time() * 1000.0)); } } diff --git a/src/CRE/task_effect.cpp b/src/CRE/task_effect.cpp new file mode 100644 index 00000000..24eb93c5 --- /dev/null +++ b/src/CRE/task_effect.cpp @@ -0,0 +1,503 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "task_effect.hpp" +#include "auth_3d.hpp" +#include "data.hpp" +#include "render_context.hpp" +#include "shader_ft.hpp" +#include "texture.hpp" + +extern render_context* rctx_ptr; + +static TaskEffectFogAnim::Data* task_effect_fog_anim_data; +static TaskEffectFogRing::Data* task_effect_fog_ring_data; + +TaskEffect::TaskEffect() { + +} + +TaskEffect::~TaskEffect() { + +} + +void TaskEffect::PreInit(int32_t stage_index) { + +} + +void TaskEffect::SetStageIndices(std::vector& stage_indices) { + PreInit(stage_indices[0]); +} + +void TaskEffect::SetFrame(int32_t value) { + +} + +void TaskEffect::Field_48() { + +} + +void TaskEffect::SetEnable(bool value) { + +} + +void TaskEffect::SetStageIndex(int32_t value) { + +} + +void TaskEffect::SetFrameRateControl(FrameRateControl* value) { + +} + +void TaskEffect::Field_68() { + +} + +void TaskEffect::Reset() { + +} + +void TaskEffect::Field_78() { + +} + +void TaskEffect::Field_80() { + +} + +void TaskEffect::Field_88() { + +} + +void TaskEffect::Field_90() { + +} + +void TaskEffect::Field_98(int32_t a2, int32_t* a3) { + if (a3) + *a3 = 0; +} + +void TaskEffect::Field_A0(int32_t a2, int32_t* a3) { + if (a3) + *a3 = 0; +} + +void TaskEffect::Field_A8(int32_t a2, int8_t* a3) { + if (a3) + *a3 = 0; +} + +TaskEffectAuth3D::Stage::Stage() : auth_3d_ids() { + count = 0; + max_count = TASK_STAGE_STAGE_COUNT; + for (int32_t& i : auth_3d_ids) + i = -1; + auth_3d_ids_ptr = auth_3d_ids; +} + +TaskEffectAuth3D::TaskEffectAuth3D() : enable(), +field_13C(), field_158(), field_159(), field_15C(), frame() { + stage_index = -1; +} + +TaskEffectAuth3D::~TaskEffectAuth3D() { + +} + +bool TaskEffectAuth3D::Init() { + if (!task_auth_3d_check_task_ready()) { + SetDest(); + return true; + } + + if (stage.count) { + for (int32_t i = 0; i < stage.count; i++) + if (!auth_3d_data_check_id_loaded(&stage.auth_3d_ids_ptr[i])) + return false; + } + + for (int32_t i = 0; i < stage.count; i++) { + int32_t& id = stage.auth_3d_ids_ptr[i]; + auth_3d_data_set_repeat(&id, true); + auth_3d_data_set_paused(&id, false); + auth_3d_data_set_enable(&id, true); + } + + //if (field_158) + // sub_14036D310(2, (__int64)sub_140345B70, (__int64)this); + return true; +} + +bool TaskEffectAuth3D::Ctrl() { + if (field_158 && field_15C > 0) + field_15C = 0; + + if (field_159) { + int32_t frame_int; + if (frame >= 0.0) + { + frame_int = (int32_t)frame; + frame += get_delta_frame(); + if (frame > (float_t)(512 * 360)) + frame = 0.0f; + } + else + frame_int = 0; + + mat4 mat; + mat4_translate(0.0f, -0.2f, 0.0f, &mat); + mat4_rotate_x_mult(&mat, sinf((float_t)((double_t)((float_t)(frame_int % 512) + * (float_t)(2.0 / 512.0)) * M_PI)) * 0.015f, &mat); + mat4_rotate_z_mult(&mat, sinf((float_t)((double_t)((float_t)(frame_int % 360) + * (float_t)(2.0 / 360.0)) * M_PI)) * 0.015f, &mat); + task_stage_set_mat(&mat); + } + return false; +} + +bool TaskEffectAuth3D::Dest() { + //if (field_158) + // sub_14036D1E0(2, (__int64)sub_140345B70, (__int64)this); + ResetData(); + return true; +} + +void TaskEffectAuth3D::Disp() { + +} + +void TaskEffectAuth3D::PreInit(int32_t stage_index) { + +} + +void sub_140344BE0(TaskEffectAuth3D* a1, int32_t stage_index) { +} + +void TaskEffectAuth3D::SetStageIndices(std::vector& stage_indices) { + this->stage_indices = stage_indices; + for (int32_t& i : this->stage_indices) { + data_struct* aft_data = &data_list[DATA_AFT]; + auth_3d_database* aft_auth_3d_db = &aft_data->data_ft.auth_3d_db; + stage_database* aft_stage_data = &aft_data->data_ft.stage_data; + + stage_data* stage_data = aft_stage_data->get_stage_data(i); + if (!stage_data || !stage_data->auth_3d_ids.size()) + continue; + + struc_621 v30; + v30.stage_index = i; + + if (stage.count != stage.max_count) { + int32_t id = -1; + for (int32_t& j : stage_data->auth_3d_ids) { + id = -1; + if (stage.count == stage.max_count) + break; + + id = auth_3d_data_load_uid(j, aft_auth_3d_db); + if (auth_3d_data_check_id_not_empty(&id)) + break; + } + + if (id != -1) { + auth_3d_data_read_file(&id, aft_auth_3d_db); + auth_3d_data_set_visibility(&id, false); + if (stage.count + 1 <= stage.max_count) + stage.auth_3d_ids_ptr[stage.count++] = id; + v30.auth_3d_ids.push_back(id); + } + } + + field_120.push_back(v30); + } +} + +void TaskEffectAuth3D::SetFrame(int32_t value) { + double_t frame = (double_t)value; + for (int32_t i = 0; i < stage.count; i++) { + int32_t& id = stage.auth_3d_ids_ptr[i]; + float_t play_control_size = auth_3d_data_get_play_control_size(&id); + float_t req_frame; + if (play_control_size != 0.0) + req_frame = (float_t)fmod(frame, play_control_size); + else + req_frame = 0.0f; + auth_3d_data_set_req_frame(&id, req_frame); + } +} + +void TaskEffectAuth3D::SetStageIndex(int32_t value) { + if (stage_index == value) + return; + + SetVisibility(false); + stage_index = value; + SetVisibility(enable); +} + +void TaskEffectAuth3D::SetFrameRateControl(FrameRateControl* value) { + for (int32_t i = 0; i < stage.count; i++) { + int32_t& id = stage.auth_3d_ids_ptr[i]; + auth_3d_data_set_frame_rate(&id, value); + } +} + +void TaskEffectAuth3D::Reset() { + for (int32_t i = 0; i < stage.count; i++) { + int32_t& id = stage.auth_3d_ids_ptr[i]; + auth_3d_data_set_enable(&id, true); + auth_3d_data_set_paused(&id, false); + auth_3d_data_set_req_frame(&id, 0.0f); + } +} + +void TaskEffectAuth3D::ResetData() { + for (int32_t i = 0; i < stage.count; i++) { + int32_t& id = stage.auth_3d_ids_ptr[i]; + auth_3d_data_unload_id(id, rctx_ptr); + } + stage.count = 0; + enable = false; + + field_120.clear(); + stage_index = -1; + stage_indices.clear(); + field_158 = 0; + field_159 = 0; + field_15C = 0; + frame = -1.0f; +} + +void TaskEffectAuth3D::SetVisibility(bool value) { + if (stage_index == -1) + return; + + for (struc_621& i : field_120) { + if (i.stage_index != stage_index) + continue; + + for (int32_t& j : i.auth_3d_ids) + auth_3d_data_set_visibility(&j, value); + } +} + +void TaskEffectAuth3D::SetEnable(bool value) { + enable = value; + SetVisibility(value); +} + +TaskEffectFogAnim::Data::Data() : field_0(), field_4(), field_8(), field_C(), +field_18(), field_24(), field_28(), field_2C(), field_30(), field_34() { + Reset(); +} + +void TaskEffectFogAnim::Data::Ctrl() { + if (!field_0 || !field_8) + return; + + float_t v4 = field_C[0] * DEG_TO_RAD_FLOAT; + float_t v7 = (sinf(v4 - 1.5f) + 1.0f) * 0.5f + field_34.x; + v7 = min(v7, 1.0f) * field_24; + float_t v8 = sinf(v4) * v7; + float_t v9 = cosf(v4); + + vec4 color; + color.x = (float_t)((v9 * v7) * 1.4022 + 1.0); + color.y = (float_t)(1.0 - v8 * 0.345686 - ((double_t)v9 * v7) * 0.714486); + color.z = (float_t)(v8 * 1.771 + 1.0); + color.w = 1.0f; + vec3_max(*(vec3*)&color, vec3_null, *(vec3*)&color); + + for (int32_t i = 0; i < 3; i++) { + float_t v20 = (field_18[i] * 10.0f) + field_C[i]; + if (v20 > 360.0) + v20 = fmodf(v20, 360.0); + field_C[i] = v20; + } + + fog& fog = rctx_ptr->fog[FOG_DEPTH]; + fog.set_color(color); + + vec3_add_scalar(*(vec3*)&color, 1.0f, *(vec3*)&color); + vec3_mult_scalar(*(vec3*)&color, 0.8f, *(vec3*)&color); + + light_set& light_set = rctx_ptr->light_set[LIGHT_SET_MAIN]; + light_set.lights[LIGHT_CHARA].set_diffuse(color); + light_set.lights[LIGHT_CHARA].set_specular(color); + light_set.lights[LIGHT_STAGE].set_diffuse(color); + light_set.lights[LIGHT_STAGE].set_specular(color); +} + +void TaskEffectFogAnim::Data::Reset() { + field_0 = 0; + field_4 = -1; + field_8 = 1; + field_C[0] = 0.0f; + field_C[1] = 0.0f; + field_C[2] = 0.0f; + field_18[0] = 0.0f; + field_18[1] = 0.0f; + field_18[2] = 0.0f; + field_24 = 0; + field_28 = 0; + field_2C = 0; + field_30 = 0; + field_34 = vec4u_identity; +} + +TaskEffectFogAnim::TaskEffectFogAnim() { + +} + +TaskEffectFogAnim::~TaskEffectFogAnim() { + +} + +bool TaskEffectFogAnim::Init() { + return true; +} + +bool TaskEffectFogAnim::Ctrl() { + data.Ctrl(); + return false; +} + +bool TaskEffectFogAnim::Dest() { + data.Reset(); + task_effect_fog_anim_data = 0; + return true; +} + +void TaskEffectFogAnim::Disp() { + +} + +void TaskEffectFogAnim::PreInit(int32_t) { + data.Reset(); + task_effect_fog_anim_data = &data; +} + +TaskEffectFogRing::Data::Data() { + +} + +TaskEffectFogRing::Data::~Data() { + +} + +void TaskEffectFogRing::Data::Ctrl() { + if (!disp) + return; + + //sub_140349FD0(this, delta_frame * (float_t)(1.0 / 60.0)); + //sub_1403495B0(this); + field_8 = 0; +} + +void TaskEffectFogRing::Data::SetStageIndices(std::vector& stage_indices) { + +} + +TaskEffectFogRing::TaskEffectFogRing() { + +} + +TaskEffectFogRing::~TaskEffectFogRing() { + +} + +bool TaskEffectFogRing::Init() { + return true; +} + +bool TaskEffectFogRing::Ctrl() { + data.delta_frame = data.frame_rate_control->GetDeltaFrame(); + data.Ctrl();; + return 0; +} + +bool TaskEffectFogRing::Dest() { + //sub_140348090(&this->data); + task_effect_fog_ring_data = 0; + return 1; +} + +void draw_fog_particle(TaskEffectFogRing::Data* data) { + if (!data->count) + return; + + glPushAttrib(GL_SCISSOR_BIT | GL_TEXTURE_BIT | GL_LIST_BIT | GL_EVAL_BIT | GL_HINT_BIT + | GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT + | GL_STENCIL_BUFFER_BIT | GL_ACCUM_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_FOG_BIT + | GL_LIGHTING_BIT | GL_PIXEL_MODE_BIT | GL_POLYGON_STIPPLE_BIT | GL_POLYGON_BIT | GL_LINE_BIT | GL_CLIENT_VERTEX_ARRAY_BIT | GL_CLIENT_PIXEL_STORE_BIT); + glPushClientAttrib(GL_POINT_BIT); + glDisableClientState(GL_NORMAL_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); + shaders_ft.set(SHADER_FT_FOGPTCL); + glEnable(GL_BLEND); + glPointSize(data->point_size); + glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); + glEnable(GL_POINT_SPRITE); + glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, 1); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); + texture* tex = texture_storage_get_texture(data->tex_id); + if (tex) + gl_state_active_bind_texture_2d(0, tex->tex); + + glVertexPointer(3, GL_FLOAT, 32, data->data); + glColorPointer(4, GL_FLOAT, 32, &data->data->color); + glEnableVertexAttribArray(0xE); + glVertexAttribPointer(0xE, 1, GL_FLOAT, 0, 32, &data->data->size); + glDrawArrays(GL_POINTS, 0, data->count); + shaders_ft.set(-1); + glPopClientAttrib(); + glPopAttrib(); +} + +void TaskEffectFogRing::Disp() { + //if (data.enable && data.disp) + // draw_task_preprocess_append((void(*)(void*))draw_fog_particle, &data, DRAW_OBJECT_RIPPLE); +} + +void TaskEffectFogRing::PreInit(int32_t stage_index) { + +} + +void TaskEffectFogRing::SetStageIndices(std::vector& stage_indices) { + SetFrameRateControl(0); + task_effect_fog_ring_data = &data; + data.SetStageIndices(stage_indices); +} + +void TaskEffectFogRing::SetEnable(bool value) { + data.enable = value; +} + +void TaskEffectFogRing::SetStageIndex(int32_t value) { + if (data.stage_index == value) + return; + + data.stage_index = value; + if (value != -1) { + for (int32_t& i : data.stage_indices) + if (i == value) { + data.disp = true; + return; + } + } + data.disp = false; +} + +void TaskEffectFogRing::SetFrameRateControl(FrameRateControl* value) { + if (value) + data.frame_rate_control = value; + else + data.frame_rate_control = &sys_frame_rate; +} + +void TaskEffectFogRing::Reset() { + //sub_140349C30(&this->data); +} diff --git a/src/CRE/task_effect.hpp b/src/CRE/task_effect.hpp new file mode 100644 index 00000000..f02a22c3 --- /dev/null +++ b/src/CRE/task_effect.hpp @@ -0,0 +1,802 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include +#include "../KKdLib/default.hpp" +#include "../KKdLib/database/object.hpp" +#include "../KKdLib/mat.hpp" +#include "../KKdLib/vec.hpp" +#include "frame_rate_control.hpp" +#include "render_texture.hpp" +#include "stage.hpp" +#include "task.hpp" + +enum TaskEffectType { + TASK_EFFECT_INVALID = -1, + TASK_EFFECT_AUTH_3D = 0x00, + TASK_EFFECT_TYPE_1 = 0x01, + TASK_EFFECT_LEAF = 0x02, + TASK_EFFECT_TYPE_3 = 0x03, + TASK_EFFECT_SNOW = 0x04, + TASK_EFFECT_TYPE_5 = 0x05, + TASK_EFFECT_RIPPLE = 0x06, + TASK_EFFECT_RAIN = 0x07, + TASK_EFFECT_TYPE_8 = 0x08, + TASK_EFFECT_TYPE_9 = 0x09, + TASK_EFFECT_TYPE_10 = 0x0A, + TASK_EFFECT_TYPE_11 = 0x0B, + TASK_EFFECT_SPLASH = 0x0C, + TASK_EFFECT_TYPE_13 = 0x0D, + TASK_EFFECT_FOG_ANIM = 0x0E, + TASK_EFFECT_TYPE_15 = 0x0F, + TASK_EFFECT_FOG_RING = 0x10, + TASK_EFFECT_TYPE_17 = 0x11, + TASK_EFFECT_PARTICLE = 0x12, + TASK_EFFECT_LITPROJ = 0x13, + TASK_EFFECT_STAR = 0x14, +}; + +class TaskEffect : public app::Task { +public: + TaskEffect(); + virtual ~TaskEffect() override; + + virtual void PreInit(int32_t stage_index); + virtual void SetStageIndices(std::vector& stage_indices); + virtual void SetFrame(int32_t value); + virtual void Field_48(); + virtual void SetEnable(bool); + virtual void SetStageIndex(int32_t value); + virtual void SetFrameRateControl(FrameRateControl* value); + virtual void Field_68(); + virtual void Reset(); + virtual void Field_78(); + virtual void Field_80(); + virtual void Field_88(); + virtual void Field_90(); + virtual void Field_98(int32_t a2, int32_t* a3); + virtual void Field_A0(int32_t a2, int32_t* a3); + virtual void Field_A8(int32_t a2, int8_t* a3); +}; + +; + +struct struc_621 { + int32_t stage_index; + std::vector auth_3d_ids; +}; + +struct TaskEffectAuth3D : public TaskEffect { + struct Stage { + size_t count; + size_t max_count; + int32_t* auth_3d_ids_ptr; + int32_t auth_3d_ids[TASK_STAGE_STAGE_COUNT]; + + Stage(); + } stage; + bool enable; + std::vector field_120; + int32_t stage_index; + int32_t field_13C; + std::vector stage_indices; + int8_t field_158; + int8_t field_159; + int32_t field_15C; + float_t frame; + + TaskEffectAuth3D(); + virtual ~TaskEffectAuth3D() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void SetEnable(bool value) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Reset() override; + + void ResetData(); + void SetVisibility(bool value); +}; + +struct TaskEffectFogAnim : public TaskEffect { + struct Data { + bool field_0; + int32_t field_4; + bool field_8; + float_t field_C[3]; + float_t field_18[3]; + float_t field_24; + int32_t field_28; + int32_t field_2C; + int32_t field_30; + vec4 field_34; + + Data(); + + void Ctrl(); + void Reset(); + } data; + + TaskEffectFogAnim(); + virtual ~TaskEffectFogAnim() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct point_particle_data { + vec3 position; + vec4 color; + float_t size; +}; + +struct struc_371 { + vec3 field_0; + float_t field_C; + int32_t field_10; + int32_t field_14; + int32_t field_18; + int32_t field_1C; + int32_t field_20; + int32_t field_24; +}; + +struct TaskEffectFogRing : public TaskEffect { + struct Data { + bool enable; + float_t delta_frame; + int8_t field_8; + float_t ring_size; + vec3 wind_dir; + int32_t tex_id; + vec4 color; + float_t point_size; + int32_t max_ptcls; + int32_t num_ptcls; + float_t density; + float_t density_offset; + int32_t field_44; + int64_t field_48; + point_particle_data* data; + int32_t count; + int32_t field_5C; + int32_t field_60; + int32_t field_64; + int32_t field_68; + int32_t field_6C; + int32_t field_70; + int32_t field_74; + int32_t field_78; + int32_t field_7C; + int32_t field_80; + int32_t field_84; + int32_t field_88; + int32_t field_8C; + int32_t field_90; + int32_t field_94; + int32_t field_98; + int32_t field_9C; + int32_t field_A0; + int32_t field_A4; + int32_t field_A8; + int32_t field_AC; + int32_t field_B0; + int32_t field_B4; + int32_t field_B8; + int32_t field_BC; + int32_t field_C0; + int32_t field_C4; + int32_t field_C8; + int32_t field_CC; + int32_t field_D0; + int32_t field_D4; + int32_t field_D8; + int32_t field_DC; + int32_t field_E0; + int32_t field_E4; + int32_t field_E8; + int32_t field_EC; + int32_t field_F0; + int32_t field_F4; + int32_t field_F8; + int32_t field_FC; + int32_t field_100; + int32_t field_104; + int32_t field_108; + int32_t field_10C; + int32_t field_110; + int32_t field_114; + int32_t field_118; + int32_t field_11C; + int32_t field_120; + int32_t field_124; + int8_t field_128[4]; + float_t field_12C[2]; + int32_t field_134; + float_t field_138[2]; + struc_371 field_140[2]; + int32_t field_190; + int32_t field_194; + int32_t field_198; + int32_t field_19C; + int32_t field_1A0; + int32_t field_1A4; + int32_t field_1A8; + int32_t field_1AC; + int32_t field_1B0; + int32_t field_1B4; + int32_t field_1B8; + int32_t field_1BC; + int32_t field_1C0; + int32_t field_1C4; + int32_t field_1C8; + int32_t field_1CC; + int32_t field_1D0; + int32_t field_1D4; + int32_t field_1D8; + int32_t field_1DC; + int32_t field_1E0; + int32_t field_1E4; + int32_t field_1E8; + int32_t field_1EC; + int32_t field_1F0; + int32_t field_1F4; + int32_t field_1F8; + int32_t field_1FC; + int32_t field_200; + int32_t field_204; + int32_t field_208; + int32_t field_20C; + int32_t field_210; + int32_t field_214; + int32_t field_218; + int32_t field_21C; + int32_t field_220; + int32_t field_224; + int32_t field_228; + int32_t field_22C; + int32_t field_230; + int32_t field_234; + int32_t field_238; + int32_t field_23C; + int32_t field_240; + int32_t field_244; + int32_t field_248; + int32_t field_24C; + int32_t field_250; + int32_t field_254; + int32_t field_258; + int32_t field_25C; + int32_t field_260; + int32_t field_264; + int32_t field_268; + int32_t field_26C; + int32_t field_270; + int32_t field_274; + int32_t field_278; + int32_t field_27C; + int32_t field_280; + int32_t field_284; + int32_t field_288; + int32_t field_28C; + int32_t field_290; + int32_t field_294; + int32_t field_298; + int32_t field_29C; + int32_t field_2A0; + int32_t field_2A4; + int64_t field_2A8; + int32_t field_2B0; + int32_t field_2B4; + int8_t field_2B8; + int8_t field_2B9; + bool disp; + int32_t stage_index; + std::vector stage_indices; + FrameRateControl* frame_rate_control; + int64_t field_2E0; + + Data(); + ~Data(); + + void Ctrl(); + void SetStageIndices(std::vector& stage_indices); + } data; + + TaskEffectFogRing(); + virtual ~TaskEffectFogRing() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Reset() override; +}; + +struct TaskEffectLeaf : public TaskEffect { + FrameRateControl* frame_rate_control; + int32_t stage_index; + std::vector stage_indices; + int32_t field_90; + int32_t field_94; + int64_t field_98; + + TaskEffectLeaf(); + virtual ~TaskEffectLeaf() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct TaskEffectLitproj : public TaskEffect { + int32_t stage_index; + std::vector stage_indices; + int32_t field_88; + vec4 diffuse; + vec4 specular; + int32_t field_AC; + + TaskEffectLitproj(); + virtual ~TaskEffectLitproj() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct TaskEffectParticle : public TaskEffect { + FrameRateControl* frame_rate_control; + int32_t field_70; + int32_t field_74; + int64_t field_78; + + TaskEffectParticle(); + virtual ~TaskEffectParticle() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct TaskEffectRain : public TaskEffect { + FrameRateControl* frame_rate_control; + int32_t stage_index; + std::vector stage_indices; + + TaskEffectRain(); + virtual ~TaskEffectRain() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct color4u8 { + uint8_t r; + uint8_t g; + uint8_t b; + uint8_t a; +}; + +struct struc_101 { + int32_t ripple_uniform; + int32_t ripple_emit_uniform; + int32_t count; + int32_t field_C; + vec3* vertex; + color4u8* color; + float_t size; + int32_t field_24; +}; + +struct struc_202 { + vec2 field_0; + float_t field_8; +}; + +struct ripple_emit_draw_data { + struc_101 data; + vec3 vertex[16]; + color4u8 color[16]; +}; + +struct struc_192 { + int32_t field_0; + vec3 field_4; +}; + +struct struc_207 { + struc_192 field_0[18]; +}; + +struct ripple_emit { + float_t delta_frame; + int8_t field_4; + int32_t rain_ripple_num; + float_t rain_ripple_min_value; + float_t rain_ripple_max_value; + int32_t field_14; + float_t ground_y; + float_t emit_pos_scale; + float_t emit_pos_ofs_x; + float_t emit_pos_ofs_z; + int32_t ripple_tex_id; + bool use_float_ripplemap; + int32_t field_30; + float_t rob_emitter_size; + size_t emitter_num; + struc_202* emitter_list; + float_t emitter_size; + int32_t field_4C; + ripple_emit_draw_data field_50; + ripple_emit_draw_data field_178; + ripple_emit_draw_data field_2A0; + ripple_emit_draw_data field_3C8; + int32_t field_4F0; + struc_207 field_4F4[6]; + int32_t field_BB4; + render_texture field_BB8; + int32_t field_BE8; + int8_t field_BEC; + float_t wake_attn; + float speed; + float field_BF8; + float field_BFC; + int8_t field_C00; + int32_t stage_index; + std::vector stage_indices; +}; + +struct TaskEffectRipple : public TaskEffect { + int64_t field_68; + FrameRateControl* frame_rate_control; + ripple_emit* emit_struct; + + TaskEffectRipple(); + virtual ~TaskEffectRipple() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct TaskEffectSnow : public TaskEffect { + FrameRateControl* frame_rate_control; + int32_t stage_index; + std::vector stage_indices; + + TaskEffectSnow(); + virtual ~TaskEffectSnow() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct struc_180 { + uint32_t count; + int32_t field_4; + int64_t field_8; + int64_t field_10; + int64_t field_18; + int32_t field_20; + int64_t field_28; + int64_t field_30; + int64_t field_38; +}; + +struct ParticleEmitter { + struc_180* field_8; + int64_t field_10; + int64_t field_18; + float_t field_20; + int32_t field_24; + float_t field_28; + float_t particle_size; + + ParticleEmitter(); + virtual ~ParticleEmitter(); + + virtual bool Field_8(); + virtual bool Field_10(); +}; + +struct ParticleEmitterRob : ParticleEmitter { + int32_t field_30; + int32_t field_34; + int32_t field_38; + int32_t field_3C; + int32_t field_40; + int32_t field_44; + int32_t field_48; + int32_t field_4C; + int32_t field_50; + int32_t field_54; + int32_t field_58; + int32_t emit_num; + int32_t field_60; + float_t emission_ratio_attn; + float_t emission_velocity_scale; + bool in_water; + int8_t field_6D; +}; + +struct water_particle { + struc_180* field_0; + vec4 color; + float_t particle_size; + std::vector field_20; + int32_t count; + int32_t tex_id; + bool blink; + std::vector field_48; + std::vector field_60; + struc_101 field_78; + float_t ripple_emission; +}; + +struct ParticleDispObj { + struc_180* field_8; + object_info object; + std::vector instances_mat; + + ParticleDispObj(); + virtual ~ParticleDispObj(); + + void Disp(); +}; + +struct TaskEffectSplash : public TaskEffect { + struct Data { + struct Sub { + int32_t field_0; + struc_180* field_8; + int32_t field_10; + ParticleEmitterRob* field_18; + int32_t field_20; + water_particle* field_28; + int8_t field_30; + struc_180 field_38; + int32_t field_78; + ParticleEmitterRob* field_80; + ParticleDispObj field_88; + vec4 color; + float_t particle_size; + int32_t emit_num; + float_t ripple_emission; + float_t emission_ratio_attn; + float_t emission_velocity_scale; + int32_t splash_tex_id; + object_info splash_obj_id; + int8_t in_water; + int8_t blink; + int64_t field_E8; + int64_t field_F0; + int64_t field_F8; + }; + + int8_t field_0; + int32_t field_4; + int8_t field_8; + Sub field_10; + int8_t field_110; + int32_t stage_index; + std::vector stage_indices; + FrameRateControl* frame_rate_control; + int64_t field_138; + }; + + bool enable; + Data data; + + TaskEffectSplash(); + virtual ~TaskEffectSplash() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; + +struct TaskEffectStar : public TaskEffect { + FrameRateControl* frame_rate_control; + int32_t stage_index; + float_t delta_frame; + std::vector stage_indices; + + TaskEffectStar(); + virtual ~TaskEffectStar() override; + + virtual bool Init() override; + virtual bool Ctrl() override; + virtual bool Dest() override; + virtual void Disp() override; + virtual void Basic() override; + + virtual void PreInit(int32_t stage_index) override; + virtual void SetStageIndices(std::vector& stage_indices) override; + virtual void SetFrame(int32_t value) override; + virtual void Field_48() override; + virtual void SetEnable(bool) override; + virtual void SetStageIndex(int32_t value) override; + virtual void SetFrameRateControl(FrameRateControl* value) override; + virtual void Field_68() override; + virtual void Reset() override; + virtual void Field_78() override; + virtual void Field_80() override; + virtual void Field_88() override; + virtual void Field_90() override; + virtual void Field_98(int32_t a2, int32_t* a3) override; + virtual void Field_A0(int32_t a2, int32_t* a3) override; + virtual void Field_A8(int32_t a2, int8_t* a3) override; +}; diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index 1ba11628..4f955189 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -6,8 +6,8 @@ #include "texture.hpp" #include "../KKdLib/mat.hpp" #include "../KKdLib/txp.hpp" -#include "gl_state.h" -#include "static_var.h" +#include "gl_state.hpp" +#include "static_var.hpp" static void texture_get_format_type_by_internal_format(GLenum internal_format, GLenum* format, GLenum* type); static uint32_t texture_get_height_align_mip_level(texture* tex, int32_t mip_level); diff --git a/src/CRE/time.c b/src/CRE/time.c deleted file mode 100644 index 8cf6ecdb..00000000 --- a/src/CRE/time.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#include "time.h" - -static double_t time_struct_get_freq(); - -inline void time_struct_init(time_struct* t) { - if (!QueryPerformanceCounter(&t->timestamp)) - t->timestamp.QuadPart = 0; - t->inv_freq = time_struct_get_freq(); -} - -inline double_t time_struct_calc_time(time_struct* t) { - LARGE_INTEGER timestamp; - if (!QueryPerformanceCounter(×tamp)) - return 0; - - return (double_t)(timestamp.QuadPart - t->timestamp.QuadPart) * t->inv_freq; -} - -inline void time_struct_get_timestamp(time_struct* t) { - if (!QueryPerformanceCounter(&t->timestamp)) - t->timestamp.QuadPart = 0; -} - -static double_t time_struct_get_freq() { - LARGE_INTEGER freq; - if (QueryPerformanceFrequency(&freq)) - return 1000.0 / (double_t)freq.LowPart; - return 0.0; -} diff --git a/src/CRE/time.cpp b/src/CRE/time.cpp new file mode 100644 index 00000000..bb837991 --- /dev/null +++ b/src/CRE/time.cpp @@ -0,0 +1,33 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "time.hpp" + +static double_t time_struct_get_freq(); + +time_struct::time_struct() : timestamp() { + get_timestamp(); + inv_freq = time_struct_get_freq(); +} + +double_t time_struct::calc_time() { + LARGE_INTEGER timestamp; + if (!QueryPerformanceCounter(×tamp)) + return 0; + + return (double_t)(timestamp.QuadPart - this->timestamp.QuadPart) * inv_freq; +} + +void time_struct::get_timestamp() { + if (!QueryPerformanceCounter(×tamp)) + timestamp.QuadPart = 0; +} + +static double_t time_struct_get_freq() { + LARGE_INTEGER freq; + if (QueryPerformanceFrequency(&freq)) + return 1000.0 / (double_t)freq.LowPart; + return 0.0; +} diff --git a/src/CRE/time.h b/src/CRE/time.hpp similarity index 53% rename from src/CRE/time.h rename to src/CRE/time.hpp index 8237c3a8..8a4c49b6 100644 --- a/src/CRE/time.h +++ b/src/CRE/time.hpp @@ -10,8 +10,9 @@ struct time_struct { LARGE_INTEGER timestamp; double_t inv_freq; -}; -extern void time_struct_init(time_struct* t); -extern double_t time_struct_calc_time(time_struct* t); -extern void time_struct_get_timestamp(time_struct* t); + time_struct(); + + double_t calc_time(); + void get_timestamp(); +}; diff --git a/src/CRE/timer.c b/src/CRE/timer.c deleted file mode 100644 index 694e20c9..00000000 --- a/src/CRE/timer.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#include "timer.h" - -inline void timer_init(timer* t, double_t freq) { - for (size_t i = 0; i < HISTORY_COUNT; i++) - t->history[i] = freq; - t->history_counter = 0; - time_struct_init(&t->curr_time); - time_struct_init(&t->prev_time); - lock_init(&t->freq_lock); - lock_init(&t->freq_hist_lock); - lock_lock(&t->freq_lock); - t->freq = freq; - lock_unlock(&t->freq_lock); - lock_lock(&t->freq_hist_lock); - t->freq_hist = freq; - lock_unlock(&t->freq_hist_lock); - t->timer = timer_handle_init(); -} - -inline void timer_start_of_cycle(timer* t) { - double_t time = time_struct_calc_time(&t->prev_time); - time_struct_get_timestamp(&t->prev_time); - double_t freq = 0; - for (uint8_t i = 0; i < t->history_counter; i++) - freq += t->history[i]; - freq += t->history[t->history_counter] = 1000.0 / time; - for (uint8_t i = t->history_counter + 1; i < HISTORY_COUNT; i++) - freq += t->history[i]; - t->history_counter++; - if (t->history_counter >= HISTORY_COUNT) - t->history_counter = 0; - lock_lock(&t->freq_hist_lock); - t->freq_hist = freq / HISTORY_COUNT; - lock_unlock(&t->freq_hist_lock); -} - -inline void timer_end_of_cycle(timer* t) { - double_t msec = 1000.0 / timer_get_freq(t) - time_struct_calc_time(&t->prev_time); - timer_handle_sleep(t->timer, msec); -} - -inline double_t timer_get_freq(timer* t) { - double_t freq = 0.0; - lock_lock(&t->freq_lock); - freq = t->freq; - lock_unlock(&t->freq_lock); - return freq; -} - -inline void timer_set_freq(timer* t, double_t freq) { - lock_lock(&t->freq_lock); - t->freq = freq; - lock_unlock(&t->freq_lock); -} - -inline double_t timer_get_freq_hist(timer* t) { - double_t freq = 0.0; - lock_lock(&t->freq_hist_lock); - freq = t->freq_hist; - lock_unlock(&t->freq_hist_lock); - return freq; -} - -inline double_t timer_get_freq_ratio(timer* t) { - double_t freq = 0.0; - lock_lock(&t->freq_lock); - freq = t->freq; - lock_unlock(&t->freq_lock); - lock_lock(&t->freq_hist_lock); - freq /= t->freq_hist; - lock_unlock(&t->freq_hist_lock); - return freq; -} - -inline void timer_reset(timer* t) { - time_struct_get_timestamp(&t->curr_time); - time_struct_get_timestamp(&t->prev_time); -} - -inline void timer_sleep(timer* t, double_t msec) { - timer_handle_sleep(t->timer, msec); -} - -inline void timer_dispose(timer* t) { - lock_free(&t->freq_lock); - lock_free(&t->freq_hist_lock); - timer_handle_dispose(t->timer); -} - -inline HANDLE timer_handle_init() { - return CreateWaitableTimerW(0, 0, 0); -} - -inline void timer_handle_sleep(HANDLE timer, double_t msec) { - if (msec <= 0.0) - return; - - if (timer) { - LARGE_INTEGER t; - t.QuadPart = (LONGLONG)round(msec * -10000.0); - SetWaitableTimer(timer, &t, 0, 0, 0, 0); - WaitForSingleObject(timer, INFINITE); - } - else { - DWORD msec_dw = (DWORD)round(msec); - if (msec_dw) - Sleep(msec_dw); - } -} - -inline void timer_handle_dispose(HANDLE timer) { - if (timer) - CloseHandle(timer); -} diff --git a/src/CRE/timer.cpp b/src/CRE/timer.cpp new file mode 100644 index 00000000..b3eab31b --- /dev/null +++ b/src/CRE/timer.cpp @@ -0,0 +1,113 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#include "timer.hpp" + +timer::timer(double_t freq) : history() { + for (double_t& i : history) + i = freq; + history_counter = 0; + this->freq = freq; + this->freq_hist = freq; + lock_init(&freq_lock); + lock_init(&freq_hist_lock); + timer_handle = timer_handle_init(); +} + +timer::~timer() { + lock_free(&freq_lock); + lock_free(&freq_hist_lock); + timer_handle_dispose(timer_handle); +} + +void timer::start_of_cycle() { + double_t time = prev_time.calc_time(); + prev_time.get_timestamp(); + double_t freq = 0; + for (uint8_t i = 0; i < history_counter; i++) + freq += history[i]; + freq += history[history_counter] = 1000.0 / time; + for (uint8_t i = history_counter + 1; i < HISTORY_COUNT; i++) + freq += history[i]; + history_counter++; + if (history_counter >= HISTORY_COUNT) + history_counter = 0; + lock_lock(&freq_hist_lock); + freq_hist = freq / HISTORY_COUNT; + lock_unlock(&freq_hist_lock); +} + +void timer::end_of_cycle() { + double_t msec = 1000.0 / get_freq() - prev_time.calc_time(); + timer_handle_sleep(timer_handle, msec); +} + +double_t timer::get_freq() { + double_t freq = 0.0; + lock_lock(&freq_lock); + freq = this->freq; + lock_unlock(&freq_lock); + return freq; +} + +void timer::set_freq(double_t freq) { + lock_lock(&freq_lock); + this->freq = freq; + lock_unlock(&freq_lock); +} + +double_t timer::get_freq_hist() { + double_t freq = 0.0; + lock_lock(&freq_hist_lock); + freq = freq_hist; + lock_unlock(&freq_hist_lock); + return freq; +} + +double_t timer::get_freq_ratio() { + double_t freq = 0.0; + lock_lock(&freq_lock); + freq = this->freq; + lock_unlock(&freq_lock); + lock_lock(&freq_hist_lock); + freq /= freq_hist; + lock_unlock(&freq_hist_lock); + return freq; +} + +void timer::reset() { + curr_time.get_timestamp(); + prev_time.get_timestamp(); +} + +void timer::sleep(double_t msec) { + timer_handle_sleep(timer_handle, msec); +} + +inline HANDLE timer_handle_init() { + return CreateWaitableTimerW(0, 0, 0); +} + +inline void timer_handle_sleep(HANDLE timer, double_t msec) { + if (msec <= 0.0) + return; + + if (timer) { + LARGE_INTEGER t; + t.QuadPart = (LONGLONG)round(msec * -10000.0); + SetWaitableTimer(timer, &t, 0, 0, 0, 0); + WaitForSingleObject(timer, INFINITE); + } + else { + DWORD msec_dw = (DWORD)round(msec); + if (msec_dw) + Sleep(msec_dw); + } +} + +inline void timer_handle_dispose(HANDLE timer) { + if (timer) + CloseHandle(timer); +} diff --git a/src/CRE/timer.h b/src/CRE/timer.hpp similarity index 52% rename from src/CRE/timer.h rename to src/CRE/timer.hpp index ea046e65..5255a248 100644 --- a/src/CRE/timer.h +++ b/src/CRE/timer.hpp @@ -6,8 +6,8 @@ #pragma once #include "../KKdLib/default.hpp" -#include "lock.h" -#include "time.h" +#include "lock.hpp" +#include "time.hpp" #define HISTORY_COUNT 0x08 @@ -20,22 +20,23 @@ struct timer { double_t freq_hist; lock freq_lock; lock freq_hist_lock; - HANDLE timer; + HANDLE timer_handle; + + timer(double_t freq); + virtual ~timer(); + + void start_of_cycle(); + void end_of_cycle(); + double_t get_freq(); + void set_freq(double_t freq); + double_t get_freq_hist(); + double_t get_freq_ratio(); + void reset(); + void sleep(double_t msec); }; extern LARGE_INTEGER performance_frequency; -extern void timer_init(timer* t, double_t freq); -extern void timer_start_of_cycle(timer* t); -extern void timer_end_of_cycle(timer* t); -extern double_t timer_get_freq(timer* t); -extern void timer_set_freq(timer* t, double_t freq); -extern double_t timer_get_freq_hist(timer* t); -extern double_t timer_get_freq_ratio(timer* t); -extern void timer_reset(timer* t); -extern void timer_sleep(timer* t, double_t msec); -extern void timer_dispose(timer* t); - extern HANDLE timer_handle_init(); extern void timer_handle_sleep(HANDLE timer, double_t msec); extern void timer_handle_dispose(HANDLE timer); diff --git a/src/DivaGL/bone_data.hpp b/src/DivaGL/bone_data.hpp index 1b222552..2124abdf 100644 --- a/src/DivaGL/bone_data.hpp +++ b/src/DivaGL/bone_data.hpp @@ -3634,7 +3634,7 @@ struct obj_sub_mesh_attrib_member { uint32_t recieve_shadow : 1; uint32_t cast_shadow : 1; uint32_t transparent : 1; - uint32_t flag_3 : 1; + uint32_t cloth : 1; uint32_t dummy : 28; }; @@ -3697,7 +3697,7 @@ union obj_mesh_vertex_array_union { }; struct obj_mesh_attrib_member { - uint32_t flag_0 : 1; + uint32_t double_buffer : 1; uint32_t billboard_y_axis : 1; uint32_t translucent_no_shadow : 1; uint32_t billboard : 1; diff --git a/src/DivaGL/inject.cpp b/src/DivaGL/inject.cpp index d910bb2b..6416be1d 100644 --- a/src/DivaGL/inject.cpp +++ b/src/DivaGL/inject.cpp @@ -67,13 +67,14 @@ static patch_struct patch_data[] = { { (void*)0x00000001405E4FC0, (uint64_t)&aft_shader_load_all_shaders, }, { (void*)0x00000001405E4B50, (uint64_t)&aft_shader_bind, }, { (void*)0x00000001401D3860, (uint64_t)&printf_proxy, }, + { (void*)0x00000001400DE640, (uint64_t)&printf_proxy, }, //{ (void*)0x0000000140507210, (uint64_t)&rob_chara_reset_data, }, - { (void*)0x00000001401EBD30, (uint64_t)&bone_data_mult_ik, }, - { (void*)0x00000001401EB6D0, (uint64_t)&bone_data_mult_1, }, - { (void*)0x000000014041DA50, (uint64_t)&bone_data_mult_2, }, + //{ (void*)0x00000001401EBD30, (uint64_t)&bone_data_mult_ik, }, + //{ (void*)0x00000001401EB6D0, (uint64_t)&bone_data_mult_1, }, + //{ (void*)0x000000014041DA50, (uint64_t)&bone_data_mult_2, }, //{ (void*)0x000000014041CF50, (uint64_t)&rob_chara_bone_data_motion_load, }, - { (void*)0x0000000140418870, (uint64_t)&rob_chara_bone_data_interpolate, }, - { (void*)0x0000000140418A60, (uint64_t)&rob_chara_bone_data_update, }, + //{ (void*)0x0000000140418870, (uint64_t)&rob_chara_bone_data_interpolate, }, + //{ (void*)0x0000000140418A60, (uint64_t)&rob_chara_bone_data_update, }, //{ (void*)0x00000001405EEAE0, (uint64_t)&ex_osage_block_dispose, }, //{ (void*)0x00000001405F3640, (uint64_t)&ex_osage_block_init, }, //{ (void*)0x00000001405F39E0, (uint64_t)&ex_node_block_field_10, }, diff --git a/src/KKdLib/a3da.cpp b/src/KKdLib/a3da.cpp index 4db030dd..45885675 100644 --- a/src/KKdLib/a3da.cpp +++ b/src/KKdLib/a3da.cpp @@ -741,7 +741,7 @@ static void a3da_read_text(a3da* a, void* data, size_t size) { kv.read("ref", e->ref); kv.read("time_ref_scale", e->time_ref_scale); - int32_t type = 0; + int32_t type; if (kv.read("type", type)) e->type = (a3da_event_type)type; @@ -808,7 +808,7 @@ static void a3da_read_text(a3da* a, void* data, size_t size) { if (key_val_read(&kv, "FAR", l->_far)) enum_or(l->flags, A3DA_LIGHT_FAR); - int32_t id = 0; + int32_t id; if (kv.read("id", id)) l->id = (light_id)id; @@ -2266,25 +2266,28 @@ static bool key_val_read(key_val* kv, return true; } - int32_t type = 0; + int32_t type; if (!kv->read("type", type)) { kv->close_scope(); return false; } value.type = (a3da_key_type)type; - if (value.type == A3DA_KEY_NONE) + if (value.type == A3DA_KEY_NONE) { + kv->close_scope(); return true; + } else if (value.type == A3DA_KEY_STATIC) { kv->read("value", value.value); + kv->close_scope(); return true; } - int32_t ep_type_post = 0; + int32_t ep_type_post; if (kv->read("ep_type_post", ep_type_post)) value.ep_type_post = (a3da_ep_type)ep_type_post; - int32_t ep_type_pre = 0; + int32_t ep_type_pre; if (kv->read("ep_type_pre", ep_type_pre)) value.ep_type_pre = (a3da_ep_type)ep_type_pre; @@ -2293,7 +2296,7 @@ static bool key_val_read(key_val* kv, if (key_val_read_raw_data(kv, value)) return true; - int32_t length = 0; + int32_t length; if (!kv->read("key", "length", length)) { kv->close_scope(); return false; @@ -2305,10 +2308,12 @@ static bool key_val_read(key_val* kv, for (int32_t i = 0; i < length; i++) { kv->open_scope(i); - const char* data = 0; - int32_t type = 0; - kv->read("data", data); - kv->read("type", type); + const char* data; + int32_t type; + if (!kv->read("data", data) || !kv->read("type", type)) { + kv->close_scope(); + continue; + } switch (type) { case 0: { @@ -2448,7 +2453,7 @@ static void key_val_out_write(key_val_out* kv, stream& s, static bool key_val_read_raw_data(key_val* kv, a3da_key& value) { - int32_t key_type = 0; + int32_t key_type; if (!kv->read("raw_data_key_type", key_type)) return false; @@ -2457,10 +2462,10 @@ static bool key_val_read_raw_data(key_val* kv, if (str_utils_compare(value_type, "float")) return false; - int32_t value_list_size = 0; + int32_t value_list_size; kv->read("raw_data.value_list_size", value_list_size); - int32_t value_list_offset = 0; + int32_t value_list_offset; if (kv->read( "raw_data.value_list_offset", value_list_offset)) { if (key_type != 3) return false; @@ -2472,7 +2477,7 @@ static bool key_val_read_raw_data(key_val* kv, return true; } - const char* value_list = 0; + const char* value_list; if (!kv->read("raw_data.value_list", value_list)) return false; diff --git a/src/KKdLib/database/auth_3d.cpp b/src/KKdLib/database/auth_3d.cpp index f29215ab..40b67889 100644 --- a/src/KKdLib/database/auth_3d.cpp +++ b/src/KKdLib/database/auth_3d.cpp @@ -131,6 +131,17 @@ int32_t auth_3d_database::get_category_index(const char* name) { return -1; } +void auth_3d_database::get_category_uids(const char* name, std::vector& uid) { + uid.clear(); + + uint32_t name_hash = hash_utf8_murmurhash(name); + for (auth_3d_database_category& i : category) + if (hash_string_murmurhash(&i.name) == name_hash) { + uid = i.uid; + return; + } +} + int32_t auth_3d_database::get_uid(const char* name) { uint32_t name_hash = hash_utf8_murmurhash(name); for (auth_3d_database_uid& i : uid) diff --git a/src/KKdLib/database/auth_3d.hpp b/src/KKdLib/database/auth_3d.hpp index c75e0e40..138d5c04 100644 --- a/src/KKdLib/database/auth_3d.hpp +++ b/src/KKdLib/database/auth_3d.hpp @@ -74,6 +74,7 @@ struct auth_3d_database { ~auth_3d_database(); int32_t get_category_index(const char* name); + void get_category_uids(const char* name, std::vector& uid); int32_t get_uid(const char* name); void merge_mdata(auth_3d_database_file* base_auth_3d_db, auth_3d_database_file* mdata_auth_3d_db); diff --git a/src/KKdLib/database/stage.cpp b/src/KKdLib/database/stage.cpp index eedef5eb..5c275e88 100644 --- a/src/KKdLib/database/stage.cpp +++ b/src/KKdLib/database/stage.cpp @@ -215,6 +215,19 @@ bool stage_database::load_file(void* data, const char* path, const char* file, u return stage_data->ready; } +::stage_data* stage_database::get_stage_data(int32_t stage_index) { + if (stage_index >= 0 && stage_index < stage_data.size()) + return &stage_data[stage_index]; + return 0; +} + +::stage_data_modern* stage_database::get_stage_data_modern(uint32_t stage_hash) { + for (::stage_data_modern& i : stage_modern) + if (stage_hash == i.hash) + return &i; + return 0; +} + int32_t stage_database::get_stage_index(const char* name) { uint32_t name_hash = hash_utf8_murmurhash(name); for (::stage_data& i : stage_data) diff --git a/src/KKdLib/database/stage.hpp b/src/KKdLib/database/stage.hpp index aa503d04..f0a918f8 100644 --- a/src/KKdLib/database/stage.hpp +++ b/src/KKdLib/database/stage.hpp @@ -153,7 +153,7 @@ struct stage_database { bool is_x; stage_data_format format; - std::vector stage_data; + std::vector<::stage_data> stage_data; std::vector stage_modern; stage_database(); @@ -166,6 +166,8 @@ struct stage_database { void write(const wchar_t* path); void write(void** data, size_t* size); + ::stage_data* get_stage_data(int32_t stage_index); + ::stage_data_modern* get_stage_data_modern(uint32_t stage_hash); int32_t get_stage_index(const char* name); void merge_mdata(stage_database* base_stage_data, stage_database* mdata_stage_data); void split_mdata(stage_database* base_stage_data, stage_database* mdata_stage_data); diff --git a/src/KKdLib/io/stream.cpp b/src/KKdLib/io/stream.cpp index c7234716..6cb9f5ea 100644 --- a/src/KKdLib/io/stream.cpp +++ b/src/KKdLib/io/stream.cpp @@ -1056,10 +1056,10 @@ void stream::write_utf16_string_null_terminated(const wchar_t* str) { write_uint16_t(0); } -int64_t stream::read_offset(int32_t offset, bool is_x) { +int64_t stream::read_offset(int64_t offset, bool is_x) { int64_t val; if (!is_x) { - val = read_int32_t_reverse_endianness(); + val = read_uint32_t_reverse_endianness(); if (val) val -= offset; } @@ -1070,8 +1070,8 @@ int64_t stream::read_offset(int32_t offset, bool is_x) { return val; } -int64_t stream::read_offset_f2(int32_t offset) { - int64_t val = read_int32_t_reverse_endianness(); +int64_t stream::read_offset_f2(int64_t offset) { + int64_t val = read_uint32_t_reverse_endianness(); if (val) val -= offset; return val; @@ -1083,11 +1083,11 @@ int64_t stream::read_offset_x() { return val; } -void stream::write_offset(int64_t val, int32_t offset, bool is_x) { +void stream::write_offset(int64_t val, int64_t offset, bool is_x) { if (!is_x) { if (val) val += offset; - write_int32_t_reverse_endianness((int32_t)val); + write_uint32_t_reverse_endianness((uint32_t)val); } else { align_write(0x08); @@ -1095,10 +1095,10 @@ void stream::write_offset(int64_t val, int32_t offset, bool is_x) { } } -void stream::write_offset_f2(int64_t val, int32_t offset) { +void stream::write_offset_f2(int64_t val, int64_t offset) { if (val) val += offset; - write_int32_t_reverse_endianness((int32_t)val); + write_uint32_t_reverse_endianness((uint32_t)val); } void stream::write_offset_x(int64_t val) { diff --git a/src/KKdLib/io/stream.hpp b/src/KKdLib/io/stream.hpp index 7217c602..bf2c4108 100644 --- a/src/KKdLib/io/stream.hpp +++ b/src/KKdLib/io/stream.hpp @@ -162,10 +162,10 @@ struct stream { void write_utf8_string_null_terminated(const char* str); void write_utf16_string_null_terminated(const wchar_t* str); - int64_t read_offset(int32_t offset, bool is_x); - int64_t read_offset_f2(int32_t offset); + int64_t read_offset(int64_t offset, bool is_x); + int64_t read_offset_f2(int64_t offset); int64_t read_offset_x(); - void write_offset(int64_t val, int32_t offset, bool is_x); - void write_offset_f2(int64_t val, int32_t offset); + void write_offset(int64_t val, int64_t offset, bool is_x); + void write_offset_f2(int64_t val, int64_t offset); void write_offset_x(int64_t val); }; diff --git a/src/KKdLib/key_val.cpp b/src/KKdLib/key_val.cpp index 1a2d3433..5a19ae5e 100644 --- a/src/KKdLib/key_val.cpp +++ b/src/KKdLib/key_val.cpp @@ -134,14 +134,14 @@ bool key_val::open_scope(std::string& str) { return true; } - ssize_t offset = curr_scope->key.size(); + size_t offset = curr_scope->key.size(); if (offset) offset++; key_val_pair* first = 0; key_val_pair* last = 0; const char* s = str.c_str(); - ssize_t s_len = str.size(); + size_t s_len = str.size(); key_val_pair* i = key.data() + curr_scope->index; size_t j = curr_scope->count; diff --git a/src/KKdLib/mat.cpp b/src/KKdLib/mat.cpp index 652172f8..0f6e9357 100644 --- a/src/KKdLib/mat.cpp +++ b/src/KKdLib/mat.cpp @@ -46,6 +46,34 @@ const mat4u mat4u_null = { { 0.0f, 0.0f, 0.0f, 0.0f }, }; + +mat3::mat3() : row0(), row1(), row2() { + +} + +mat3::mat3(vec3 row0, vec3 row1, vec3 row2) : + row0(row0), row1(row1), row2(row2) { + +} + +mat4::mat4() : row0(), row1(), row2(), row3() { + +} + +mat4::mat4(vec4 row0, vec4 row1, vec4 row2, vec4 row3) : + row0(row0), row1(row1), row2(row2), row3(row3) { + +} + +mat4u::mat4u() : row0(), row1(), row2(), row3() { + +} + +mat4u::mat4u(vec4u row0, vec4u row1, vec4u row2, vec4u row3) : + row0(row0), row1(row1), row2(row2), row3(row3) { + +} + inline void mat3_add(const mat3* x, const mat3* y, mat3* z) { __m128 xt; __m128 yt; @@ -1478,12 +1506,12 @@ inline void mat4_scale_z(float_t x, mat4* y) { inline void mat4_scale_mult(const mat4* s, float_t x, float_t y, float_t z, float_t w, mat4* d) { mat4 dt; - if (x != 1.0f || y != 1.0f || z != 1.0f) { + if (x != 1.0f || y != 1.0f || z != 1.0f || w != 1.0f) { dt = mat4_identity; dt.row0.x = x; dt.row1.y = y; dt.row2.z = z; - dt.row3.z = w; + dt.row3.w = w; mat4_mult(s, &dt, d); } else if (s != d) diff --git a/src/KKdLib/mat.hpp b/src/KKdLib/mat.hpp index 08d493b3..f91a9c27 100644 --- a/src/KKdLib/mat.hpp +++ b/src/KKdLib/mat.hpp @@ -13,6 +13,9 @@ struct mat3 { vec3 row0; vec3 row1; vec3 row2; + + mat3(); + mat3(vec3 row0, vec3 row1, vec3 row2); }; struct mat4; @@ -24,6 +27,9 @@ struct mat4 { vec4 row2; vec4 row3; + mat4(); + mat4(vec4 row0, vec4 row1, vec4 row2, vec4 row3); + operator mat4u() const; }; @@ -33,6 +39,9 @@ struct mat4u { vec4u row2; vec4u row3; + mat4u(); + mat4u(vec4u row0, vec4u row1, vec4u row2, vec4u row3); + operator mat4() const; }; diff --git a/src/KKdLib/obj.cpp b/src/KKdLib/obj.cpp index 744bba64..72618a4d 100644 --- a/src/KKdLib/obj.cpp +++ b/src/KKdLib/obj.cpp @@ -14,20 +14,20 @@ #include "str_utils.hpp" enum obj_vertex_format_file { - OBJ_VERTEX_FORMAT_FILE_POSITION = 0x00000001, - OBJ_VERTEX_FORMAT_FILE_NORMAL = 0x00000002, - OBJ_VERTEX_FORMAT_FILE_TANGENT = 0x00000004, - OBJ_VERTEX_FORMAT_FILE_BINORMAL = 0x00000008, - OBJ_VERTEX_FORMAT_FILE_TEXCOORD0 = 0x00000010, - OBJ_VERTEX_FORMAT_FILE_TEXCOORD1 = 0x00000020, - OBJ_VERTEX_FORMAT_FILE_TEXCOORD2 = 0x00000040, - OBJ_VERTEX_FORMAT_FILE_TEXCOORD3 = 0x00000080, - OBJ_VERTEX_FORMAT_FILE_COLOR0 = 0x00000100, - OBJ_VERTEX_FORMAT_FILE_COLOR1 = 0x00000200, - OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT = 0x00000400, - OBJ_VERTEX_FORMAT_FILE_BONE_INDEX = 0x00000800, - OBJ_VERTEX_FORMAT_FILE_UNKNOWN = 0x00001000, - OBJ_VERTEX_FORMAT_FILE_MODERN_STORAGE = 0x80000000, + OBJ_VERTEX_FILE_POSITION = 0x00000001, + OBJ_VERTEX_FILE_NORMAL = 0x00000002, + OBJ_VERTEX_FILE_TANGENT = 0x00000004, + OBJ_VERTEX_FILE_BINORMAL = 0x00000008, + OBJ_VERTEX_FILE_TEXCOORD0 = 0x00000010, + OBJ_VERTEX_FILE_TEXCOORD1 = 0x00000020, + OBJ_VERTEX_FILE_TEXCOORD2 = 0x00000040, + OBJ_VERTEX_FILE_TEXCOORD3 = 0x00000080, + OBJ_VERTEX_FILE_COLOR0 = 0x00000100, + OBJ_VERTEX_FILE_COLOR1 = 0x00000200, + OBJ_VERTEX_FILE_BONE_WEIGHT = 0x00000400, + OBJ_VERTEX_FILE_BONE_INDEX = 0x00000800, + OBJ_VERTEX_FILE_UNKNOWN = 0x00001000, + OBJ_VERTEX_FILE_MODERN_STORAGE = 0x80000000, }; struct obj_skin_block_header { @@ -127,15 +127,11 @@ static void obj_classic_read_skin_block_cloth(obj_skin_block_cloth* b, stream& s, char** str); static void obj_classic_write_skin_block_cloth(obj_skin_block_cloth* b, stream& s, std::vector& strings, std::vector& string_offsets, - int64_t* field_18_offset, int64_t* field_1C_offset, int64_t* field_20_offset, - int64_t* field_24_offset, int64_t* field_28_offset); -static void obj_classic_read_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, + int64_t* mats_offset, int64_t* root_offset, int64_t* nodes_offset, + int64_t* mesh_indices_offset, int64_t* backface_mesh_indices_offset); +static void obj_classic_read_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, char** str); -static void obj_classic_write_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, - stream& s, std::vector& strings, std::vector& string_offsets); -static void obj_classic_read_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, char** str); -static void obj_classic_write_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, +static void obj_classic_write_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, std::vector& strings, std::vector& string_offsets); static void obj_classic_read_skin_block_constraint(obj_skin_block_constraint* b, stream& s, char** str); @@ -166,6 +162,10 @@ static void obj_classic_read_skin_block_osage(obj_skin_block_osage* b, stream& s, char** str); static void obj_classic_write_skin_block_osage(obj_skin_block_osage* b, stream& s, std::vector& strings, std::vector& string_offsets, int64_t* nodes_offset); +static void obj_classic_read_skin_param(obj_skin_skin_param* skp, + stream& s, char** str); +static void obj_classic_write_skin_param(obj_skin_skin_param* skp, + stream& s, std::vector& strings, std::vector& string_offsets); static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_mesh* mesh, int64_t base_offset, uint32_t num_vertex, obj_vertex_format_file vertex_format_file); static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_mesh* mesh, @@ -188,15 +188,11 @@ static void obj_modern_read_skin_block_cloth(obj_skin_block_cloth* b, stream& s, uint32_t header_length, char** str, bool is_x); static void obj_modern_write_skin_block_cloth(obj_skin_block_cloth* b, stream& s, std::vector& strings, std::vector& string_offsets, bool is_x, - int64_t* field_18_offset, int64_t* field_1C_offset, int64_t* field_20_offset, - int64_t* field_24_offset, int64_t* field_28_offset); -static void obj_modern_read_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, + int64_t* mats_offset, int64_t* root_offset, int64_t* nodes_offset, + int64_t* mesh_indices_offset, int64_t* backface_mesh_indices_offset); +static void obj_modern_read_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, uint32_t header_length, char** str, bool is_x); -static void obj_modern_write_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, - stream& s, std::vector& strings, std::vector& string_offsets, bool is_x); -static void obj_modern_read_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, uint32_t header_length, char** str, bool is_x); -static void obj_modern_write_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, +static void obj_modern_write_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, std::vector& strings, std::vector& string_offsets, bool is_x); static void obj_modern_read_skin_block_constraint(obj_skin_block_constraint* b, stream& s, uint32_t header_length, char** str, bool is_x); @@ -243,6 +239,10 @@ static void obj_skin_strings_push_back_check(std::vector& vec, cons static void obj_skin_strings_push_back_check_by_index(std::vector& vec, char** strings, uint32_t index); +obj_bounding_sphere::obj_bounding_sphere() : radius() { + +} + obj_material_shader_lighting_type obj_material_shader_attrib::get_lighting_type() { if (!m.is_lgt_diffuse && !m.is_lgt_specular) return OBJ_MATERIAL_SHADER_LIGHTING_CONSTANT; @@ -265,6 +265,28 @@ int32_t obj_texture_attrib::get_blend() { } } +obj_sub_mesh::obj_sub_mesh() : flags(), bounding_sphere(), material_index(), uv_index(), bone_indices(), +bone_indices_count(), bones_per_vertex(), primitive_type(), index_format(), indices(), indices_count(), +attrib(), axis_aligned_bounding_box(), first_index(), last_index(), indices_offset() { + +} + +obj_mesh* obj::get_obj_mesh(const char* name) { + uint32_t name_hash = hash_utf8_murmurhash(name); + for (uint32_t k = 0; k < num_mesh; k++) + if (hash_utf8_murmurhash(mesh_array[k].name) == name_hash) + return &mesh_array[k]; + return 0; +} + + uint32_t obj::get_obj_mesh_index(const char* name) { + uint32_t name_hash = hash_utf8_murmurhash(name); + for (uint32_t k = 0; k < num_mesh; k++) + if (hash_utf8_murmurhash(mesh_array[k].name) == name_hash) + return k; + return -1; +} + obj_set::obj_set() : ready(), modern(), is_x(), obj_data(), obj_num(), tex_id_data(), tex_id_num(), reserved() { @@ -285,15 +307,16 @@ obj_set::~obj_set() { free(cloth->mesh_name); free(cloth->backface_mesh_name); - for (uint32_t k = 0; k < cloth->count; k++) { - obj_skin_block_cloth_field_1C* sub = &cloth->field_1C[k]; + for (uint32_t k = 0; k < cloth->root_count; k++) { + obj_skin_block_cloth_root* sub = &cloth->root[k]; for (uint32_t l = 0; l < 4; l++) - free(sub->sub_data[l].bone_name); + free(sub->bone_weights[l].bone_name); } - free(cloth->field_1C); - free(cloth->field_20); - free(cloth->field_24); - free(cloth->field_28); + free(cloth->root); + free(cloth->nodes); + free(cloth->mesh_indices); + free(cloth->backface_mesh_indices); + free(cloth->skin_param.coli); } break; case OBJ_SKIN_BLOCK_CONSTRAINT: { obj_skin_block_constraint* constraint = &block->constraint; @@ -316,7 +339,7 @@ obj_set::~obj_set() { case OBJ_SKIN_BLOCK_OSAGE: { obj_skin_block_osage* osage = &block->osage; obj_skin_block_node_free(&osage->base); - free(osage->root.coli); + free(osage->skin_param.coli); free(osage->nodes); } break; } @@ -411,35 +434,35 @@ static void obj_set_classic_read_inner(obj_set* os, stream& s) { os->reserved[0] = s.read_uint32_t(); os->reserved[1] = s.read_uint32_t(); - uint32_t count = os->obj_num; + uint32_t obj_num = os->obj_num; os->obj_data = force_malloc_s(obj, os->obj_num); int32_t* obj_datas = 0; if (osh.obj_data) { - obj_datas = force_malloc_s(int32_t, count); + obj_datas = force_malloc_s(int32_t, obj_num); s.set_position(osh.obj_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) obj_datas[i] = s.read_int32_t(); } int32_t* obj_skin_datas = 0; if (osh.obj_skin_data) { - obj_skin_datas = force_malloc_s(int32_t, count); + obj_skin_datas = force_malloc_s(int32_t, obj_num); s.set_position(osh.obj_skin_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) obj_skin_datas[i] = s.read_int32_t(); } int32_t* obj_name_datas = 0; if (osh.obj_name_data) { - obj_name_datas = force_malloc_s(int32_t, count); + obj_name_datas = force_malloc_s(int32_t, obj_num); s.set_position(osh.obj_name_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) obj_name_datas[i] = s.read_int32_t(); } if (osh.obj_data) { - for (uint32_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < obj_num; i++) { obj* obj = &os->obj_data[i]; if (obj_datas[i]) obj_classic_read_model(obj, s, obj_datas[i]); @@ -456,7 +479,7 @@ static void obj_set_classic_read_inner(obj_set* os, stream& s) { } s.set_position(osh.obj_id_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) os->obj_data[i].id = s.read_uint32_t(); } @@ -495,28 +518,28 @@ static void obj_set_classic_write_inner(obj_set* os, stream& s) { obj_set_header osh = {}; osh.last_obj_id = -1; - uint32_t count = os->obj_num; + uint32_t obj_num = os->obj_num; osh.obj_data = s.get_position(); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s.write_int32_t(0); s.align_write(0x10); - int32_t* obj_datas = force_malloc_s(int32_t, count); - for (uint32_t i = 0; i < count; i++) { - obj_datas[i] = (int32_t)s.get_position(); + uint32_t* obj_datas = force_malloc_s(uint32_t, obj_num); + for (uint32_t i = 0; i < obj_num; i++) { + obj_datas[i] = (uint32_t)s.get_position(); obj_classic_write_model(&os->obj_data[i], s, obj_datas[i]); } s.align_write(0x10); s.position_push(osh.obj_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) - s.write_int32_t((int32_t)obj_datas[i]); + for (uint32_t i = 0; i < obj_num; i++) + s.write_uint32_t(obj_datas[i]); s.position_pop(); free(obj_datas); osh.obj_id_data = s.get_position(); - for (uint32_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < obj_num; i++) { int32_t object_id = os->obj_data[i].id; s.write_uint32_t(object_id); if (osh.last_obj_id < object_id) @@ -524,15 +547,15 @@ static void obj_set_classic_write_inner(obj_set* os, stream& s) { } s.align_write(0x10); - int32_t* obj_name_datas = force_malloc_s(int32_t, count); - for (uint32_t i = 0; i < count; i++) { + int32_t* obj_name_datas = force_malloc_s(int32_t, obj_num); + for (uint32_t i = 0; i < obj_num; i++) { obj_name_datas[i] = (int32_t)s.get_position(); s.write_utf8_string_null_terminated(os->obj_data[i].name); } s.align_write(0x10); osh.obj_name_data = s.get_position(); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s.write_int32_t(obj_name_datas[i]); s.align_write(0x10); free(obj_name_datas); @@ -543,12 +566,12 @@ static void obj_set_classic_write_inner(obj_set* os, stream& s) { s.align_write(0x10); osh.obj_skin_data = s.get_position(); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s.write_int32_t(0); s.align_write(0x10); - int32_t* obj_skin_datas = force_malloc_s(int32_t, count); - for (uint32_t i = 0; i < count; i++) { + int32_t* obj_skin_datas = force_malloc_s(int32_t, obj_num); + for (uint32_t i = 0; i < obj_num; i++) { if (!os->obj_data[i].skin_init) { obj_skin_datas[i] = 0; continue; @@ -560,7 +583,7 @@ static void obj_set_classic_write_inner(obj_set* os, stream& s) { s.align_write(0x10); s.position_push(osh.obj_skin_data, SEEK_SET); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s.write_int32_t(obj_skin_datas[i]); s.position_pop(); free(obj_skin_datas); @@ -569,11 +592,11 @@ static void obj_set_classic_write_inner(obj_set* os, stream& s) { s.write_uint32_t(0x05062500); s.write_int32_t(os->obj_num); s.write_uint32_t(osh.last_obj_id); - s.write_int32_t((int32_t)osh.obj_data); - s.write_int32_t((int32_t)osh.obj_skin_data); - s.write_int32_t((int32_t)osh.obj_name_data); - s.write_int32_t((int32_t)osh.obj_id_data); - s.write_int32_t((int32_t)osh.tex_id_data); + s.write_uint32_t((uint32_t)osh.obj_data); + s.write_uint32_t((uint32_t)osh.obj_skin_data); + s.write_uint32_t((uint32_t)osh.obj_name_data); + s.write_uint32_t((uint32_t)osh.obj_id_data); + s.write_uint32_t((uint32_t)osh.tex_id_data); s.write_int32_t(os->tex_id_num); s.write_uint32_t(os->reserved[0]); s.write_uint32_t(os->reserved[1]); @@ -703,12 +726,12 @@ static void obj_classic_read_model(obj* obj, stream& s, int64_t base_offset) { sub_mesh->material_index = s.read_uint32_t(); s.read(&sub_mesh->uv_index, 0x08); sub_mesh->bone_indices_count = s.read_int32_t(); - smh.bone_indices_offset = s.read_int32_t(); + smh.bone_indices_offset = s.read_uint32_t(); sub_mesh->bones_per_vertex = s.read_uint32_t(); sub_mesh->primitive_type = (obj_primitive_type)s.read_uint32_t(); sub_mesh->index_format = (obj_index_format)s.read_uint32_t(); sub_mesh->indices_count = s.read_int32_t(); - smh.indices_offset = s.read_int32_t(); + smh.indices_offset = s.read_uint32_t(); sub_mesh->attrib.w = s.read_uint32_t(); sub_mesh->bounding_box.center = sub_mesh->bounding_sphere.center; sub_mesh->bounding_box.size.x = sub_mesh->bounding_sphere.radius * 2.0f; @@ -846,12 +869,12 @@ static void obj_classic_write_model(obj* obj, stream& s, int64_t base_offset) { s.write_uint32_t(sub_mesh->material_index); s.write(&sub_mesh->uv_index, 0x08); s.write_int32_t(sub_mesh->bone_indices_count); - s.write_int32_t((int32_t)smh.bone_indices_offset); + s.write_uint32_t((uint32_t)smh.bone_indices_offset); s.write_uint32_t(sub_mesh->bones_per_vertex); s.write_uint32_t(sub_mesh->primitive_type); s.write_uint32_t(sub_mesh->index_format); s.write_int32_t(sub_mesh->indices_count); - s.write_int32_t((int32_t)smh.indices_offset); + s.write_uint32_t((uint32_t)smh.indices_offset); s.write_uint32_t(sub_mesh->attrib.w); s.write(0x18); s.write_uint32_t(sub_mesh->indices_offset); @@ -870,13 +893,13 @@ static void obj_classic_write_model(obj* obj, stream& s, int64_t base_offset) { s.write_float_t(mesh->bounding_sphere.center.z); s.write_float_t(mesh->bounding_sphere.radius); s.write_int32_t(mesh->num_submesh); - s.write_int32_t((int32_t)mh->submesh_array); + s.write_uint32_t((uint32_t)mh->submesh_array); s.write_uint32_t(mh->format); s.write_int32_t(mh->size_vertex); s.write_int32_t(mh->num_vertex); for (uint32_t j = 0; j < 20; j++) - s.write_int32_t((int32_t)mh->vertex[j]); + s.write_uint32_t((uint32_t)mh->vertex[j]); s.write_uint32_t(mesh->attrib.w); s.write_uint32_t(mh->vertex_flags); @@ -907,9 +930,9 @@ static void obj_classic_write_model(obj* obj, stream& s, int64_t base_offset) { s.write_float_t(obj->bounding_sphere.center.z); s.write_float_t(obj->bounding_sphere.radius); s.write_int32_t(obj->num_mesh); - s.write_int32_t((int32_t)oh.mesh_array); + s.write_uint32_t((uint32_t)oh.mesh_array); s.write_int32_t(obj->num_material); - s.write_int32_t((int32_t)oh.material_array); + s.write_uint32_t((uint32_t)oh.material_array); s.write_uint32_t(obj->reserved[0]); s.write_uint32_t(obj->reserved[1]); s.write_uint32_t(obj->reserved[2]); @@ -929,12 +952,12 @@ static void obj_classic_read_skin(obj* obj, stream& s, int64_t base_offset) { s.set_position(base_offset, SEEK_SET); obj_skin_header sh = {}; - sh.bone_ids_offset = s.read_int32_t(); - sh.bone_matrices_offset = s.read_int32_t(); - sh.bone_names_offset = s.read_int32_t(); - sh.ex_data_offset = s.read_int32_t(); + sh.bone_ids_offset = s.read_uint32_t(); + sh.bone_matrices_offset = s.read_uint32_t(); + sh.bone_names_offset = s.read_uint32_t(); + sh.ex_data_offset = s.read_uint32_t(); sk->bones_count = s.read_int32_t(); - sh.bone_parent_ids_offset = s.read_int32_t(); + sh.bone_parent_ids_offset = s.read_uint32_t(); s.read(0, 0x0C); if (sh.bone_ids_offset) { @@ -999,12 +1022,12 @@ static void obj_classic_read_skin(obj* obj, stream& s, int64_t base_offset) { exh.osage_count = s.read_int32_t(); ex->osage_nodes_count = s.read_int32_t(); s.read(0, 0x04); - exh.osage_nodes_offset = s.read_int32_t(); - exh.osage_names_offset = s.read_int32_t(); - exh.blocks_offset = s.read_int32_t(); + exh.osage_nodes_offset = s.read_uint32_t(); + exh.osage_names_offset = s.read_uint32_t(); + exh.blocks_offset = s.read_uint32_t(); exh.bone_names_count = s.read_int32_t(); - exh.bone_names_offset = s.read_int32_t(); - exh.osage_sibling_infos_offset = s.read_int32_t(); + exh.bone_names_offset = s.read_uint32_t(); + exh.osage_sibling_infos_offset = s.read_uint32_t(); exh.cloth_count = s.read_uint32_t(); ex->reserved[0] = s.read_uint32_t(); ex->reserved[1] = s.read_uint32_t(); @@ -1084,8 +1107,8 @@ static void obj_classic_read_skin(obj* obj, stream& s, int64_t base_offset) { obj_skin_block_header* bhs = force_malloc_s(obj_skin_block_header, ex->blocks_count); s.set_position(exh.blocks_offset, SEEK_SET); for (uint32_t i = 0; i < ex->blocks_count; i++) { - bhs[i].block_signature_offset = s.read_int32_t(); - bhs[i].block_offset = s.read_int32_t(); + bhs[i].block_signature_offset = s.read_uint32_t(); + bhs[i].block_offset = s.read_uint32_t(); } ex->blocks = force_malloc_s(obj_skin_block, ex->blocks_count); @@ -1239,11 +1262,11 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { int64_t osage_block_node = 0; int64_t motion_block_node_mats = 0; int64_t motion_block_node_name_offset = 0; - int64_t field_18 = 0; - int64_t field_1C = 0; - int64_t field_20 = 0; - int64_t field_24 = 0; - int64_t field_28 = 0; + int64_t cloth_mats = 0; + int64_t cloth_root = 0; + int64_t cloth_nodes = 0; + int64_t cloth_mesh_indices = 0; + int64_t cloth_backface_mesh_indices = 0; obj_skin_ex_data_header exh = {}; if (sk->ex_data_init) { @@ -1312,11 +1335,14 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { obj_skin_block_cloth* cloth = &block->cloth; obj_skin_strings_push_back_check(strings, cloth->mesh_name); obj_skin_strings_push_back_check(strings, cloth->backface_mesh_name); - for (uint32_t k = 0; k < cloth->count; k++) { - obj_skin_block_cloth_field_1C* sub = &cloth->field_1C[k]; + for (uint32_t k = 0; k < cloth->root_count; k++) { + obj_skin_block_cloth_root* sub = &cloth->root[k]; for (uint32_t l = 0; l < 4; l++) - obj_skin_strings_push_back_check(strings, sub->sub_data[l].bone_name); + obj_skin_strings_push_back_check(strings, sub->bone_weights[l].bone_name); } + + if (cloth->skin_param_init) + obj_skin_strings_push_back_check(strings, cloth->skin_param.name); obj_skin_strings_push_back_check(strings, "CLS"); } break; case OBJ_SKIN_BLOCK_CONSTRAINT: { @@ -1396,6 +1422,9 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { osage_sibling_infos++; } } + + if (osage->skin_param_init) + obj_skin_strings_push_back_check(strings, osage->skin_param.name); obj_skin_strings_push_back_check(strings, "OSG"); obj_skin_strings_push_back_check_by_index(bone_names, @@ -1437,8 +1466,8 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { obj_skin_strings_push_back_check_by_index(bone_names, bone_names_ptr, osage->name_index); - if (osage->root_init) - obj_skin_strings_push_back_check(strings, osage->root.name); + if (osage->skin_param_init) + obj_skin_strings_push_back_check(strings, osage->skin_param.name); } break; } } @@ -1466,10 +1495,10 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { continue; obj_skin_block_osage* osage = &block->osage; - if (osage->root_init) { - obj_skin_osage_root_node* root = &osage->root; - if (root->coli) { - s.write(0x28LL * root->coli_count); + if (osage->skin_param_init) { + obj_skin_skin_param* skin_param = &osage->skin_param; + if (skin_param->coli) { + s.write(0x28ULL * skin_param->coli_count); s.align_write(0x10); } s.write(0x38); @@ -1499,6 +1528,17 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; + obj_skin_block_cloth* cloth = &block->cloth; + if (cloth->skin_param_init) { + obj_skin_skin_param* skin_param = &cloth->skin_param; + if (skin_param->coli) { + s.write(0x28ULL * skin_param->coli_count); + s.align_write(0x10); + } + s.write(0x38); + s.align_write(0x10); + } + bhs[i].block_offset = s.get_position(); s.write(0x34); } @@ -1586,61 +1626,60 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { } if (exh.cloth_count) { - field_18 = s.get_position(); + cloth_mats = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - for (uint32_t j = 0; j < 32; j++) - if (cloth->field_10 & (1 << j)) - s.write(sizeof(mat4)); + for (uint32_t j = 0; j < 3; j++) + s.write(sizeof(mat4)); } s.align_write(0x10); - field_1C = s.get_position(); + cloth_root = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write((10 * sizeof(int32_t) - + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) * cloth->count); + s.write((sizeof(int32_t) + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) + * cloth->root_count * (cloth->nodes_count - 1ULL)); } s.align_write(0x10); - field_20 = s.get_position(); + cloth_nodes = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(10 * (11 * sizeof(int32_t)) * cloth->count); + s.write((11 * sizeof(int32_t)) * cloth->root_count * (cloth->nodes_count - 1ULL)); } s.align_write(0x10); - field_24 = s.get_position(); + cloth_mesh_indices = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(sizeof(uint16_t) + cloth->field_24_count * sizeof(uint16_t)); + s.write(sizeof(uint16_t) + cloth->mesh_indices_count * sizeof(uint16_t)); } s.align_write(0x10); - field_28 = s.get_position(); + cloth_backface_mesh_indices = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(sizeof(uint16_t) + cloth->field_28_count * sizeof(uint16_t)); + s.write(sizeof(uint16_t) + cloth->backface_mesh_indices_count * sizeof(uint16_t)); } s.align_write(0x10); } @@ -1675,7 +1714,8 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { s.position_push(bhs[i].block_offset, SEEK_SET); obj_classic_write_skin_block_cloth(&block->cloth, - s, strings, string_offsets, &field_18, &field_1C, &field_20, &field_24, &field_28); + s, strings, string_offsets, &cloth_mats, &cloth_root, + &cloth_nodes, &cloth_mesh_indices, &cloth_backface_mesh_indices); s.position_pop(); } @@ -1753,28 +1793,28 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { obj_skin_block* block = &ex->blocks[i]; switch (block->type) { case OBJ_SKIN_BLOCK_CLOTH: - s.write_int32_t((int32_t)cls_offset); - s.write_int32_t((int32_t)bhs[i].block_offset); + s.write_uint32_t((uint32_t)cls_offset); + s.write_uint32_t((uint32_t)bhs[i].block_offset); break; case OBJ_SKIN_BLOCK_CONSTRAINT: - s.write_int32_t((int32_t)cns_offset); - s.write_int32_t((int32_t)bhs[i].block_offset); + s.write_uint32_t((uint32_t)cns_offset); + s.write_uint32_t((uint32_t)bhs[i].block_offset); break; case OBJ_SKIN_BLOCK_EXPRESSION: - s.write_int32_t((int32_t)exp_offset); - s.write_int32_t((int32_t)bhs[i].block_offset); + s.write_uint32_t((uint32_t)exp_offset); + s.write_uint32_t((uint32_t)bhs[i].block_offset); break; case OBJ_SKIN_BLOCK_MOTION: - s.write_int32_t((int32_t)mot_offset); - s.write_int32_t((int32_t)bhs[i].block_offset); + s.write_uint32_t((uint32_t)mot_offset); + s.write_uint32_t((uint32_t)bhs[i].block_offset); break; case OBJ_SKIN_BLOCK_OSAGE: - s.write_int32_t((int32_t)osg_offset); - s.write_int32_t((int32_t)bhs[i].block_offset); + s.write_uint32_t((uint32_t)osg_offset); + s.write_uint32_t((uint32_t)bhs[i].block_offset); break; default: - s.write_int32_t(0); - s.write_int32_t(0); + s.write_uint32_t(0); + s.write_uint32_t(0); break; } } @@ -1790,7 +1830,7 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { for (uint32_t i = 0; i < sk->bones_count; i++) { size_t str_offset = obj_skin_strings_get_string_offset( strings, string_offsets, sk->bones[i].name); - s.write_int32_t((int32_t)str_offset); + s.write_uint32_t((uint32_t)str_offset); } s.position_pop(); } @@ -1803,7 +1843,7 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { for (std::string& i : bone_names) { size_t str_offset = obj_skin_strings_get_string_offset(strings, string_offsets, i.c_str()); - s.write_int32_t((int32_t)str_offset); + s.write_uint32_t((uint32_t)str_offset); } s.position_pop(); @@ -1834,7 +1874,7 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { for (std::string& i : osage_names) { size_t str_offset = obj_skin_strings_get_string_offset(strings, string_offsets, i.c_str()); - s.write_int32_t((int32_t)str_offset); + s.write_uint32_t((uint32_t)str_offset); } s.position_pop(); } @@ -1861,41 +1901,38 @@ static void obj_classic_write_skin(obj* obj, stream& s, int64_t base_offset) { } s.position_push(base_offset, SEEK_SET); - s.write_int32_t((int32_t)sh.bone_ids_offset); - s.write_int32_t((int32_t)sh.bone_matrices_offset); - s.write_int32_t((int32_t)sh.bone_names_offset); - s.write_int32_t((int32_t)sh.ex_data_offset); + s.write_uint32_t((uint32_t)sh.bone_ids_offset); + s.write_uint32_t((uint32_t)sh.bone_matrices_offset); + s.write_uint32_t((uint32_t)sh.bone_names_offset); + s.write_uint32_t((uint32_t)sh.ex_data_offset); s.write_int32_t(sk->bones_count); - s.write_int32_t((int32_t)sh.bone_parent_ids_offset); + s.write_uint32_t((uint32_t)sh.bone_parent_ids_offset); s.write(0x0C); s.position_pop(); } static void obj_classic_read_skin_block_cloth(obj_skin_block_cloth* b, stream& s, char** str) { - int32_t mesh_name_offset = s.read_int32_t(); - int32_t backface_mesh_name_offset = s.read_int32_t(); + uint32_t mesh_name_offset = s.read_uint32_t(); + uint32_t backface_mesh_name_offset = s.read_uint32_t(); b->field_8 = s.read_int32_t(); - b->count = s.read_int32_t(); - b->field_10 = s.read_int32_t(); + b->root_count = s.read_int32_t(); + b->nodes_count = s.read_int32_t(); b->field_14 = s.read_int32_t(); - int32_t field_18_offset = s.read_int32_t(); - int32_t field_1C_offset = s.read_int32_t(); - int32_t field_20_offset = s.read_int32_t(); - int32_t field_24_offset = s.read_int32_t(); - int32_t field_28_offset = s.read_int32_t(); - b->field_2C = s.read_uint32_t(); - b->field_30 = s.read_uint32_t(); + uint32_t mats_offset = s.read_uint32_t(); + uint32_t root_offset = s.read_uint32_t(); + uint32_t nodes_offset = s.read_uint32_t(); + uint32_t mesh_indices_offset = s.read_uint32_t(); + uint32_t backface_mesh_indices_offset = s.read_uint32_t(); + uint32_t skin_param_offset = s.read_uint32_t(); + b->reserved = s.read_uint32_t(); b->mesh_name = s.read_utf8_string_null_terminated_offset(mesh_name_offset); b->backface_mesh_name = s.read_utf8_string_null_terminated_offset(backface_mesh_name_offset); - if (field_18_offset) { - s.position_push(field_18_offset, SEEK_SET); - for (uint32_t i = 0; i < 32; i++) { - if (~b->field_10 & (1 << i)) - continue; - + if (mats_offset) { + s.position_push(mats_offset, SEEK_SET); + for (uint32_t i = 0; i < 3; i++) { mat4 mat; mat.row0.x = s.read_float_t(); mat.row0.y = s.read_float_t(); @@ -1914,91 +1951,112 @@ static void obj_classic_read_skin_block_cloth(obj_skin_block_cloth* b, mat.row3.z = s.read_float_t(); mat.row3.w = s.read_float_t(); mat4_transpose(&mat, &mat); - b->field_18[i] = mat; + b->mats[i] = mat; } s.position_pop(); } - if (field_1C_offset) { - s.position_push(field_1C_offset, SEEK_SET); - b->field_1C = force_malloc_s(obj_skin_block_cloth_field_1C, b->count); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_1C* f = &b->field_1C[i]; - f->field_0 = s.read_float_t(); - f->field_4 = s.read_float_t(); - f->field_8 = s.read_float_t(); - f->field_C = s.read_float_t(); - f->field_10 = s.read_float_t(); - f->field_14 = s.read_float_t(); + if (root_offset) { + s.position_push(root_offset, SEEK_SET); + b->root = force_malloc_s(obj_skin_block_cloth_root, b->root_count); + for (uint32_t i = 0; i < b->root_count; i++) { + obj_skin_block_cloth_root* f = &b->root[i]; + f->trans.x = s.read_float_t(); + f->trans.y = s.read_float_t(); + f->trans.z = s.read_float_t(); + f->normal.x = s.read_float_t(); + f->normal.y = s.read_float_t(); + f->normal.z = s.read_float_t(); f->field_18 = s.read_float_t(); - f->field_1C = s.read_uint32_t(); - f->field_20 = s.read_uint32_t(); - f->field_24 = s.read_uint32_t(); + f->field_1C = s.read_int32_t(); + f->field_20 = s.read_int32_t(); + f->field_24 = s.read_int32_t(); for (uint32_t j = 0; j < 4; j++) - obj_classic_read_skin_block_cloth_field_1C_sub(&f->sub_data[j], s, str); + obj_classic_read_skin_block_cloth_root_bone_weight(&f->bone_weights[j], s, str); } s.position_pop(); } - if (field_20_offset) { - s.position_push(field_20_offset, SEEK_SET); - b->field_20 = force_malloc_s(obj_skin_block_cloth_field_20, b->count); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_20* f = &b->field_20[i]; - for (uint32_t j = 0; j < 10; j++) - obj_classic_read_skin_block_cloth_field_20_sub(&f->sub_data[j], s, str); - } + if (nodes_offset) { + s.position_push(nodes_offset, SEEK_SET); + b->nodes = force_malloc_s(obj_skin_block_cloth_node, + b->root_count * (b->nodes_count - 1ULL)); + for (uint32_t i = 0; i < b->nodes_count - 1; i++) + for (uint32_t j = 0; j < b->root_count; j++) { + obj_skin_block_cloth_node* f = &b->nodes[i * b->root_count + j]; + f->flags = s.read_uint32_t(); + f->trans.x = s.read_float_t(); + f->trans.y = s.read_float_t(); + f->trans.z = s.read_float_t(); + f->trans_diff.x = s.read_float_t(); + f->trans_diff.y = s.read_float_t(); + f->trans_diff.z = s.read_float_t(); + f->length = s.read_float_t(); + f->field_20 = s.read_float_t(); + f->field_24 = s.read_float_t(); + f->field_28 = s.read_float_t(); + } s.position_pop(); } - if (field_24_offset) { - s.position_push(field_24_offset, SEEK_SET); - b->field_24_count = s.read_uint16_t_reverse_endianness(); - b->field_24 = force_malloc_s(uint16_t, b->field_24_count); - s.read(b->field_24, b->field_24_count * sizeof(uint16_t)); + if (mesh_indices_offset) { + s.position_push(mesh_indices_offset, SEEK_SET); + b->mesh_indices_count = s.read_uint16_t_reverse_endianness(); + b->mesh_indices = force_malloc_s(uint16_t, b->mesh_indices_count); + s.read(b->mesh_indices, b->mesh_indices_count * sizeof(uint16_t)); s.position_pop(); } - if (field_28_offset) { - s.position_push(field_28_offset, SEEK_SET); - b->field_28_count = s.read_uint16_t_reverse_endianness(); - b->field_28 = force_malloc_s(uint16_t, b->field_28_count); - s.read(b->field_28, b->field_28_count * sizeof(uint16_t)); + if (backface_mesh_indices_offset) { + s.position_push(backface_mesh_indices_offset, SEEK_SET); + b->backface_mesh_indices_count = s.read_uint16_t_reverse_endianness(); + b->backface_mesh_indices = force_malloc_s(uint16_t, b->backface_mesh_indices_count); + s.read(b->backface_mesh_indices, b->backface_mesh_indices_count * sizeof(uint16_t)); s.position_pop(); } + + if (skin_param_offset) { + obj_classic_read_skin_param(&b->skin_param, s, str); + b->skin_param_init = true; + } + else + b->skin_param_init = false; } static void obj_classic_write_skin_block_cloth(obj_skin_block_cloth* b, stream& s, std::vector& strings, std::vector& string_offsets, - int64_t* field_18_offset, int64_t* field_1C_offset, int64_t* field_20_offset, - int64_t* field_24_offset, int64_t* field_28_offset) { + int64_t* mats_offset, int64_t* root_offset, int64_t* nodes_offset, + int64_t* mesh_indices_offset, int64_t* backface_mesh_indices_offset) { + int64_t skin_param_offset = 0; + if (b->skin_param_init) { + skin_param_offset = s.get_position(); + obj_classic_write_skin_param(&b->skin_param, s, strings, string_offsets); + } + int64_t mesh_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->mesh_name); int64_t backface_mesh_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->backface_mesh_name); - s.write_int32_t((int32_t)mesh_name_offset); - s.write_int32_t((int32_t)backface_mesh_name_offset); + s.write_uint32_t((uint32_t)mesh_name_offset); + s.write_uint32_t((uint32_t)backface_mesh_name_offset); s.write_int32_t(b->field_8); - s.write_int32_t(b->count); - s.write_int32_t(b->field_10); + s.write_int32_t(b->root_count); + s.write_int32_t(b->nodes_count); s.write_int32_t(b->field_14); - s.write_int32_t((int32_t)*field_18_offset); - s.write_int32_t((int32_t)*field_1C_offset); - s.write_int32_t((int32_t)*field_20_offset); - s.write_int32_t((int32_t)*field_24_offset); - s.write_int32_t((int32_t)*field_28_offset); - s.write_uint32_t(b->field_2C); - s.write_uint32_t(b->field_30); + s.write_uint32_t((uint32_t)*mats_offset); + s.write_uint32_t((uint32_t)*root_offset); + s.write_uint32_t((uint32_t)*nodes_offset); + s.write_uint32_t((uint32_t)*mesh_indices_offset); + s.write_uint32_t((uint32_t)*backface_mesh_indices_offset); + s.write_uint32_t((uint32_t)skin_param_offset); + s.write_uint32_t(b->reserved); - if (b->field_10) { - s.position_push(*field_18_offset, SEEK_SET); - for (uint32_t i = 0; i < 32; i++) { - if (~b->field_10 & (1 << i)) - continue; - - mat4u& mat = b->field_18[i]; + if (b->nodes_count) { + s.position_push(*mats_offset, SEEK_SET); + for (uint32_t i = 0; i < 3; i++) { + mat4u& mat = b->mats[i]; s.write_float_t(mat.row0.x); s.write_float_t(mat.row1.x); s.write_float_t(mat.row2.x); @@ -2015,121 +2073,100 @@ static void obj_classic_write_skin_block_cloth(obj_skin_block_cloth* b, s.write_float_t(mat.row1.w); s.write_float_t(mat.row2.w); s.write_float_t(mat.row3.w); - *field_18_offset += sizeof(mat4); + *mats_offset += sizeof(mat4); } s.position_pop(); } - if (b->field_1C) { - s.position_push(*field_1C_offset, SEEK_SET); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_1C* f = &b->field_1C[i]; - s.write_float_t(f->field_0); - s.write_float_t(f->field_4); - s.write_float_t(f->field_8); - s.write_float_t(f->field_C); - s.write_float_t(f->field_10); - s.write_float_t(f->field_14); + if (b->root) { + s.position_push(*root_offset, SEEK_SET); + for (uint32_t i = 0; i < b->root_count; i++) { + obj_skin_block_cloth_root* f = &b->root[i]; + s.write_float_t(f->trans.x); + s.write_float_t(f->trans.y); + s.write_float_t(f->trans.z); + s.write_float_t(f->normal.x); + s.write_float_t(f->normal.y); + s.write_float_t(f->normal.z); s.write_float_t(f->field_18); - s.write_uint32_t(f->field_1C); - s.write_uint32_t(f->field_20); - s.write_uint32_t(f->field_24); + s.write_int32_t(f->field_1C); + s.write_int32_t(f->field_20); + s.write_int32_t(f->field_24); for (uint32_t j = 0; j < 4; j++) - obj_classic_write_skin_block_cloth_field_1C_sub(&f->sub_data[j], + obj_classic_write_skin_block_cloth_root_bone_weight(&f->bone_weights[j], s, strings, string_offsets); } s.position_pop(); - *field_1C_offset += (10 * sizeof(int32_t) - + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) * b->count; + *root_offset += (sizeof(int32_t) + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) + * b->root_count * (b->nodes_count - 1ULL); } - if (b->field_20) { - s.position_push(*field_20_offset, SEEK_SET); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_20* f = &b->field_20[i]; - for (uint32_t j = 0; j < 10; j++) - obj_classic_write_skin_block_cloth_field_20_sub(&f->sub_data[j], - s, strings, string_offsets); - } + if (b->nodes) { + s.position_push(*nodes_offset, SEEK_SET); + for (uint32_t i = 0; i < b->nodes_count - 1; i++) + for (uint32_t j = 0; j < b->root_count; j++) { + obj_skin_block_cloth_node* f = &b->nodes[i * b->root_count + j]; + s.write_uint32_t(f->flags); + s.write_float_t(f->trans.x); + s.write_float_t(f->trans.y); + s.write_float_t(f->trans.z); + s.write_float_t(f->trans_diff.x); + s.write_float_t(f->trans_diff.y); + s.write_float_t(f->trans_diff.z); + s.write_float_t(f->length); + s.write_float_t(f->field_20); + s.write_float_t(f->field_24); + s.write_float_t(f->field_24); + } s.position_pop(); - *field_20_offset += 10 * (11 * sizeof(int32_t)) * b->count; + *nodes_offset += (11 * sizeof(int32_t)) * b->root_count * (b->nodes_count - 1ULL); } - if (b->field_24) { - s.position_push(*field_24_offset, SEEK_SET); - s.write_uint16_t((uint16_t)b->field_24_count); - s.write(b->field_24, b->field_24_count * sizeof(uint16_t)); + if (b->mesh_indices) { + s.position_push(*mesh_indices_offset, SEEK_SET); + s.write_uint16_t((uint16_t)b->mesh_indices_count); + s.write(b->mesh_indices, b->mesh_indices_count * sizeof(uint16_t)); s.position_pop(); - *field_28_offset += sizeof(uint16_t) + b->field_24_count * sizeof(uint16_t); + *mesh_indices_offset += sizeof(uint16_t) + b->mesh_indices_count * sizeof(uint16_t); } - if (b->field_28) { - s.position_push(*field_28_offset, SEEK_SET); - s.write_uint16_t((uint16_t)b->field_28_count); - s.write(b->field_28, b->field_28_count * sizeof(uint16_t)); + if (b->backface_mesh_indices) { + s.position_push(*backface_mesh_indices_offset, SEEK_SET); + s.write_uint16_t((uint16_t)b->backface_mesh_indices_count); + s.write(b->backface_mesh_indices, b->backface_mesh_indices_count * sizeof(uint16_t)); s.position_pop(); - *field_28_offset += sizeof(uint16_t) + b->field_28_count * sizeof(uint16_t); + *backface_mesh_indices_offset += sizeof(uint16_t) + b->backface_mesh_indices_count * sizeof(uint16_t); } } -static void obj_classic_read_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, +static void obj_classic_read_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, char** str) { - int32_t bone_name_offset = s.read_int32_t(); + int32_t bone_name_offset = s.read_uint32_t(); sub->bone_name = s.read_utf8_string_null_terminated_offset(bone_name_offset); sub->weight = s.read_float_t(); sub->matrix_index = s.read_uint32_t(); - sub->field_C = s.read_uint32_t(); + sub->reserved = s.read_uint32_t(); } -static void obj_classic_write_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, +static void obj_classic_write_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, std::vector& strings, std::vector& string_offsets) { int64_t bone_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, sub->bone_name); - s.write_int32_t((int32_t)bone_name_offset); + s.write_uint32_t((uint32_t)bone_name_offset); s.write_float_t(sub->weight); s.write_uint32_t(sub->matrix_index); - s.write_uint32_t(sub->field_C); -} - -static void obj_classic_read_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, char** str) { - sub->field_0 = s.read_uint32_t(); - sub->field_4 = s.read_float_t(); - sub->field_8 = s.read_float_t(); - sub->field_C = s.read_float_t(); - sub->field_10 = s.read_float_t(); - sub->field_14 = s.read_float_t(); - sub->field_18 = s.read_float_t(); - sub->field_1C = s.read_float_t(); - sub->field_20 = s.read_float_t(); - sub->field_24 = s.read_float_t(); - sub->field_28 = s.read_float_t(); -} - -static void obj_classic_write_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, std::vector& strings, std::vector& string_offsets) { - s.write_uint32_t(sub->field_0); - s.write_float_t(sub->field_4); - s.write_float_t(sub->field_8); - s.write_float_t(sub->field_C); - s.write_float_t(sub->field_10); - s.write_float_t(sub->field_14); - s.write_float_t(sub->field_18); - s.write_float_t(sub->field_1C); - s.write_float_t(sub->field_20); - s.write_float_t(sub->field_24); - s.write_float_t(sub->field_28); + s.write_uint32_t(sub->reserved); } static void obj_classic_read_skin_block_constraint(obj_skin_block_constraint* b, stream& s, char** str) { obj_classic_read_skin_block_node(&b->base, s, str); - int32_t type_offset = s.read_int32_t(); + uint32_t type_offset = s.read_uint32_t(); char* type = s.read_utf8_string_null_terminated_offset(type_offset); - int32_t name_offset = s.read_int32_t(); + uint32_t name_offset = s.read_uint32_t(); char* name = s.read_utf8_string_null_terminated_offset(name_offset); b->name_index = 0; @@ -2142,7 +2179,7 @@ static void obj_classic_read_skin_block_constraint(obj_skin_block_constraint* b, b->coupling = (obj_skin_block_constraint_coupling)s.read_int32_t(); - int32_t source_node_name_offset = s.read_int32_t(); + uint32_t source_node_name_offset = s.read_uint32_t(); b->source_node_name = s.read_utf8_string_null_terminated_offset(source_node_name_offset); if (!str_utils_compare(type, "Orientation")) { @@ -2205,17 +2242,17 @@ static void obj_classic_write_skin_block_constraint(obj_skin_block_constraint* b type_offset = offsets[3]; break; } - s.write_int32_t((int32_t)type_offset); + s.write_uint32_t((uint32_t)type_offset); int64_t name_offset = obj_skin_strings_get_string_offset_by_index(strings, string_offsets, bone_names, b->name_index); - s.write_int32_t((int32_t)name_offset); + s.write_uint32_t((uint32_t)name_offset); s.write_int32_t(b->coupling); int64_t source_node_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->source_node_name); - s.write_int32_t((int32_t)source_node_name_offset); + s.write_uint32_t((uint32_t)source_node_name_offset); switch (b->type) { case OBJ_SKIN_BLOCK_CONSTRAINT_ORIENTATION: @@ -2282,7 +2319,7 @@ static void obj_classic_read_skin_block_constraint_up_vector_old(obj_skin_block_ up->point_at.y = s.read_float_t(); up->point_at.z = s.read_float_t(); - int32_t name_offset = s.read_int32_t(); + uint32_t name_offset = s.read_uint32_t(); up->name = s.read_utf8_string_null_terminated_offset(name_offset); } @@ -2299,14 +2336,14 @@ static void obj_classic_write_skin_block_constraint_up_vector_old(obj_skin_block int64_t name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, up->name); - s.write_int32_t((int32_t)name_offset); + s.write_uint32_t((uint32_t)name_offset); } static void obj_classic_read_skin_block_expression(obj_skin_block_expression* b, stream& s, char** str) { obj_classic_read_skin_block_node(&b->base, s, str); - int32_t name_offset = s.read_int32_t(); + uint32_t name_offset = s.read_uint32_t(); char* name = s.read_utf8_string_null_terminated_offset(name_offset); b->name_index = 0; @@ -2320,7 +2357,7 @@ static void obj_classic_read_skin_block_expression(obj_skin_block_expression* b, b->expressions_count = s.read_int32_t(); b->expressions_count = min(b->expressions_count, 9); for (uint32_t i = 0; i < b->expressions_count; i++) { - int32_t expression_offset = s.read_int32_t(); + uint32_t expression_offset = s.read_uint32_t(); if (expression_offset) b->expressions[i] = s.read_utf8_string_null_terminated_offset(expression_offset); } @@ -2335,13 +2372,13 @@ static void obj_classic_write_skin_block_expression(obj_skin_block_expression* b int64_t name_offset = obj_skin_strings_get_string_offset_by_index(strings, string_offsets, bone_names, b->name_index); - s.write_int32_t((int32_t)name_offset); + s.write_uint32_t((uint32_t)name_offset); s.write_int32_t(min(b->expressions_count, 9)); for (uint32_t i = 0; i < b->expressions_count && i < 9; i++) { int64_t expression_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->expressions[i]); - s.write_int32_t((int32_t)expression_offset); + s.write_uint32_t((uint32_t)expression_offset); } for (uint32_t i = b->expressions_count; i < 9; i++) @@ -2352,10 +2389,10 @@ static void obj_classic_read_skin_block_motion(obj_skin_block_motion* b, stream& s, char** str) { obj_classic_read_skin_block_node(&b->base, s, str); - int32_t name_offset = s.read_int32_t(); + uint32_t name_offset = s.read_uint32_t(); b->nodes_count = s.read_int32_t(); - int32_t bone_names_offset = s.read_int32_t(); - int32_t bone_matrices_offset = s.read_int32_t(); + uint32_t bone_names_offset = s.read_uint32_t(); + uint32_t bone_matrices_offset = s.read_uint32_t(); char* name = s.read_utf8_string_null_terminated_offset(name_offset); @@ -2413,10 +2450,10 @@ static void obj_classic_write_skin_block_motion(obj_skin_block_motion* b, int64_t name_offset = obj_skin_strings_get_string_offset_by_index(strings, string_offsets, bone_names, b->name_index); - s.write_int32_t((int32_t)name_offset); + s.write_uint32_t((uint32_t)name_offset); s.write_int32_t(b->nodes_count); - s.write_int32_t((int32_t)*bone_names_offset); - s.write_int32_t((int32_t)*bone_matrices_offset); + s.write_uint32_t((uint32_t)*bone_names_offset); + s.write_uint32_t((uint32_t)*bone_matrices_offset); if (b->nodes) { s.position_push(*bone_names_offset, SEEK_SET); @@ -2452,7 +2489,7 @@ static void obj_classic_write_skin_block_motion(obj_skin_block_motion* b, static void obj_classic_read_skin_block_node(obj_skin_block_node* b, stream& s, char** str) { - int32_t parent_name_offset = s.read_int32_t(); + uint32_t parent_name_offset = s.read_uint32_t(); b->parent_name = s.read_utf8_string_null_terminated_offset(parent_name_offset); b->position.x = s.read_float_t(); @@ -2470,7 +2507,7 @@ static void obj_classic_write_skin_block_node(obj_skin_block_node* b, stream& s, std::vector& strings, std::vector& string_offsets) { int64_t parent_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->parent_name); - s.write_int32_t((int32_t)parent_name_offset); + s.write_uint32_t((uint32_t)parent_name_offset); s.write_float_t(b->position.x); s.write_float_t(b->position.y); @@ -2505,52 +2542,8 @@ static void obj_classic_read_skin_block_osage(obj_skin_block_osage* b, s.position_push(offset, SEEK_SET); if (~s.read_uint32_t() & 0x8000) { - obj_skin_osage_root_node* root = &b->root; - root->coli = 0; - root->coli_count = 0; - - root->unk0 = s.read_int32_t(); - root->force = s.read_float_t(); - root->force_gain = s.read_float_t(); - root->air_res = s.read_float_t(); - root->rot_y = s.read_float_t(); - root->rot_z = s.read_float_t(); - root->hinge_y = s.read_float_t(); - root->hinge_z = s.read_float_t(); - root->name = s.read_utf8_string_null_terminated(); - int32_t coli_offset = s.read_int32_t(); - root->coli_r = s.read_float_t(); - root->friction = s.read_float_t(); - root->wind_afc = s.read_float_t(); - root->unk44 = s.read_int32_t(); - - if (coli_offset) { - s.set_position(coli_offset, SEEK_SET); - int32_t coli_count = 0; - while (s.read_int32_t()) { - s.read(44); - coli_count++; - } - - root->coli = force_malloc_s(obj_skin_osage_root_coli, coli_count); - root->coli_count = coli_count; - - s.set_position(coli_offset, SEEK_SET); - for (int32_t i = 0; i < root->coli_count; i++) { - obj_skin_osage_root_coli* coli = &root->coli[i]; - coli->type = (obj_skin_osage_root_coli_type)s.read_int32_t(); - coli->bone0_index = s.read_int32_t(); - coli->bone1_index = s.read_int32_t(); - coli->radius = s.read_float_t(); - coli->bone0_pos.x = s.read_float_t(); - coli->bone0_pos.y = s.read_float_t(); - coli->bone0_pos.z = s.read_float_t(); - coli->bone1_pos.x = s.read_float_t(); - coli->bone1_pos.y = s.read_float_t(); - coli->bone1_pos.z = s.read_float_t(); - } - } - b->root_init = true; + obj_classic_read_skin_param(&b->skin_param, s, str); + b->skin_param_init = true; } else { s.set_position(offset, SEEK_SET); @@ -2562,52 +2555,17 @@ static void obj_classic_read_skin_block_osage(obj_skin_block_osage* b, node->rotation.y = s.read_float_t(); node->rotation.z = s.read_float_t(); } - b->root_init = false; + b->skin_param_init = false; } s.position_pop(); } static void obj_classic_write_skin_block_osage(obj_skin_block_osage* b, stream& s, std::vector& strings, std::vector& string_offsets, int64_t* nodes_offset) { - int32_t nodes_offset_i32 = (int32_t)*nodes_offset; - if (b->root_init) { - nodes_offset_i32 = (int32_t)s.get_position(); - - obj_skin_osage_root_node* root = &b->root; - int32_t coli_offset = 0; - if (root->coli) { - coli_offset = (int32_t)s.get_position(); - for (int32_t i = 0; i < root->coli_count; i++) { - obj_skin_osage_root_coli* coli = &root->coli[i]; - s.write_int32_t(coli->type); - s.write_int32_t(coli->bone0_index); - s.write_int32_t(coli->bone1_index); - s.write_float_t(coli->radius); - s.write_float_t(coli->bone0_pos.x); - s.write_float_t(coli->bone0_pos.y); - s.write_float_t(coli->bone0_pos.z); - s.write_float_t(coli->bone1_pos.x); - s.write_float_t(coli->bone1_pos.y); - s.write_float_t(coli->bone1_pos.z); - } - s.align_write(0x10); - } - - s.write_int32_t(root->unk0); - s.write_float_t(root->force); - s.write_float_t(root->force_gain); - s.write_float_t(root->air_res); - s.write_float_t(root->rot_y); - s.write_float_t(root->rot_z); - s.write_float_t(root->hinge_y); - s.write_float_t(root->hinge_z); - s.write_utf8_string_null_terminated(root->name); - s.write_int32_t(coli_offset); - s.write_float_t(root->coli_r); - s.write_float_t(root->friction); - s.write_float_t(root->wind_afc); - s.write_int32_t(root->unk44); - s.write(0x08); + int64_t skin_param_offset = 0; + if (b->skin_param_init) { + skin_param_offset = s.get_position(); + obj_classic_write_skin_param(&b->skin_param, s, strings, string_offsets); } obj_classic_write_skin_block_node(&b->base, s, strings, string_offsets); @@ -2617,10 +2575,13 @@ static void obj_classic_write_skin_block_osage(obj_skin_block_osage* b, s.write_uint32_t(b->external_name_index); s.write_uint32_t(b->name_index); - s.write_int32_t(nodes_offset_i32); + if (b->skin_param_init) + s.write_uint32_t((uint32_t)skin_param_offset); + else + s.write_uint32_t((uint32_t)*nodes_offset); s.write(0x14); - if (!b->root_init && b->nodes) { + if (!b->skin_param_init && b->nodes) { s.position_push(*nodes_offset, SEEK_SET); for (uint32_t i = 0; i < b->nodes_count; i++) { obj_skin_osage_node* node = &b->nodes[i]; @@ -2635,47 +2596,138 @@ static void obj_classic_write_skin_block_osage(obj_skin_block_osage* b, } } +static void obj_classic_read_skin_param(obj_skin_skin_param* skp, + stream& s, char** str) { + skp->coli = 0; + skp->coli_count = 0; + + skp->unk0 = s.read_int32_t(); + skp->force = s.read_float_t(); + skp->force_gain = s.read_float_t(); + skp->air_res = s.read_float_t(); + skp->rot_y = s.read_float_t(); + skp->rot_z = s.read_float_t(); + skp->hinge_y = s.read_float_t(); + skp->hinge_z = s.read_float_t(); + uint32_t name_offset = s.read_uint32_t(); + uint32_t coli_offset = s.read_uint32_t(); + skp->coli_r = s.read_float_t(); + skp->friction = s.read_float_t(); + skp->wind_afc = s.read_float_t(); + skp->unk44 = s.read_int32_t(); + + skp->name = s.read_utf8_string_null_terminated_offset(name_offset); + + if (coli_offset) { + s.set_position(coli_offset, SEEK_SET); + int32_t coli_count = 0; + while (s.read_int32_t()) { + s.read(44); + coli_count++; + } + + skp->coli = force_malloc_s(obj_skin_skin_param_coli, coli_count); + skp->coli_count = coli_count; + + s.set_position(coli_offset, SEEK_SET); + for (int32_t i = 0; i < skp->coli_count; i++) { + obj_skin_skin_param_coli* coli = &skp->coli[i]; + coli->type = (obj_skin_skin_param_coli_type)s.read_int32_t(); + coli->bone0_index = s.read_int32_t(); + coli->bone1_index = s.read_int32_t(); + coli->radius = s.read_float_t(); + coli->bone0_pos.x = s.read_float_t(); + coli->bone0_pos.y = s.read_float_t(); + coli->bone0_pos.z = s.read_float_t(); + coli->bone1_pos.x = s.read_float_t(); + coli->bone1_pos.y = s.read_float_t(); + coli->bone1_pos.z = s.read_float_t(); + } + } +} + +static void obj_classic_write_skin_param(obj_skin_skin_param* skp, + stream& s, std::vector& strings, std::vector& string_offsets) { + int64_t coli_offset = 0; + if (skp->coli) { + coli_offset = s.get_position(); + for (int32_t i = 0; i < skp->coli_count; i++) { + obj_skin_skin_param_coli* coli = &skp->coli[i]; + s.write_int32_t(coli->type); + s.write_int32_t(coli->bone0_index); + s.write_int32_t(coli->bone1_index); + s.write_float_t(coli->radius); + s.write_float_t(coli->bone0_pos.x); + s.write_float_t(coli->bone0_pos.y); + s.write_float_t(coli->bone0_pos.z); + s.write_float_t(coli->bone1_pos.x); + s.write_float_t(coli->bone1_pos.y); + s.write_float_t(coli->bone1_pos.z); + } + s.align_write(0x10); + } + + int64_t name_offset = obj_skin_strings_get_string_offset(strings, + string_offsets, skp->name); + + s.write_int32_t(skp->unk0); + s.write_float_t(skp->force); + s.write_float_t(skp->force_gain); + s.write_float_t(skp->air_res); + s.write_float_t(skp->rot_y); + s.write_float_t(skp->rot_z); + s.write_float_t(skp->hinge_y); + s.write_float_t(skp->hinge_z); + s.write_uint32_t((uint32_t)name_offset); + s.write_uint32_t((uint32_t)coli_offset); + s.write_float_t(skp->coli_r); + s.write_float_t(skp->friction); + s.write_float_t(skp->wind_afc); + s.write_int32_t(skp->unk44); + s.write(0x08); +} + static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_mesh* mesh, int64_t base_offset, uint32_t num_vertex, obj_vertex_format_file vertex_format_file) { - obj_vertex_format vertex_format = OBJ_VERTEX_FORMAT_NONE; - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_POSITION) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_POSITION); + obj_vertex_format vertex_format = OBJ_VERTEX_NONE; + if (vertex_format_file & OBJ_VERTEX_FILE_POSITION) + enum_or(vertex_format, OBJ_VERTEX_POSITION); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_NORMAL) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_NORMAL); + if (vertex_format_file & OBJ_VERTEX_FILE_NORMAL) + enum_or(vertex_format, OBJ_VERTEX_NORMAL); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TANGENT) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TANGENT); + if (vertex_format_file & OBJ_VERTEX_FILE_TANGENT) + enum_or(vertex_format, OBJ_VERTEX_TANGENT); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_BINORMAL) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_BINORMAL); + if (vertex_format_file & OBJ_VERTEX_FILE_BINORMAL) + enum_or(vertex_format, OBJ_VERTEX_BINORMAL); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD0) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD0); + if (vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD0) + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD0); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD1) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD1); + if (vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD1) + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD1); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD2) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD2); + if (vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD2) + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD2); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD3) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD3); + if (vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD3) + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD3); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_COLOR0) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_COLOR0); + if (vertex_format_file & OBJ_VERTEX_FILE_COLOR0) + enum_or(vertex_format, OBJ_VERTEX_COLOR0); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_COLOR1) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_COLOR1); + if (vertex_format_file & OBJ_VERTEX_FILE_COLOR1) + enum_or(vertex_format, OBJ_VERTEX_COLOR1); - if ((vertex_format_file & (OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT | OBJ_VERTEX_FORMAT_FILE_BONE_INDEX)) - == (OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT | OBJ_VERTEX_FORMAT_FILE_BONE_INDEX)) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_BONE_DATA); + if ((vertex_format_file & (OBJ_VERTEX_FILE_BONE_WEIGHT | OBJ_VERTEX_FILE_BONE_INDEX)) + == (OBJ_VERTEX_FILE_BONE_WEIGHT | OBJ_VERTEX_FILE_BONE_INDEX)) + enum_or(vertex_format, OBJ_VERTEX_BONE_DATA); else - enum_and(vertex_format_file, ~(OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT | OBJ_VERTEX_FORMAT_FILE_BONE_INDEX)); + enum_and(vertex_format_file, ~(OBJ_VERTEX_FILE_BONE_WEIGHT | OBJ_VERTEX_FILE_BONE_INDEX)); - if (vertex_format_file & OBJ_VERTEX_FORMAT_FILE_UNKNOWN) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_UNKNOWN); + if (vertex_format_file & OBJ_VERTEX_FILE_UNKNOWN) + enum_or(vertex_format, OBJ_VERTEX_UNKNOWN); obj_vertex_data* vtx = force_malloc_s(obj_vertex_data, num_vertex); for (uint32_t i = 0; i < 20; i++) { @@ -2685,21 +2737,21 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me s.set_position(base_offset + vertex[i], SEEK_SET); switch (attribute) { - case OBJ_VERTEX_FORMAT_FILE_POSITION: + case OBJ_VERTEX_FILE_POSITION: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].position.x = s.read_float_t(); vtx[j].position.y = s.read_float_t(); vtx[j].position.z = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_NORMAL: + case OBJ_VERTEX_FILE_NORMAL: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].normal.x = s.read_float_t(); vtx[j].normal.y = s.read_float_t(); vtx[j].normal.z = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_TANGENT: + case OBJ_VERTEX_FILE_TANGENT: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].tangent.x = s.read_float_t(); vtx[j].tangent.y = s.read_float_t(); @@ -2707,38 +2759,38 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me vtx[j].tangent.w = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_BINORMAL: + case OBJ_VERTEX_FILE_BINORMAL: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].binormal.x = s.read_float_t(); vtx[j].binormal.y = s.read_float_t(); vtx[j].binormal.z = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_TEXCOORD0: + case OBJ_VERTEX_FILE_TEXCOORD0: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].texcoord0.x = s.read_float_t(); vtx[j].texcoord0.y = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_TEXCOORD1: + case OBJ_VERTEX_FILE_TEXCOORD1: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].texcoord1.x = s.read_float_t(); vtx[j].texcoord1.y = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_TEXCOORD2: + case OBJ_VERTEX_FILE_TEXCOORD2: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].texcoord2.x = s.read_float_t(); vtx[j].texcoord2.y = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_TEXCOORD3: + case OBJ_VERTEX_FILE_TEXCOORD3: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].texcoord3.x = s.read_float_t(); vtx[j].texcoord3.y = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_COLOR0: + case OBJ_VERTEX_FILE_COLOR0: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].color0.x = s.read_float_t(); vtx[j].color0.y = s.read_float_t(); @@ -2746,7 +2798,7 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me vtx[j].color0.w = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_COLOR1: + case OBJ_VERTEX_FILE_COLOR1: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].color1.x = s.read_float_t(); vtx[j].color1.y = s.read_float_t(); @@ -2754,7 +2806,7 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me vtx[j].color1.w = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT: + case OBJ_VERTEX_FILE_BONE_WEIGHT: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].bone_weight.x = s.read_float_t(); vtx[j].bone_weight.y = s.read_float_t(); @@ -2762,7 +2814,7 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me vtx[j].bone_weight.w = s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_BONE_INDEX: + case OBJ_VERTEX_FILE_BONE_INDEX: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].bone_index.x = (int32_t)s.read_float_t(); vtx[j].bone_index.y = (int32_t)s.read_float_t(); @@ -2770,7 +2822,7 @@ static void obj_classic_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_me vtx[j].bone_index.w = (int32_t)s.read_float_t(); } break; - case OBJ_VERTEX_FORMAT_FILE_UNKNOWN: + case OBJ_VERTEX_FILE_UNKNOWN: for (uint32_t j = 0; j < num_vertex; j++) { vtx[j].unknown.x = s.read_float_t(); vtx[j].unknown.y = s.read_float_t(); @@ -2793,70 +2845,70 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m obj_vertex_format_file _vertex_format_file = (obj_vertex_format_file)0; uint32_t _size_vertex = 0; - if (vertex_format & OBJ_VERTEX_FORMAT_POSITION) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_POSITION); + if (vertex_format & OBJ_VERTEX_POSITION) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_POSITION); _size_vertex += 0x0C; } - if (vertex_format & OBJ_VERTEX_FORMAT_NORMAL) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_NORMAL); + if (vertex_format & OBJ_VERTEX_NORMAL) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_NORMAL); _size_vertex += 0x0C; } - if (vertex_format & OBJ_VERTEX_FORMAT_TANGENT) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_TANGENT); + if (vertex_format & OBJ_VERTEX_TANGENT) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_TANGENT); _size_vertex += 0x10; } - if (vertex_format & OBJ_VERTEX_FORMAT_BINORMAL) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_BINORMAL); + if (vertex_format & OBJ_VERTEX_BINORMAL) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_BINORMAL); _size_vertex += 0x0C; } - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD0) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_TEXCOORD0); + if (vertex_format & OBJ_VERTEX_TEXCOORD0) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_TEXCOORD0); _size_vertex += 0x08; } - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD1) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_TEXCOORD1); + if (vertex_format & OBJ_VERTEX_TEXCOORD1) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_TEXCOORD1); _size_vertex += 0x08; } - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_TEXCOORD2); + if (vertex_format & OBJ_VERTEX_TEXCOORD2) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_TEXCOORD2); _size_vertex += 0x08; } - if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD3) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_TEXCOORD3); + if (vertex_format & OBJ_VERTEX_TEXCOORD3) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_TEXCOORD3); _size_vertex += 0x08; } - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR0) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_COLOR0); + if (vertex_format & OBJ_VERTEX_COLOR0) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_COLOR0); _size_vertex += 0x10; } - if (vertex_format & OBJ_VERTEX_FORMAT_COLOR1) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_COLOR1); + if (vertex_format & OBJ_VERTEX_COLOR1) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_COLOR1); _size_vertex += 0x10; } - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT | OBJ_VERTEX_FORMAT_FILE_BONE_INDEX); + if (vertex_format & OBJ_VERTEX_BONE_DATA) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_BONE_WEIGHT | OBJ_VERTEX_FILE_BONE_INDEX); _size_vertex += 0x20; } - if (vertex_format & OBJ_VERTEX_FORMAT_UNKNOWN) { - enum_or(_vertex_format_file, OBJ_VERTEX_FORMAT_FILE_UNKNOWN); + if (vertex_format & OBJ_VERTEX_UNKNOWN) { + enum_or(_vertex_format_file, OBJ_VERTEX_FILE_UNKNOWN); _size_vertex += 0x10; } *num_vertex = _num_vertex; *vertex_format_file = _vertex_format_file; *size_vertex = _size_vertex; - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_POSITION) { + if (_vertex_format_file & OBJ_VERTEX_FILE_POSITION) { vertex[0] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].position.x); @@ -2865,7 +2917,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_NORMAL) { + if (_vertex_format_file & OBJ_VERTEX_FILE_NORMAL) { vertex[1] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].normal.x); @@ -2874,7 +2926,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TANGENT) { + if (_vertex_format_file & OBJ_VERTEX_FILE_TANGENT) { vertex[2] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].tangent.x); @@ -2884,7 +2936,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_BINORMAL) { + if (_vertex_format_file & OBJ_VERTEX_FILE_BINORMAL) { vertex[3] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].binormal.x); @@ -2893,7 +2945,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD0) { + if (_vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD0) { vertex[4] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].texcoord0.x); @@ -2901,7 +2953,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_BONE_WEIGHT) { + if (_vertex_format_file & OBJ_VERTEX_FILE_BONE_WEIGHT) { vertex[10] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].bone_weight.x); @@ -2911,7 +2963,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_BONE_INDEX) { + if (_vertex_format_file & OBJ_VERTEX_FILE_BONE_INDEX) { vertex[11] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t((float_t)vtx[i].bone_index.x); @@ -2921,7 +2973,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD1) { + if (_vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD1) { vertex[5] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].texcoord1.x); @@ -2929,7 +2981,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD2) { + if (_vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD2) { vertex[6] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].texcoord2.x); @@ -2937,7 +2989,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_TEXCOORD3) { + if (_vertex_format_file & OBJ_VERTEX_FILE_TEXCOORD3) { vertex[7] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].texcoord3.x); @@ -2945,7 +2997,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_COLOR0) { + if (_vertex_format_file & OBJ_VERTEX_FILE_COLOR0) { vertex[8] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].color0.x); @@ -2955,7 +3007,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_COLOR1) { + if (_vertex_format_file & OBJ_VERTEX_FILE_COLOR1) { vertex[9] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].color1.x); @@ -2965,7 +3017,7 @@ static void obj_classic_write_vertex(obj* obj, stream& s, int64_t* vertex, obj_m } } - if (_vertex_format_file & OBJ_VERTEX_FORMAT_FILE_UNKNOWN) { + if (_vertex_format_file & OBJ_VERTEX_FILE_UNKNOWN) { vertex[12] = s.get_position() - base_offset; for (uint32_t i = 0; i < _num_vertex; i++) { s.write_float_t(vtx[i].unknown.x); @@ -3169,7 +3221,7 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { obj_set_header osh = {}; osh.last_obj_id = -1; - uint32_t count = os->obj_num; + uint32_t obj_num = os->obj_num; if (!is_x) { ee = { 0, 1, 44, 1 }; @@ -3188,35 +3240,35 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { } if (!is_x) - off += (uint32_t)(count * 4ULL); + off += (uint32_t)(obj_num * 4ULL); else - off += (uint32_t)(count * 8ULL); + off += (uint32_t)(obj_num * 8ULL); off = align_val(off, 0x10); if (!is_x) - off += (uint32_t)(count * 4ULL); + off += (uint32_t)(obj_num * 4ULL); else - off += (uint32_t)(count * 8ULL); + off += (uint32_t)(obj_num * 8ULL); off = align_val(off, 0x10); if (!is_x) { - ee = { off, 1, 4, (uint32_t)count }; + ee = { off, 1, 4, (uint32_t)obj_num }; ee.append(0, 1, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(count * 4ULL); + off = (uint32_t)(obj_num * 4ULL); } else { - ee = { off, 1, 8, (uint32_t)count }; + ee = { off, 1, 8, (uint32_t)obj_num }; ee.append(0, 1, ENRS_QWORD); e.vec.push_back(ee); - off = (uint32_t)(count * 8ULL); + off = (uint32_t)(obj_num * 8ULL); } off = align_val(off, 0x10); - ee = { off, 1, 4, (uint32_t)count }; + ee = { off, 1, 4, (uint32_t)obj_num }; ee.append(0, 1, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(count * 4ULL); + off = (uint32_t)(obj_num * 4ULL); off = align_val(off, 0x10); ee = { off, 1, 4, (uint32_t)os->tex_id_num }; @@ -3255,33 +3307,33 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { osh.obj_data = s_mosd.get_position(); if (!is_x) - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_f2(0, 0x20); else - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_x(0); s_mosd.align_write(0x10); osh.obj_skin_data = s_mosd.get_position(); if (!is_x) - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_f2(0, 0x20); else - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_x(0); s_mosd.align_write(0x10); osh.obj_name_data = s_mosd.get_position(); if (!is_x) - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) io_write_offset_f2_pof_add(s_mosd, 0, 0x20, &pof); else - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) io_write_offset_x_pof_add(s_mosd, 0, &pof); s_mosd.align_write(0x10); osh.obj_id_data = s_mosd.get_position(); - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_uint32_t(os->obj_data[i].id); s_mosd.align_write(0x10); @@ -3290,8 +3342,8 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { s_mosd.write_uint32_t(os->tex_id_data[i]); s_mosd.align_write(0x10); - int64_t* obj_name_datas = force_malloc_s(int64_t, count); - for (uint32_t i = 0; i < count; i++) { + int64_t* obj_name_datas = force_malloc_s(int64_t, obj_num); + for (uint32_t i = 0; i < obj_num; i++) { obj_name_datas[i] = (int32_t)s_mosd.get_position(); s_mosd.write_utf8_string_null_terminated(os->obj_data[i].name); } @@ -3299,10 +3351,10 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { s_mosd.position_push(osh.obj_name_data, SEEK_SET); if (!is_x) - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_f2(obj_name_datas[i], 0x20); else - for (uint32_t i = 0; i < count; i++) + for (uint32_t i = 0; i < obj_num; i++) s_mosd.write_offset_x(obj_name_datas[i]); s_mosd.position_pop(); free(obj_name_datas); @@ -3337,7 +3389,7 @@ static void obj_set_modern_write_inner(obj_set* os, stream& s) { s_mosd.position_pop(); f2_struct st; - for (uint32_t i = 0; i < count; i++) { + for (uint32_t i = 0; i < obj_num; i++) { obj* obj = &os->obj_data[i]; st.sub_structs.push_back({}); @@ -3851,7 +3903,7 @@ static void obj_modern_write_model(obj* obj, stream& s, obj_mesh* mesh = &obj->mesh_array[i]; obj_mesh_header* mh = &mhs[i]; - mh->format = OBJ_VERTEX_FORMAT_FILE_MODERN_STORAGE; + mh->format = OBJ_VERTEX_FILE_MODERN_STORAGE; if (mesh->num_submesh) { mh->submesh_array = s.get_position() - base_offset; for (uint32_t j = 0; j < mesh->num_submesh; j++) { @@ -4455,11 +4507,11 @@ static void obj_modern_write_skin(obj* obj, stream& s, obj_skin_block_header* bhs = 0; int64_t motion_block_node_mats = 0; int64_t motion_block_node_name_offset = 0; - int64_t field_18 = 0; - int64_t field_1C = 0; - int64_t field_20 = 0; - int64_t field_24 = 0; - int64_t field_28 = 0; + int64_t cloth_mats = 0; + int64_t cloth_root = 0; + int64_t cloth_nodes = 0; + int64_t cloth_mesh_indices = 0; + int64_t cloth_backface_mesh_indices = 0; int32_t expressions_count = 0; int32_t motion_count = 0; int32_t motion_nodes_count = 0; @@ -4476,10 +4528,10 @@ static void obj_modern_write_skin(obj* obj, stream& s, obj_skin_strings_push_back_check(strings, cloth->mesh_name); obj_skin_strings_push_back_check(strings, cloth->backface_mesh_name); - for (uint32_t k = 0; k < cloth->count; k++) { - obj_skin_block_cloth_field_1C* sub = &cloth->field_1C[k]; + for (uint32_t k = 0; k < cloth->root_count; k++) { + obj_skin_block_cloth_root* sub = &cloth->root[k]; for (uint32_t l = 0; l < 4; l++) - obj_skin_strings_push_back_check(strings, sub->sub_data[l].bone_name); + obj_skin_strings_push_back_check(strings, sub->bone_weights[l].bone_name); } obj_skin_strings_push_back_check(strings, "CLS"); } break; @@ -4874,42 +4926,41 @@ static void obj_modern_write_skin(obj* obj, stream& s, } if (exh.cloth_count) { - int32_t field_18_count = 0; - int32_t field_1C_count = 0; - int32_t field_20_count = 0; - int32_t field_24_count = 0; - int32_t field_28_count = 0; + int32_t mats_count = 0; + int32_t root_count = 0; + int32_t nodes_count = 0; + int32_t mesh_indices_count = 0; + int32_t backface_mesh_indices_count = 0; for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type == OBJ_SKIN_BLOCK_CLOTH) { - for (uint32_t j = 0; j < 32; j++) - if (block->cloth.field_10 & (1 << j)) - field_18_count++; + for (uint32_t j = 0; j < 3; j++) + mats_count++; - field_1C_count += block->cloth.field_1C ? block->cloth.count : 0; - field_20_count += block->cloth.field_20 ? block->cloth.count : 0; - field_24_count += block->cloth.field_24 ? block->cloth.field_24_count + 1 : 0; - field_28_count += block->cloth.field_28 ? block->cloth.field_28_count + 1 : 0; + root_count += block->cloth.root ? block->cloth.root_count : 0; + nodes_count += block->cloth.nodes ? block->cloth.root_count * (block->cloth.nodes_count - 1) : 0; + mesh_indices_count += block->cloth.mesh_indices ? block->cloth.mesh_indices_count + 1 : 0; + backface_mesh_indices_count += block->cloth.backface_mesh_indices ? block->cloth.backface_mesh_indices_count + 1 : 0; } } - if (field_18_count) { - ee = { off, 1, 64, (uint32_t)field_18_count }; + if (mats_count) { + ee = { off, 1, 64, (uint32_t)mats_count }; ee.append(0, 16, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(field_18_count * 64ULL); + off = (uint32_t)(mats_count * 64ULL); off = align_val(off, 0x10); } - if (field_1C_count) { + if (root_count) { if (!is_x) { - ee = { off, 1, 104, (uint32_t)field_1C_count }; + ee = { off, 1, 104, (uint32_t)root_count }; ee.append(0, 26, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(field_1C_count * 104ULL); + off = (uint32_t)(root_count * 104ULL); } else { - ee = { off, 9, 136, (uint32_t)field_1C_count }; + ee = { off, 9, 136, (uint32_t)root_count }; ee.append(0, 10, ENRS_DWORD); ee.append(0, 1, ENRS_QWORD); ee.append(0, 3, ENRS_DWORD); @@ -4920,32 +4971,32 @@ static void obj_modern_write_skin(obj* obj, stream& s, ee.append(4, 1, ENRS_QWORD); ee.append(0, 3, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(field_1C_count * 136ULL); + off = (uint32_t)(root_count * 136ULL); } off = align_val(off, 0x10); } - if (field_20_count) { - ee = { off, 1, 440, (uint32_t)field_20_count }; - ee.append(0, 110, ENRS_DWORD); + if (nodes_count) { + ee = { off, 1, 44, (uint32_t)nodes_count }; + ee.append(0, 11, ENRS_DWORD); e.vec.push_back(ee); - off = (uint32_t)(field_20_count * 440ULL); + off = (uint32_t)(nodes_count * 44ULL); off = align_val(off, 0x10); } - if (field_24_count) { - ee = { off, 1, 2, (uint32_t)field_24_count }; + if (mesh_indices_count) { + ee = { off, 1, 2, (uint32_t)mesh_indices_count }; ee.append(0, 1, ENRS_WORD); e.vec.push_back(ee); - off = (uint32_t)(field_24_count * 2ULL); + off = (uint32_t)(mesh_indices_count * 2ULL); off = align_val(off, 0x10); } - if (field_28_count) { - ee = { off, 1, 2, (uint32_t)field_28_count }; + if (backface_mesh_indices_count) { + ee = { off, 1, 2, (uint32_t)backface_mesh_indices_count }; ee.append(0, 1, ENRS_WORD); e.vec.push_back(ee); - off = (uint32_t)(field_28_count * 2ULL); + off = (uint32_t)(backface_mesh_indices_count * 2ULL); off = align_val(off, 0x10); } } @@ -5219,24 +5270,24 @@ static void obj_modern_write_skin(obj* obj, stream& s, io_write_offset_f2_pof_add(s, 0, 0x20, &pof); s.write(0x10); - if (cloth->field_10) + if (cloth->nodes_count) io_write_offset_f2_pof_add(s, 0, 0x20, &pof); else s.write(0x04); - if (cloth->count) { + if (cloth->root_count) { io_write_offset_f2_pof_add(s, 0, 0x20, &pof); io_write_offset_f2_pof_add(s, 0, 0x20, &pof); } else s.write(0x08); - if (cloth->field_24_count) + if (cloth->mesh_indices_count) io_write_offset_f2_pof_add(s, 0, 0x20, &pof); else s.write(0x04); - if (cloth->field_28_count) + if (cloth->backface_mesh_indices_count) io_write_offset_f2_pof_add(s, 0, 0x20, &pof); else s.write(0x04); @@ -5256,24 +5307,24 @@ static void obj_modern_write_skin(obj* obj, stream& s, io_write_offset_x_pof_add(s, 0, &pof); s.write(0x10); - if (cloth->field_10) + if (cloth->nodes_count) io_write_offset_x_pof_add(s, 0, &pof); else s.write(0x08); - if (cloth->count) { + if (cloth->root_count) { io_write_offset_x_pof_add(s, 0, &pof); io_write_offset_x_pof_add(s, 0, &pof); } else s.write(0x10); - if (cloth->field_24_count) + if (cloth->mesh_indices_count) io_write_offset_x_pof_add(s, 0, &pof); else s.write(0x08); - if (cloth->field_28_count) + if (cloth->backface_mesh_indices_count) io_write_offset_x_pof_add(s, 0, &pof); else s.write(0x08); @@ -5415,20 +5466,19 @@ static void obj_modern_write_skin(obj* obj, stream& s, } if (exh.cloth_count) { - field_18 = s.get_position(); + cloth_mats = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - for (uint32_t j = 0; j < 32; j++) - if (cloth->field_10 & (1 << j)) - s.write(sizeof(mat4)); + for (uint32_t j = 0; j < 3; j++) + s.write(sizeof(mat4)); } s.align_write(0x10); - field_1C = s.get_position(); + cloth_root = s.get_position(); if (!is_x) for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; @@ -5436,8 +5486,8 @@ static void obj_modern_write_skin(obj* obj, stream& s, continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write((10 * sizeof(int32_t) - + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) * cloth->count); + s.write((sizeof(int32_t) + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) + * cloth->root_count * (cloth->nodes_count - 1ULL)); } else for (uint32_t i = 0; i < ex->blocks_count; i++) { @@ -5446,41 +5496,41 @@ static void obj_modern_write_skin(obj* obj, stream& s, continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write((10 * sizeof(int32_t) + 4 * (sizeof(int64_t) - + 4 * sizeof(int32_t))) * cloth->count); + s.write((sizeof(int32_t) + 4 * (sizeof(int64_t) + 4 * sizeof(int32_t))) + * cloth->root_count* (cloth->nodes_count - 1ULL)); } s.align_write(0x10); - field_20 = s.get_position(); + cloth_nodes = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(10 * (11 * sizeof(int32_t)) * cloth->count); + s.write((11 * sizeof(int32_t)) * cloth->root_count * (cloth->nodes_count - 1ULL)); } s.align_write(0x10); - field_24 = s.get_position(); + cloth_mesh_indices = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(sizeof(uint16_t) + cloth->field_24_count * sizeof(uint16_t)); + s.write(sizeof(uint16_t) + cloth->mesh_indices_count * sizeof(uint16_t)); } s.align_write(0x10); - field_28 = s.get_position(); + cloth_backface_mesh_indices = s.get_position(); for (uint32_t i = 0; i < ex->blocks_count; i++) { obj_skin_block* block = &ex->blocks[i]; if (block->type != OBJ_SKIN_BLOCK_CLOTH) continue; obj_skin_block_cloth* cloth = &block->cloth; - s.write(sizeof(uint16_t) + cloth->field_28_count * sizeof(uint16_t)); + s.write(sizeof(uint16_t) + cloth->backface_mesh_indices_count * sizeof(uint16_t)); } s.align_write(0x10); } @@ -5514,8 +5564,9 @@ static void obj_modern_write_skin(obj* obj, stream& s, continue; s.position_push(bhs[i].block_offset, SEEK_SET); - obj_modern_write_skin_block_cloth(&block->cloth, s, strings, string_offsets, - is_x, &field_18, &field_1C, &field_20, &field_24, &field_28); + obj_modern_write_skin_block_cloth(&block->cloth, + s, strings, string_offsets, is_x, &cloth_mats, &cloth_root, + &cloth_nodes, &cloth_mesh_indices, &cloth_backface_mesh_indices); s.position_pop(); } @@ -5811,29 +5862,26 @@ static void obj_modern_read_skin_block_cloth(obj_skin_block_cloth* b, b->backface_mesh_name = s.read_utf8_string_null_terminated_offset(backface_mesh_name_offset); b->field_8 = s.read_int32_t_reverse_endianness(); - b->count = s.read_int32_t_reverse_endianness(); - b->field_10 = s.read_int32_t_reverse_endianness(); + b->root_count = s.read_int32_t_reverse_endianness(); + b->nodes_count = s.read_int32_t_reverse_endianness(); b->field_14 = s.read_int32_t_reverse_endianness(); - int64_t field_18_offset = s.read_offset(header_length, is_x); - int64_t field_1C_offset = s.read_offset(header_length, is_x); + int64_t mats_offset = s.read_offset(header_length, is_x); + int64_t root_offset = s.read_offset(header_length, is_x); - b->field_1C = 0; - b->field_20 = 0; - b->field_24 = 0; - b->field_28 = 0; - int64_t field_20_offset = s.read_offset(header_length, is_x); - int64_t field_24_offset = s.read_offset(header_length, is_x); - int64_t field_28_offset = s.read_offset(header_length, is_x); - b->field_2C = s.read_uint32_t_reverse_endianness(); - b->field_30 = s.read_uint32_t_reverse_endianness(); + b->root = 0; + b->nodes = 0; + b->mesh_indices = 0; + b->backface_mesh_indices = 0; + int64_t nodes_offset = s.read_offset(header_length, is_x); + int64_t mesh_indices_offset = s.read_offset(header_length, is_x); + int64_t backface_mesh_indices_offset = s.read_offset(header_length, is_x); + int64_t skp_root_offset = s.read_uint32_t_reverse_endianness(); + b->reserved = s.read_uint32_t_reverse_endianness(); - if (field_18_offset) { - s.position_push(field_18_offset, SEEK_SET); - for (uint32_t i = 0; i < 32; i++) { - if (~b->field_10 & (1 << i)) - continue; - - mat4u& mat = b->field_18[i]; + if (mats_offset) { + s.position_push(mats_offset, SEEK_SET); + for (uint32_t i = 0; i < 3; i++) { + mat4u& mat = b->mats[i]; mat.row0.x = s.read_float_t_reverse_endianness(); mat.row1.x = s.read_float_t_reverse_endianness(); mat.row2.x = s.read_float_t_reverse_endianness(); @@ -5854,63 +5902,73 @@ static void obj_modern_read_skin_block_cloth(obj_skin_block_cloth* b, s.position_pop(); } - if (field_1C_offset) { - s.position_push(field_1C_offset, SEEK_SET); - b->field_1C = force_malloc_s(obj_skin_block_cloth_field_1C, b->count); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_1C* f = &b->field_1C[i]; - f->field_0 = s.read_float_t_reverse_endianness(); - f->field_4 = s.read_float_t_reverse_endianness(); - f->field_8 = s.read_float_t_reverse_endianness(); - f->field_C = s.read_float_t_reverse_endianness(); - f->field_10 = s.read_float_t_reverse_endianness(); - f->field_14 = s.read_float_t_reverse_endianness(); + if (root_offset) { + s.position_push(root_offset, SEEK_SET); + b->root = force_malloc_s(obj_skin_block_cloth_root, b->root_count); + for (uint32_t i = 0; i < b->root_count; i++) { + obj_skin_block_cloth_root* f = &b->root[i]; + f->trans.x = s.read_float_t_reverse_endianness(); + f->trans.y = s.read_float_t_reverse_endianness(); + f->trans.z = s.read_float_t_reverse_endianness(); + f->normal.x = s.read_float_t_reverse_endianness(); + f->normal.y = s.read_float_t_reverse_endianness(); + f->normal.z = s.read_float_t_reverse_endianness(); f->field_18 = s.read_float_t_reverse_endianness(); - f->field_1C = s.read_uint32_t_reverse_endianness(); - f->field_20 = s.read_uint32_t_reverse_endianness(); - f->field_24 = s.read_uint32_t_reverse_endianness(); + f->field_1C = s.read_int32_t_reverse_endianness(); + f->field_20 = s.read_int32_t_reverse_endianness(); + f->field_24 = s.read_int32_t_reverse_endianness(); for (uint32_t j = 0; j < 4; j++) - obj_modern_read_skin_block_cloth_field_1C_sub(&f->sub_data[j], + obj_modern_read_skin_block_cloth_root_bone_weight(&f->bone_weights[j], s, header_length, str, is_x); } s.position_pop(); } - if (field_20_offset) { - s.position_push(field_20_offset, SEEK_SET); - b->field_20 = force_malloc_s(obj_skin_block_cloth_field_20, b->count); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_20* f = &b->field_20[i]; - for (uint32_t j = 0; j < 10; j++) - obj_modern_read_skin_block_cloth_field_20_sub(&f->sub_data[j], - s, header_length, str, is_x); + if (nodes_offset) { + s.position_push(nodes_offset, SEEK_SET); + b->nodes = force_malloc_s(obj_skin_block_cloth_node, + b->root_count * (b->nodes_count - 1ULL)); + for (uint32_t i = 0; i < b->nodes_count - 1; i++) + for (uint32_t j = 0; j < b->root_count; j++) { + obj_skin_block_cloth_node* f = &b->nodes[i * b->root_count + j]; + f->flags = s.read_uint32_t_reverse_endianness(); + f->trans.x = s.read_float_t_reverse_endianness(); + f->trans.y = s.read_float_t_reverse_endianness(); + f->trans.z = s.read_float_t_reverse_endianness(); + f->trans_diff.x = s.read_float_t_reverse_endianness(); + f->trans_diff.y = s.read_float_t_reverse_endianness(); + f->trans_diff.z = s.read_float_t_reverse_endianness(); + f->length = s.read_float_t_reverse_endianness(); + f->field_20 = s.read_float_t_reverse_endianness(); + f->field_24 = s.read_float_t_reverse_endianness(); + f->field_28 = s.read_float_t_reverse_endianness(); + } + s.position_pop(); + } + + if (mesh_indices_offset) { + s.position_push(mesh_indices_offset, SEEK_SET); + b->mesh_indices_count = s.read_uint16_t_reverse_endianness(); + b->mesh_indices = force_malloc_s(uint16_t, b->mesh_indices_count); + s.read(b->mesh_indices, b->mesh_indices_count * sizeof(uint16_t)); + if (s.is_big_endian) { + uint16_t* mesh_indices = b->mesh_indices; + for (int32_t i = 0; i < b->mesh_indices_count; i++) + mesh_indices[i] = reverse_endianness_uint16_t(mesh_indices[i]); } s.position_pop(); } - if (field_24_offset) { - s.position_push(field_24_offset, SEEK_SET); - b->field_24_count = s.read_uint16_t_reverse_endianness(); - b->field_24 = force_malloc_s(uint16_t, b->field_24_count); - s.read(b->field_24, b->field_24_count * sizeof(uint16_t)); + if (backface_mesh_indices_offset) { + s.position_push(backface_mesh_indices_offset, SEEK_SET); + b->backface_mesh_indices_count = s.read_uint16_t_reverse_endianness(); + b->backface_mesh_indices = force_malloc_s(uint16_t, b->backface_mesh_indices_count); + s.read(b->backface_mesh_indices, b->backface_mesh_indices_count * sizeof(uint16_t)); if (s.is_big_endian) { - uint16_t* field_24 = b->field_24; - for (int32_t i = 0; i < b->field_24_count; i++) - field_24[i] = reverse_endianness_uint16_t(field_24[i]); - } - s.position_pop(); - } - - if (field_28_offset) { - s.position_push(field_28_offset, SEEK_SET); - b->field_28_count = s.read_uint16_t_reverse_endianness(); - b->field_28 = force_malloc_s(uint16_t, b->field_28_count); - s.read(b->field_28, b->field_28_count * sizeof(uint16_t)); - if (s.is_big_endian) { - uint16_t* field_28 = b->field_28; - for (int32_t i = 0; i < b->field_28_count; i++) - field_28[i] = reverse_endianness_uint16_t(field_28[i]); + uint16_t* backface_mesh_indices = b->backface_mesh_indices; + for (int32_t i = 0; i < b->backface_mesh_indices_count; i++) + backface_mesh_indices[i] = reverse_endianness_uint16_t(backface_mesh_indices[i]); } s.position_pop(); } @@ -5919,8 +5977,8 @@ static void obj_modern_read_skin_block_cloth(obj_skin_block_cloth* b, static void obj_modern_write_skin_block_cloth(obj_skin_block_cloth* b, stream& s, std::vector& strings, std::vector& string_offsets, bool is_x, - int64_t* field_18_offset, int64_t* field_1C_offset, int64_t* field_20_offset, - int64_t* field_24_offset, int64_t* field_28_offset) { + int64_t* mats_offset, int64_t* root_offset, int64_t* nodes_offset, + int64_t* mesh_indices_offset, int64_t* backface_mesh_indices_offset) { int64_t mesh_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, b->mesh_name); int64_t backface_mesh_name_offset = obj_skin_strings_get_string_offset(strings, @@ -5930,40 +5988,37 @@ static void obj_modern_write_skin_block_cloth(obj_skin_block_cloth* b, s.write_offset_f2(mesh_name_offset, 0x20); s.write_offset_f2(backface_mesh_name_offset, 0x20); s.write_int32_t(b->field_8); - s.write_int32_t(b->count); - s.write_int32_t(b->field_10); + s.write_int32_t(b->root_count); + s.write_int32_t(b->nodes_count); s.write_int32_t(b->field_14); - s.write_offset_f2(b->field_10 ? *field_18_offset : 0, 0x20); - s.write_offset_f2(b->field_1C ? *field_1C_offset : 0, 0x20); - s.write_offset_f2(b->field_20 ? *field_20_offset : 0, 0x20); - s.write_offset_f2(b->field_24 ? *field_24_offset : 0, 0x20); - s.write_offset_f2(b->field_28 ? *field_28_offset : 0, 0x20); - s.write_uint32_t(b->field_2C); - s.write_uint32_t(b->field_30); + s.write_offset_f2(b->nodes_count ? *mats_offset : 0, 0x20); + s.write_offset_f2(b->root ? *root_offset : 0, 0x20); + s.write_offset_f2(b->nodes ? *nodes_offset : 0, 0x20); + s.write_offset_f2(b->mesh_indices ? *mesh_indices_offset : 0, 0x20); + s.write_offset_f2(b->backface_mesh_indices ? *backface_mesh_indices_offset : 0, 0x20); + s.write_uint32_t(0); + s.write_uint32_t(b->reserved); } else { s.write_offset_x(mesh_name_offset); s.write_offset_x(backface_mesh_name_offset); s.write_int32_t(b->field_8); - s.write_int32_t(b->count); - s.write_int32_t(b->field_10); + s.write_int32_t(b->root_count); + s.write_int32_t(b->nodes_count); s.write_int32_t(b->field_14); - s.write_offset_x(b->field_10 ? *field_18_offset : 0); - s.write_offset_x(b->field_1C ? *field_1C_offset : 0); - s.write_offset_x(b->field_20 ? *field_20_offset : 0); - s.write_offset_x(b->field_24 ? *field_24_offset : 0); - s.write_offset_x(b->field_28 ? *field_28_offset : 0); - s.write_uint32_t(b->field_2C); - s.write_uint32_t(b->field_30); + s.write_offset_x(b->nodes_count ? *mats_offset : 0); + s.write_offset_x(b->root ? *root_offset : 0); + s.write_offset_x(b->nodes ? *nodes_offset : 0); + s.write_offset_x(b->mesh_indices ? *mesh_indices_offset : 0); + s.write_offset_x(b->backface_mesh_indices ? *backface_mesh_indices_offset : 0); + s.write_uint32_t(0); + s.write_uint32_t(b->reserved); } - if (b->field_10) { - s.position_push(*field_18_offset, SEEK_SET); - for (uint32_t i = 0; i < 32; i++) { - if (~b->field_10 & (1 << i)) - continue; - - mat4u& mat = b->field_18[i]; + if (b->nodes_count) { + s.position_push(*mats_offset, SEEK_SET); + for (uint32_t i = 0; i < 3; i++) { + mat4u& mat = b->mats[i]; s.write_float_t(mat.row0.x); s.write_float_t(mat.row1.x); s.write_float_t(mat.row2.x); @@ -5980,121 +6035,100 @@ static void obj_modern_write_skin_block_cloth(obj_skin_block_cloth* b, s.write_float_t(mat.row1.w); s.write_float_t(mat.row2.w); s.write_float_t(mat.row3.w); - *field_18_offset += sizeof(mat4); + *mats_offset += sizeof(mat4); } s.position_pop(); } - if (b->field_1C) { - s.position_push(*field_1C_offset, SEEK_SET); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_1C* f = &b->field_1C[i]; - s.write_float_t(f->field_0); - s.write_float_t(f->field_4); - s.write_float_t(f->field_8); - s.write_float_t(f->field_C); - s.write_float_t(f->field_10); - s.write_float_t(f->field_14); + if (b->root) { + s.position_push(*root_offset, SEEK_SET); + for (uint32_t i = 0; i < b->root_count; i++) { + obj_skin_block_cloth_root* f = &b->root[i]; + s.write_float_t(f->trans.x); + s.write_float_t(f->trans.y); + s.write_float_t(f->trans.z); + s.write_float_t(f->normal.x); + s.write_float_t(f->normal.y); + s.write_float_t(f->normal.z); s.write_float_t(f->field_18); - s.write_uint32_t(f->field_1C); - s.write_uint32_t(f->field_20); - s.write_uint32_t(f->field_24); + s.write_int32_t(f->field_1C); + s.write_int32_t(f->field_20); + s.write_int32_t(f->field_24); for (uint32_t j = 0; j < 4; j++) - obj_modern_write_skin_block_cloth_field_1C_sub(&f->sub_data[j], + obj_modern_write_skin_block_cloth_root_bone_weight(&f->bone_weights[j], s, strings, string_offsets, is_x); } s.position_pop(); if (!is_x) - *field_1C_offset += (10 * sizeof(int32_t) - + 4 * (sizeof(int64_t) + 4 * sizeof(int32_t))) * b->count; + *root_offset += (sizeof(int32_t) + 4 * (sizeof(int64_t) + 4 * sizeof(int32_t))) + * b->root_count * (b->nodes_count - 1ULL); else - *field_1C_offset += (10 * sizeof(int32_t) - + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) * b->count; + *root_offset += (sizeof(int32_t) + 4 * (sizeof(int32_t) + 3 * sizeof(int32_t))) + * b->root_count * (b->nodes_count - 1ULL); } - if (b->field_20) { - s.position_push(*field_20_offset, SEEK_SET); - for (uint32_t i = 0; i < b->count; i++) { - obj_skin_block_cloth_field_20* f = &b->field_20[i]; - for (uint32_t j = 0; j < 10; j++) - obj_modern_write_skin_block_cloth_field_20_sub(&f->sub_data[j], - s, strings, string_offsets, is_x); - } + if (b->nodes) { + s.position_push(*nodes_offset, SEEK_SET); + for (uint32_t i = 0; i < b->nodes_count - 1; i++) + for (uint32_t j = 0; j < b->root_count; j++) { + obj_skin_block_cloth_node* f = &b->nodes[i * b->root_count + j]; + s.write_uint32_t(f->flags); + s.write_float_t(f->trans.x); + s.write_float_t(f->trans.y); + s.write_float_t(f->trans.z); + s.write_float_t(f->trans_diff.x); + s.write_float_t(f->trans_diff.y); + s.write_float_t(f->trans_diff.z); + s.write_float_t(f->length); + s.write_float_t(f->field_20); + s.write_float_t(f->field_24); + s.write_float_t(f->field_28); + } s.position_pop(); - *field_20_offset += 10 * (11 * sizeof(int32_t)) * b->count; + *nodes_offset += (11 * sizeof(int32_t)) * b->root_count * (b->nodes_count - 1ULL); } - if (b->field_24) { - s.position_push(*field_24_offset, SEEK_SET); - s.write_uint16_t((uint16_t)b->field_24_count); - s.write(b->field_24, b->field_24_count * sizeof(uint16_t)); + if (b->mesh_indices) { + s.position_push(*mesh_indices_offset, SEEK_SET); + s.write_uint16_t((uint16_t)b->mesh_indices_count); + s.write(b->mesh_indices, b->mesh_indices_count * sizeof(uint16_t)); s.position_pop(); - *field_28_offset += sizeof(uint16_t) + b->field_24_count * sizeof(uint16_t); + *mesh_indices_offset += sizeof(uint16_t) + b->mesh_indices_count * sizeof(uint16_t); } - if (b->field_28) { - s.position_push(*field_28_offset, SEEK_SET); - s.write_uint16_t((uint16_t)b->field_28_count); - s.write(b->field_28, b->field_28_count * sizeof(uint16_t)); + if (b->backface_mesh_indices) { + s.position_push(*backface_mesh_indices_offset, SEEK_SET); + s.write_uint16_t((uint16_t)b->backface_mesh_indices_count); + s.write(b->backface_mesh_indices, b->backface_mesh_indices_count * sizeof(uint16_t)); s.position_pop(); - *field_28_offset += sizeof(uint16_t) + b->field_28_count * sizeof(uint16_t); + *backface_mesh_indices_offset += sizeof(uint16_t) + b->backface_mesh_indices_count * sizeof(uint16_t); } } -static void obj_modern_read_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, +static void obj_modern_read_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, uint32_t header_length, char** str, bool is_x) { int64_t bone_name_offset = s.read_offset(header_length, is_x); sub->bone_name = s.read_utf8_string_null_terminated_offset(bone_name_offset); sub->weight = s.read_float_t_reverse_endianness(); sub->matrix_index = s.read_uint32_t_reverse_endianness(); - sub->field_C = s.read_uint32_t_reverse_endianness(); + sub->reserved = s.read_uint32_t_reverse_endianness(); if (is_x) s.read(0, 0x04); } -static void obj_modern_write_skin_block_cloth_field_1C_sub(obj_skin_block_cloth_field_1C_sub* sub, +static void obj_modern_write_skin_block_cloth_root_bone_weight(obj_skin_block_cloth_root_bone_weight* sub, stream& s, std::vector& strings, std::vector& string_offsets, bool is_x) { int64_t bone_name_offset = obj_skin_strings_get_string_offset(strings, string_offsets, sub->bone_name); s.write_offset(bone_name_offset, 0x20, is_x); s.write_float_t(sub->weight); s.write_uint32_t(sub->matrix_index); - s.write_uint32_t(sub->field_C); + s.write_uint32_t(sub->reserved); if (is_x) s.write(0x04); } -static void obj_modern_read_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, uint32_t header_length, char** str, bool is_x) { - sub->field_0 = s.read_uint32_t_reverse_endianness(); - sub->field_4 = s.read_float_t_reverse_endianness(); - sub->field_8 = s.read_float_t_reverse_endianness(); - sub->field_C = s.read_float_t_reverse_endianness(); - sub->field_10 = s.read_float_t_reverse_endianness(); - sub->field_14 = s.read_float_t_reverse_endianness(); - sub->field_18 = s.read_float_t_reverse_endianness(); - sub->field_1C = s.read_float_t_reverse_endianness(); - sub->field_20 = s.read_float_t_reverse_endianness(); - sub->field_24 = s.read_float_t_reverse_endianness(); - sub->field_28 = s.read_float_t_reverse_endianness(); -} - -static void obj_modern_write_skin_block_cloth_field_20_sub(obj_skin_block_cloth_field_20_sub* sub, - stream& s, std::vector& strings, std::vector& string_offsets, bool is_x) { - s.write_uint32_t(sub->field_0); - s.write_float_t(sub->field_4); - s.write_float_t(sub->field_8); - s.write_float_t(sub->field_C); - s.write_float_t(sub->field_10); - s.write_float_t(sub->field_14); - s.write_float_t(sub->field_18); - s.write_float_t(sub->field_1C); - s.write_float_t(sub->field_20); - s.write_float_t(sub->field_24); - s.write_float_t(sub->field_28); -} - static void obj_modern_read_skin_block_constraint(obj_skin_block_constraint* b, stream& s, uint32_t header_length, char** str, bool is_x) { obj_modern_read_skin_block_node(&b->base, s, header_length, str, is_x); @@ -6532,19 +6566,19 @@ static void obj_modern_write_skin_block_osage(obj_skin_block_osage* b, static void obj_modern_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_mesh* mesh, const uint32_t vertex_flags, uint32_t num_vertex, uint32_t size_vertex) { - obj_vertex_format vertex_format = (obj_vertex_format)(OBJ_VERTEX_FORMAT_POSITION - | OBJ_VERTEX_FORMAT_NORMAL - | OBJ_VERTEX_FORMAT_TANGENT - | OBJ_VERTEX_FORMAT_TEXCOORD0 - | OBJ_VERTEX_FORMAT_TEXCOORD1 - | OBJ_VERTEX_FORMAT_COLOR0); + obj_vertex_format vertex_format = (obj_vertex_format)(OBJ_VERTEX_POSITION + | OBJ_VERTEX_NORMAL + | OBJ_VERTEX_TANGENT + | OBJ_VERTEX_TEXCOORD0 + | OBJ_VERTEX_TEXCOORD1 + | OBJ_VERTEX_COLOR0); if (vertex_flags == 0x06) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD2); + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD2); else if (vertex_flags == 0x0A) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_TEXCOORD2 | OBJ_VERTEX_FORMAT_TEXCOORD3); + enum_or(vertex_format, OBJ_VERTEX_TEXCOORD2 | OBJ_VERTEX_TEXCOORD3); else if (vertex_flags == 0x04) - enum_or(vertex_format, OBJ_VERTEX_FORMAT_BONE_DATA); + enum_or(vertex_format, OBJ_VERTEX_BONE_DATA); int64_t vtx_offset = vertex[13]; @@ -6639,7 +6673,7 @@ static void obj_modern_read_vertex(obj* obj, stream& s, int64_t* vertex, obj_mes } if (!has_tangents) - enum_and(vertex_format, ~OBJ_VERTEX_FORMAT_TANGENT); + enum_and(vertex_format, ~OBJ_VERTEX_TANGENT); mesh->vertex = vtx; mesh->num_vertex = num_vertex; @@ -6657,18 +6691,18 @@ static void obj_modern_write_vertex(obj* obj, stream& s, bool is_x, uint32_t _vertex_flags = 0x02; uint32_t _size_vertex = 0x2C; uint32_t enrs_se3_rc = 12; - if (vertex_format & OBJ_VERTEX_FORMAT_BONE_DATA) { + if (vertex_format & OBJ_VERTEX_BONE_DATA) { _vertex_flags = 0x04; _size_vertex += 0x0C; enrs_se3_rc += 4; } - else if ((vertex_format & (OBJ_VERTEX_FORMAT_TEXCOORD2 & OBJ_VERTEX_FORMAT_TEXCOORD3)) - == (OBJ_VERTEX_FORMAT_TEXCOORD2 | OBJ_VERTEX_FORMAT_TEXCOORD3)) { + else if ((vertex_format & (OBJ_VERTEX_TEXCOORD2 & OBJ_VERTEX_TEXCOORD3)) + == (OBJ_VERTEX_TEXCOORD2 | OBJ_VERTEX_TEXCOORD3)) { _vertex_flags = 0x0A; _size_vertex += 0x08; enrs_se3_rc += 4; } - else if (vertex_format & OBJ_VERTEX_FORMAT_TEXCOORD2) { + else if (vertex_format & OBJ_VERTEX_TEXCOORD2) { _vertex_flags = 0x06; _size_vertex += 0x04; enrs_se3_rc += 2; diff --git a/src/KKdLib/obj.hpp b/src/KKdLib/obj.hpp index b71aa69d..9c7cf6ed 100644 --- a/src/KKdLib/obj.hpp +++ b/src/KKdLib/obj.hpp @@ -121,28 +121,28 @@ enum obj_skin_block_type : uint32_t { OBJ_SKIN_BLOCK_OSAGE, }; -enum obj_skin_osage_root_coli_type { - OBJ_SKIN_OSAGE_ROOT_COLI_TYPE_NONE = 0x00, - OBJ_SKIN_OSAGE_ROOT_COLI_TYPE_BALL = 0x01, - OBJ_SKIN_OSAGE_ROOT_COLI_TYPE_CYLINDER = 0x02, - OBJ_SKIN_OSAGE_ROOT_COLI_TYPE_PLANE = 0x03, - OBJ_SKIN_OSAGE_ROOT_COLI_TYPE_ELLIPSE = 0x04, +enum obj_skin_skin_param_coli_type { + OBJ_SKIN_SKIN_PARAM_COLI_TYPE_NONE = 0x00, + OBJ_SKIN_SKIN_PARAM_COLI_TYPE_BALL = 0x01, + OBJ_SKIN_SKIN_PARAM_COLI_TYPE_CYLINDER = 0x02, + OBJ_SKIN_SKIN_PARAM_COLI_TYPE_PLANE = 0x03, + OBJ_SKIN_SKIN_PARAM_COLI_TYPE_ELLIPSE = 0x04, }; enum obj_vertex_format : uint32_t { - OBJ_VERTEX_FORMAT_NONE = 0x000, - OBJ_VERTEX_FORMAT_POSITION = 0x001, - OBJ_VERTEX_FORMAT_NORMAL = 0x002, - OBJ_VERTEX_FORMAT_TANGENT = 0x004, - OBJ_VERTEX_FORMAT_BINORMAL = 0x008, - OBJ_VERTEX_FORMAT_TEXCOORD0 = 0x010, - OBJ_VERTEX_FORMAT_TEXCOORD1 = 0x020, - OBJ_VERTEX_FORMAT_TEXCOORD2 = 0x040, - OBJ_VERTEX_FORMAT_TEXCOORD3 = 0x080, - OBJ_VERTEX_FORMAT_COLOR0 = 0x100, - OBJ_VERTEX_FORMAT_COLOR1 = 0x200, - OBJ_VERTEX_FORMAT_BONE_DATA = 0x400, - OBJ_VERTEX_FORMAT_UNKNOWN = 0x800, + OBJ_VERTEX_NONE = 0x000, + OBJ_VERTEX_POSITION = 0x001, + OBJ_VERTEX_NORMAL = 0x002, + OBJ_VERTEX_TANGENT = 0x004, + OBJ_VERTEX_BINORMAL = 0x008, + OBJ_VERTEX_TEXCOORD0 = 0x010, + OBJ_VERTEX_TEXCOORD1 = 0x020, + OBJ_VERTEX_TEXCOORD2 = 0x040, + OBJ_VERTEX_TEXCOORD3 = 0x080, + OBJ_VERTEX_COLOR0 = 0x100, + OBJ_VERTEX_COLOR1 = 0x200, + OBJ_VERTEX_BONE_DATA = 0x400, + OBJ_VERTEX_UNKNOWN = 0x800, }; struct obj_axis_aligned_bounding_box { @@ -158,6 +158,8 @@ struct obj_bounding_box { struct obj_bounding_sphere { vec3 center; float_t radius; + + obj_bounding_sphere(); }; struct obj_shader_compo_member { @@ -317,7 +319,7 @@ struct obj_sub_mesh_attrib_member { uint32_t recieve_shadow : 1; uint32_t cast_shadow : 1; uint32_t transparent : 1; - uint32_t flag_3 : 1; + uint32_t cloth : 1; uint32_t dummy : 28; }; @@ -346,6 +348,8 @@ struct obj_sub_mesh { uint16_t first_index; uint16_t last_index; uint32_t indices_offset; + + obj_sub_mesh(); }; struct obj_vertex_data { @@ -365,7 +369,7 @@ struct obj_vertex_data { }; struct obj_mesh_attrib_member { - uint32_t flag_0 : 1; + uint32_t double_buffer : 1; uint32_t billboard_y_axis : 1; uint32_t translucent_no_shadow : 1; uint32_t billboard : 1; @@ -392,45 +396,33 @@ struct obj_mesh { char name[0x40]; }; -struct obj_skin_block_cloth_field_1C_sub { +struct obj_skin_block_cloth_root_bone_weight { char* bone_name; float_t weight; - uint32_t matrix_index; - uint32_t field_C; + int32_t matrix_index; + int32_t reserved; }; -struct obj_skin_block_cloth_field_1C { - float_t field_0; - float_t field_4; - float_t field_8; - float_t field_C; - float_t field_10; - float_t field_14; +struct obj_skin_block_cloth_root { + vec3 trans; + vec3 normal; float_t field_18; - uint32_t field_1C; - uint32_t field_20; - uint32_t field_24; - obj_skin_block_cloth_field_1C_sub sub_data[4]; + int32_t field_1C; + int32_t field_20; + int32_t field_24; + obj_skin_block_cloth_root_bone_weight bone_weights[4]; }; -struct obj_skin_block_cloth_field_20_sub { - uint32_t field_0; - float_t field_4; - float_t field_8; - float_t field_C; - float_t field_10; - float_t field_14; - float_t field_18; - float_t field_1C; +struct obj_skin_block_cloth_node { + uint32_t flags; + vec3 trans; + vec3 trans_diff; + float_t length; float_t field_20; float_t field_24; float_t field_28; }; -struct obj_skin_block_cloth_field_20 { - obj_skin_block_cloth_field_20_sub sub_data[10]; -}; - struct obj_skin_block_node { char* parent_name; vec3 position; @@ -438,22 +430,49 @@ struct obj_skin_block_node { vec3 scale; }; +struct obj_skin_skin_param_coli { + obj_skin_skin_param_coli_type type; + int32_t bone0_index; + int32_t bone1_index; + float_t radius; + vec3 bone0_pos; + vec3 bone1_pos; +}; + +struct obj_skin_skin_param { + int32_t unk0; + float_t force; + float_t force_gain; + float_t air_res; + float_t rot_y; + float_t rot_z; + float_t hinge_y; + float_t hinge_z; + char* name; + obj_skin_skin_param_coli* coli; + int32_t coli_count; + float_t coli_r; + float_t friction; + float_t wind_afc; + int32_t unk44; +}; struct obj_skin_block_cloth { char* mesh_name; char* backface_mesh_name; uint32_t field_8; - uint32_t count; - uint32_t field_10; + uint32_t root_count; + uint32_t nodes_count; uint32_t field_14; - mat4u field_18[32]; - obj_skin_block_cloth_field_1C* field_1C; - obj_skin_block_cloth_field_20* field_20; - uint16_t* field_24; - int32_t field_24_count; - uint16_t* field_28; - int32_t field_28_count; - uint32_t field_2C; - uint32_t field_30; + mat4u mats[3]; + obj_skin_block_cloth_root* root; + obj_skin_block_cloth_node* nodes; + uint16_t* mesh_indices; + int32_t mesh_indices_count; + uint16_t* backface_mesh_indices; + int32_t backface_mesh_indices_count; + obj_skin_skin_param skin_param; + bool skin_param_init; + uint32_t reserved; }; struct obj_skin_block_constraint_attach_point { @@ -535,41 +554,14 @@ struct obj_skin_osage_node { vec3 rotation; }; -struct obj_skin_osage_root_coli { - obj_skin_osage_root_coli_type type; - int32_t bone0_index; - int32_t bone1_index; - float_t radius; - vec3 bone0_pos; - vec3 bone1_pos; -}; - -struct obj_skin_osage_root_node { - int32_t unk0; - float_t force; - float_t force_gain; - float_t air_res; - float_t rot_y; - float_t rot_z; - float_t hinge_y; - float_t hinge_z; - char* name; - obj_skin_osage_root_coli* coli; - int32_t coli_count; - float_t coli_r; - float_t friction; - float_t wind_afc; - int32_t unk44; -}; - struct obj_skin_block_osage { obj_skin_block_node base; uint32_t start_index; uint32_t count; obj_skin_osage_node* nodes; uint32_t nodes_count; - obj_skin_osage_root_node root; - bool root_init; + obj_skin_skin_param skin_param; + bool skin_param_init; uint32_t external_name_index; uint32_t name_index; char* motion_node_name; @@ -633,6 +625,9 @@ struct obj { char* name; uint32_t id; uint32_t hash; + + obj_mesh* get_obj_mesh(const char* name); + uint32_t get_obj_mesh_index(const char* name); }; struct obj_set { diff --git a/src/KKdLib/vec.cpp b/src/KKdLib/vec.cpp index f3b490c7..c69f0bb5 100644 --- a/src/KKdLib/vec.cpp +++ b/src/KKdLib/vec.cpp @@ -36,38 +36,306 @@ const vec4u vec4u_null = { 0.0f, 0.0f, 0.0f, 0.0f }; const vec4iu vec4iu_null = { 0, 0, 0, 0 }; +vec2i8::vec2i8() : x(), y() { + +} + +vec2i8::vec2i8(int8_t value) : x(value), y(value) { + +} + +vec2i8::vec2i8(int8_t x, int8_t y) : x(x), y(y) { + +} + +vec3i8::vec3i8() : x(), y(), z() { + +} + +vec3i8::vec3i8(int8_t value) : x(value), y(value), z(value) { + +} + +vec3i8::vec3i8(int8_t x, int8_t y, int8_t z) : x(x), y(y), z(z) { + +} + +vec4i8::vec4i8() : x(), y(), z(), w() { + +} + +vec4i8::vec4i8(int8_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4i8::vec4i8(int8_t x, int8_t y, int8_t z, int8_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2u8::vec2u8() : x(), y() { + +} + +vec2u8::vec2u8(uint8_t value) : x(value), y(value) { + +} + +vec2u8::vec2u8(uint8_t x, uint8_t y) : x(x), y(y) { + +} + +vec3u8::vec3u8() : x(), y(), z() { + +} + +vec3u8::vec3u8(uint8_t value) : x(value), y(value), z(value) { + +} + +vec3u8::vec3u8(uint8_t x, uint8_t y, uint8_t z) : x(x), y(y), z(z) { + +} + +vec4u8::vec4u8() : x(), y(), z(), w() { + +} + +vec4u8::vec4u8(uint8_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4u8::vec4u8(uint8_t x, uint8_t y, uint8_t z, uint8_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2i16::vec2i16() : x(), y() { + +} + +vec2i16::vec2i16(int16_t value) : x(value), y(value) { + +} + +vec2i16::vec2i16(int16_t x, int16_t y) : x(x), y(y) { + +} + +vec3i16::vec3i16() : x(), y(), z() { + +} + +vec3i16::vec3i16(int16_t value) : x(value), y(value), z(value) { + +} + +vec3i16::vec3i16(int16_t x, int16_t y, int16_t z) : x(x), y(y), z(z) { + +} + +vec4i16::vec4i16() : x(), y(), z(), w() { + +} + +vec4i16::vec4i16(int16_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4i16::vec4i16(int16_t x, int16_t y, int16_t z, int16_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2u16::vec2u16() : x(), y() { + +} + +vec2u16::vec2u16(uint16_t value) : x(value), y(value) { + +} + +vec2u16::vec2u16(uint16_t x, uint16_t y) : x(x), y(y) { + +} + +vec3u16::vec3u16() : x(), y(), z() { + +} +; +vec3u16::vec3u16(uint16_t value) : x(value), y(value), z(value) { + +} + +vec3u16::vec3u16(uint16_t x, uint16_t y, uint16_t z) : x(x), y(y), z(z) { + +} + +vec4u16::vec4u16() : x(), y(), z(), w() { + +} + +vec4u16::vec4u16(uint16_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4u16::vec4u16(uint16_t x, uint16_t y, uint16_t z, uint16_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2h::vec2h() : x(), y() { + +} + +vec2h::vec2h(half_t value) : x(value), y(value) { + +} + +vec2h::vec2h(half_t x, half_t y) : x(x), y(y) { + +} + +vec3h::vec3h() : x(), y(), z() { + +} + +vec3h::vec3h(half_t value) : x(value), y(value), z(value) { + +} + +vec3h::vec3h(half_t x, half_t y, half_t z) : x(x), y(y), z(z) { + +} + +vec4h::vec4h() : x(), y(), z(), w() { + +} + +vec4h::vec4h(half_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4h::vec4h(half_t x, half_t y, half_t z, half_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2::vec2() : x(), y() { + +} + +vec2::vec2(float_t value) : x(value), y(value) { + +} + +vec2::vec2(float_t x, float_t y) : x(x), y(y) { + +} + +vec3::vec3() : x(), y(), z() { + +} +; +vec3::vec3(float_t value) : x(value), y(value), z(value) { + +} + +vec3::vec3(float_t x, float_t y, float_t z) : x(x), y(y), z(z) { + +} + +vec4::vec4() : x(), y(), z(), w() { + +} +; +vec4::vec4(float_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4::vec4(float_t x, float_t y, float_t z, float_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2i::vec2i() : x(), y() { + +} + +vec2i::vec2i(int32_t value) : x(value), y(value) { + +} + +vec2i::vec2i(int32_t x, int32_t y) : x(x), y(y) { + +} + +vec3i::vec3i() : x(), y(), z() { + +} + +vec3i::vec3i(int32_t value) : x(value), y(value), z(value) { + +} + +vec3i::vec3i(int32_t x, int32_t y, int32_t z) : x(x), y(y), z(z) { + +} + +vec4i::vec4i() : x(), y(), z(), w() { + +} + +vec4i::vec4i(int32_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4i::vec4i(int32_t x, int32_t y, int32_t z, int32_t w) : x(x), y(y), z(z), w(w) { + +} + +vec2d::vec2d() : x(), y() { + +} + +vec2d::vec2d(double_t value) : x(value), y(value) { + +} + +vec2d::vec2d(double_t x, double_t y) : x(x), y(y) { + +} + +vec4u::vec4u() : x(), y(), z(), w() { + +} + +vec4u::vec4u(float_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4u::vec4u(float_t x, float_t y, float_t z, float_t w) : x(x), y(y), z(z), w(w) { + +} + +vec4iu::vec4iu() : x(), y(), z(), w() { + +} + +vec4iu::vec4iu(int32_t value) : x(value), y(value), z(value), w(value) { + +} + +vec4iu::vec4iu(int32_t x, int32_t y, int32_t z, int32_t w) : x(x), y(y), z(z), w(w) { + +} + vec4::operator vec4u() const { - vec4u v; - v.x = x; - v.y = y; - v.z = z; - v.w = w; - return v; + return { x, y, z, w }; } vec4u::operator vec4() const { - vec4 v; - v.x = x; - v.y = y; - v.z = z; - v.w = w; - return v; + return { x, y, z, w }; } vec4i::operator vec4iu() const { - vec4iu v; - v.x = x; - v.y = y; - v.z = z; - v.w = w; - return v; + return { x, y, z, w }; } vec4iu::operator vec4i() const { - vec4i v; - v.x = x; - v.y = y; - v.z = z; - v.w = w; - return v; + return { x, y, z, w }; } diff --git a/src/KKdLib/vec.hpp b/src/KKdLib/vec.hpp index a1bbc539..53a1eded 100644 --- a/src/KKdLib/vec.hpp +++ b/src/KKdLib/vec.hpp @@ -13,12 +13,20 @@ struct vec2i8 { int8_t x; int8_t y; + + vec2i8(); + vec2i8(int8_t value); + vec2i8(int8_t x, int8_t y); }; struct vec3i8 { int8_t x; int8_t y; int8_t z; + + vec3i8(); + vec3i8(int8_t value); + vec3i8(int8_t x, int8_t y, int8_t z); }; struct vec4i8 { @@ -26,17 +34,29 @@ struct vec4i8 { int8_t y; int8_t z; int8_t w; + + vec4i8(); + vec4i8(int8_t value); + vec4i8(int8_t x, int8_t y, int8_t z, int8_t w); }; struct vec2u8 { uint8_t x; uint8_t y; + + vec2u8(); + vec2u8(uint8_t value); + vec2u8(uint8_t x, uint8_t y); }; struct vec3u8 { uint8_t x; uint8_t y; uint8_t z; + + vec3u8(); + vec3u8(uint8_t value); + vec3u8(uint8_t x, uint8_t y, uint8_t z); }; struct vec4u8 { @@ -44,17 +64,29 @@ struct vec4u8 { uint8_t y; uint8_t z; uint8_t w; + + vec4u8(); + vec4u8(uint8_t value); + vec4u8(uint8_t x, uint8_t y, uint8_t z, uint8_t w); }; struct vec2i16 { int16_t x; int16_t y; + + vec2i16(); + vec2i16(int16_t value); + vec2i16(int16_t x, int16_t y); }; struct vec3i16 { int16_t x; int16_t y; int16_t z; + + vec3i16(); + vec3i16(int16_t value); + vec3i16(int16_t x, int16_t y, int16_t z); }; struct vec4i16 { @@ -62,17 +94,29 @@ struct vec4i16 { int16_t y; int16_t z; int16_t w; + + vec4i16(); + vec4i16(int16_t value); + vec4i16(int16_t x, int16_t y, int16_t z, int16_t w); }; struct vec2u16 { uint16_t x; uint16_t y; + + vec2u16(); + vec2u16(uint16_t value); + vec2u16(uint16_t x, uint16_t y); }; struct vec3u16 { uint16_t x; uint16_t y; uint16_t z; + + vec3u16(); + vec3u16(uint16_t value); + vec3u16(uint16_t x, uint16_t y, uint16_t z); }; struct vec4u16 { @@ -80,17 +124,29 @@ struct vec4u16 { uint16_t y; uint16_t z; uint16_t w; + + vec4u16(); + vec4u16(uint16_t value); + vec4u16(uint16_t x, uint16_t y, uint16_t z, uint16_t w); }; struct vec2h { half_t x; half_t y; + + vec2h(); + vec2h(half_t value); + vec2h(half_t x, half_t y); }; struct vec3h { half_t x; half_t y; half_t z; + + vec3h(); + vec3h(half_t value); + vec3h(half_t x, half_t y, half_t z); }; struct vec4h { @@ -98,17 +154,29 @@ struct vec4h { half_t y; half_t z; half_t w; + + vec4h(); + vec4h(half_t value); + vec4h(half_t x, half_t y, half_t z, half_t w); }; struct vec2 { float_t x; float_t y; + + vec2(); + vec2(float_t value); + vec2(float_t x, float_t y); }; struct vec3 { float_t x; float_t y; float_t z; + + vec3(); + vec3(float_t value); + vec3(float_t x, float_t y, float_t z); }; union vec4; @@ -125,18 +193,30 @@ union vec4 { }; __m128 data; + vec4(); + vec4(float_t value); + vec4(float_t x, float_t y, float_t z, float_t w); + operator vec4u() const; }; struct vec2i { int32_t x; int32_t y; + + vec2i(); + vec2i(int32_t value); + vec2i(int32_t x, int32_t y); }; struct vec3i { int32_t x; int32_t y; int32_t z; + + vec3i(); + vec3i(int32_t value); + vec3i(int32_t x, int32_t y, int32_t z); }; union vec4i { @@ -148,6 +228,10 @@ union vec4i { }; __m128 data; + vec4i(); + vec4i(int32_t value); + vec4i(int32_t x, int32_t y, int32_t z, int32_t w); + operator vec4iu() const; }; @@ -157,6 +241,10 @@ union vec2d { double_t y; }; __m128d data; + + vec2d(); + vec2d(double_t value); + vec2d(double_t x, double_t y); }; struct vec4u { @@ -165,6 +253,10 @@ struct vec4u { float_t z; float_t w; + vec4u(); + vec4u(float_t value); + vec4u(float_t x, float_t y, float_t z, float_t w); + operator vec4() const; }; @@ -174,6 +266,10 @@ struct vec4iu { int32_t z; int32_t w; + vec4iu(); + vec4iu(int32_t value); + vec4iu(int32_t x, int32_t y, int32_t z, int32_t w); + operator vec4i() const; };