Skip to content

Commit

Permalink
Adding bare bone model format manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 21, 2017
1 parent 8a1b3c5 commit 646f87b
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 24 deletions.
61 changes: 37 additions & 24 deletions include/imodel.h
@@ -1,26 +1,4 @@
/*
Copyright (C) 2001-2006, William Joseph.
All Rights Reserved.
This file is part of GtkRadiant.
GtkRadiant is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GtkRadiant is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GtkRadiant; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if !defined(INCLUDED_IMODEL_H)
#define INCLUDED_IMODEL_H
#pragma once

#include "Bounded.h"
#include "irender.h"
Expand Down Expand Up @@ -128,6 +106,32 @@ class ModelNode {
};
typedef std::shared_ptr<ModelNode> ModelNodePtr;

/**
* Exporter Interface for models (meshes).
*/
class IModelExporter
{
public:
virtual ~IModelExporter()
{}

// Returns the uppercase file extension this exporter is suitable for
virtual const std::string& getExtension() const = 0;
};
typedef std::shared_ptr<IModelExporter> IModelExporterPtr;

class IModelFormatManager :
public RegisterableModule
{
public:
virtual ~IModelFormatManager()
{}

// Register/unregister an exporter class
virtual void registerExporter(const IModelExporterPtr& exporter) = 0;
virtual void unregisterExporter(const IModelExporterPtr& exporter) = 0;
};

} // namespace model

// Utility methods
Expand All @@ -139,6 +143,7 @@ inline model::ModelNodePtr Node_getModel(const scene::INodePtr& node) {
return std::dynamic_pointer_cast<model::ModelNode>(node);
}

const char* const MODULE_MODELFORMATMANAGER("ModelFormatManager");
const std::string MODULE_MODELLOADER("ModelLoader"); // fileType is appended ("ModeLoaderASE")

/** Model loader module API interface.
Expand Down Expand Up @@ -176,4 +181,12 @@ inline ModelLoader& GlobalModelLoader(const std::string& fileType) {
return *_modelLoader;
}

#endif /* _IMODEL_H_ */
inline model::IModelFormatManager& GlobalModelFormatManager()
{
std::shared_ptr<model::IModelFormatManager> _modelFormatManager(
std::static_pointer_cast<model::IModelFormatManager>(
module::GlobalModuleRegistry().getModule(MODULE_MODELFORMATMANAGER)
)
);
return *_modelFormatManager;
}
1 change: 1 addition & 0 deletions radiant/Makefile.am
Expand Up @@ -252,6 +252,7 @@ darkradiant_SOURCES = main.cpp \
log/LogStreamBuf.cpp \
log/LogFile.cpp \
model/ModelCache.cpp \
model/ModelFormatManager.cpp \
model/NullModel.cpp \
model/NullModelNode.cpp

Expand Down
56 changes: 56 additions & 0 deletions radiant/model/ModelFormatManager.cpp
@@ -0,0 +1,56 @@
#include "ModelFormatManager.h"

#include "itextstream.h"
#include <boost/algorithm/string/case_conv.hpp>

namespace model
{

const std::string& ModelFormatManager::getName() const
{
static std::string _name(MODULE_MODELFORMATMANAGER);
return _name;
}

const StringSet& ModelFormatManager::getDependencies() const
{
static StringSet _dependencies;
return _dependencies;
}

void ModelFormatManager::initialiseModule(const ApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
}

void ModelFormatManager::registerExporter(const IModelExporterPtr& exporter)
{
assert(exporter);

std::string extension = boost::algorithm::to_upper_copy(exporter->getExtension());

if (_exporters.find(extension) != _exporters.end())
{
rWarning() << "Cannot register more than one model exporter for extension " << extension << std::endl;
return;
}

_exporters[extension] = exporter;
}

void ModelFormatManager::unregisterExporter(const IModelExporterPtr& exporter)
{
assert(exporter);

std::string extension = boost::algorithm::to_upper_copy(exporter->getExtension());

if (_exporters.find(extension) != _exporters.end())
{
_exporters.erase(extension);
return;
}

rWarning() << "Cannot unregister exporter for extension " << extension << std::endl;
}

}
26 changes: 26 additions & 0 deletions radiant/model/ModelFormatManager.h
@@ -0,0 +1,26 @@
#pragma once

#include <map>
#include "imodel.h"

namespace model
{

class ModelFormatManager :
public IModelFormatManager
{
private:
// Map file extension to implementation
typedef std::map<std::string, IModelExporterPtr> ExporterMap;
ExporterMap _exporters;

public:
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const ApplicationContext& ctx) override;

void registerExporter(const IModelExporterPtr& exporter) override;
void unregisterExporter(const IModelExporterPtr& exporter) override;
};

}
2 changes: 2 additions & 0 deletions tools/msvc2015/DarkRadiant.vcxproj
Expand Up @@ -346,6 +346,7 @@
<ClCompile Include="..\..\radiant\map\infofile\InfoFileManager.cpp" />
<ClCompile Include="..\..\radiant\map\RenderableAasFile.cpp" />
<ClCompile Include="..\..\radiant\model\ModelCache.cpp" />
<ClCompile Include="..\..\radiant\model\ModelFormatManager.cpp" />
<ClCompile Include="..\..\radiant\model\NullModel.cpp" />
<ClCompile Include="..\..\radiant\model\NullModelNode.cpp" />
<ClCompile Include="..\..\radiant\namespace\ComplexName.cpp" />
Expand Down Expand Up @@ -592,6 +593,7 @@
<ClInclude Include="..\..\radiant\map\infofile\InfoFileManager.h" />
<ClInclude Include="..\..\radiant\map\RenderableAasFile.h" />
<ClInclude Include="..\..\radiant\model\ModelCache.h" />
<ClInclude Include="..\..\radiant\model\ModelFormatManager.h" />
<ClInclude Include="..\..\radiant\model\NullModel.h" />
<ClInclude Include="..\..\radiant\model\NullModelLoader.h" />
<ClInclude Include="..\..\radiant\model\NullModelNode.h" />
Expand Down
6 changes: 6 additions & 0 deletions tools/msvc2015/DarkRadiant.vcxproj.filters
Expand Up @@ -895,6 +895,9 @@
<ClCompile Include="..\..\radiant\model\NullModelNode.cpp">
<Filter>src\model</Filter>
</ClCompile>
<ClCompile Include="..\..\radiant\model\ModelFormatManager.cpp">
<Filter>src\model</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\RadiantModule.h">
Expand Down Expand Up @@ -1821,6 +1824,9 @@
<ClInclude Include="..\..\radiant\model\NullModelNode.h">
<Filter>src\model</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\model\ModelFormatManager.h">
<Filter>src\model</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\radiant\darkradiant.rc" />
Expand Down

0 comments on commit 646f87b

Please sign in to comment.