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 #if 0 // stop using windowing systems in plugins - put the text in SynapseClient::GetInfo
26 // =============================================================================
28 static void dialog_button_callback (GtkWidget *widget, gpointer data)
33 parent = gtk_widget_get_toplevel (widget);
34 loop = (int*)g_object_get_data (G_OBJECT (parent), "loop");
35 ret = (int*)g_object_get_data (G_OBJECT (parent), "ret");
41 static gint dialog_delete_callback (GtkWidget *widget, GdkEvent* event, gpointer data)
45 gtk_widget_hide (widget);
46 loop = (int*)g_object_get_data (G_OBJECT (widget), "loop");
52 int DoAboutBox( GtkWidget *parent )
54 GtkWidget *window, *w, *text, *vbox, *hbox, *hbox2, *frame;
60 const picoModule_t **modules, *pm;
62 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
63 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
64 GTK_SIGNAL_FUNC (dialog_delete_callback), NULL);
65 gtk_signal_connect (GTK_OBJECT (window), "destroy",
66 GTK_SIGNAL_FUNC (gtk_widget_destroy), NULL);
67 gtk_window_set_title (GTK_WINDOW (window), "About...");
68 gtk_container_border_width (GTK_CONTAINER (window), 10);
69 g_object_set_data (G_OBJECT (window), "loop", &loop);
70 g_object_set_data (G_OBJECT (window), "ret", &ret);
71 gtk_widget_realize (window);
74 gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (parent));
76 vbox = gtk_vbox_new (FALSE, 10);
77 gtk_container_add (GTK_CONTAINER (window), vbox);
78 gtk_widget_show (vbox);
80 style = gtk_widget_get_style(window);
82 hbox2 = gtk_hbox_new (FALSE, 10);
83 gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 2);
84 gtk_widget_show (hbox2);
86 frame = gtk_frame_new (NULL);
87 gtk_box_pack_start (GTK_BOX (hbox2), frame, FALSE, FALSE, 2);
88 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
89 gtk_widget_show (frame);
91 if( g_FuncTable.m_pfnLoadBitmap( "picomodel.bmp", (void **)&pixmap, (void **)&mask ) ) {
92 w = gtk_pixmap_new (pixmap, mask);
93 gtk_container_add (GTK_CONTAINER (frame), w);
97 w = gtk_label_new ("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" );
98 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 2);
99 gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT);
102 w = gtk_scrolled_window_new(NULL, NULL);
103 gtk_box_pack_start(GTK_BOX(vbox), w, TRUE, TRUE, 2);
104 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(w), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
107 text = gtk_text_new(NULL, NULL);
108 gtk_text_set_editable(GTK_TEXT(text), FALSE);
109 gtk_container_add(GTK_CONTAINER(w), text);
111 strcpy( buf, "#Supported Model Formats:\n" );
112 gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buf, -1);
114 for( modules = PicoModuleList( NULL ); *modules != NULL; modules++ )
121 sprintf( buf, "\n%s, version %s, (c) %s", pm->displayName, pm->version, pm->copyright );
122 gtk_text_insert(GTK_TEXT(text), NULL, NULL, NULL, buf, -1);
125 gtk_text_set_word_wrap(GTK_TEXT(text), FALSE);
126 gtk_widget_show(text);
128 gtk_text_set_point(GTK_TEXT(text), 0);
129 gtk_text_forward_delete(GTK_TEXT(text), 1);
131 w = gtk_hseparator_new ();
132 gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 2);
135 hbox = gtk_hbox_new (FALSE, 10);
136 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2);
137 gtk_widget_show (hbox);
139 w = gtk_button_new_with_label ("Ok");
140 gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
141 gtk_signal_connect (GTK_OBJECT (w), "clicked",
142 GTK_SIGNAL_FUNC (dialog_button_callback), GINT_TO_POINTER (IDOK));
143 GTK_WIDGET_SET_FLAGS (w, GTK_CAN_DEFAULT);
144 gtk_widget_grab_default (w);
148 gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
149 gtk_widget_show (window);
150 gtk_grab_add (window);
153 gtk_main_iteration ();
155 gtk_grab_remove (window);
156 gtk_widget_destroy (window);
162 // toolbar implementation
164 class CFlushReloadSelectedToolbarButton : public IToolbarButton
167 virtual const char* getImage() const
169 return "model_reload_entity.bmp";
171 virtual const char* getText() const
175 virtual const char* getTooltip() const
177 return "Flush & Reload Selected Model";
179 virtual void activate() const
181 DoFlushReloadSelected();
183 virtual EType getType() const
189 CFlushReloadSelectedToolbarButton g_flushreloadselected;
191 unsigned int ToolbarButtonCount()
196 const IToolbarButton* GetToolbarButton(unsigned int index)
198 return &g_flushreloadselected;
201 // =============================================================================
202 // Pico utility functions
204 #include "picomodel.h"
206 void PicoPrintFunc( int level, const char *str )
213 Sys_Printf( "%s\n", str );
217 Sys_FPrintf( SYS_VRB, "%s\n", str );
221 Sys_Printf( "WARNING: %s\n", str );
225 Sys_FPrintf( SYS_VRB, "ERROR: %s\n", str );
229 Sys_Printf( "ERROR: %s\n", str );
234 void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize )
236 *bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 );
239 void PicoFreeFileFunc( void* file )
244 static void initialise()
247 PicoSetMallocFunc( malloc );
248 PicoSetFreeFunc( free );
249 PicoSetPrintFunc( PicoPrintFunc );
250 PicoSetLoadFileFunc( PicoLoadFileFunc );
251 PicoSetFreeFileFunc( PicoFreeFileFunc );
254 static void add_model_apis(CSynapseClient& client)
256 const picoModule_t** modules = PicoModuleList( NULL );
257 while(*modules != NULL)
259 const picoModule_t* module = *modules++;
260 if(module->canload && module->load)
261 for(unsigned int j = 0; module->defaultExts[j] != NULL; j++)
262 client.AddAPI(MODEL_MAJOR, module->defaultExts[j], sizeof(_QERPlugModelTable));
266 static bool model_is_supported(const char* extension)
268 const picoModule_t** modules = PicoModuleList( NULL );
269 while(*modules != NULL)
271 const picoModule_t* module = *modules++;
272 if(module->canload && module->load)
273 for(unsigned int j = 0; module->defaultExts[j] != NULL; j++)
274 if(strcmp(extension, module->defaultExts[j]) == 0)
280 void init_filetypes()
282 const picoModule_t **modules = PicoModuleList(NULL);
283 while(*modules != NULL)
285 const picoModule_t* module = *modules++;
286 if(module->canload && module->load)
288 for(char*const* ext = module->defaultExts; *ext != NULL; ++ext)
294 GetFileTypeRegistry()->addType(MODEL_MAJOR, filetype_t(module->displayName, buf));
300 // plugin implementation
302 static const char *PLUGIN_NAME = "Model loading module";
303 static const char *PLUGIN_COMMANDS = "Flush & Reload Models,Flush & Reload Selected";
304 static const char *PLUGIN_ABOUT = "Model loading module";
306 extern "C" const char* QERPlug_Init (void *hApp, void* pMainWidget)
309 return (char *) PLUGIN_NAME;
312 extern "C" const char* QERPlug_GetName ()
314 return (char *) PLUGIN_NAME;
317 extern "C" const char* QERPlug_GetCommandList ()
319 return (char *) PLUGIN_COMMANDS;
322 extern "C" void QERPlug_Dispatch (const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush)
324 if( !strcmp( p, "Flush & Reload Selected" ) )
325 DoFlushReloadSelected();
326 else if( !strcmp( p, "Flush & Reload Models" ) )
331 void DoFlushReloadSelected() {
334 void DoFlushReloadAll() {
335 GetModelCache()->RefreshAll();
338 // =============================================================================
341 _QERFuncTable_1 g_FuncTable;
342 _QERQglTable g_QglTable;
343 _QERShadersTable g_ShadersTable;
344 _QERFileSystemTable g_FileSystemTable;
346 // =============================================================================
349 CSynapseServer* g_pSynapseServer = NULL;
350 CSynapseClientModel g_SynapseClient;
352 static const XMLConfigEntry_t entries[] =
353 { { SHADERS_MAJOR, SYN_REQUIRE, sizeof(g_ShadersTable), &g_ShadersTable },
354 { VFS_MAJOR, SYN_REQUIRE, sizeof(g_FileSystemTable), &g_FileSystemTable },
355 { NULL, SYN_UNKNOWN, 0, NULL } };
358 #pragma GCC visibility push(default)
360 extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
362 #pragma GCC visibility pop
364 if (strcmp(version, SYNAPSE_VERSION))
366 Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
369 g_pSynapseServer = pServer;
370 g_pSynapseServer->IncRef();
371 Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
375 add_model_apis(g_SynapseClient);
376 g_SynapseClient.AddAPI(TOOLBAR_MAJOR, "model", sizeof(_QERPlugToolbarTable));
377 g_SynapseClient.AddAPI(PLUGIN_MAJOR, "model", sizeof(_QERPluginTable));
379 g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(g_FuncTable), SYN_REQUIRE, &g_FuncTable);
380 g_SynapseClient.AddAPI(QGL_MAJOR, NULL, sizeof(g_QglTable), SYN_REQUIRE, &g_QglTable);
382 if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
386 return &g_SynapseClient;
389 bool CSynapseClientModel::RequestAPI(APIDescriptor_t *pAPI)
391 if (!strcmp(pAPI->major_name, MODEL_MAJOR))
393 _QERPlugModelTable* pTable= static_cast<_QERPlugModelTable*>(pAPI->mpTable);
395 if (model_is_supported(pAPI->minor_name))
397 pTable->m_pfnLoadModel = &LoadModel;
401 else if (!strcmp(pAPI->major_name, TOOLBAR_MAJOR))
403 _QERPlugToolbarTable* pTable= static_cast<_QERPlugToolbarTable*>(pAPI->mpTable);
405 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
406 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
409 else if (!strcmp(pAPI->major_name, PLUGIN_MAJOR))
411 _QERPluginTable* pTable= static_cast<_QERPluginTable*>(pAPI->mpTable);
413 pTable->m_pfnQERPlug_Init = QERPlug_Init;
414 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
415 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
416 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
420 Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
426 const char* CSynapseClientModel::GetInfo()
428 return "picomodel loader module built " __DATE__ " " RADIANT_VERSION;
431 const char* CSynapseClientModel::GetName()