Skip to content

Commit

Permalink
Merge branch 'sorted_saveMaterials'
Browse files Browse the repository at this point in the history
  • Loading branch information
darksylinc committed Oct 5, 2023
2 parents 07303b4 + 8fd92e4 commit 2b0f66d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion OgreMain/include/OgreHlmsJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace Ogre
Leave it blank if you don't know what to put
*/
void saveMaterials( const Hlms *hlms, String &outString,
const String &additionalTextureExtension );
const String &additionalTextureExtension, bool sortByName = false );

/** Saves a single datablock to a string
@param datablock
Expand Down
43 changes: 37 additions & 6 deletions OgreMain/src/OgreHlmsJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ THE SOFTWARE.
# include "OgreHlms.h"
# include "OgreHlmsJsonCompute.h"
# include "OgreHlmsManager.h"
# include "OgreIdString.h"
# include "OgreLogManager.h"
# include "OgreLwString.h"
# include "OgreRenderSystem.h"
Expand Down Expand Up @@ -1012,7 +1013,7 @@ namespace Ogre
}
//-----------------------------------------------------------------------------------
void HlmsJson::saveMaterials( const Hlms *hlms, String &outString,
const String &additionalTextureExtension )
const String &additionalTextureExtension, bool sortByName )
{
outString += "{";

Expand Down Expand Up @@ -1114,13 +1115,43 @@ namespace Ogre
Hlms::HlmsDatablockMap::const_iterator itor = datablockMap.begin();
Hlms::HlmsDatablockMap::const_iterator endt = datablockMap.end();

while( itor != endt )
if( sortByName )
{
const HlmsDatablock *datablock = itor->second.datablock;
std::map<std::string, IdString> sortedMap;
while( itor != endt )
{
sortedMap[itor->second.name] = itor->first;
++itor;
}

if( datablock != defaultDatablock )
saveDatablock( itor->second.name, datablock, outString, additionalTextureExtension );
++itor;
std::map<std::string, IdString>::const_iterator itor2 = sortedMap.begin();
std::map<std::string, IdString>::const_iterator endt2 = sortedMap.end();

while( itor2 != endt2 )
{
Hlms::HlmsDatablockMap::const_iterator itorFind = datablockMap.find( itor2->second );
if( itorFind != endt )
{
const HlmsDatablock *datablock = itorFind->second.datablock;

if( datablock != defaultDatablock )
saveDatablock( itorFind->second.name, datablock, outString,
additionalTextureExtension );
}
++itor2;
}
}
else
{
while( itor != endt )
{
const HlmsDatablock *datablock = itor->second.datablock;

if( datablock != defaultDatablock )
saveDatablock( itor->second.name, datablock, outString,
additionalTextureExtension );
++itor;
}
}

if( numDatablocks > 1u )
Expand Down

0 comments on commit 2b0f66d

Please sign in to comment.