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\n\nSupported models:\n";
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 const picoModule_t** modules = PicoModuleList( NULL );
193 char about_buf[1024];
194 strncpy(about_buf, PLUGIN_ABOUT, sizeof(about_buf) - 1);
195 while(*modules != NULL) {
196 const picoModule_t* module = *modules++;
197 strncat(about_buf, module->displayName, sizeof(about_buf) - 1);
198 strncat(about_buf, " (", sizeof(about_buf) - 1);
199 strncat(about_buf, module->defaultExts[0], sizeof(about_buf) - 1);
200 strncat(about_buf, ")\n\t", sizeof(about_buf) - 1);
201 strncat(about_buf, module->copyright, sizeof(about_buf) - 1);
202 strncat(about_buf, "\n", sizeof(about_buf) - 1);
204 g_FuncTable.m_pfnMessageBox(NULL, about_buf, "About", MB_OK, NULL);
209 void DoFlushReloadSelected() {
212 void DoFlushReloadAll() {
213 GetModelCache()->RefreshAll();
216 // =============================================================================
219 _QERFuncTable_1 g_FuncTable;
220 _QERQglTable g_QglTable;
221 _QERShadersTable g_ShadersTable;
222 _QERFileSystemTable g_FileSystemTable;
224 // =============================================================================
227 CSynapseServer* g_pSynapseServer = NULL;
228 CSynapseClientModel g_SynapseClient;
230 static const XMLConfigEntry_t entries[] =
231 { { SHADERS_MAJOR, SYN_REQUIRE, sizeof(g_ShadersTable), &g_ShadersTable },
232 { VFS_MAJOR, SYN_REQUIRE, sizeof(g_FileSystemTable), &g_FileSystemTable },
233 { NULL, SYN_UNKNOWN, 0, NULL } };
236 #pragma GCC visibility push(default)
238 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
240 #pragma GCC visibility pop
242 if (strcmp(version, SYNAPSE_VERSION))
244 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
247 g_pSynapseServer = pServer;
248 g_pSynapseServer->IncRef();
249 Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
253 add_model_apis(g_SynapseClient);
254 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "model", sizeof(_QERPlugToolbarTable));
255 g_SynapseClient.AddAPI(PLUGIN_MAJOR, "model", sizeof(_QERPluginTable));
257 g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
258 g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
260 if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
264 return &g_SynapseClient;
267 bool CSynapseClientModel::RequestAPI(APIDescriptor_t *pAPI)
269 if (!strcmp(pAPI->major_name, MODEL_MAJOR))
271 _QERPlugModelTable* pTable= static_cast<_QERPlugModelTable*>(pAPI->mpTable);
273 if (model_is_supported(pAPI->minor_name))
275 pTable->m_pfnLoadModel = &LoadModel;
279 else if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
281 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
283 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
284 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
287 else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
289 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
291 pTable->m_pfnQERPlug_Init = QERPlug_Init;
292 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
293 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
294 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
298 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
304 const char* CSynapseClientModel::GetInfo()
306 return "picomodel loader module built " __DATE__ " " RADIANT_VERSION;
309 const char* CSynapseClientModel::GetName()