mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 01:23:51 +00:00
perf: eliminate ~70 unnecessary sqrt ops per frame, optimize caches and threading
Squared distance optimizations across 30 files: - Convert glm::length() comparisons to glm::dot() (no sqrt) - Use glm::inversesqrt() for check-then-normalize patterns (1 rsqrt vs 2 sqrt) - Defer sqrt to after early-out checks in collision/movement code - Hottest paths: camera_controller (21), weather particles, WMO collision, transport movement, creature interpolation, nameplate culling Container and algorithm improvements: - std::map<string> → std::unordered_map for asset/DBC/MPQ/warden caches - std::mutex → std::shared_mutex for asset_manager and mpq_manager caches - std::sort → std::partial_sort in lighting_manager (top-2 of N volumes) - Double-lookup find()+operator[] → insert_or_assign in game_handler - Add reserve() for per-frame vectors: weather, swim_effects, WMO/M2 collision Threading and synchronization: - Replace 1ms busy-wait polling with condition_variable in character_renderer - Move timestamp capture before mutex in logger - Use memory_order_acquire/release for normal map completion signaling API additions: - DBC getStringView()/getStringViewByOffset() for zero-copy string access - Parse creature display IDs from SMSG_CREATURE_QUERY_SINGLE_RESPONSE
This commit is contained in:
parent
cf0e2aa240
commit
b0466e9029
29 changed files with 328 additions and 196 deletions
|
|
@ -2990,10 +2990,11 @@ void GameScreen::processTargetInput(game::GameHandler& gameHandler) {
|
|||
if (leftClickWasPress_ && input.isMouseButtonJustReleased(SDL_BUTTON_LEFT)) {
|
||||
leftClickWasPress_ = false;
|
||||
glm::vec2 releasePos = input.getMousePosition();
|
||||
float dragDist = glm::length(releasePos - leftClickPressPos_);
|
||||
glm::vec2 dragDelta = releasePos - leftClickPressPos_;
|
||||
float dragDistSq = glm::dot(dragDelta, dragDelta);
|
||||
constexpr float CLICK_THRESHOLD = 5.0f; // pixels
|
||||
|
||||
if (dragDist < CLICK_THRESHOLD) {
|
||||
if (dragDistSq < CLICK_THRESHOLD * CLICK_THRESHOLD) {
|
||||
auto* renderer = core::Application::getInstance().getRenderer();
|
||||
auto* camera = renderer ? renderer->getCamera() : nullptr;
|
||||
auto* window = core::Application::getInstance().getWindow();
|
||||
|
|
@ -11557,9 +11558,10 @@ void GameScreen::renderNameplates(game::GameHandler& gameHandler) {
|
|||
renderPos.z += 2.3f;
|
||||
|
||||
// Cull distance: target or other players up to 40 units; NPC others up to 20 units
|
||||
float dist = glm::length(renderPos - camPos);
|
||||
glm::vec3 nameDelta = renderPos - camPos;
|
||||
float distSq = glm::dot(nameDelta, nameDelta);
|
||||
float cullDist = (isTarget || isPlayer) ? 40.0f : 20.0f;
|
||||
if (dist > cullDist) continue;
|
||||
if (distSq > cullDist * cullDist) continue;
|
||||
|
||||
// Project to clip space
|
||||
glm::vec4 clipPos = viewProj * glm::vec4(renderPos, 1.0f);
|
||||
|
|
@ -11576,7 +11578,9 @@ void GameScreen::renderNameplates(game::GameHandler& gameHandler) {
|
|||
float sy = (ndc.y * 0.5f + 0.5f) * screenH;
|
||||
|
||||
// Fade out in the last 5 units of cull range
|
||||
float alpha = dist < (cullDist - 5.0f) ? 1.0f : 1.0f - (dist - (cullDist - 5.0f)) / 5.0f;
|
||||
float fadeSq = (cullDist - 5.0f) * (cullDist - 5.0f);
|
||||
float dist = std::sqrt(distSq);
|
||||
float alpha = distSq < fadeSq ? 1.0f : 1.0f - (dist - (cullDist - 5.0f)) / 5.0f;
|
||||
auto A = [&](int v) { return static_cast<int>(v * alpha); };
|
||||
|
||||
// Bar colour by hostility (grey for corpses)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue