32 #include "PropertyMaps.h"
33 #include "PagedGeometry.h"
35 #include <OgreConfigFile.h>
40 Landusemap::Landusemap(String configFilename) :
42 , default_ground_model(nullptr)
43 , mapsize(App::
GetGameContext()->GetTerrain()->getMaxTerrainSize())
47 LOG(
"RoR was not compiled with PagedGeometry support. You cannot use Landuse maps with it.");
74 std::map<unsigned int, String> usemap;
75 String textureFilename =
"";
77 LOG(
"Parsing landuse config: '"+filename+
"'");
82 group = ResourceGroupManager::getSingleton().findGroupContainingResource(filename);
94 cfg.loadDirect(filename);
96 cfg.loadFromResourceSystem(filename, group,
"\x09:=",
true);
98 catch (Ogre::Exception& e)
101 fmt::format(
"{}: {}",
_L(
"Error while loading landuse config"), e.getDescription()));
105 Ogre::ConfigFile::SectionIterator seci = cfg.getSectionIterator();
106 Ogre::String secName, kname, kvalue;
107 while (seci.hasMoreElements())
109 secName = seci.peekNextKey();
110 Ogre::ConfigFile::SettingsMultiMap* settings = seci.getNext();
111 Ogre::ConfigFile::SettingsMultiMap::iterator i;
112 for (i = settings->begin(); i != settings->end(); ++i)
117 if (secName ==
"general" || secName ==
"config")
120 if (kname ==
"texture")
121 textureFilename = kvalue;
122 else if (kname ==
"frictionconfig" || kname ==
"loadGroundModelsConfig")
124 else if (kname ==
"defaultuse")
127 else if (secName ==
"use-map")
129 if (kname.size() != 10)
131 LOG(
"invalid color in landuse line in " + filename);
135 unsigned int color = strtoul(kname.c_str(), &ptr, 16);
136 usemap[color] = kvalue;
144 Forests::ColorMap* colourMap = Forests::ColorMap::load(textureFilename, Forests::CHANNEL_COLOR);
145 colourMap->setFilter(Forests::MAPFILTER_NONE);
156 bool bgr = colourMap->getPixelBox().format == PF_A8B8G8R8;
158 Ogre::TRect<Ogre::Real> bounds = Forests::TBounds(0, 0,
mapsize.x,
mapsize.z);
168 unsigned int col = colourMap->getColorAt(
x,
z, bounds);
172 unsigned int cols = col & 0xFF00FF00;
173 cols |= (col & 0xFF) << 16;
174 cols |= (col & 0xFF0000) >> 16;
177 String
use = usemap[col];
187 catch (Ogre::Exception& oex)
189 LogFormat(
"[RoR|Physics] Landuse: failed to load texture '%s', <Ogre::Exception> message: '%s'",
190 textureFilename.c_str(), oex.getFullDescription().c_str());
192 catch (std::exception& stex)
194 LogFormat(
"[RoR|Physics] Landuse: failed to load texture '%s', <std::exception> message: '%s'",
195 textureFilename.c_str(), stex.what());
199 LogFormat(
"[RoR|Physics] Landuse: failed to load texture '%s', unknown error", textureFilename.c_str());