Skip to content

Commit

Permalink
Main: rewrite strict mode using OGRE_RESOURCE_GROUP_INIT
Browse files Browse the repository at this point in the history
This allows us to globally set a custom resource group.
Make a separation into strict/ pedantic modes, where
PEDANTIC = not default init
STRICT = init to default group
  • Loading branch information
paroj committed Mar 31, 2018
1 parent 0b9a270 commit f13749c
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 103 deletions.
8 changes: 5 additions & 3 deletions CMake/FeatureSummary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,12 @@ else ()
set(_buildtype "shared")
endif ()

if (OGRE_RESOURCEMANAGER_STRICT)
set(_resmgr "strict")
else ()
if (OGRE_RESOURCEMANAGER_STRICT EQUAL 0)
set(_resmgr "legacy [DEPRECATED]")
elseif (OGRE_RESOURCEMANAGER_STRICT EQUAL 1)
set(_resmgr "pedantic")
else ()
set(_resmgr "strict")
endif ()

if (OGRE_NODE_STORAGE_LEGACY)
Expand Down
8 changes: 7 additions & 1 deletion CMake/Templates/OgreBuildSettings.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

#cmakedefine OGRE_STATIC_LIB
#cmakedefine01 OGRE_DEBUG_MODE
#cmakedefine01 OGRE_RESOURCEMANAGER_STRICT

/** There are three modes for resource lookup
0 - LEGACY - search in all groups twice - for case sensitive and insensitive lookup
1 - PEDANTIC - require an explicit resource group. Case sensitive lookup.
2 - STRICT - search in default group if not specified otherwise. Case sensitive lookup.
*/
#define OGRE_RESOURCEMANAGER_STRICT @OGRE_RESOURCEMANAGER_STRICT@

#cmakedefine OGRE_BUILD_RENDERSYSTEM_D3D9
#cmakedefine OGRE_BUILD_RENDERSYSTEM_D3D11
Expand Down
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ include(Dependencies)

# Customise what to build
option(OGRE_STATIC "Static build" FALSE)
option(OGRE_RESOURCEMANAGER_STRICT "Make ResourceManager strict for faster operation. (case sensitive, indexing required etc.)" FALSE)
set(OGRE_RESOURCEMANAGER_STRICT "0" CACHE STRING
"Make ResourceManager strict for faster operation. Possible values:
0 - OFF search in all groups twice - for case sensitive and insensitive lookup [DEPRECATED]
1 - PEDANTIC require an explicit resource group. Case sensitive lookup.
2 - STRICT search in default group if not specified otherwise. Case sensitive lookup.
")
set_property(CACHE OGRE_RESOURCEMANAGER_STRICT PROPERTY STRINGS 0 1 2)
option(OGRE_USE_STD11 "Use C++11 std library. Changes API, requires compiler support" FALSE)
option(OGRE_NODE_STORAGE_LEGACY "use maps for child nodes instead of vectors. About 20% slower but backwards compatible. " TRUE)
cmake_dependent_option(OGRE_BUILD_RENDERSYSTEM_D3D9 "Build Direct3D9 RenderSystem" TRUE "WIN32;DirectX9_FOUND;NOT WINDOWS_STORE;NOT WINDOWS_PHONE" FALSE)
Expand Down
7 changes: 1 addition & 6 deletions Components/Overlay/include/OgreFontManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ namespace Ogre

/// Get a resource by name
/// @see ResourceManager::getResourceByName
FontPtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& groupName);
#else
getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
FontPtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/** @copydoc ScriptLoader::parseScript */
void parseScript(DataStreamPtr& stream, const String& groupName);
Expand Down
35 changes: 5 additions & 30 deletions Components/RTShaderSystem/include/OgreShaderGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,7 @@ class _OgreRTSSExport ShaderGenerator : public Singleton<ShaderGenerator>, publi
@param materialName The source material name.
@param groupName The source group name.
*/
bool
#if OGRE_RESOURCEMANAGER_STRICT
removeAllShaderBasedTechniques(const String& materialName, const String& groupName);
#else
removeAllShaderBasedTechniques(const String& materialName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
bool removeAllShaderBasedTechniques(const String& materialName, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/**
Clone all shader based techniques from one material to another.
Expand Down Expand Up @@ -389,12 +384,7 @@ class _OgreRTSSExport ShaderGenerator : public Singleton<ShaderGenerator>, publi
@param materialName The material to invalidate.
@param groupName The source group name.
*/
void
#if OGRE_RESOURCEMANAGER_STRICT
invalidateMaterial(const String& schemeName, const String& materialName, const String& groupName);
#else
invalidateMaterial(const String& schemeName, const String& materialName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
void invalidateMaterial(const String& schemeName, const String& materialName, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/**
Validate specific material scheme. This action will generate shader programs for the technique of the
Expand All @@ -403,12 +393,7 @@ class _OgreRTSSExport ShaderGenerator : public Singleton<ShaderGenerator>, publi
@param materialName The material to validate.
@param groupName The source group name.
*/
bool
#if OGRE_RESOURCEMANAGER_STRICT
validateMaterial(const String& schemeName, const String& materialName, const String& groupName);
#else
validateMaterial(const String& schemeName, const String& materialName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
bool validateMaterial(const String& schemeName, const String& materialName, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/**
Invalidate specific material scheme. This action will lead to shader regeneration of the technique belongs to the
Expand All @@ -417,12 +402,7 @@ class _OgreRTSSExport ShaderGenerator : public Singleton<ShaderGenerator>, publi
@param materialName The material to invalidate.
@param groupName The source group name.
*/
void
#if OGRE_RESOURCEMANAGER_STRICT
invalidateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName);
#else
invalidateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
void invalidateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/**
Validate specific material scheme. This action will generate shader programs illumination passes of the technique of the
Expand All @@ -431,12 +411,7 @@ class _OgreRTSSExport ShaderGenerator : public Singleton<ShaderGenerator>, publi
@param materialName The material to validate.
@param groupName The source group name.
*/
bool
#if OGRE_RESOURCEMANAGER_STRICT
validateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName);
#else
validateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
bool validateMaterialIlluminationPasses(const String& schemeName, const String& materialName, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/**
Return custom material Serializer of the shader generator.
Expand Down
15 changes: 3 additions & 12 deletions OgreMain/include/OgreGpuProgramManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ namespace Ogre {

/// Get a resource by name
/// @see GpuProgramManager::getResourceByName
GpuProgramPtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& group, bool preferHighLevelPrograms = true);
#else
getByName(const String& name, const String& group = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, bool preferHighLevelPrograms = true);
#endif
GpuProgramPtr getByName(const String& name, const String& group OGRE_RESOURCE_GROUP_INIT, bool preferHighLevelPrograms = true);


/** Loads a GPU program from a file of assembly.
@remarks
Expand Down Expand Up @@ -177,12 +173,7 @@ namespace Ogre {
@param preferHighLevelPrograms If set to true (the default), high level programs will be
returned in preference to low-level programs.
*/
ResourcePtr
#if OGRE_RESOURCEMANAGER_STRICT
getResourceByName(const String& name, const String& group, bool preferHighLevelPrograms = true);
#else
getResourceByName(const String& name, const String& group = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, bool preferHighLevelPrograms = true);
#endif
ResourcePtr getResourceByName(const String& name, const String& group OGRE_RESOURCE_GROUP_INIT, bool preferHighLevelPrograms = true);

/** Create a new set of shared parameters, which can be used across many
GpuProgramParameters objects of different structures.
Expand Down
7 changes: 1 addition & 6 deletions OgreMain/include/OgreHighLevelGpuProgramManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ namespace Ogre {

/// Get a resource by name
/// @see ResourceManager::getResourceByName
HighLevelGpuProgramPtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& groupName);
#else
getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
HighLevelGpuProgramPtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/** Create a new, unloaded HighLevelGpuProgram.
@par
Expand Down
7 changes: 1 addition & 6 deletions OgreMain/include/OgreMeshManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ namespace Ogre {

/// Get a resource by name
/// @see ResourceManager::getResourceByName
MeshPtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& groupName);
#else
getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
MeshPtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/// Create a new mesh
/// @see ResourceManager::createResource
Expand Down
8 changes: 8 additions & 0 deletions OgreMain/include/OgreResourceGroupManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ THE SOFTWARE.
#undef Status
#endif

#if OGRE_RESOURCEMANAGER_STRICT == 0
# define OGRE_RESOURCE_GROUP_INIT = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME
#elif OGRE_RESOURCEMANAGER_STRICT == 1
# define OGRE_RESOURCE_GROUP_INIT
#else
# define OGRE_RESOURCE_GROUP_INIT = ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME
#endif

namespace Ogre {

/** \addtogroup Core
Expand Down
30 changes: 5 additions & 25 deletions OgreMain/include/OgreResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,7 @@ namespace Ogre {
as much as they can and wait to be reloaded.
@see ResourceGroupManager for unloading of resource groups.
*/
void
#if OGRE_RESOURCEMANAGER_STRICT
unload(const String& name, const String& group);
#else
unload(const String& name, const String& group = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
void unload(const String& name, const String& group OGRE_RESOURCE_GROUP_INIT);

/** Unloads a single resource by handle.
@remarks
Expand Down Expand Up @@ -307,13 +302,7 @@ namespace Ogre {
void remove(const ResourcePtr& r);

/// @overload
void
#if OGRE_RESOURCEMANAGER_STRICT
remove(const String& name, const String& group);

#else
remove(const String& name, const String& group = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
void remove(const String& name, const String& group OGRE_RESOURCE_GROUP_INIT);

/// @overload
void remove(ResourceHandle handle);
Expand Down Expand Up @@ -351,23 +340,14 @@ namespace Ogre {

/** Retrieves a pointer to a resource by name, or null if the resource does not exist.
*/
virtual ResourcePtr
#if OGRE_RESOURCEMANAGER_STRICT
getResourceByName(const String& name, const String& groupName);
#else
getResourceByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
virtual ResourcePtr getResourceByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/** Retrieves a pointer to a resource by handle, or null if the resource does not exist.
*/
virtual ResourcePtr getByHandle(ResourceHandle handle);

/// Returns whether the named resource exists in this manager
bool
#if OGRE_RESOURCEMANAGER_STRICT
resourceExists(const String& name, const String& group)
#else
resourceExists(const String& name, const String& group = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME)
#endif
bool resourceExists(const String& name, const String& group OGRE_RESOURCE_GROUP_INIT)
{
return getResourceByName(name, group).get() != 0;
}
Expand Down
7 changes: 1 addition & 6 deletions OgreMain/include/OgreSkeletonManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ namespace Ogre {

/// Get a resource by name
/// @see ResourceManager::getResourceByName
SkeletonPtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& groupName);
#else
getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
SkeletonPtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

/// @copydoc Singleton::getSingleton()
static SkeletonManager& getSingleton(void);
Expand Down
7 changes: 1 addition & 6 deletions OgreMain/include/OgreTextureManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ namespace Ogre {
const NameValuePairList* createParams = 0);
/// Get a resource by name
/// @see ResourceManager::getResourceByName
TexturePtr
#if OGRE_RESOURCEMANAGER_STRICT
getByName(const String& name, const String& groupName);
#else
getByName(const String& name, const String& groupName = ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
#endif
TexturePtr getByName(const String& name, const String& groupName OGRE_RESOURCE_GROUP_INIT);

using ResourceManager::createOrRetrieve;

Expand Down
2 changes: 1 addition & 1 deletion OgreMain/include/OgreZip.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Ogre {
ZipArchive(const String& name, const String& archType, zzip_plugin_io_handlers* pluginIo = NULL);
~ZipArchive();
/// @copydoc Archive::isCaseSensitive
bool isCaseSensitive(void) const { return OGRE_RESOURCEMANAGER_STRICT; }
bool isCaseSensitive(void) const { return OGRE_RESOURCEMANAGER_STRICT != 0; }

/// @copydoc Archive::load
void load();
Expand Down

0 comments on commit f13749c

Please sign in to comment.