Skip to content

Commit

Permalink
OGRE14 migration (WIP, build broken)
Browse files Browse the repository at this point in the history
Codechanges:
* GUIUtils, InputEngine: `getModifierKeyName()` replaced OIS keycodes with OgreBites/SDL keycodes
* ImGuiAngelscript: commented out some dead items, added (ImGuiKey) casts where needed, see ocornut/imgui#4921
* GUI_VehicleButtons: build fix for `ImGui::ImageButton()` - added parameter ID-string.
* GUI_RepositorySelector: updated thumbnail downloading to use new OGRE WorkQueue API, see https://github.com/OGRECave/ogre/blob/master/Docs/14-Notes.md#task-based-workqueue
* Application.h, main.cpp: added ✉️ `MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS`, used instead of OGRE WorkQueue's `addMainThreadTask` for consistency across the various background threads in the codebase.
* GodRaysManager: build fix - RENDER_QUEUE_9 was removed from OGRE, using 8.
* RttManager: rendersystem-specific `getProjectionMatrixRS()` was removed from OGRE, using portable  `getProjectionMatrix()`
  • Loading branch information
ohlidalp committed Sep 22, 2023
1 parent 4751803 commit 6e8f8cc
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cmake/DependenciesConfig.cmake
Expand Up @@ -3,7 +3,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD YES)
find_package(Threads REQUIRED)

# --- Ogre 3D graphics engine ---
find_package(OGRE 1.13 REQUIRED COMPONENTS Bites Overlay Paging RTShaderSystem MeshLodGenerator Terrain)
find_package(OGRE 14 REQUIRED COMPONENTS Bites Overlay Paging RTShaderSystem MeshLodGenerator Terrain)

# --- Object Oriented Input System ---
find_package(OIS REQUIRED)
Expand Down
8 changes: 4 additions & 4 deletions conanfile.py
Expand Up @@ -13,10 +13,10 @@ def requirements(self):
self.requires("discord-rpc/3.4.0@anotherfoxguy/stable")
self.requires("fmt/8.0.1")
self.requires("libcurl/7.79.1")
self.requires("mygui/3.4.0@anotherfoxguy/stable")
self.requires("ogre3d-caelum/0.6.3.1@anotherfoxguy/stable")
self.requires("ogre3d-pagedgeometry/1.2.0@anotherfoxguy/stable")
self.requires("ogre3d/1.11.6.1@anotherfoxguy/stable", force=True)
self.requires("mygui/3.4.3@anotherfoxguy/stable")
self.requires("ogre3d-caelum/2022.08@anotherfoxguy/stable")
self.requires("ogre3d-pagedgeometry/2023.07@anotherfoxguy/stable")
self.requires("ogre3d/14.1.0@anotherfoxguy/stable", force=True)
self.requires("ois/1.4.1@rigsofrods/custom")
self.requires("openal-soft/1.22.2")
self.requires("openssl/1.1.1s", force=True)
Expand Down
1 change: 1 addition & 0 deletions source/main/Application.h
Expand Up @@ -89,6 +89,7 @@ enum MsgType
MSG_NET_OPEN_RESOURCE_SUCCESS, //!< Payload = GUI::ResourcesCollection* (owner)
MSG_NET_REFRESH_REPOLIST_FAILURE, //!< Payload = RoR::CurlFailInfo* (owner)
MSG_NET_REFRESH_AI_PRESETS,
MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS, //!< Payload = int* (owner)
// Simulation
MSG_SIM_PAUSE_REQUESTED,
MSG_SIM_UNPAUSE_REQUESTED,
Expand Down
2 changes: 1 addition & 1 deletion source/main/gfx/hydrax/GodRaysManager.cpp
Expand Up @@ -132,7 +132,7 @@ namespace Hydrax
mManualGodRays->setVisible(mHydrax->_isCurrentFrameUnderwater());

mManualGodRays->begin(_def_GodRays_Material_Name, Ogre::RenderOperation::OT_TRIANGLE_LIST);
mManualGodRays->setRenderQueueGroup(Ogre::RENDER_QUEUE_9+1);
mManualGodRays->setRenderQueueGroup(Ogre::RENDER_QUEUE_8+1);

for(int r = 0; r < mNumberOfRays; r++)
{
Expand Down
4 changes: 2 additions & 2 deletions source/main/gfx/hydrax/RttManager.cpp
Expand Up @@ -504,7 +504,7 @@ namespace Hydrax
&& mActive)
{
mRttManager->mHydrax->getCamera()->disableCustomNearClipPlane();
Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrix());
}
}

Expand All @@ -518,7 +518,7 @@ namespace Hydrax
&& mActive)
{
mRttManager->mHydrax->getCamera()->enableCustomNearClipPlane(mRttManager->mPlanes[RTT_REFLECTION]);
Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrixRS());
Ogre::Root::getSingleton().getRenderSystem()->_setProjectionMatrix(mRttManager->mHydrax->getCamera()->getProjectionMatrix());
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/main/gui/GUIUtils.cpp
Expand Up @@ -468,7 +468,7 @@ void RoR::ImDrawEventHighlighted(events input_event)

}

void RoR::ImDrawModifierKeyHighlighted(OIS::KeyCode key)
void RoR::ImDrawModifierKeyHighlighted(OgreBites::Keycode key)
{
ImVec4 col = ImGui::GetStyle().Colors[ImGuiCol_Text];
if (App::GetInputEngine()->isKeyDown(key))
Expand Down
2 changes: 1 addition & 1 deletion source/main/gui/GUIUtils.h
Expand Up @@ -100,6 +100,6 @@ void ImSetNextWindowPosCenter(ImGuiCond c = 0);

// Input engine helpers
void ImDrawEventHighlighted(events input_event);
void ImDrawModifierKeyHighlighted(OIS::KeyCode key);
void ImDrawModifierKeyHighlighted(OgreBites::Keycode key);

} // namespace RoR
33 changes: 16 additions & 17 deletions source/main/gui/panels/GUI_RepositorySelector.cpp
Expand Up @@ -373,11 +373,6 @@ void DownloadResourceFile(int resource_id, std::string filename, int id)

RepositorySelector::RepositorySelector()
{
Ogre::WorkQueue* wq = Ogre::Root::getSingleton().getWorkQueue();
m_ogre_workqueue_channel = wq->getChannel("RoR/RepoThumbnails");
wq->addRequestHandler(m_ogre_workqueue_channel, this);
wq->addResponseHandler(m_ogre_workqueue_channel, this);

m_fallback_thumbnail = FetchIcon("ror.png");
}

Expand All @@ -399,11 +394,11 @@ void RepositorySelector::Draw()

ImGui::Begin(_LC("RepositorySelector", "Rigs of Rods Repository"), &keep_open, window_flags);

if (m_resource_view && ImGui::ImageButton(reinterpret_cast<ImTextureID>(tex4->getHandle()), ImVec2(16, 16)))
if (m_resource_view && ImGui::ImageButton("GoBack", reinterpret_cast<ImTextureID>(tex4->getHandle()), ImVec2(16, 16)))
{
m_resource_view = false;
}
else if (!m_resource_view && ImGui::ImageButton(reinterpret_cast<ImTextureID>(tex1->getHandle()), ImVec2(16, 16)))
else if (!m_resource_view && ImGui::ImageButton("Refresh", reinterpret_cast<ImTextureID>(tex1->getHandle()), ImVec2(16, 16)))
{
this->Refresh();
}
Expand Down Expand Up @@ -1255,7 +1250,8 @@ void RepositorySelector::SetVisible(bool visible)

// --------------------------------------------
// Async thumbnail download via Ogre::WorkQueue
// see https://wiki.ogre3d.org/How+to+use+the+WorkQueue
// NOTE: The API changed in OGRE 14.0
// see https://github.com/OGRECave/ogre/blob/master/Docs/14-Notes.md#task-based-workqueue

void RepositorySelector::DrawThumbnail(int resource_item_idx)
{
Expand Down Expand Up @@ -1289,7 +1285,11 @@ void RepositorySelector::DrawThumbnail(int resource_item_idx)
&& !m_data.items[resource_item_idx].thumbnail_dl_queued)
{
// Image is in visible screen area and not yet downloading.
Ogre::Root::getSingleton().getWorkQueue()->addRequest(m_ogre_workqueue_channel, 1234, Ogre::Any(resource_item_idx));
Ogre::Root::getSingleton().getWorkQueue()->addTask(
[this, resource_item_idx]()
{
this->DownloadThumbnail(resource_item_idx);
});
m_data.items[resource_item_idx].thumbnail_dl_queued = true;
}
}
Expand Down Expand Up @@ -1323,20 +1323,19 @@ void RepositorySelector::DrawThumbnail(int resource_item_idx)
}
}

Ogre::WorkQueue::Response* RepositorySelector::handleRequest(const Ogre::WorkQueue::Request *req, const Ogre::WorkQueue *srcQ)
bool RepositorySelector::DownloadThumbnail(int item_idx)
{
// This runs on background worker thread in Ogre::WorkQueue's thread pool.
// Purpose: to fetch one thumbnail image using CURL.
// -----------------------------------------------------------------------

int item_idx = Ogre::any_cast<int>(req->getData());
std::string filename = std::to_string(m_data.items[item_idx].resource_id) + ".png";
std::string file = PathCombine(App::sys_thumbnails_dir->getStr(), filename);
long response_code = 0;

if (FileExists(file))
{
return OGRE_NEW Ogre::WorkQueue::Response(req, /*success:*/false, Ogre::Any(item_idx));
return /*success:*/false;
}
else
{
Expand All @@ -1360,11 +1359,12 @@ Ogre::WorkQueue::Response* RepositorySelector::handleRequest(const Ogre::WorkQue
<< "[RoR|Repository] Failed to download thumbnail;"
<< " Error: '" << curl_easy_strerror(curl_result) << "'; HTTP status code: " << response_code;

return OGRE_NEW Ogre::WorkQueue::Response(req, /*success:*/false, Ogre::Any(item_idx));
return /*success:*/false;
}
else
{
return OGRE_NEW Ogre::WorkQueue::Response(req, /*success:*/true, Ogre::Any(item_idx));
App::GetGameContext()->PushMessage(Message(MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS, new int(item_idx)));
return /*success:*/true;
}
}
catch (Ogre::Exception& oex)
Expand All @@ -1374,18 +1374,17 @@ Ogre::WorkQueue::Response* RepositorySelector::handleRequest(const Ogre::WorkQue
fmt::format("Repository UI: cannot download thumbnail '{}' - {}",
m_data.items[item_idx].icon_url, oex.getFullDescription()));

return OGRE_NEW Ogre::WorkQueue::Response(req, /*success:*/false, Ogre::Any(item_idx));
return /*success:*/false;
}
}
}

void RepositorySelector::handleResponse(const Ogre::WorkQueue::Response *req, const Ogre::WorkQueue *srcQ)
void RepositorySelector::LoadDownloadedThumbnail(int item_idx)
{
// This runs on main thread.
// It's safe to load the texture and modify GUI data.
// --------------------------------------------------

int item_idx = Ogre::any_cast<int>(req->getData());
std::string filename = std::to_string(m_data.items[item_idx].resource_id) + ".png";
std::string file = PathCombine(App::sys_thumbnails_dir->getStr(), filename);

Expand Down
11 changes: 3 additions & 8 deletions source/main/gui/panels/GUI_RepositorySelector.h
Expand Up @@ -82,12 +82,9 @@ struct ResourcesCollection
std::vector<ResourceFiles> files;
};

class RepositorySelector:
public Ogre::WorkQueue::RequestHandler, // Processes tasks on background thread
public Ogre::WorkQueue::ResponseHandler // Processes task results on rendering thread
class RepositorySelector
{
public:
const Ogre::uint16 WORKQUEUE_ROR_REPO_THUMBNAIL = 1; // Work queue request type, named by OGRE convention.

RepositorySelector();
~RepositorySelector();
Expand All @@ -103,10 +100,8 @@ class RepositorySelector:
void UpdateFiles(ResourcesCollection* data);
void ShowError(CurlFailInfo* failinfo);
void DrawThumbnail(int resource_item_idx);

/// Ogre::WorkQueue API
virtual Ogre::WorkQueue::Response* handleRequest(const Ogre::WorkQueue::Request *req, const Ogre::WorkQueue *srcQ) override; //!< Processes tasks on background thread
virtual void handleResponse(const Ogre::WorkQueue::Response *req, const Ogre::WorkQueue *srcQ) override; //!< Processes task results on main thread
bool DownloadThumbnail(int item_idx); //!< To be run on background via Ogre WorkQueue
void LoadDownloadedThumbnail(int item_idx); //!< To be run on main thread

private:
bool m_is_visible = false;
Expand Down

0 comments on commit 6e8f8cc

Please sign in to comment.