Skip to content

Commit

Permalink
VR (Single pass): Stability improvements (mostly for MHRise)
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Oct 21, 2024
1 parent 7990c00 commit d967aa7
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/mods/vr/CameraDuplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ void CameraDuplicator::on_pre_application_entry(void* entry, const char* name, s
if (camera->referenceCount == 1) {
cameras_to_remove.push_back(camera);
spdlog::info("Removing camera {:x}", (uintptr_t)camera);
} else {
static const auto game_object_t = sdk::find_type_definition("via.GameObject");
static const auto get_Valid = game_object_t != nullptr ? game_object_t->get_method("get_Valid") : nullptr;
auto owner = utility::re_component::get_game_object(camera);

// if the owning game object was destroyed then well... destroy the camera
if (owner == nullptr || (get_Valid != nullptr && !get_Valid->call<bool>(sdk::get_thread_context(), owner))) {
cameras_to_remove.push_back(camera);
spdlog::info("Removing camera (destroyed gameobject) {:x}", (uintptr_t)camera);
}
}
}

Expand All @@ -32,6 +42,15 @@ void CameraDuplicator::on_pre_application_entry(void* entry, const char* name, s
m_old_to_new_camera.erase((RECamera*)camera);
m_new_to_old_camera.erase((RECamera*)camera);

// Remove anything from the map that has the value of the camera, not just the key.
std::erase_if(m_old_to_new_camera, [camera](const auto& pair) {
return pair.second == camera;
});

std::erase_if(m_new_to_old_camera, [camera](const auto& pair) {
return pair.second == camera;
});

utility::re_managed_object::release(camera);
}
}
Expand Down Expand Up @@ -244,6 +263,7 @@ void CameraDuplicator::clone_camera() {
"via.motion.MotionCamera", // Unnecessarily takes control of the camera transform which we don't want
"via.motion.ActorMotionCamera", // Unnecessarily takes control of the camera transform which we don't want
"via.wwise.WwiseListener",
"via.physics.Colliders",
// todo
};

Expand All @@ -270,8 +290,11 @@ void CameraDuplicator::clone_camera() {
continue;
}

const auto full_name = tdef->get_full_name();

// TODO: other game framework prefixes or maybe app is just okay?
if (tdef->get_full_name().starts_with("app.")) {
// snow is for MHRise, app is for most of the other games
if (full_name.starts_with("app.") || full_name.starts_with("snow.")) {
spdlog::info("Skipping app component {}", tdef->get_full_name());
component = component->childComponent;
continue;
Expand Down

0 comments on commit d967aa7

Please sign in to comment.