2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "picomodel.h"
26 typedef unsigned char byte;
31 #include "iscenegraph.h"
33 #include "iselection.h"
37 #include "ifilesystem.h"
39 #include "ifiletypes.h"
41 #include "modulesystem/singletonmodule.h"
42 #include "stream/textstream.h"
43 #include "string/string.h"
44 #include "stream/stringstream.h"
45 #include "typesystem.h"
49 void PicoPrintFunc( int level, const char *str ){
56 globalOutputStream() << str << "\n";
60 //globalOutputStream() << "PICO_VERBOSE: " << str << "\n";
64 globalErrorStream() << "PICO_WARNING: " << str << "\n";
68 globalErrorStream() << "PICO_ERROR: " << str << "\n";
72 globalErrorStream() << "PICO_FATAL: " << str << "\n";
77 void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ){
78 *bufSize = vfsLoadFile( name, (void**) buffer );
81 void PicoFreeFileFunc( void* file ){
85 void pico_initialise(){
87 PicoSetMallocFunc( malloc );
88 PicoSetFreeFunc( free );
89 PicoSetPrintFunc( PicoPrintFunc );
90 PicoSetLoadFileFunc( PicoLoadFileFunc );
91 PicoSetFreeFileFunc( PicoFreeFileFunc );
95 class PicoModelLoader : public ModelLoader
97 const picoModule_t* m_module;
99 PicoModelLoader( const picoModule_t* module ) : m_module( module ){
101 scene::Node& loadModel( ArchiveFile& file ){
102 return loadPicoModel( m_module, file );
106 class ModelPicoDependencies :
107 public GlobalFileSystemModuleRef,
108 public GlobalOpenGLModuleRef,
109 public GlobalUndoModuleRef,
110 public GlobalSceneGraphModuleRef,
111 public GlobalShaderCacheModuleRef,
112 public GlobalSelectionModuleRef,
113 public GlobalFiletypesModuleRef
117 class ModelPicoAPI : public TypeSystemRef
119 PicoModelLoader m_modelLoader;
121 typedef ModelLoader Type;
123 ModelPicoAPI( const char* extension, const picoModule_t* module ) :
124 m_modelLoader( module ){
125 StringOutputStream filter( 128 );
126 filter << "*." << extension;
127 GlobalFiletypesModule::getTable().addType( Type::Name(), extension, filetype_t( module->displayName, filter.c_str() ) );
129 ModelLoader* getTable(){
130 return &m_modelLoader;
134 class PicoModelAPIConstructor
136 std::string m_extension;
137 const picoModule_t* m_module;
139 PicoModelAPIConstructor( const char* extension, const picoModule_t* module ) :
140 m_extension( extension ), m_module( module ){
142 const char* getName(){
143 return m_extension.c_str();
145 ModelPicoAPI* constructAPI( ModelPicoDependencies& dependencies ){
146 return new ModelPicoAPI( m_extension.c_str(), m_module );
148 void destroyAPI( ModelPicoAPI* api ){
154 typedef SingletonModule<ModelPicoAPI, ModelPicoDependencies, PicoModelAPIConstructor> PicoModelModule;
155 typedef std::list<PicoModelModule> PicoModelModules;
156 PicoModelModules g_PicoModelModules;
159 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
160 initialiseModule( server );
164 const picoModule_t** modules = PicoModuleList( 0 );
165 while ( *modules != 0 )
167 const picoModule_t* module = *modules++;
168 if ( module->canload && module->load ) {
169 for ( char*const* ext = module->defaultExts; *ext != 0; ++ext )
171 g_PicoModelModules.push_back( PicoModelModule( PicoModelAPIConstructor( *ext, module ) ) );
172 g_PicoModelModules.back().selfRegister();