Skip to content

Commit

Permalink
Plugins: Revert back to initializing plugins on separate threads
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Jun 15, 2024
1 parent fce175e commit 50cd000
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
25 changes: 17 additions & 8 deletions src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,16 +643,11 @@ void PluginLoader::early_init() try {
}

void PluginLoader::on_frame() {
if (m_plugins_loaded) {
return;
}

m_plugins_loaded = true;

std::scoped_lock _{m_mux};
init_d3d_pointers();
}

void PluginLoader::init_d3d_pointers() {
// Call reframework_plugin_required_version on any dlls that export it.
g_plugin_initialize_param.reframework_module = g_framework->get_reframework_module();
reframework::g_renderer_data.renderer_type = (int)g_framework->get_renderer_type();

if (reframework::g_renderer_data.renderer_type == REFRAMEWORK_RENDERER_D3D11) {
Expand All @@ -667,9 +662,15 @@ void PluginLoader::on_frame() {
reframework::g_renderer_data.swapchain = d3d12->get_swap_chain();
reframework::g_renderer_data.command_queue = d3d12->get_command_queue();
}
}

std::optional<std::string> PluginLoader::on_initialize() {
std::scoped_lock _{m_mux};

verify_sdk_pointers();

g_plugin_initialize_param.reframework_module = g_framework->get_reframework_module();

for (auto it = m_plugins.begin(); it != m_plugins.end();) {
auto name = it->first;
auto mod = it->second;
Expand Down Expand Up @@ -759,6 +760,10 @@ void PluginLoader::on_frame() {

++it;
}

m_plugins_loaded = true;

return Mod::on_initialize();
}

void PluginLoader::on_draw_ui() {
Expand Down Expand Up @@ -892,6 +897,8 @@ bool reframework_on_imgui_frame(REFOnImGuiFrameCb cb) {
if (cb == nullptr) {
return false;
}

PluginLoader::get()->init_d3d_pointers();

return APIProxy::get()->add_on_imgui_frame(cb);
}
Expand All @@ -902,5 +909,7 @@ bool reframework_on_imgui_draw_ui(REFOnImGuiFrameCb cb) {
return false;
}

PluginLoader::get()->init_d3d_pointers();

return APIProxy::get()->add_on_imgui_draw_ui(cb);
}
5 changes: 4 additions & 1 deletion src/mods/PluginLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class PluginLoader : public Mod {
void early_init();

std::string_view get_name() const override { return "PluginLoader"; }
std::optional<std::string> on_initialize() override;
void on_frame() override;
void on_draw_ui() override;


void init_d3d_pointers();

private:
bool m_plugins_loaded{false};

Expand Down

0 comments on commit 50cd000

Please sign in to comment.