diff --git a/src/CLOUD/classes/data_test/auth_3d_test.c b/src/CLOUD/classes/data_test/auth_3d_test.c index d0ed17d7..c51c50a7 100644 --- a/src/CLOUD/classes/data_test/auth_3d_test.c +++ b/src/CLOUD/classes/data_test/auth_3d_test.c @@ -12,7 +12,7 @@ #include "../../../CRE/data.h" #include "../../../CRE/render_context.h" #include "../../../CRE/stage.h" -#include "../../input.h" +#include "../../input.hpp" #include "../imgui_helper.h" struct data_test_auth_3d_test_uid { diff --git a/src/CLOUD/classes/data_test/glitter_test.c b/src/CLOUD/classes/data_test/glitter_test.c index c2ef5e43..76464908 100644 --- a/src/CLOUD/classes/data_test/glitter_test.c +++ b/src/CLOUD/classes/data_test/glitter_test.c @@ -11,7 +11,7 @@ #include "../../../CRE/data.h" #include "../../../CRE/render_context.h" #include "../../../CRE/stage.h" -#include "../../input.h" +#include "../../input.hpp" #include "../data_test.h" #include "../imgui_helper.h" #include "stage_test.h" diff --git a/src/CLOUD/classes/data_test/stage_test.c b/src/CLOUD/classes/data_test/stage_test.c index c4ff0deb..16d94333 100644 --- a/src/CLOUD/classes/data_test/stage_test.c +++ b/src/CLOUD/classes/data_test/stage_test.c @@ -11,7 +11,7 @@ #include "../../../CRE/data.h" #include "../../../CRE/render_context.h" #include "../../../CRE/stage.h" -#include "../../input.h" +#include "../../input.hpp" #include "../data_test.h" #include "../imgui_helper.h" diff --git a/src/CLOUD/classes/data_view/auth_3d.c b/src/CLOUD/classes/data_view/auth_3d.c index 2f7f7dd1..d88e415f 100644 --- a/src/CLOUD/classes/data_view/auth_3d.c +++ b/src/CLOUD/classes/data_view/auth_3d.c @@ -5,7 +5,7 @@ #include "auth_3d.h" #include "../../../CRE/auth_3d.h" -#include "../../input.h" +#include "../../input.hpp" #include "../imgui_helper.h" static const char* auth_3d_fog_name[] = { diff --git a/src/CLOUD/classes/glitter_editor.c b/src/CLOUD/classes/glitter_editor.c index dad3fbd5..80ef56a1 100644 --- a/src/CLOUD/classes/glitter_editor.c +++ b/src/CLOUD/classes/glitter_editor.c @@ -24,7 +24,7 @@ #include "../../CRE/shader_glsl.h" #include "../../CRE/stage.h" #include "../../CRE/static_var.h" -#include "../input.h" +#include "../input.hpp" #include #include #include @@ -723,13 +723,29 @@ void glitter_editor_ctrl(class_data* data) { LARGE_INTEGER time; QueryPerformanceCounter(&time); - /*Glitter::Effect* e = Glitter::Effect_copy(glt_edt->selected_effect); - snprintf(e->name, sizeof(e->name), "eff_%08x", - (uint32_t)((eff_count + 1) * time.LowPart * hash_murmurhash_empty)); - eg->effects.push_back(e);*/ + Glitter::Effect* e = new Glitter::Effect(eg->type); + *e = *glt_edt->selected_effect; + if (eg->type != Glitter::X) { + if (glt_edt->selected_effect->data.ext_anim) { + e->data.ext_anim = force_malloc_s(Glitter::Effect::ExtAnim, 1); + *e->data.ext_anim = *glt_edt->selected_effect->data.ext_anim; + } + } + else { + if (glt_edt->selected_effect->data.ext_anim_x) { + e->data.ext_anim_x = force_malloc_s(Glitter::Effect::ExtAnimX, 1); + *e->data.ext_anim_x = *glt_edt->selected_effect->data.ext_anim_x; + } + } + + char name[0x80]; + sprintf_s(name, sizeof(name), "eff_%08x", + (uint32_t)((eff_count + 1)* time.LowPart* hash_murmurhash_empty)); + e->name = std::string(name); + eg->effects.push_back(e); glt_edt->input_reload = true; } - else if ((glt_edt->effect_flags & GLITTER_EDITOR_DELETE)) { + else if (glt_edt->effect_flags & GLITTER_EDITOR_DELETE) { ssize_t j = -1; for (Glitter::Effect*& i : eg->effects) if (i && i == glt_edt->selected_effect) { @@ -788,8 +804,9 @@ void glitter_editor_ctrl(class_data* data) { if (eg && has_emitter) if (glt_edt->emitter_flags & GLITTER_EDITOR_DUPLICATE) { - /*Glitter::Emitter* e = Glitter::Emitter_copy(glt_edt->selected_emitter); - sel_efct->emitters.push_back(e);*/ + Glitter::Emitter* e = new Glitter::Emitter(eg->type); + *e = *glt_edt->selected_emitter; + sel_efct->emitters.push_back(e); glt_edt->input_reload = true; } else if (glt_edt->emitter_flags & GLITTER_EDITOR_DELETE) { @@ -845,8 +862,9 @@ void glitter_editor_ctrl(class_data* data) { if (eg && has_particle) if (glt_edt->particle_flags & GLITTER_EDITOR_DUPLICATE) { - /*Glitter::Particle* p = Glitter::Particle_copy(glt_edt->selected_particle); - sel_emit->particles.push_back(p);*/ + Glitter::Particle* p = new Glitter::Particle(eg->type); + *p = *glt_edt->selected_particle; + sel_emit->particles.push_back(p); glt_edt->input_reload = true; } else if (glt_edt->particle_flags & GLITTER_EDITOR_DELETE) { @@ -1052,6 +1070,7 @@ void glitter_editor_ctrl(class_data* data) { glt_edt->effect_group->emission = Glitter::glt_particle_manager.emission; Glitter::glt_particle_manager.SetFrame(glt_edt->effect_group, &glt_edt->scene, glt_edt->frame_counter, glt_edt->old_frame_counter, glt_edt->counter, &glt_edt->random, true); + Glitter::glt_particle_manager.scene = glt_edt->scene; glt_edt->scene_counter = glt_edt->scene->counter; glt_edt->old_frame_counter = glt_edt->frame_counter; glt_edt->input_reload = false; @@ -1067,6 +1086,7 @@ void glitter_editor_ctrl(class_data* data) { Glitter::glt_particle_manager.SetFrame(glt_edt->effect_group, &glt_edt->scene, glt_edt->frame_counter, glt_edt->old_frame_counter, glt_edt->counter, &glt_edt->random, false); + Glitter::glt_particle_manager.scene = glt_edt->scene; glt_edt->scene_counter = glt_edt->scene->counter; glt_edt->old_frame_counter = glt_edt->frame_counter; } @@ -1078,6 +1098,7 @@ void glitter_editor_ctrl(class_data* data) { glt_edt->frame_counter = (float_t)glt_edt->start_frame; Glitter::glt_particle_manager.SetFrame(glt_edt->effect_group, &glt_edt->scene, glt_edt->frame_counter, glt_edt->old_frame_counter, glt_edt->counter, &glt_edt->random, true); + Glitter::glt_particle_manager.scene = glt_edt->scene; glt_edt->scene_counter = glt_edt->scene->counter; glt_edt->old_frame_counter = glt_edt->frame_counter; glt_edt->input_pause = true; @@ -1130,29 +1151,29 @@ void glitter_editor_input(class_data* data) { if (!glt_edt) return; - if (input_is_down(VK_CONTROL) && input_is_tapped('O')) + if (Input::IsKeyTapped(GLFW_KEY_O, GLFW_MOD_CONTROL)) glitter_editor_open_window(glt_edt); - else if (input_is_down(VK_CONTROL) && input_is_tapped(VK_F4)) + else if (Input::IsKeyTapped(GLFW_KEY_F4, GLFW_MOD_CONTROL)) glt_edt->close = true; - else if (input_is_down(VK_CONTROL) && input_is_tapped(VK_F3)) + else if (Input::IsKeyTapped(GLFW_KEY_F3, GLFW_MOD_CONTROL)) enum_or(data->flags, CLASS_DISPOSE); - else if (input_is_down(VK_CONTROL) && input_is_tapped('Q')) + else if (Input::IsKeyTapped(GLFW_KEY_Q, GLFW_MOD_CONTROL)) close = true; - else if (input_is_tapped('P')) + else if (Input::IsKeyTapped(GLFW_KEY_P)) glt_edt->test ^= true; - else if (input_is_tapped('T')) + else if (Input::IsKeyTapped(GLFW_KEY_T)) glt_edt->input_play = true; - else if (input_is_tapped('Y')) + else if (Input::IsKeyTapped(GLFW_KEY_Y)) glt_edt->input_reload = true; - else if (input_is_tapped('F')) + else if (Input::IsKeyTapped(GLFW_KEY_F)) glt_edt->input_pause = true; - else if (input_is_tapped('G')) + else if (Input::IsKeyTapped(GLFW_KEY_G)) glt_edt->input_reset = true; if (data->imgui_focus) { - if (input_is_down(VK_CONTROL) && input_is_down(VK_SHIFT) && input_is_tapped('S')) + if (Input::IsKeyTapped(GLFW_KEY_S, GLFW_MOD_CONTROL | GLFW_MOD_SHIFT)) glitter_editor_save_as_window(glt_edt); - else if (input_is_down(VK_CONTROL) && input_is_tapped('S')) + else if (Input::IsKeyTapped(GLFW_KEY_S, GLFW_MOD_CONTROL)) glitter_editor_save_window(glt_edt); } } @@ -2305,7 +2326,7 @@ static void glitter_editor_effects_context_menu(glitter_editor_struct* glt_edt, eff_str = "%s (%08X)"; Glitter::EffectGroup* eg = glt_edt->effect_group; - ImGui::Text(eff_str, effect->name, (uint32_t)((size_t)effect * hash_fnv1a64m_empty)); + ImGui::Text(eff_str, effect->name.c_str(), (uint32_t)((size_t)effect * hash_fnv1a64m_empty)); ImGui::Separator(); if (ImGui::MenuItem("Duplicate Effect")) { enum_or(glt_edt->effect_flags, GLITTER_EDITOR_DUPLICATE); @@ -4212,7 +4233,8 @@ static bool glitter_editor_property_particle_texture(glitter_editor_struct* glt_ case Glitter::UV_INDEX_INITIAL_RANDOM_REVERSE: { LARGE_INTEGER time; QueryPerformanceCounter(&time); - uv_index += time.LowPart % particle->data.uv_index_count; + uv_index = particle->data.uv_index_start + + time.LowPart % particle->data.uv_index_count; } break; } } diff --git a/src/CLOUD/classes/graphics/render_settings.c b/src/CLOUD/classes/graphics/render_settings.c index d8e6cdef..0aa61f94 100644 --- a/src/CLOUD/classes/graphics/render_settings.c +++ b/src/CLOUD/classes/graphics/render_settings.c @@ -14,7 +14,6 @@ extern int32_t height; extern timer render_timer; extern timer sound_timer; -extern timer input_timer; extern size_t render_scale_table_count; extern double_t render_get_scale(); @@ -84,46 +83,36 @@ void graphics_render_settings_imgui(class_data* data) { double_t render_freq = timer_get_freq(&render_timer); double_t sound_freq = timer_get_freq(&sound_timer); - double_t input_freq = timer_get_freq(&input_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 input_freq_hist = timer_get_freq_hist(&input_timer); char render_freq_str[0x20]; char sound_freq_str[0x20]; - char input_freq_str[0x20]; char render_ms_str[0x20]; char sound_ms_str[0x20]; - char input_ms_str[0x20]; render_settings_freq_to_string(render_freq, render_freq_str, sizeof(render_freq_str), render_ms_str, sizeof(render_ms_str)); render_settings_freq_to_string(sound_freq, sound_freq_str, sizeof(sound_freq_str), sound_ms_str, sizeof(sound_ms_str)); - render_settings_freq_to_string(input_freq, input_freq_str, - sizeof(input_freq_str), input_ms_str, sizeof(input_ms_str)); char render_freq_hist_str[0x20]; char sound_freq_hist_str[0x20]; - char input_freq_hist_str[0x20]; char render_ms_hist_str[0x20]; char sound_ms_hist_str[0x20]; - char input_ms_hist_str[0x20]; render_settings_freq_to_string(render_freq_hist, render_freq_hist_str, sizeof(render_freq_hist_str), render_ms_hist_str, sizeof(render_ms_hist_str)); render_settings_freq_to_string(sound_freq_hist, sound_freq_hist_str, sizeof(sound_freq_hist_str), sound_ms_hist_str, sizeof(sound_ms_hist_str)); - render_settings_freq_to_string(input_freq_hist, input_freq_hist_str, - sizeof(input_freq_hist_str), input_ms_hist_str, sizeof(input_ms_hist_str)); - ImGui::Text("Targ: Render / Sound / Input"); - ImGui::Text("freq: %s / %s / %s", render_freq_str, sound_freq_str, input_freq_str); - ImGui::Text(" ms: %s / %s / %s", render_ms_str, sound_ms_str, input_ms_str); + ImGui::Text("Targ: Render / Sound"); + ImGui::Text("freq: %s / %s", render_freq_str, sound_freq_str); + ImGui::Text(" ms: %s / %s", render_ms_str, sound_ms_str); ImGui::Separator(); - ImGui::Text("Curr: Render / Sound / Input"); - ImGui::Text("freq: %s / %s / %s", render_freq_hist_str, sound_freq_hist_str, input_freq_hist_str); - ImGui::Text(" ms: %s / %s / %s", render_ms_hist_str, sound_ms_hist_str, input_ms_hist_str); + ImGui::Text("Curr: Render / Sound"); + ImGui::Text("freq: %s / %s", render_freq_hist_str, sound_freq_hist_str); + ImGui::Text(" ms: %s / %s", render_ms_hist_str, sound_ms_hist_str); #endif ImGui::Separator(); diff --git a/src/CLOUD/input.c b/src/CLOUD/input.c deleted file mode 100644 index 7ae9ba78..00000000 --- a/src/CLOUD/input.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder - - Some input code is from samyuu's TLAC -*/ - -#include "input.h" -#include "../KKdLib/vec.h" -#include "../CRE/timer.h" -#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS -#include - -#define KEYBOARD_KEYS 0xFF - -struct key_state { - bool key_states[KEYBOARD_KEYS]; -}; - -struct mouse_state { - POINT position; -}; - -timer input_timer; - -key_state input_key_current_state; -key_state input_key_last_state; - -mouse_state input_mouse_current_state; -mouse_state input_mouse_last_state; - -double_t input_movement_speed = 0.1; -double_t input_rotation_sensitivity = 0.5; -vec2d input_move; -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; -lock input_lock; -extern lock render_lock; -extern timer render_timer; -extern HWND window_handle; -extern ImGuiContext* imgui_context; -extern lock imgui_context_lock; - -static void input_poll(); - -int32_t input_main(void* arg) { - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - timeBeginPeriod(1); - timer_init(&input_timer, 60.0); - lock_init(&input_lock); - - bool state_wait = false; - bool state_disposed = false; - bool local_close = false; - if (!lock_check_init(&input_lock)) - goto End; - - do { - lock_lock(&state_lock); - state_wait = state != RENDER_INITIALIZING; - state_disposed = state == RENDER_DISPOSING; - lock_unlock(&state_lock); - if (state_disposed) { - lock_free(&input_lock); - goto End; - } - timer_sleep(&input_timer, 0.0625); - } while (state_wait); - - lock_lock(&state_lock); - enum_or(thread_flags, THREAD_INPUT); - lock_unlock(&state_lock); - - timer_reset(&input_timer); - while (!close && !local_close) { - timer_start_of_cycle(&input_timer); - lock_lock(&state_lock); - local_close = state == RENDER_DISPOSING; - lock_unlock(&state_lock); - - lock_lock(&input_lock); - input_poll(); - lock_unlock(&input_lock); - timer_end_of_cycle(&input_timer); - } - lock_free(&input_lock); - -End: - timer_dispose(&input_timer); - - lock_lock(&state_lock); - enum_and(thread_flags, ~THREAD_INPUT); - lock_unlock(&state_lock); - return 0; -} - -static void input_poll() { - input_mouse_last_state = input_mouse_current_state; - input_key_last_state = input_key_current_state; - - for (uint8_t i = 0; i < KEYBOARD_KEYS; i++) - input_key_current_state.key_states[i] = GetAsyncKeyState(i) < 0; - - if (window_handle) { - GetCursorPos(&input_mouse_current_state.position); - ScreenToClient(window_handle, &input_mouse_current_state.position); - } - - input_move.x = 0.0; - input_move.y = 0.0; - input_rotate.x = 0.0; - input_rotate.y = 0.0; - input_roll = 0.0; - - 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 frame_speed = freq / freq_hist; - - input_locked = false; - classes_process_input(classes, classes_count); - - if (!input_locked) { - double_t speed; - if (input_is_down(VK_SHIFT)) - speed = input_movement_speed * 10.0; - else if (input_is_down(VK_CONTROL)) - speed = input_movement_speed / 10.0; - else - speed = input_movement_speed; - speed *= freq / freq_hist; - - if (input_is_down('W')) - input_move.x += speed; - if (input_is_down('S')) - input_move.x -= speed; - - if (input_is_down('A')) - input_move.y -= speed; - if (input_is_down('D')) - input_move.y += speed; - - if (input_is_down(VK_SHIFT)) - speed = input_movement_speed * 2.0; - else if (input_is_down(VK_CONTROL)) - speed = input_movement_speed / 2.0; - else - speed = input_movement_speed; - speed *= freq / freq_hist; - speed *= 10.0; - - if (input_is_down(VK_UP)) - input_rotate.y += speed; - if (input_is_down(VK_DOWN)) - input_rotate.y -= speed; - - if (input_is_down(VK_LEFT)) - input_rotate.x -= speed; - if (input_is_down(VK_RIGHT)) - input_rotate.x += speed; - - if (input_is_down('Q')) - input_roll -= speed; - if (input_is_down('E')) - input_roll += speed; - - if (input_is_tapped('R')) - if (input_is_down(VK_CONTROL)) - input_shaders_reload = true; - else - input_reset = true; - } - - lock_lock(&imgui_context_lock); - ImGui::SetCurrentContext(imgui_context); - if (!ImGui::GetIO().WantCaptureMouse && input_is_down(VK_MBUTTON)) { - if (!input_reset_mouse_position) { - POINT last = input_mouse_last_state.position; - POINT curr = input_mouse_current_state.position; - input_rotate.y += ((double_t)last.y - (double_t)curr.y) * input_rotation_sensitivity; - input_rotate.x += ((double_t)curr.x - (double_t)last.x) * input_rotation_sensitivity; - } - input_reset_mouse_position = false; - } - else - input_reset_mouse_position = true; - lock_unlock(&imgui_context_lock); -} - -inline bool input_is_down(uint8_t keycode) { - return input_key_current_state.key_states[keycode]; -} - -inline bool input_is_up(uint8_t keycode) { - return !input_key_current_state.key_states[keycode]; -} - -inline bool input_is_tapped(uint8_t keycode) { - return input_key_current_state.key_states[keycode] && !input_key_last_state.key_states[keycode]; -} - -inline bool input_is_released(uint8_t keycode) { - return !input_key_current_state.key_states[keycode] && input_key_last_state.key_states[keycode]; -} - -inline bool input_was_down(uint8_t keycode) { - return input_key_last_state.key_states[keycode]; -} - -inline bool input_was_up(uint8_t keycode) { - return !input_key_last_state.key_states[keycode]; -} - -inline POINT input_mouse_position() { - return input_mouse_current_state.position; -} diff --git a/src/CLOUD/input.cpp b/src/CLOUD/input.cpp new file mode 100644 index 00000000..c3a9de25 --- /dev/null +++ b/src/CLOUD/input.cpp @@ -0,0 +1,301 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder + + Some input code is from samyuu's TLAC +*/ + +#include "input.hpp" +#include +#include "../KKdLib/vec.h" +#include "../CRE/timer.h" +#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS +#include + +double_t input_movement_speed = 0.1; +double_t input_rotation_sensitivity = 0.5; +vec2d input_move; +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 HWND window_handle; +extern ImGuiContext* imgui_context; +extern lock imgui_context_lock; + +namespace Input { + struct Key { + int32_t key; + int32_t scancode; + int32_t action; + int32_t mods; + }; + + struct MouseButton { + int32_t button; + int32_t action; + int32_t mods; + }; + + std::map keys; + std::map mouse_buttons; + POINT pos; + + std::map keys_prev; + std::map mouse_buttons_prev; + POINT pos_prev; + + 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); + + bool IsKeyDown(int32_t key, int32_t mods) { + auto elem = keys.find(key); + if (elem != keys.end()) + if (!mods || elem->second.mods == mods) + return elem->second.action != GLFW_RELEASE; + return false; + } + + bool IsKeyUp(int32_t key, int32_t mods) { + auto elem = keys.find(key); + if (elem != keys.end()) + if (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || (elem->second.mods == mods && elem_prev->second.mods == mods)) + return elem->second.action != GLFW_RELEASE && elem_prev->second.action == GLFW_RELEASE; + } + else { + if (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || (elem->second.mods == mods && elem_prev->second.mods == mods)) + return elem->second.action == GLFW_RELEASE && elem_prev->second.action != GLFW_RELEASE; + } + else { + if (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || (elem->second.mods == mods && elem_prev->second.mods == mods)) + return elem->second.action != GLFW_RELEASE && elem_prev->second.action == GLFW_RELEASE; + } + else { + if (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || (elem->second.mods == mods && elem_prev->second.mods == mods)) + return elem->second.action == GLFW_RELEASE && elem_prev->second.action != GLFW_RELEASE; + } + else { + if (!mods || elem->second.mods == mods) + return elem->second.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 (!mods || elem_prev->second.mods == mods) + return elem_prev->second.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 (!mods || elem_prev->second.mods == mods) + return elem_prev->second.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 (!mods || elem_prev->second.mods == mods) + return elem_prev->second.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 (!mods || elem_prev->second.mods == mods) + return elem_prev->second.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); + } + + void NewFrame() { + pos_prev = pos; + + if (window_handle) { + GetCursorPos(&pos); + ScreenToClient(window_handle, &pos); + } + + input_move.x = 0.0; + input_move.y = 0.0; + input_rotate.x = 0.0; + input_rotate.y = 0.0; + input_roll = 0.0; + + 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 frame_speed = freq / freq_hist; + + input_locked = false; + classes_process_input(classes, classes_count); + + if (!input_locked) { + double_t speed; + if (IsKeyDown(GLFW_KEY_LEFT_SHIFT) || IsKeyDown(GLFW_KEY_RIGHT_SHIFT)) + speed = input_movement_speed * 10.0; + else if (IsKeyDown(GLFW_KEY_LEFT_CONTROL) || IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) + speed = input_movement_speed / 10.0; + else + speed = input_movement_speed; + speed *= frame_speed; + + if (IsKeyDown(GLFW_KEY_W)) + input_move.x += speed; + if (IsKeyDown(GLFW_KEY_S)) + input_move.x -= speed; + + if (IsKeyDown(GLFW_KEY_A)) + input_move.y -= speed; + if (IsKeyDown(GLFW_KEY_D)) + input_move.y += speed; + + if (IsKeyDown(GLFW_KEY_LEFT_SHIFT) || IsKeyDown(GLFW_KEY_RIGHT_SHIFT)) + speed = input_movement_speed * 2.0; + else if (IsKeyDown(GLFW_KEY_LEFT_CONTROL) || IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) + speed = input_movement_speed / 2.0; + else + speed = input_movement_speed; + speed *= freq / freq_hist; + speed *= 10.0; + + if (IsKeyDown(GLFW_KEY_UP)) + input_rotate.y += speed; + if (IsKeyDown(GLFW_KEY_DOWN)) + input_rotate.y -= speed; + + if (IsKeyDown(GLFW_KEY_LEFT)) + input_rotate.x -= speed; + if (IsKeyDown(GLFW_KEY_RIGHT)) + input_rotate.x += speed; + + if (IsKeyDown(GLFW_KEY_Q)) + input_roll -= speed; + if (IsKeyDown(GLFW_KEY_E)) + input_roll += speed; + + if (IsKeyDown(GLFW_KEY_R)) + if (IsKeyDown(GLFW_KEY_LEFT_CONTROL) || IsKeyDown(GLFW_KEY_RIGHT_CONTROL)) + input_shaders_reload = true; + else + input_reset = true; + } + + lock_lock(&imgui_context_lock); + ImGui::SetCurrentContext(imgui_context); + if (!ImGui::GetIO().WantCaptureMouse && Input::IsMouseButtonDown(GLFW_MOUSE_BUTTON_MIDDLE)) { + 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; + } + input_reset_mouse_position = false; + } + else + input_reset_mouse_position = true; + lock_unlock(&imgui_context_lock); + } + + void SetInputs(GLFWwindow* window) { + glfwSetKeyCallback(window, (GLFWkeyfun)KeyboardCallback); + glfwSetMouseButtonCallback(window, (GLFWmousebuttonfun)MouseButtonCallback); + } + + 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 }; + else + keys.insert({ key, { 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 }; + else + mouse_buttons.insert({ button, { button, action, mods } }); + } +}; diff --git a/src/CLOUD/input.h b/src/CLOUD/input.h deleted file mode 100644 index 41a749aa..00000000 --- a/src/CLOUD/input.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - by korenkonder - GitHub/GitLab: korenkonder -*/ - -#pragma once - -#include "shared.h" - -extern int32_t input_main(void* arg); -extern bool input_is_down(uint8_t keycode); -extern bool input_is_up(uint8_t keycode); -extern bool input_is_tapped(uint8_t keycode); -extern bool input_is_released(uint8_t keycode); -extern bool input_was_down(uint8_t keycode); -extern bool input_was_up(uint8_t keycode); -extern POINT input_mouse_position(); diff --git a/src/CLOUD/input.hpp b/src/CLOUD/input.hpp new file mode 100644 index 00000000..9b0c352e --- /dev/null +++ b/src/CLOUD/input.hpp @@ -0,0 +1,27 @@ +/* + by korenkonder + GitHub/GitLab: korenkonder +*/ + +#pragma once + +#include "shared.h" +#include + +namespace Input { + bool IsKeyDown(int32_t key, int32_t mods = 0); + bool IsKeyUp(int32_t key, int32_t mods = 0); + bool IsKeyTapped(int32_t key, int32_t mods = 0); + bool IsKeyReleased(int32_t key, int32_t mods = 0); + bool IsMouseButtonDown(int32_t button, int32_t mods = 0); + bool IsMouseButtonUp(int32_t button, int32_t mods = 0); + bool IsMouseButtonTapped(int32_t button, int32_t mods = 0); + bool IsMouseButtonReleased(int32_t button, int32_t mods = 0); + bool WasKeyDown(int32_t key, int32_t mods = 0); + bool WasKeyUp(int32_t key, int32_t mods = 0); + bool WasMouseButtonDown(int32_t button, int32_t mods = 0); + bool WasMouseButtonUp(int32_t button, int32_t mods = 0); + void EndFrame(); + void NewFrame(); + void SetInputs(GLFWwindow* window); +}; diff --git a/src/CLOUD/main.c b/src/CLOUD/main.c index b06cec7b..e02903ea 100644 --- a/src/CLOUD/main.c +++ b/src/CLOUD/main.c @@ -339,14 +339,11 @@ int32_t wmain(int32_t argc, wchar_t** argv) { ris.res.y = 0; ris.scale = 0.0f; - thread input, render, sound; - HANDLE h[3]; - h[0] = input.handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)input_main, 0, 0, &input.id); - h[1] = render.handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)render_main, &ris, 0, &render.id); - h[2] = sound.handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sound_main, 0, 0, &sound.id); + thread render, sound; + HANDLE h[2]; + h[0] = render.handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)render_main, &ris, 0, &render.id); + h[1] = sound.handle = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)sound_main, 0, 0, &sound.id); - if (input.handle) - SetThreadDescription(input.handle, L"Input Thread"); if (render.handle) SetThreadDescription(render.handle, L"Render Thread"); if (sound.handle) @@ -354,12 +351,10 @@ int32_t wmain(int32_t argc, wchar_t** argv) { lock_init(&state_lock); state = RENDER_UNINITIALIZED; - if (input.handle && render.handle && sound.handle) - WaitForMultipleObjects(3, h, true, INFINITE); + if (render.handle && sound.handle) + WaitForMultipleObjects(2, h, true, INFINITE); lock_free(&state_lock); - if (input.handle) - CloseHandle(input.handle); if (render.handle) CloseHandle(render.handle); if (sound.handle) diff --git a/src/CLOUD/main.h b/src/CLOUD/main.h index efb890c3..766c1110 100644 --- a/src/CLOUD/main.h +++ b/src/CLOUD/main.h @@ -6,6 +6,6 @@ #pragma once #include "../KKdLib/default.h" -#include "input.h" +#include "input.hpp" #include "render.h" #include "sound.h" diff --git a/src/CLOUD/render.c b/src/CLOUD/render.c index 6a535eb3..59d3c3cf 100644 --- a/src/CLOUD/render.c +++ b/src/CLOUD/render.c @@ -39,7 +39,8 @@ #include "../KKdLib/sort.h" #include "../KKdLib/str_utils.h" #include "classes/imgui_helper.h" -#include "x_pv_game.h" +#include "input.hpp" +#include "x_pv_game.hpp" #include #if defined(DEBUG) @@ -224,6 +225,8 @@ int32_t render_main(void* arg) { glfwSetWindowSizeLimits(window, 896, 504, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowPos(window, 8, 31); + Input::SetInputs(window); + RECT window_rect; GetClientRect(window_handle, &window_rect); width = window_rect.right; @@ -282,6 +285,7 @@ int32_t render_main(void* arg) { ImGui_ImplGlfw_NewFrame(); ImGui_ImplOpenGL3_NewFrame(); ImGui::NewFrame(); + Input::NewFrame(); lock_lock(&render_lock); render_ctrl(rctx); lock_unlock(&render_lock); @@ -289,6 +293,7 @@ int32_t render_main(void* arg) { glfwSwapBuffers(window); close |= !!glfwWindowShouldClose(window); frame_counter++; + Input::EndFrame(); timer_end_of_cycle(&render_timer); } @@ -573,7 +578,7 @@ static render_context* render_load() { task_auth_3d_append_task(); TaskWork::AppendTask(&Glitter::glt_particle_manager, "GLITTER_TASK", 2); - //TaskWork::AppendTask(&x_pv_game_data, "X_PV_GAME", 0); + TaskWork::AppendTask(&x_pv_game_data, "X_PV_GAME", 0); task_rob_manager_append_task(); aft_data->load_file(aft_data, "rom/", "chritm_prop.farc", item_table_array_load_file); @@ -731,7 +736,7 @@ static render_context* render_load() { clear_color = { (float_t)(96.0 / 255.0), (float_t)(96.0 / 255.0), (float_t)(96.0 / 255.0) }; set_clear_color = true; - //x_pv_game_data.Load(826, 26); + x_pv_game_data.Load(826, 26); shader_env_vert_set_ptr(&shaders_ft, 3, (vec4*)&vec4_identity); shader_env_vert_set_ptr(&shaders_ft, 4, (vec4*)&vec4_null); @@ -1158,7 +1163,7 @@ static void render_dispose(render_context* rctx) { ImGui::DestroyContext(imgui_context); lock_free(&imgui_context_lock); - //x_pv_game_data.SetDest(); + x_pv_game_data.SetDest(); Glitter::glt_particle_manager.SetDest(); //rob_chara_array_free_chara_id(0); diff --git a/src/CLOUD/x_pv_game.c b/src/CLOUD/x_pv_game.cpp similarity index 98% rename from src/CLOUD/x_pv_game.c rename to src/CLOUD/x_pv_game.cpp index ae1d4eaf..267d7905 100644 --- a/src/CLOUD/x_pv_game.c +++ b/src/CLOUD/x_pv_game.cpp @@ -7,7 +7,7 @@ #if defined(CLOUD_DEV) #include -#include "x_pv_game.h" +#include "x_pv_game.hpp" #include "../CRE/Glitter/glitter.hpp" #include "../CRE/light_param/light.h" #include "../CRE/data.h" @@ -15,7 +15,7 @@ #include "../CRE/stage_modern.h" #include "../KKdLib/farc.h" #include "../KKdLib/sort.h" -#include "input.h" +#include "input.hpp" #include "classes/imgui_helper.h" enum dsc_x_func { @@ -481,7 +481,6 @@ bool x_pv_game::Ctrl() { i.set_motion_data_offset = 0; } - std::vector> bar_frames; std::vector state_vec; @@ -514,7 +513,8 @@ bool x_pv_game::Ctrl() { } break; case DSC_X_BAR_POINT: { int32_t bar = data[0]; - bar_frames.push_back({ frame, bar }); + if (bar % 2) + bar_frames.push_back({ frame, bar }); } break; case DSC_X_STAGE_EFFECT: { int32_t stage_effect = (int32_t)data[0]; @@ -541,6 +541,7 @@ bool x_pv_game::Ctrl() { bar_count_change = effect.bar_count; } } + bar_count_change /= 2; int32_t stage_effect_frame = frame; int32_t bar = 1; @@ -549,8 +550,6 @@ bool x_pv_game::Ctrl() { stage_effect_frame = (&i)[-bar_count_change].first; bar = (&i)[-bar_count_change].second; } - else if (frame < i.first) - break; stage_effects.push_back({ stage_effect_frame, stage_effect, bar_count + bar_count_change, bar }); @@ -714,6 +713,10 @@ void x_pv_game::Disp() { bool x_pv_game::Dest() { Unload(); task_stage_modern_unload(); + + Glitter::glt_particle_manager.SetPause(false); + extern float_t frame_speed; + frame_speed = 1.0f; return true; } @@ -721,9 +724,16 @@ void x_pv_game::Window() { if (state != 10) return; - if (ImGui::IsKeyPressed(GLFW_KEY_K, false)) + if (Input::IsKeyTapped(GLFW_KEY_K, GLFW_MOD_CONTROL)) + state = 11; + else if (Input::IsKeyTapped(GLFW_KEY_K)) pause ^= true; + if (Input::IsKeyTapped(GLFW_KEY_L)) { + pause = true; + step_frame = true; + } + if (!pause) return; @@ -758,23 +768,29 @@ void x_pv_game::Window() { ImGui::TableNextColumn(); w = imguiGetContentRegionAvailWidth(); - if (imguiButton("Step Frame (L)", { w, 0.0f }) || ImGui::IsKeyPressed(GLFW_KEY_L)) { + if (imguiButton("Step Frame (L)", { w, 0.0f })) { pause = true; step_frame = true; } + + ImGui::TableNextColumn(); + w = imguiGetContentRegionAvailWidth(); + if (imguiButton("Stop (Ctrl+K)", { w, 0.0f })) + state = 11; + + ImGui::TableNextColumn(); + w = imguiGetContentRegionAvailWidth(); + 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 + | ImGuiButtonFlags_NoNavFocus | ImGuiButtonFlags_NoHoveredOnFocus); + ImGui::PopStyleColor(3); ImGui::EndTable(); } - w = imguiGetContentRegionAvailWidth(); - 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 - | ImGuiButtonFlags_NoNavFocus | ImGuiButtonFlags_NoHoveredOnFocus); - ImGui::PopStyleColor(3); - extern bool input_locked; input_locked |= ImGui::IsWindowFocused(); ImGui::End(); diff --git a/src/CLOUD/x_pv_game.h b/src/CLOUD/x_pv_game.hpp similarity index 100% rename from src/CLOUD/x_pv_game.h rename to src/CLOUD/x_pv_game.hpp diff --git a/src/CRE/Glitter/particle_inst.cpp b/src/CRE/Glitter/particle_inst.cpp index a49ecd2b..e844febc 100644 --- a/src/CRE/Glitter/particle_inst.cpp +++ b/src/CRE/Glitter/particle_inst.cpp @@ -227,7 +227,8 @@ namespace Glitter { case UV_INDEX_INITIAL_RANDOM_FIXED: case UV_INDEX_INITIAL_RANDOM_FORWARD: case UV_INDEX_INITIAL_RANDOM_REVERSE: - rend_elem->uv_index += random->F2GetInt(GLT_VAL, ptcl_inst_data->data.uv_index_count); + rend_elem->uv_index = ptcl_inst_data->data.uv_index_start + + random->F2GetInt(GLT_VAL, ptcl_inst_data->data.uv_index_count); break; } rend_elem->uv_index = min(rend_elem->uv_index, ptcl_inst_data->data.uv_index_end); @@ -646,7 +647,8 @@ namespace Glitter { case UV_INDEX_INITIAL_RANDOM_FIXED: case UV_INDEX_INITIAL_RANDOM_FORWARD: case UV_INDEX_INITIAL_RANDOM_REVERSE: - rend_elem->uv_index += random->XGetInt(ptcl_inst_data->data.uv_index_count); + rend_elem->uv_index = ptcl_inst_data->data.uv_index_start + + random->XGetInt(ptcl_inst_data->data.uv_index_count); break; } rend_elem->uv_index = min(rend_elem->uv_index, ptcl_inst_data->data.uv_index_end); diff --git a/src/CRE/Glitter/render_scene.cpp b/src/CRE/Glitter/render_scene.cpp index c79ccdb2..2ba022c3 100644 --- a/src/CRE/Glitter/render_scene.cpp +++ b/src/CRE/Glitter/render_scene.cpp @@ -238,6 +238,7 @@ namespace Glitter { ctrl_quad = 0; ctrl_line = 0; ctrl_locus = 0; + ctrl_mesh = 0; for (F2RenderGroup*& i : groups) if (i) { @@ -252,54 +253,11 @@ namespace Glitter { ctrl_locus += i->ctrl; break; } + i->Ctrl(GLT_VAL, delta_frame, true); } } - void F2RenderScene::Disp(GPM, draw_pass_3d_type alpha) { - disp_quad = 0; - disp_line = 0; - disp_locus = 0; - - F2EffectInst* eff = dynamic_cast(GPM_VAL->effect); - F2EmitterInst* emit = dynamic_cast(GPM_VAL->emitter); - F2ParticleInst* ptcl = dynamic_cast(GPM_VAL->particle); - for (F2RenderGroup*& i : groups) { - if (!i) - continue; - - F2RenderGroup* rend_group = i; - if ((rend_group)->alpha != alpha - || (rend_group->CannotDisp() && !GPM_VAL->draw_all)) - continue; - -#if !defined(CRE_DEV) - Disp(GPM_VAL, rend_group); -#else - if (!GPM_VAL->draw_selected || !eff) { - Disp(GPM_VAL, rend_group); - } - else if ((eff && ptcl) || (eff && !emit)) { - if (!ptcl || rend_group->particle == ptcl) - Disp(GPM_VAL, rend_group); - } - else if (emit) - for (F2ParticleInst*& i : emit->particles) { - if (!i) - continue; - - F2ParticleInst* particle = i; - if (rend_group->particle == particle) - Disp(GPM_VAL, rend_group); - - for (F2ParticleInst*& j : particle->data.children) - if (j && rend_group->particle == j) - Disp(GPM_VAL, rend_group); - } -#endif - } - } - void F2RenderScene::CalcDispLocus(GPM, F2RenderGroup* rend_group) { if (!rend_group->elements || !rend_group->vbo || rend_group->ctrl < 1) return; @@ -573,8 +531,7 @@ namespace Glitter { float_t v10; float_t v11; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -731,8 +688,7 @@ namespace Glitter { float_t v11; float_t v10; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -815,8 +771,7 @@ namespace Glitter { float_t v11; float_t v10; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -872,6 +827,51 @@ namespace Glitter { gl_state_bind_array_buffer(0); } + void F2RenderScene::Disp(GPM, draw_pass_3d_type alpha) { + disp_quad = 0; + disp_line = 0; + disp_locus = 0; + disp_mesh = 0; + + F2EffectInst* eff = dynamic_cast(GPM_VAL->effect); + F2EmitterInst* emit = dynamic_cast(GPM_VAL->emitter); + F2ParticleInst* ptcl = dynamic_cast(GPM_VAL->particle); + for (F2RenderGroup*& i : groups) { + if (!i) + continue; + + F2RenderGroup* rend_group = i; + if ((rend_group)->alpha != alpha + || (rend_group->CannotDisp() && !GPM_VAL->draw_all)) + continue; + +#if !defined(CRE_DEV) + Disp(GPM_VAL, rend_group); +#else + if (!GPM_VAL->draw_selected || !eff) { + Disp(GPM_VAL, rend_group); + } + else if ((eff && ptcl) || (eff && !emit)) { + if (!ptcl || rend_group->particle == ptcl) + Disp(GPM_VAL, rend_group); + } + else if (emit) + for (F2ParticleInst*& i : emit->particles) { + if (!i) + continue; + + F2ParticleInst* particle = i; + if (rend_group->particle == particle) + Disp(GPM_VAL, rend_group); + + for (F2ParticleInst*& j : particle->data.children) + if (j && rend_group->particle == j) + Disp(GPM_VAL, rend_group); + } +#endif + } + } + void F2RenderScene::Disp(GPM, F2RenderGroup* rend_group) { switch (rend_group->type) { case PARTICLE_QUAD: @@ -1133,6 +1133,8 @@ namespace Glitter { } void XRenderScene::CalcDisp(GPM, XRenderGroup* rend_group) { + disp_mesh = 0; + switch (rend_group->type) { case PARTICLE_MESH: break; @@ -1144,6 +1146,7 @@ namespace Glitter { switch (rend_group->type) { case PARTICLE_MESH: CalcDispMesh(GPM_VAL, rend_group); + disp_mesh += rend_group->disp; break; } } @@ -1685,8 +1688,7 @@ namespace Glitter { float_t v10; float_t v11; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -1832,8 +1834,7 @@ namespace Glitter { float_t v11; float_t v10; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -1911,8 +1912,7 @@ namespace Glitter { float_t v11; float_t v10; CalcDispQuadSetPivot(rend_group->pivot, - scale_particle.x, - scale_particle.y, + scale_particle.x, scale_particle.y, &v00, &v01, &v10, &v11); vec2 pos_add[4]; @@ -1969,12 +1969,37 @@ namespace Glitter { } void XRenderScene::Ctrl(float_t delta_frame, bool copy_mats) { + ctrl_quad = 0; + ctrl_line = 0; + ctrl_locus = 0; + ctrl_mesh = 0; + for (XRenderGroup*& i : groups) - if (i) + if (i) { + switch (i->type) { + case PARTICLE_QUAD: + ctrl_quad += i->ctrl; + break; + case PARTICLE_LINE: + ctrl_line += i->ctrl; + break; + case PARTICLE_LOCUS: + ctrl_locus += i->ctrl; + break; + case PARTICLE_MESH: + ctrl_mesh += i->ctrl; + break; + } + i->Ctrl(delta_frame, copy_mats); + } } void XRenderScene::Disp(GPM, draw_pass_3d_type alpha) { + disp_quad = 0; + disp_line = 0; + disp_locus = 0; + XEffectInst* eff = dynamic_cast(GPM_VAL->effect); XEmitterInst* emit = dynamic_cast(GPM_VAL->emitter); XParticleInst* ptcl = dynamic_cast(GPM_VAL->particle); @@ -2027,12 +2052,15 @@ namespace Glitter { switch (rend_group->type) { case PARTICLE_QUAD: CalcDispQuad(GPM_VAL, rend_group); + disp_quad += rend_group->disp; break; case PARTICLE_LINE: CalcDispLine(rend_group); + disp_line += rend_group->disp; break; case PARTICLE_LOCUS: CalcDispLocus(GPM_VAL, rend_group); + disp_locus += rend_group->disp; break; }