simplify TYPE_CONSTANT code

This commit is contained in:
Garux 2021-03-25 21:59:31 +03:00
parent edabdd157e
commit 5008fa278f
15 changed files with 63 additions and 83 deletions

View File

@ -130,10 +130,10 @@ class ModuleRef
public: public:
ModuleRef( const char* name ) : m_table( 0 ){ ModuleRef( const char* name ) : m_table( 0 ){
if ( !globalModuleServer().getError() ) { if ( !globalModuleServer().getError() ) {
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name ); m_module = globalModuleServer().findModule( Type::Name, Type::Version, name );
if ( m_module == 0 ) { if ( m_module == 0 ) {
globalModuleServer().setError( true ); globalModuleServer().setError( true );
globalErrorStream() << "ModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n"; globalErrorStream() << "ModuleRef::initialise: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " name=" << makeQuoted( name ) << " - not found\n";
} }
else else
{ {
@ -151,7 +151,7 @@ public:
} }
Type* getTable(){ Type* getTable(){
#if defined( _DEBUG ) #if defined( _DEBUG )
ASSERT_MESSAGE( m_table != 0, "ModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" ); ASSERT_MESSAGE( m_table != 0, "ModuleRef::getTable: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " - module-reference used without being initialised" );
#endif #endif
return m_table; return m_table;
} }
@ -173,16 +173,16 @@ public:
} }
void initialise( const char* name ){ void initialise( const char* name ){
m_module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name ); m_module = globalModuleServer().findModule( Type::Name, Type::Version, name );
if ( m_module == 0 ) { if ( m_module == 0 ) {
globalModuleServer().setError( true ); globalModuleServer().setError( true );
globalErrorStream() << "SingletonModuleRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n"; globalErrorStream() << "SingletonModuleRef::initialise: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " name=" << makeQuoted( name ) << " - not found\n";
} }
} }
Type* getTable(){ Type* getTable(){
#if defined( _DEBUG ) #if defined( _DEBUG )
ASSERT_MESSAGE( m_table != 0, "SingletonModuleRef::getTable: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " - module-reference used without being initialised" ); ASSERT_MESSAGE( m_table != 0, "SingletonModuleRef::getTable: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " - module-reference used without being initialised" );
#endif #endif
return m_table; return m_table;
} }

View File

@ -33,8 +33,8 @@ public:
INTEGER_CONSTANT( Version, 1 ); INTEGER_CONSTANT( Version, 1 );
}; };
int version = Bleh::Version(); int version = Bleh::Version;
const char* name = Bleh::Name(); const char* name = Bleh::Name;
} }
#endif #endif

View File

@ -25,25 +25,7 @@
/// \file /// \file
/// \brief Language extensions for constants that are guaranteed to be evaluated at compile-time. /// \brief Language extensions for constants that are guaranteed to be evaluated at compile-time.
/// \brief A compile-time-constant as a type. #define STRING_CONSTANT( name, value ) static constexpr const char* name = value
template<typename Type> #define INTEGER_CONSTANT( name, value ) static constexpr int name = value
struct ConstantWrapper
{
typedef typename Type::Value Value;
operator Value() const
{
return Type::evaluate();
}
};
template<typename TextOutputStreamType, typename Type>
inline TextOutputStreamType& ostream_write( TextOutputStreamType& ostream, const ConstantWrapper<Type>& c ){
return ostream_write( ostream, typename Type::Value( c ) );
}
#define TYPE_CONSTANT( name, value, type ) struct name ## _CONSTANT_ { typedef type Value; static Value evaluate() { return value; } }; typedef ConstantWrapper<name ## _CONSTANT_> name
#define STRING_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, const char* )
#define INTEGER_CONSTANT( name, value ) TYPE_CONSTANT ( name, value, int )
STRING_CONSTANT( EmptyString, "" );
#endif #endif

View File

@ -102,7 +102,7 @@ public:
if ( !globalModuleServer().getError() ) { if ( !globalModuleServer().getError() ) {
if ( string_equal( names, "*" ) ) { if ( string_equal( names, "*" ) ) {
InsertModules<Type> visitor( m_modules ); InsertModules<Type> visitor( m_modules );
globalModuleServer().foreachModule( typename Type::Name(), typename Type::Version(), visitor ); globalModuleServer().foreachModule( Type::Name, Type::Version, visitor );
} }
else else
{ {
@ -113,11 +113,11 @@ public:
if ( string_empty( name ) ) { if ( string_empty( name ) ) {
break; break;
} }
Module* module = globalModuleServer().findModule( typename Type::Name(), typename Type::Version(), name ); Module* module = globalModuleServer().findModule( Type::Name, Type::Version, name );
if ( module == 0 ) { if ( module == 0 ) {
globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted( typename Type::Name() ) << " version=" << makeQuoted( typename Type::Version() ) << " name=" << makeQuoted( name ) << " - not found\n"; globalErrorStream() << "ModulesRef::initialise: type=" << makeQuoted( Type::Name ) << " version=" << makeQuoted( Type::Version ) << " name=" << makeQuoted( name ) << " - not found\n";
// do not fail on missing image or model plugin, they can be optional // do not fail on missing image or model plugin, they can be optional
if ( !string_equal( typename Type::Name(), "image" ) && !string_equal( typename Type::Name(), "model" ) ){ if ( !string_equal( Type::Name, "image" ) && !string_equal( Type::Name, "model" ) ){
globalModuleServer().setError( true ); globalModuleServer().setError( true );
break; break;
} }

View File

@ -33,7 +33,7 @@ class DefaultAPIConstructor
{ {
public: public:
const char* getName(){ const char* getName(){
return typename API::Name(); return API::Name;
} }
API* constructAPI( Dependencies& dependencies ){ API* constructAPI( Dependencies& dependencies ){
@ -49,7 +49,7 @@ class DependenciesAPIConstructor
{ {
public: public:
const char* getName(){ const char* getName(){
return typename API::Name(); return API::Name;
} }
API* constructAPI( Dependencies& dependencies ){ API* constructAPI( Dependencies& dependencies ){
@ -87,7 +87,7 @@ public:
} }
void selfRegister(){ void selfRegister(){
globalModuleServer().registerModule( typename Type::Name(), typename Type::Version(), APIConstructor::getName(), *this ); globalModuleServer().registerModule( Type::Name, Type::Version, APIConstructor::getName(), *this );
} }
Dependencies& getDependencies(){ Dependencies& getDependencies(){
@ -101,16 +101,16 @@ public:
} }
void capture(){ void capture(){
if ( ++m_refcount == 1 ) { if ( ++m_refcount == 1 ) {
globalOutputStream() << "Module Initialising: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n"; globalOutputStream() << "Module Initialising: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
m_dependencies = new Dependencies(); m_dependencies = new Dependencies();
m_dependencyCheck = !globalModuleServer().getError(); m_dependencyCheck = !globalModuleServer().getError();
if ( m_dependencyCheck ) { if ( m_dependencyCheck ) {
m_api = APIConstructor::constructAPI( *m_dependencies ); m_api = APIConstructor::constructAPI( *m_dependencies );
globalOutputStream() << "Module Ready: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n"; globalOutputStream() << "Module Ready: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
} }
else else
{ {
globalErrorStream() << "Module Dependencies Failed: '" << typename Type::Name() << "' '" << APIConstructor::getName() << "'\n"; globalErrorStream() << "Module Dependencies Failed: '" << Type::Name << "' '" << APIConstructor::getName() << "'\n";
} }
m_cycleCheck = true; m_cycleCheck = true;
} }

View File

@ -98,17 +98,16 @@ class NodeType : public StaticTypeSystemInitialiser
{ {
TypeId m_typeId; TypeId m_typeId;
public: public:
typedef typename Type::Name Name;
NodeType() : m_typeId( NODETYPEID_NONE ){ NodeType() : m_typeId( NODETYPEID_NONE ){
StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) ); StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) );
} }
void initialise(){ void initialise(){
m_typeId = GlobalSceneGraph().getNodeTypeId( Name() ); m_typeId = GlobalSceneGraph().getNodeTypeId( Type::Name );
} }
typedef MemberCaller<NodeType<Type>, &NodeType<Type>::initialise> InitialiseCaller; typedef MemberCaller<NodeType<Type>, &NodeType<Type>::initialise> InitialiseCaller;
TypeId getTypeId(){ TypeId getTypeId(){
#if defined( _DEBUG ) #if defined( _DEBUG )
ASSERT_MESSAGE( m_typeId != NODETYPEID_NONE, "node-type " << makeQuoted( Name() ) << " used before being initialised" ); ASSERT_MESSAGE( m_typeId != NODETYPEID_NONE, "node-type " << makeQuoted( Name ) << " used before being initialised" );
#endif #endif
return m_typeId; return m_typeId;
} }
@ -433,17 +432,16 @@ class InstanceType : public StaticTypeSystemInitialiser
{ {
TypeId m_typeId; TypeId m_typeId;
public: public:
typedef typename Type::Name Name;
InstanceType() : m_typeId( INSTANCETYPEID_NONE ){ InstanceType() : m_typeId( INSTANCETYPEID_NONE ){
StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) ); StaticTypeSystemInitialiser::instance().addInitialiser( InitialiseCaller( *this ) );
} }
void initialise(){ void initialise(){
m_typeId = GlobalSceneGraph().getInstanceTypeId( Name() ); m_typeId = GlobalSceneGraph().getInstanceTypeId( Type::Name );
} }
typedef MemberCaller<InstanceType<Type>, &InstanceType<Type>::initialise> InitialiseCaller; typedef MemberCaller<InstanceType<Type>, &InstanceType<Type>::initialise> InitialiseCaller;
TypeId getTypeId(){ TypeId getTypeId(){
#if defined( _DEBUG ) #if defined( _DEBUG )
ASSERT_MESSAGE( m_typeId != INSTANCETYPEID_NONE, "instance-type " << makeQuoted( Name() ) << " used before being initialised" ); ASSERT_MESSAGE( m_typeId != INSTANCETYPEID_NONE, "instance-type " << makeQuoted( Type::Name ) << " used before being initialised" );
#endif #endif
return m_typeId; return m_typeId;
} }

View File

@ -76,8 +76,8 @@ public:
INTEGER_CONSTANT( MapVersion, 2 ); INTEGER_CONSTANT( MapVersion, 2 );
MapDoom3API( MapDoom3Dependencies& dependencies ) : m_dependencies( dependencies ){ MapDoom3API( MapDoom3Dependencies& dependencies ) : m_dependencies( dependencies ){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "doom3 maps", "*.map" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "doom3 maps", "*.map" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "doom3 region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "doom3 region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -110,8 +110,8 @@ public:
if ( !Tokeniser_getInteger( tokeniser, version ) ) { if ( !Tokeniser_getInteger( tokeniser, version ) ) {
return; return;
} }
if ( version != MapVersion() ) { if ( version != MapVersion ) {
globalErrorStream() << "Doom 3 map version " << MapVersion() << " supported, version is " << version << "\n"; globalErrorStream() << "Doom 3 map version " << MapVersion << " supported, version is " << version << "\n";
return; return;
} }
tokeniser.nextLine(); tokeniser.nextLine();
@ -121,7 +121,7 @@ public:
void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream ) const { void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream ) const {
TokenWriter& writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter( outputStream ); TokenWriter& writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter( outputStream );
writer.writeToken( "Version" ); writer.writeToken( "Version" );
writer.writeInteger( MapVersion() ); writer.writeInteger( MapVersion );
writer.nextLine(); writer.nextLine();
Map_Write( root, traverse, writer, false ); Map_Write( root, traverse, writer, false );
writer.release(); writer.release();
@ -147,8 +147,8 @@ public:
INTEGER_CONSTANT( MapVersion, 3 ); INTEGER_CONSTANT( MapVersion, 3 );
MapQuake4API( MapDoom3Dependencies& dependencies ) : m_dependencies( dependencies ){ MapQuake4API( MapDoom3Dependencies& dependencies ) : m_dependencies( dependencies ){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake4 maps", "*.map" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake4 maps", "*.map" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake4 region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake4 region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -181,8 +181,8 @@ public:
if ( !Tokeniser_getInteger( tokeniser, version ) ) { if ( !Tokeniser_getInteger( tokeniser, version ) ) {
return; return;
} }
if ( version != MapVersion() ) { if ( version != MapVersion ) {
globalErrorStream() << "Quake 4 map version " << MapVersion() << " supported, version is " << version << "\n"; globalErrorStream() << "Quake 4 map version " << MapVersion << " supported, version is " << version << "\n";
return; return;
} }
tokeniser.nextLine(); tokeniser.nextLine();
@ -192,7 +192,7 @@ public:
void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream ) const { void writeGraph( scene::Node& root, GraphTraversalFunc traverse, TextOutputStream& outputStream ) const {
TokenWriter& writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter( outputStream ); TokenWriter& writer = GlobalScripLibModule::getTable().m_pfnNewSimpleTokenWriter( outputStream );
writer.writeToken( "Version" ); writer.writeToken( "Version" );
writer.writeInteger( MapVersion() ); writer.writeInteger( MapVersion );
writer.nextLine(); writer.nextLine();
Map_Write( root, traverse, writer, false ); Map_Write( root, traverse, writer, false );
writer.release(); writer.release();
@ -234,9 +234,9 @@ public:
STRING_CONSTANT( Name, "mapq3" ); STRING_CONSTANT( Name, "mapq3" );
MapQ3API(){ MapQ3API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake3 maps", "*.map", true, true, true ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake3 maps", "*.map", true, true, true ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake3 region", "*.reg", true, true, true ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake3 region", "*.reg", true, true, true ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake3 compiled maps", "*.bsp", false, true, false ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake3 compiled maps", "*.bsp", false, true, false ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -316,8 +316,8 @@ public:
STRING_CONSTANT( Name, "mapq1" ); STRING_CONSTANT( Name, "mapq1" );
MapQ1API(){ MapQ1API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake maps", "*.map" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake maps", "*.map" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -392,8 +392,8 @@ public:
STRING_CONSTANT( Name, "maphl" ); STRING_CONSTANT( Name, "maphl" );
MapHalfLifeAPI(){ MapHalfLifeAPI(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "half-life maps", "*.map" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "half-life maps", "*.map" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "half-life region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "half-life region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -436,8 +436,8 @@ public:
STRING_CONSTANT( Name, "mapq2" ); STRING_CONSTANT( Name, "mapq2" );
MapQ2API(){ MapQ2API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake2 maps", "*.map" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake2 maps", "*.map" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "quake2 region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "quake2 region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;
@ -639,8 +639,8 @@ public:
STRING_CONSTANT( Name, "mapvmf" ); STRING_CONSTANT( Name, "mapvmf" );
MapVMFAPI(){ MapVMFAPI(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "vmf maps", "*.vmf" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "vmf maps", "*.vmf" ) );
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "vmf region", "*.reg" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "vmf region", "*.reg" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;

View File

@ -68,7 +68,7 @@ public:
STRING_CONSTANT( Name, "xmldoom3" ); STRING_CONSTANT( Name, "xmldoom3" );
MapXMLAPI(){ MapXMLAPI(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "xml doom3 maps", "*.xmap" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "xml doom3 maps", "*.xmap" ) );
} }
MapFormat* getTable(){ MapFormat* getTable(){
return this; return this;

View File

@ -70,7 +70,7 @@ public:
STRING_CONSTANT( Name, "md3" ); STRING_CONSTANT( Name, "md3" );
ModelMD3API(){ ModelMD3API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "md3 models", "*.md3" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "md3 models", "*.md3" ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelmd3; return &m_modelmd3;
@ -99,7 +99,7 @@ public:
STRING_CONSTANT( Name, "md2" ); STRING_CONSTANT( Name, "md2" );
ModelMD2API(){ ModelMD2API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "md2 models", "*.md2" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "md2 models", "*.md2" ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelmd2; return &m_modelmd2;
@ -126,7 +126,7 @@ public:
STRING_CONSTANT( Name, "mdl" ); STRING_CONSTANT( Name, "mdl" );
ModelMDLAPI(){ ModelMDLAPI(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "mdl models", "*.mdl" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "mdl models", "*.mdl" ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelmdl; return &m_modelmdl;
@ -153,7 +153,7 @@ public:
STRING_CONSTANT( Name, "mdc" ); STRING_CONSTANT( Name, "mdc" );
ModelMDCAPI(){ ModelMDCAPI(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "mdc models", "*.mdc" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "mdc models", "*.mdc" ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelmdc; return &m_modelmdc;
@ -205,7 +205,7 @@ public:
STRING_CONSTANT( Name, "md5mesh" ); STRING_CONSTANT( Name, "md5mesh" );
ModelMD5API(){ ModelMD5API(){
GlobalFiletypesModule::getTable().addType( Type::Name(), Name(), filetype_t( "md5 meshes", "*.md5mesh" ) ); GlobalFiletypesModule::getTable().addType( Type::Name, Name, filetype_t( "md5 meshes", "*.md5mesh" ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelmd5; return &m_modelmd5;

View File

@ -124,7 +124,7 @@ public:
m_modelLoader( module ){ m_modelLoader( module ){
StringOutputStream filter( 128 ); StringOutputStream filter( 128 );
filter << "*." << extension; filter << "*." << extension;
GlobalFiletypesModule::getTable().addType( Type::Name(), extension, filetype_t( module->displayName, filter.c_str() ) ); GlobalFiletypesModule::getTable().addType( Type::Name, extension, filetype_t( module->displayName, filter.c_str() ) );
} }
ModelLoader* getTable(){ ModelLoader* getTable(){
return &m_modelLoader; return &m_modelLoader;

View File

@ -604,7 +604,7 @@ const char* misc_model_dialog( GtkWidget* parent, const char* filepath ){
} }
} }
const char *filename = file_dialog( parent, true, "Choose Model", buffer.c_str(), ModelLoader::Name() ); const char *filename = file_dialog( parent, true, "Choose Model", buffer.c_str(), ModelLoader::Name );
if ( filename != 0 ) { if ( filename != 0 ) {
// use VFS to get the correct relative path // use VFS to get the correct relative path
const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) ); const char* relative = path_make_relative( filename, GlobalFileSystem().findRoot( filename ) );

View File

@ -352,7 +352,7 @@ bool Map_Unnamed( const Map& map ){
} }
inline const MapFormat& MapFormat_forFile( const char* filename ){ inline const MapFormat& MapFormat_forFile( const char* filename ){
const char* moduleName = findModuleName( GetFileTypeRegistry(), MapFormat::Name(), path_get_extension( filename ) ); const char* moduleName = findModuleName( GetFileTypeRegistry(), MapFormat::Name, path_get_extension( filename ) );
MapFormat* format = Radiant_getMapModules().findModule( moduleName ); MapFormat* format = Radiant_getMapModules().findModule( moduleName );
ASSERT_MESSAGE( format != 0, "map format not found for file " << makeQuoted( filename ) ); ASSERT_MESSAGE( format != 0, "map format not found for file " << makeQuoted( filename ) );
return *format; return *format;
@ -1974,17 +1974,17 @@ const char* getMapsPath(){
const char* map_open( const char* title ){ const char* map_open( const char* title ){
const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str(); const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str();
return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), true, title, path, MapFormat::Name(), true, false, false ); return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), true, title, path, MapFormat::Name, true, false, false );
} }
const char* map_import( const char* title ){ const char* map_import( const char* title ){
const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str(); const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str();
return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), true, title, path, MapFormat::Name(), false, true, false ); return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), true, title, path, MapFormat::Name, false, true, false );
} }
const char* map_save( const char* title ){ const char* map_save( const char* title ){
const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str(); const char* path = Map_Unnamed( g_map )? getMapsPath() : g_map.m_name.c_str();
return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), false, title, path, MapFormat::Name(), false, false, true ); return file_dialog( GTK_WIDGET( MainFrame_getWindow() ), false, title, path, MapFormat::Name, false, false, true );
} }
void OpenMap(){ void OpenMap(){

View File

@ -1231,7 +1231,7 @@ void ModelBrowser_constructTree(){
m_modelExtensions.emplace( moduleName ); m_modelExtensions.emplace( moduleName );
} }
} typelist; } typelist;
GlobalFiletypes().getTypeList( ModelLoader::Name(), &typelist, true, false, false ); GlobalFiletypes().getTypeList( ModelLoader::Name, &typelist, true, false, false );
ModelFolders modelFolders( g_ModelBrowser.m_prefFoldersToLoad.c_str() ); ModelFolders modelFolders( g_ModelBrowser.m_prefFoldersToLoad.c_str() );

View File

@ -165,7 +165,7 @@ NullModelLoader g_NullModelLoader;
/// \brief Returns the model loader for the model \p type or 0 if the model \p type has no loader module /// \brief Returns the model loader for the model \p type or 0 if the model \p type has no loader module
ModelLoader* ModelLoader_forType( const char* type ){ ModelLoader* ModelLoader_forType( const char* type ){
const char* moduleName = findModuleName( &GlobalFiletypes(), ModelLoader::Name(), type ); const char* moduleName = findModuleName( &GlobalFiletypes(), ModelLoader::Name, type );
if ( string_not_empty( moduleName ) ) { if ( string_not_empty( moduleName ) ) {
ModelLoader* table = ReferenceAPI_getModelModules().findModule( moduleName ); ModelLoader* table = ReferenceAPI_getModelModules().findModule( moduleName );
if ( table != 0 ) { if ( table != 0 ) {
@ -283,7 +283,7 @@ NodeSmartReference Model_load( ModelLoader* loader, const char* path, const char
} }
else else
{ {
const char* moduleName = findModuleName( &GlobalFiletypes(), MapFormat::Name(), type ); const char* moduleName = findModuleName( &GlobalFiletypes(), MapFormat::Name, type );
if ( string_not_empty( moduleName ) ) { if ( string_not_empty( moduleName ) ) {
const MapFormat* format = ReferenceAPI_getMapModules().findModule( moduleName ); const MapFormat* format = ReferenceAPI_getMapModules().findModule( moduleName );
if ( format != 0 ) { if ( format != 0 ) {
@ -398,7 +398,7 @@ struct ModelResource : public Resource
} }
bool save(){ bool save(){
if ( !mapSaved() ) { if ( !mapSaved() ) {
const char* moduleName = findModuleName( GetFileTypeRegistry(), MapFormat::Name(), m_type.c_str() ); const char* moduleName = findModuleName( GetFileTypeRegistry(), MapFormat::Name, m_type.c_str() );
if ( string_not_empty( moduleName ) ) { if ( string_not_empty( moduleName ) ) {
const MapFormat* format = ReferenceAPI_getMapModules().findModule( moduleName ); const MapFormat* format = ReferenceAPI_getMapModules().findModule( moduleName );
if ( format != 0 && MapResource_save( *format, m_model.get(), m_path.c_str(), m_name.c_str() ) ) { if ( format != 0 && MapResource_save( *format, m_model.get(), m_path.c_str(), m_name.c_str() ) ) {

View File

@ -254,8 +254,8 @@ public:
m_undoables.erase( undoable ); m_undoables.erase( undoable );
} }
void setLevels( std::size_t levels ){ void setLevels( std::size_t levels ){
if ( levels > static_cast<unsigned>( MAX_UNDO_LEVELS() ) ) { if ( levels > static_cast<unsigned>( MAX_UNDO_LEVELS ) ) {
levels = MAX_UNDO_LEVELS(); levels = MAX_UNDO_LEVELS;
} }
while ( m_undo_stack.size() > levels ) while ( m_undo_stack.size() > levels )