3 Copyright (C) 1999-2007 id Software, Inc. and contributors.
4 For a list of contributors, see the accompanying CONTRIBUTORS file.
6 This file is part of GtkRadiant.
8 GtkRadiant is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 GtkRadiant is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GtkRadiant; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 // toolbar implementation
27 class CFlushReloadSelectedToolbarButton : public IToolbarButton
30 virtual const char* getImage() const
32 return "model_reload_entity.bmp";
34 virtual const char* getText() const
38 virtual const char* getTooltip() const
40 return "Flush & Reload Selected Model";
42 virtual void activate() const
44 DoFlushReloadSelected();
46 virtual EType getType() const
52 CFlushReloadSelectedToolbarButton g_flushreloadselected;
54 unsigned int ToolbarButtonCount()
59 const IToolbarButton* GetToolbarButton(unsigned int index)
61 return &g_flushreloadselected;
64 // =============================================================================
65 // Pico utility functions
67 #include "picomodel.h"
69 void PicoPrintFunc( int level, const char *str )
76 Sys_Printf( "%s\n", str );
80 Sys_FPrintf( SYS_VRB, "%s\n", str );
84 Sys_Printf( "WARNING: %s\n", str );
88 Sys_FPrintf( SYS_VRB, "ERROR: %s\n", str );
92 Sys_Printf( "ERROR: %s\n", str );
97 void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize )
99 *bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 );
102 void PicoFreeFileFunc( void* file )
107 static void initialise()
110 PicoSetMallocFunc( malloc );
111 PicoSetFreeFunc( free );
112 PicoSetPrintFunc( PicoPrintFunc );
113 PicoSetLoadFileFunc( PicoLoadFileFunc );
114 PicoSetFreeFileFunc( PicoFreeFileFunc );
117 static void add_model_apis(CSynapseClient& client)
119 const picoModule_t** modules = PicoModuleList( NULL );
120 while(*modules != NULL)
122 const picoModule_t* module = *modules++;
123 if(module->canload && module->load)
124 for(unsigned int j = 0; module->defaultExts[j] != NULL; j++)
125 client.AddAPI(MODEL_MAJOR, module->defaultExts[j], sizeof(_QERPlugModelTable));
129 static bool model_is_supported(const char* extension)
131 const picoModule_t** modules = PicoModuleList( NULL );
132 while(*modules != NULL)
134 const picoModule_t* module = *modules++;
135 if(module->canload && module->load)
136 for(unsigned int j = 0; module->defaultExts[j] != NULL; j++)
137 if(strcmp(extension, module->defaultExts[j]) == 0)
143 void init_filetypes()
145 const picoModule_t **modules = PicoModuleList(NULL);
146 while(*modules != NULL)
148 const picoModule_t* module = *modules++;
149 if(module->canload && module->load)
151 for(char*const* ext = module->defaultExts; *ext != NULL; ++ext)
157 GetFileTypeRegistry()->addType(MODEL_MAJOR, filetype_t(module->displayName, buf));
163 // plugin implementation
165 static const char *PLUGIN_NAME = "Model loading module";
166 static const char *PLUGIN_COMMANDS = "About;-;Flush & Reload Models;Flush & Reload Selected";
167 static const char *PLUGIN_ABOUT = "Model Module v1.0 for GtkRadiant\nby Arnout van Meer (rr2do2@splashdamage.com)\n\nBased on the MD3Model Module by SPoG\nPicoModel Library Copyright (c) 2002, Randy Reddig & seaw0lf";
169 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
172 return (char *) PLUGIN_NAME;
175 extern "C" const char* QERPlug_GetName ()
177 return (char *) PLUGIN_NAME;
180 extern "C" const char* QERPlug_GetCommandList ()
182 return (char *) PLUGIN_COMMANDS;
185 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
187 if( !strcmp( p, "Flush & Reload Selected" ) )
188 DoFlushReloadSelected();
189 else if( !strcmp( p, "Flush & Reload Models" ) )
191 else if( !strcmp( p, "About" ) )
192 g_FuncTable.m_pfnMessageBox(NULL, PLUGIN_ABOUT, "About", MB_OK, NULL);
196 void DoFlushReloadSelected() {
199 void DoFlushReloadAll() {
200 GetModelCache()->RefreshAll();
203 // =============================================================================
206 _QERFuncTable_1 g_FuncTable;
207 _QERQglTable g_QglTable;
208 _QERShadersTable g_ShadersTable;
209 _QERFileSystemTable g_FileSystemTable;
211 // =============================================================================
214 CSynapseServer* g_pSynapseServer = NULL;
215 CSynapseClientModel g_SynapseClient;
217 static const XMLConfigEntry_t entries[] =
218 { { SHADERS_MAJOR, SYN_REQUIRE, sizeof(g_ShadersTable), &g_ShadersTable },
219 { VFS_MAJOR, SYN_REQUIRE, sizeof(g_FileSystemTable), &g_FileSystemTable },
220 { NULL, SYN_UNKNOWN, 0, NULL } };
223 #pragma GCC visibility push(default)
225 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
227 #pragma GCC visibility pop
229 if (strcmp(version, SYNAPSE_VERSION))
231 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
234 g_pSynapseServer = pServer;
235 g_pSynapseServer->IncRef();
236 Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
240 add_model_apis(g_SynapseClient);
241 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "model", sizeof(_QERPlugToolbarTable));
242 g_SynapseClient.AddAPI(PLUGIN_MAJOR, "model", sizeof(_QERPluginTable));
244 g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
245 g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
247 if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
251 return &g_SynapseClient;
254 bool CSynapseClientModel::RequestAPI(APIDescriptor_t *pAPI)
256 if (!strcmp(pAPI->major_name, MODEL_MAJOR))
258 _QERPlugModelTable* pTable= static_cast<_QERPlugModelTable*>(pAPI->mpTable);
260 if (model_is_supported(pAPI->minor_name))
262 pTable->m_pfnLoadModel = &LoadModel;
266 else if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
268 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
270 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
271 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
274 else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
276 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
278 pTable->m_pfnQERPlug_Init = QERPlug_Init;
279 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
280 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
281 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
285 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
291 const char* CSynapseClientModel::GetInfo()
293 return "picomodel loader module built " __DATE__ " " RADIANT_VERSION;
296 const char* CSynapseClientModel::GetName()