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
23 #include "picomodel.h"
24 typedef unsigned char byte;
29 #include "iscenegraph.h"
31 #include "iselection.h"
35 #include "ifilesystem.h"
37 #include "ifiletypes.h"
39 #include "modulesystem/singletonmodule.h"
40 #include "stream/textstream.h"
41 #include "string/string.h"
42 #include "stream/stringstream.h"
43 #include "typesystem.h"
47 void PicoPrintFunc( int level, const char *str ){
54 globalOutputStream() << str << "\n";
58 //globalOutputStream() << "PICO_VERBOSE: " << str << "\n";
62 globalErrorStream() << "PICO_WARNING: " << str << "\n";
66 globalErrorStream() << "PICO_ERROR: " << str << "\n";
70 globalErrorStream() << "PICO_FATAL: " << str << "\n";
75 void PicoLoadFileFunc( const char *name, byte **buffer, int *bufSize ){
76 *bufSize = vfsLoadFile( name, (void**) buffer );
79 void PicoFreeFileFunc( void* file ){
83 void pico_initialise(){
85 PicoSetMallocFunc( malloc );
86 PicoSetFreeFunc( free );
87 PicoSetPrintFunc( PicoPrintFunc );
88 PicoSetLoadFileFunc( PicoLoadFileFunc );
89 PicoSetFreeFileFunc( PicoFreeFileFunc );
93 class PicoModelLoader : public ModelLoader
95 const picoModule_t* m_module;
97 PicoModelLoader( const picoModule_t* module ) : m_module( module ){
99 scene::Node& loadModel( ArchiveFile& file ){
100 return loadPicoModel( m_module, file );
104 class ModelPicoDependencies :
105 public GlobalFileSystemModuleRef,
106 public GlobalOpenGLModuleRef,
107 public GlobalUndoModuleRef,
108 public GlobalSceneGraphModuleRef,
109 public GlobalShaderCacheModuleRef,
110 public GlobalSelectionModuleRef,
111 public GlobalFiletypesModuleRef
115 class ModelPicoAPI : public TypeSystemRef
117 PicoModelLoader m_modelLoader;
119 typedef ModelLoader Type;
121 ModelPicoAPI( const char* extension, const picoModule_t* module ) :
122 m_modelLoader( module ){
123 StringOutputStream filter( 128 );
124 filter << "*." << extension;
125 GlobalFiletypesModule::getTable().addType( Type::Name(), extension, filetype_t( module->displayName, filter.c_str() ) );
127 ModelLoader* getTable(){
128 return &m_modelLoader;
132 class PicoModelAPIConstructor
134 CopiedString m_extension;
135 const picoModule_t* m_module;
137 PicoModelAPIConstructor( const char* extension, const picoModule_t* module ) :
138 m_extension( extension ), m_module( module ){
140 const char* getName(){
141 return m_extension.c_str();
143 ModelPicoAPI* constructAPI( ModelPicoDependencies& dependencies ){
144 return new ModelPicoAPI( m_extension.c_str(), m_module );
146 void destroyAPI( ModelPicoAPI* api ){
152 typedef SingletonModule<ModelPicoAPI, ModelPicoDependencies, PicoModelAPIConstructor> PicoModelModule;
153 typedef std::list<PicoModelModule> PicoModelModules;
154 PicoModelModules g_PicoModelModules;
157 extern "C" void RADIANT_DLLEXPORT Radiant_RegisterModules( ModuleServer& server ){
158 initialiseModule( server );
162 const picoModule_t** modules = PicoModuleList( 0 );
163 while ( *modules != 0 )
165 const picoModule_t* module = *modules++;
166 if ( module->canload && module->load ) {
167 for ( char*const* ext = module->defaultExts; *ext != 0; ++ext )
169 g_PicoModelModules.push_back( PicoModelModule( PicoModelAPIConstructor( *ext, module ) ) );
170 g_PicoModelModules.back().selfRegister();