Skip to content

Commit

Permalink
⬆️ OGRE14 migration
Browse files Browse the repository at this point in the history
Status: builds and runs, but crashes when loading terrain (RenderingAPIException)

Codechanges:
 * ImGuiAngelscript: commented out some dead items, added (ImGuiKey) casts where needed, see ocornut/imgui#4921
 * 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, skyx/VClouds: build fix - RENDER_QUEUE_9 was removed from OGRE, using 8.
 * RttManager: rendersystem-specific `getProjectionMatrixRS()` was removed from OGRE, using portable  `getProjectionMatrix()`
 * TerrainGeometryManager: updated (simplified!) to match OGRE14 API.
 * FlexBody: `reorganiseBuffers()`: updated for OGRE14 - there's no 'optimalUsage' param anymore.
 * RTTLayer, DashBoardManager: build fix for MyGUI API change.
  • Loading branch information
ohlidalp committed Sep 22, 2023
1 parent 434a2b5 commit f5c0183
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 102 deletions.
2 changes: 1 addition & 1 deletion cmake/DependenciesConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(CMAKE_THREAD_PREFER_PTHREAD YES)
find_package(Threads REQUIRED)

# --- Ogre 3D graphics engine ---
find_package(OGRE 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
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,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.2@anotherfoxguy/stable")
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/13.6.5@anotherfoxguy/stable", force=True)
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
Original file line number Diff line number Diff line change
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
3 changes: 1 addition & 2 deletions source/main/gfx/RTSSManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ void RTSSManager::SetupRTSS()
auto* schemRenderState = mShaderGenerator->getRenderState(Ogre::MSN_SHADERGEN);

App::GetGfxScene()->GetSceneManager()->setShadowCameraSetup(ShadowCameraSetupPtr(pssmSetup));
auto subRenderState = mShaderGenerator->createSubRenderState<RTShader::IntegratedPSSM3>();
subRenderState->setSplitPoints(pssmSetup->getSplitPoints());
auto subRenderState = mShaderGenerator->createSubRenderState(RTShader::SRS_INTEGRATED_PSSM3);
schemRenderState->addTemplateSubRenderState(subRenderState);
}

Expand Down
2 changes: 1 addition & 1 deletion source/main/gfx/hydrax/GodRaysManager.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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/gfx/skyx/VClouds/VClouds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace SkyX { namespace VClouds
, mCreated(false)
, mGeometrySettings(GeometrySettings())
, mDistanceFallingParams(Ogre::Vector2(1,-1))
, mRenderQueueGroups(RenderQueueGroups(Ogre::RENDER_QUEUE_MAIN, Ogre::RENDER_QUEUE_9, Ogre::RENDER_QUEUE_4))
, mRenderQueueGroups(RenderQueueGroups(Ogre::RENDER_QUEUE_MAIN, Ogre::RENDER_QUEUE_8, Ogre::RENDER_QUEUE_4))
, mWindDirection(Ogre::Degree(0))
, mWindSpeed(80.0f)
, mWheater(Ogre::Vector2(0.5f, 1.0f))
Expand Down
20 changes: 10 additions & 10 deletions source/main/gui/DashBoardManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ void DashBoard::windowResized()
void DashBoard::loadLayoutRecursive(MyGUI::WidgetPtr w)
{
std::string name = w->getName();
std::string anim = w->getUserString("anim");
std::string debug = w->getUserString("debug");
std::string linkArgs = w->getUserString("link");
std::string anim = std::string(w->getUserString("anim"));
std::string debug = std::string(w->getUserString("debug"));
std::string linkArgs = std::string(w->getUserString("link"));

// make it unclickable
w->setUserString("interactive", "0");
Expand Down Expand Up @@ -554,20 +554,20 @@ void DashBoard::loadLayoutRecursive(MyGUI::WidgetPtr w)
}

// parse more attributes
ctrl.wmin = StringConverter::parseReal(w->getUserString("min"));
ctrl.wmax = StringConverter::parseReal(w->getUserString("max"));
ctrl.vmin = StringConverter::parseReal(w->getUserString("vmin"));
ctrl.vmax = StringConverter::parseReal(w->getUserString("vmax"));
ctrl.wmin = StringConverter::parseReal(std::string(w->getUserString("min")));
ctrl.wmax = StringConverter::parseReal(std::string(w->getUserString("max")));
ctrl.vmin = StringConverter::parseReal(std::string(w->getUserString("vmin")));
ctrl.vmax = StringConverter::parseReal(std::string(w->getUserString("vmax")));

String texture = w->getUserString("texture");
String texture = Ogre::String(w->getUserString("texture"));
if (!texture.empty())
strncpy(ctrl.texture, texture.c_str(), 255);

String format = w->getUserString("format");
String format = Ogre::String(w->getUserString("format"));
if (!format.empty())
strncpy(ctrl.format, format.c_str(), 255);

String direction = w->getUserString("direction");
String direction = Ogre::String(w->getUserString("direction"));
if (direction == "right")
ctrl.direction = DIRECTION_RIGHT;
else if (direction == "left")
Expand Down
4 changes: 2 additions & 2 deletions source/main/gui/RTTLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ void RTTLayer::deserialization(xml::ElementPtr _node, Version _version)
MyGUI::xml::ElementEnumerator propert = _node->getElementEnumerator();
while (propert.next("Property"))
{
const std::string& key = propert->findAttribute("key");
const std::string& value = propert->findAttribute("value");
const std::string& key = std::string(propert->findAttribute("key"));
const std::string& value = std::string(propert->findAttribute("value"));
if (key == "TextureSize")
setTextureSize(utility::parseValue<IntSize>(value));
if (key == "TextureName")
Expand Down
2 changes: 1 addition & 1 deletion source/main/gui/imgui/OgreImGuiOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void ImGuiOverlay::ImGUIRenderable::initialise(void)
mRenderOp.indexData->indexStart = 0;
mRenderOp.operationType = RenderOperation::OT_TRIANGLE_LIST;
mRenderOp.useIndexes = true;
mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false;
//REMOVED from OGRE14 mRenderOp.useGlobalInstancingVertexBufferIsAvailable = false;

VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;

Expand Down
29 changes: 14 additions & 15 deletions source/main/gui/panels/GUI_RepositorySelector.cpp
Original file line number Diff line number Diff line change
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 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
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,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 @@ -104,10 +101,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
8 changes: 8 additions & 0 deletions source/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ int main(int argc, char *argv[])
App::GetGuiManager()->TopMenubar.Refresh(m.description);
break;

case MSG_NET_DOWNLOAD_REPOTHUMB_SUCCESS:
{
int* itemidx_ptr = static_cast<int*>(m.payload);
App::GetGuiManager()->RepositorySelector.LoadDownloadedThumbnail(*itemidx_ptr);
delete itemidx_ptr;
break;
}

// -- Gameplay events --

case MSG_SIM_PAUSE_REQUESTED:
Expand Down
3 changes: 2 additions & 1 deletion source/main/physics/ActorSpawner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include <OgreSceneManager.h>
#include <OgreMovableObject.h>
#include <OgreParticleSystem.h>
#include <OgreParticleSystemRenderer.h>
#include <OgreEntity.h>
#include <climits>
#include <fmt/format.h>
Expand Down Expand Up @@ -7112,7 +7113,7 @@ Ogre::ParticleSystem* ActorSpawner::CreateParticleSystem(std::string const & nam
params["templateName"] = template_name;

Ogre::MovableObject* obj = App::GetGfxScene()->GetSceneManager()->createMovableObject(
name, Ogre::ParticleSystemFactory::FACTORY_TYPE_NAME, &params);
name, Ogre::MOT_PARTICLE_SYSTEM, &params);
Ogre::ParticleSystem* psys = static_cast<Ogre::ParticleSystem*>(obj);
psys->setVisibilityFlags(DEPTHMAP_DISABLED); // disable particles in depthmap
return psys;
Expand Down
9 changes: 2 additions & 7 deletions source/main/physics/flex/FlexBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,6 @@ FlexBody::FlexBody(
if (m_has_texture) optimalVD->addElement(3, 0, VET_FLOAT2, VES_TEXTURE_COORDINATES);
optimalVD->sort();
optimalVD->closeGapsInSource();
BufferUsageList optimalBufferUsages;
for (size_t u = 0; u <= optimalVD->getMaxSource(); ++u)
{
optimalBufferUsages.push_back(HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE);
}

//adding color buffers, well get the reference later
if (m_has_texture_blend)
Expand Down Expand Up @@ -202,7 +197,7 @@ FlexBody::FlexBody(
//LOG("FLEXBODY reorganizing buffers");
if (mesh->sharedVertexData)
{
mesh->sharedVertexData->reorganiseBuffers(optimalVD, optimalBufferUsages);
mesh->sharedVertexData->reorganiseBuffers(optimalVD);
mesh->sharedVertexData->removeUnusedBuffers();
mesh->sharedVertexData->closeGapsInBindings();
}
Expand All @@ -212,7 +207,7 @@ FlexBody::FlexBody(
SubMesh* sm = smIt.getNext();
if (!sm->useSharedVertices)
{
sm->vertexData->reorganiseBuffers(optimalVD->clone(), optimalBufferUsages);
sm->vertexData->reorganiseBuffers(optimalVD->clone());
sm->vertexData->removeUnusedBuffers();
sm->vertexData->closeGapsInBindings();
}
Expand Down
4 changes: 2 additions & 2 deletions source/main/resources/otc_fileformat/OTCFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ struct OTCFile
bool norm_map_enabled;
bool spec_map_enabled;
bool parallax_enabled;
bool global_colormap_enabled;
bool recv_dyn_shadows_depth;
bool global_colormap_enabled; // UNUSED in OGRE14
bool recv_dyn_shadows_depth; // UNUSED in OGRE14
bool blendmap_dbg_enabled;
bool disable_cache;
bool is_flat;
Expand Down
Loading

0 comments on commit f5c0183

Please sign in to comment.