From 3edff9523e9f9161ce643b42285cced84f712590 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 25 Jan 2017 21:51:26 +1100 Subject: [PATCH 01/10] Fixed compiler warning. --- src/states_screens/race_gui_overworld.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index 5ffb1f81f..73b3e1261 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -119,7 +119,7 @@ RaceGUIOverworld::RaceGUIOverworld() { m_map_left = (int)((irr_driver->getActualScreenSize().Width - m_map_width) * 0.9f); - m_map_bottom = m_map_height + 10 * scaling; + m_map_bottom = m_map_height + int(10 * scaling); } m_speed_meter_icon = material_manager->getMaterial("speedback.png"); From 37af3a3690943579968fae7eb17fcab7f7f1981c Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 25 Jan 2017 21:55:16 +1100 Subject: [PATCH 02/10] Fixed coding style issues (same should be done with speedweight objects). --- src/karts/kart_model.cpp | 46 +++++++++++++++++-------------- src/karts/kart_model.hpp | 59 ++++++++++++++++++++++++++++++---------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index 92906ddef..e4627be24 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -273,17 +273,17 @@ KartModel::~KartModel() for (size_t i = 0; i < m_headlight_objects.size(); i++) { HeadlightObject& obj = m_headlight_objects[i]; - obj.m_node = NULL; - if (obj.m_node) + obj.setNode(NULL); + if (obj.getNode()) { - // Master KartModels should never have a speed weighted object attached. + // Master KartModels should never have a headlight attached. assert(!m_is_master); - obj.m_node->drop(); + obj.getNode()->drop(); } - if (m_is_master && obj.m_model) + if (m_is_master && obj.getModel()) { - irr_driver->dropAllTextures(obj.m_model); - irr_driver->removeMeshFromCache(obj.m_model); + irr_driver->dropAllTextures(obj.getModel()); + irr_driver->removeMeshFromCache(obj.getModel()); } } @@ -368,8 +368,8 @@ KartModel* KartModel::makeCopy(KartRenderType krt) km->m_headlight_objects.resize(m_headlight_objects.size()); for (size_t i = 0; im_headlight_objects[i] = m_headlight_objects[i]; } @@ -448,8 +448,8 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim for (size_t i = 0; isetParent(lod_node); + if (!m_headlight_objects[i].getNode()) continue; + m_headlight_objects[i].getNode()->setParent(lod_node); } #ifndef SERVER_ONLY @@ -534,16 +534,19 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim { HeadlightObject& obj = m_headlight_objects[i]; - obj.m_node = NULL; - if (obj.m_model) + obj.setNode(NULL); + if (obj.getModel()) { - obj.m_node = irr_driver->addMesh(obj.m_model, "kart_headlight", node, getRenderInfo()); - obj.m_node->grab(); - obj.m_node->setPosition(obj.getPosition()); + scene::ISceneNode *new_node = + irr_driver->addMesh(obj.getModel(), "kart_headlight", + node, getRenderInfo() ); + new_node->grab(); + obj.setNode(new_node); + Track* track = Track::getCurrentTrack(); if (track == NULL || track->getIsDuringDay()) - obj.m_node->setVisible(false); + obj.getNode()->setVisible(false); } } @@ -646,8 +649,8 @@ bool KartModel::loadModels(const KartProperties &kart_properties) { HeadlightObject& obj = m_headlight_objects[i]; std::string full_name = kart_properties.getKartDir() + obj.getFilename(); - obj.m_model = irr_driver->getMesh(full_name); - irr_driver->grabAllTextures(obj.m_model); + obj.setModel(irr_driver->getMesh(full_name)); + irr_driver->grabAllTextures(obj.getModel()); } Vec3 size = kart_max-kart_min; @@ -722,7 +725,8 @@ void KartModel::loadNitroEmitterInfo(const XMLNode &node, // ---------------------------------------------------------------------------- /** Loads a single speed weighted node. */ -void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, const SpeedWeightedObject::Properties& fallback_properties) +void KartModel::loadSpeedWeightedInfo(const XMLNode* speed_weighted_node, + const SpeedWeightedObject::Properties& fallback_properties) { SpeedWeightedObject obj; obj.m_properties = fallback_properties; @@ -778,7 +782,7 @@ void KartModel::loadHeadlights(const XMLNode &node) Log::warn("KartModel", "Unknown XML node in the headlights section"); } } -} +} // loadHeadlights // ---------------------------------------------------------------------------- /** Resets the kart model. It stops animation from being played and resets diff --git a/src/karts/kart_model.hpp b/src/karts/kart_model.hpp index c748eb001..99c180279 100644 --- a/src/karts/kart_model.hpp +++ b/src/karts/kart_model.hpp @@ -84,33 +84,64 @@ struct SpeedWeightedObject }; typedef std::vector SpeedWeightedObjectList; +// ============================================================================ +/** A class to store the headlights of a kart. + */ class HeadlightObject { +private: + /** The filename of the headlight model. */ std::string m_filename; + /** The position relative to the parent kart scene node where the + * headlight mesh is attached to. */ core::vector3df m_position; + /** The mesh for the headlight. */ + scene::IMesh* m_model; + /** The scene node of the headlight. */ + scene::ISceneNode* m_node; public: - scene::IMesh* m_model; - scene::ISceneNode* m_node; - HeadlightObject() { - m_model = NULL; - m_node = NULL; - } - - HeadlightObject(const std::string& filename, core::vector3df pos) + m_model = NULL; + m_node = NULL; + m_filename = ""; + m_position.set(0, 0, 0); + } // HeadlightObject + // ------------------------------------------------------------------------ + HeadlightObject(const std::string& filename, core::vector3df &pos) { m_filename = filename; m_position = pos; - m_model = NULL; - m_node = NULL; - } - + m_model = NULL; + m_node = NULL; + } // HeadlightObjects + // ------------------------------------------------------------------------ const std::string& getFilename() const { return m_filename; } - const core::vector3df getPosition() const { return m_position; } -}; + // ------------------------------------------------------------------------ + /** Sets the mesh for this headlight object. */ + void setModel(scene::IMesh *mesh) { m_model = mesh; } + // ------------------------------------------------------------------------ + /** Sets the node of the headlight, and (if not NULL) also sets the + * position of this scene node to be the position of the headlight. */ + void setNode(scene::ISceneNode *node) + { + m_node = node; + if (m_node) m_node->setPosition(m_position); + } // setNode + // ------------------------------------------------------------------------ + const scene::ISceneNode *getNode() const { return m_node; } + // ------------------------------------------------------------------------ + scene::ISceneNode *getNode() { return m_node; } + // ------------------------------------------------------------------------ + const scene::IMesh *getModel() const { return m_model; } + // ------------------------------------------------------------------------ + scene::IMesh *getModel() { return m_model; } + // ------------------------------------------------------------------------ +}; // class HeadlightObject + +// ============================================================================ /** * \brief This class stores a 3D kart model. From 2ca7a1468e5875091e3309d68edb218a5e92eab4 Mon Sep 17 00:00:00 2001 From: hiker Date: Wed, 25 Jan 2017 18:19:37 +1100 Subject: [PATCH 03/10] Fixed compiler warning. --- src/karts/kart_model.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/karts/kart_model.cpp b/src/karts/kart_model.cpp index e4627be24..ebd1fb17c 100644 --- a/src/karts/kart_model.cpp +++ b/src/karts/kart_model.cpp @@ -530,7 +530,7 @@ scene::ISceneNode* KartModel::attachModel(bool animated_models, bool always_anim } } - for (int i = 0; i < m_headlight_objects.size(); i++) + for (unsigned int i = 0; i < m_headlight_objects.size(); i++) { HeadlightObject& obj = m_headlight_objects[i]; @@ -645,7 +645,7 @@ bool KartModel::loadModels(const KartProperties &kart_properties) kart_max.max(obj_max); } - for (int i = 0; i < m_headlight_objects.size(); i++) + for (unsigned int i = 0; i < m_headlight_objects.size(); i++) { HeadlightObject& obj = m_headlight_objects[i]; std::string full_name = kart_properties.getKartDir() + obj.getFilename(); From 11255cb2b8db9232d79c712caf8d494244c34f81 Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 8 Mar 2017 21:12:24 +0100 Subject: [PATCH 04/10] Fixed wrong lights color for legacy pipeline. SColor is ARGB, but SColorf is RGBA... WTF? --- src/graphics/irr_driver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 9833bf744..41df7d0ce 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -2057,7 +2057,7 @@ scene::ISceneNode *IrrDriver::addLight(const core::vector3df &pos, { scene::ILightSceneNode* light = m_scene_manager ->addLightSceneNode(m_scene_manager->getRootSceneNode(), - pos, video::SColorf(1.0f, r, g, b)); + pos, video::SColorf(r, g, b, 1.0f)); light->setRadius(radius); return light; } From d339d9acefb4086a1e3c9e3cc6081b1dd2c07e9e Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 8 Mar 2017 21:41:53 +0100 Subject: [PATCH 05/10] Fixed ambient light for legacy pipeline. TODO: It should be possible to convert it once together with spherical harmonics computations. --- src/graphics/irr_driver.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 41df7d0ce..3c0e78783 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1653,7 +1653,12 @@ void IrrDriver::onUnloadWorld() void IrrDriver::setAmbientLight(const video::SColorf &light, bool force_SH_computation) { #ifndef SERVER_ONLY - m_scene_manager->setAmbientLight(light); + video::SColorf color = light; + color.r = powf(color.r, 1.0f / 2.2f); + color.g = powf(color.g, 1.0f / 2.2f); + color.b = powf(color.b, 1.0f / 2.2f); + + m_scene_manager->setAmbientLight(color); m_renderer->setAmbientLight(light, force_SH_computation); #endif } // setAmbientLight From 21cb8530790018b73e1d1907a7ecc1cf58ace07d Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 8 Mar 2017 22:09:47 +0100 Subject: [PATCH 06/10] One more tweak for hiding story mode icon if it's not available. Now it should work properly, sorry for the mess. --- src/states_screens/main_menu_screen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/states_screens/main_menu_screen.cpp b/src/states_screens/main_menu_screen.cpp index 67d47abe6..285ed1458 100644 --- a/src/states_screens/main_menu_screen.cpp +++ b/src/states_screens/main_menu_screen.cpp @@ -87,14 +87,14 @@ void MainMenuScreen::loadedFromFile() LabelWidget* w = getWidget("info_addons"); w->setScrollSpeed(15); - IconButtonWidget* iw = getWidget("story"); - assert(iw != NULL); + RibbonWidget* rw_top = getWidget("menu_toprow"); + assert(rw_top != NULL); if (track_manager->getTrack("overworld") == NULL || track_manager->getTrack("introcutscene") == NULL || track_manager->getTrack("introcutscene2") == NULL) { - iw->setVisible(false); + rw_top->removeChildNamed("story"); } #if DEBUG_MENU_ITEM != 1 From adfa8f30f900936ea66dd299a301c4267c28686f Mon Sep 17 00:00:00 2001 From: Deve Date: Wed, 8 Mar 2017 23:17:03 +0100 Subject: [PATCH 07/10] Better fix for missing transparency in GLES legacy pipeline --- data/shaders/irrlicht/COGLES2FixedPipeline.fsh | 2 +- .../Irrlicht/COGLES2FixedPipelineRenderer.cpp | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/data/shaders/irrlicht/COGLES2FixedPipeline.fsh b/data/shaders/irrlicht/COGLES2FixedPipeline.fsh index c4eb96e13..f6efdf4e2 100644 --- a/data/shaders/irrlicht/COGLES2FixedPipeline.fsh +++ b/data/shaders/irrlicht/COGLES2FixedPipeline.fsh @@ -37,7 +37,7 @@ vec4 renderSolid() if(uTextureUsage0) Color *= texture2D(uTextureUnit0, varTexCoord0); - Color.a = 1.0; + //Color.a = 1.0; return Color; } diff --git a/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp b/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp index 656cceb54..d1393f437 100644 --- a/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp +++ b/lib/irrlicht/source/Irrlicht/COGLES2FixedPipelineRenderer.cpp @@ -67,15 +67,12 @@ void COGLES2FixedPipelineRenderer::OnSetMaterial(const video::SMaterial& materia } else if (Blending) { - //E_BLEND_FACTOR srcFact,dstFact; - //E_MODULATE_FUNC modulate; - //u32 alphaSource; - //unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam); + E_BLEND_FACTOR srcFact,dstFact; + E_MODULATE_FUNC modulate; + u32 alphaSource; + unpack_textureBlendFunc(srcFact, dstFact, modulate, alphaSource, material.MaterialTypeParam); - //Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact)); - //Driver->getBridgeCalls()->setBlend(true); - - Driver->getBridgeCalls()->setBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR); + Driver->getBridgeCalls()->setBlendFunc(Driver->getGLBlend(srcFact), Driver->getGLBlend(dstFact)); Driver->getBridgeCalls()->setBlend(true); } else From 571832fbbc9f762c7e8ad7ca028545c436dbc8f5 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Wed, 8 Mar 2017 20:30:45 -0500 Subject: [PATCH 08/10] Make all material names and path lowercase upon loading them, moving several string allocations and modifications outside of hot loops --- src/graphics/material.cpp | 24 ++++++++++++++++++++++++ src/graphics/material_manager.cpp | 14 ++++---------- src/graphics/particle_emitter.cpp | 8 ++++++-- src/graphics/particle_kind.cpp | 6 +++++- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index a6b5c66db..dddb076f8 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -73,6 +73,18 @@ Material::Material(const XMLNode *node, bool deprecated) Log::warn("Material", "Cannot determine texture full path : <%s>", m_texname.c_str()); else m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str(); + + core::stringc texfname(m_texname.c_str()); + texfname.make_lower(); + m_texname = texfname.c_str(); + + if (m_full_path.size() > 0) + { + core::stringc texfname2(m_full_path.c_str()); + texfname2.make_lower(); + m_full_path = texfname2.c_str(); + } + init(); bool b = false; @@ -432,6 +444,14 @@ Material::Material(const std::string& fname, bool is_full_path, file_manager->searchTexture(m_texname).c_str()).c_str(); } + core::stringc texfname(m_texname.c_str()); + texfname.make_lower(); + m_texname = texfname.c_str(); + + core::stringc texfname2(m_full_path.c_str()); + texfname2.make_lower(); + m_full_path = texfname2.c_str(); + m_complain_if_not_found = complain_if_not_found; if (load_texture) @@ -516,6 +536,10 @@ void Material::install(bool srgb, bool premul_alpha) // now set the name to the basename, so that all tests work as expected m_texname = StringUtils::getBasename(m_texname); + core::stringc texfname(m_texname.c_str()); + texfname.make_lower(); + m_texname = texfname.c_str(); + m_texture->grab(); } // install diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index 2e7e3d907..a3c88bd20 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -81,16 +81,14 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t, Material* MaterialManager::getMaterialFor(video::ITexture* t) { core::stringc img_path = core::stringc(t->getName()); - img_path.make_lower(); + img_path.make_lower(); if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1)) { // Search backward so that temporary (track) textures are found first for (int i = (int)m_materials.size() - 1; i >= 0; i--) { - core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str()); - fullpath.make_lower(); - if (fullpath == img_path.c_str()) + if (m_materials[i]->getTexFullPath() == img_path.c_str()) { return m_materials[i]; } @@ -103,9 +101,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t) for (int i = (int)m_materials.size() - 1; i >= 0; i--) { - core::stringc texfname(m_materials[i]->getTexFname().c_str()); - texfname.make_lower(); - if (texfname == image) + if (m_materials[i]->getTexFname() == image.c_str()) { return m_materials[i]; } @@ -361,9 +357,7 @@ Material *MaterialManager::getMaterial(const std::string& fname, // Search backward so that temporary (track) textures are found first for (int i = (int)m_materials.size()-1; i>=0; i-- ) { - core::stringc fname(m_materials[i]->getTexFname().c_str()); - fname.make_lower(); - if (fname == basename_lower) + if (m_materials[i]->getTexFname() == basename_lower.c_str()) return m_materials[i]; } diff --git a/src/graphics/particle_emitter.cpp b/src/graphics/particle_emitter.cpp index b6dbb059b..4a88fea3e 100644 --- a/src/graphics/particle_emitter.cpp +++ b/src/graphics/particle_emitter.cpp @@ -470,8 +470,12 @@ void ParticleEmitter::setParticleType(const ParticleKind* type) if (m_is_glsl) { - bool additive = (type->getMaterial()->getShaderType() == Material::SHADERTYPE_ADDITIVE); - static_cast(m_node)->setAlphaAdditive(additive); + Material* material = type->getMaterial(); + if (material != nullptr) + { + bool additive = (material->getShaderType() == Material::SHADERTYPE_ADDITIVE); + static_cast(m_node)->setAlphaAdditive(additive); + } } } diff --git a/src/graphics/particle_kind.cpp b/src/graphics/particle_kind.cpp index 662d63dfb..d97e8e647 100644 --- a/src/graphics/particle_kind.cpp +++ b/src/graphics/particle_kind.cpp @@ -130,6 +130,10 @@ ParticleKind::ParticleKind(const std::string &file) { material->get("file", &m_material_file); + core::stringc tmp(m_material_file.c_str()); + tmp.make_lower(); + m_material_file = tmp.c_str(); + if (m_material_file.size() == 0) { delete xml; @@ -257,7 +261,7 @@ Material* ParticleKind::getMaterial() const if (material_manager->hasMaterial(m_material_file)) { Material* material = material_manager->getMaterial(m_material_file); - if (material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL) + if (material == NULL || material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL) { throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file); } From 2d6cf4c48780ffeab6d24005d5f9df1f43d83128 Mon Sep 17 00:00:00 2001 From: "auria.mg" Date: Wed, 8 Mar 2017 20:42:16 -0500 Subject: [PATCH 09/10] Remove a few more string allocations/manipulations --- src/graphics/material_manager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/graphics/material_manager.cpp b/src/graphics/material_manager.cpp index a3c88bd20..1a6721fd5 100644 --- a/src/graphics/material_manager.cpp +++ b/src/graphics/material_manager.cpp @@ -80,8 +80,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t, //----------------------------------------------------------------------------- Material* MaterialManager::getMaterialFor(video::ITexture* t) { - core::stringc img_path = core::stringc(t->getName()); - img_path.make_lower(); + const io::path& img_path = t->getName().getInternalName(); if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1)) { From 62d64847c4ebb1cff5a84748d4205ee088484b16 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Thu, 9 Mar 2017 18:41:35 -0500 Subject: [PATCH 10/10] Fix texture paths on case-sensitive file systems, fixes #2807 --- src/graphics/material.cpp | 8 ++++---- src/graphics/material.hpp | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/graphics/material.cpp b/src/graphics/material.cpp index dddb076f8..ce40bad83 100644 --- a/src/graphics/material.cpp +++ b/src/graphics/material.cpp @@ -72,7 +72,7 @@ Material::Material(const XMLNode *node, bool deprecated) if (relativePath.size() == 0) Log::warn("Material", "Cannot determine texture full path : <%s>", m_texname.c_str()); else - m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str(); + m_full_path = m_original_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str(); core::stringc texfname(m_texname.c_str()); texfname.make_lower(); @@ -435,12 +435,12 @@ Material::Material(const std::string& fname, bool is_full_path, if (is_full_path) { m_texname = StringUtils::getBasename(fname); - m_full_path = fname; + m_full_path = m_original_full_path = fname; } else { m_texname = fname; - m_full_path = file_manager->getFileSystem()->getAbsolutePath( + m_full_path = m_original_full_path = file_manager->getFileSystem()->getAbsolutePath( file_manager->searchTexture(m_texname).c_str()).c_str(); } @@ -527,7 +527,7 @@ void Material::install(bool srgb, bool premul_alpha) else { m_texture = STKTexManager::getInstance()->getTexture - (m_full_path, srgb, premul_alpha, false/*set_material*/, + (m_original_full_path, srgb, premul_alpha, false/*set_material*/, srgb/*mesh_tex*/); } diff --git a/src/graphics/material.hpp b/src/graphics/material.hpp index c8df14cff..c8f52aa5b 100644 --- a/src/graphics/material.hpp +++ b/src/graphics/material.hpp @@ -91,6 +91,8 @@ private: std::string m_texname; std::string m_full_path; + + std::string m_original_full_path; /** Name of a special sfx to play when a kart is on this terrain, or * "" if no special sfx exists. */