Skip to content

Commit

Permalink
GameObjectsDisplay: Slight perf improvement + flicker reduction
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
praydog committed Nov 11, 2024
1 parent fe305ee commit 0147b74
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/mods/BackBufferRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ void BackBufferRenderer::render_d3d12() {
{
std::scoped_lock _{m_d3d12.render_work_mtx};
works = m_d3d12.render_work;
m_d3d12.render_work.clear();
}

const RenderWorkData data{
Expand Down Expand Up @@ -153,4 +152,12 @@ void BackBufferRenderer::on_present() {
} else {
render_d3d11();
}
}

void BackBufferRenderer::on_frame() {
// Clearing this here instead of every time whenever we present fixes flickering in some games
if (g_framework->is_dx12() && !m_d3d12.render_work.empty()) {
std::scoped_lock _{m_d3d12.render_work_mtx};
m_d3d12.render_work.clear();
}
}
1 change: 1 addition & 0 deletions src/mods/BackBufferRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class BackBufferRenderer : public Mod {

std::optional<std::string> on_initialize_d3d_thread() override;
void on_present() override;
void on_frame() override;
void on_device_reset() override;

public:
Expand Down
13 changes: 4 additions & 9 deletions src/mods/tools/GameObjectsDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ void GameObjectsDisplay::on_frame() {
static auto get_gameobject_method = transform_def->get_method("get_GameObject");
static auto get_position_method = transform_def->get_method("get_Position");
static auto get_axisz_method = transform_def->get_method("get_AxisZ");
static auto get_world_matrix_method = transform_def->get_method("get_WorldMatrix");

auto math = sdk::get_native_singleton("via.math");
auto math_t = sdk::find_type_definition("via.math");
Expand Down Expand Up @@ -229,6 +230,8 @@ void GameObjectsDisplay::on_frame() {
});
}

__declspec(align(16)) Matrix4x4f world_matrix{};

for (auto transform = first_transform;
transform != nullptr;
transform = next_transform_method->call<RETransform*>(context, transform))
Expand Down Expand Up @@ -264,15 +267,7 @@ void GameObjectsDisplay::on_frame() {
}

if (is_d3d12) {
// Billboard rotation to make the quad face the camera
/*DirectX::SimpleMath::Matrix rotation = DirectX::SimpleMath::Matrix::CreateBillboard(
DirectX::SimpleMath::Vector3(pos.x, pos.y, pos.z),
DirectX::SimpleMath::Vector3(camera_origin.x, camera_origin.y, camera_origin.z),
DirectX::SimpleMath::Vector3::Up
);*/

Matrix4x4f world_matrix{};
sdk::call_object_func<void*>(transform, "get_WorldMatrix", &world_matrix, context, transform);
get_world_matrix_method->call<void*>(&world_matrix, context, transform);

DirectX::SimpleMath::Matrix world =
DirectX::SimpleMath::Matrix{&world_matrix[0][0]};
Expand Down

0 comments on commit 0147b74

Please sign in to comment.