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 {
31 return "model_reload_entity.bmp";
33 virtual const char* getText() const {
36 virtual const char* getTooltip() const {
37 return "Flush & Reload Selected Model";
39 virtual void activate() const {
40 DoFlushReloadSelected();
42 virtual EType getType() const {
47 CFlushReloadSelectedToolbarButton g_flushreloadselected;
49 unsigned int ToolbarButtonCount(){
53 const IToolbarButton* GetToolbarButton( unsigned int index ){
54 return &g_flushreloadselected;
57 // =============================================================================
58 // Pico utility functions
60 #include "picomodel.h"
62 void PicoPrintFunc( int level, const char *str ){
69 Sys_Printf( "%s\n", str );
73 Sys_FPrintf( SYS_VRB, "%s\n", str );
77 Sys_Printf( "WARNING: %s\n", str );
81 Sys_FPrintf( SYS_VRB, "ERROR: %s\n", str );
85 Sys_Printf( "ERROR: %s\n", str );
90 void PicoLoadFileFunc( char *name, byte **buffer, int *bufSize ){
91 *bufSize = vfsLoadFile( (const char*) name, (void**) buffer, 0 );
94 void PicoFreeFileFunc( void* file ){
98 static void initialise(){
100 PicoSetMallocFunc( malloc );
101 PicoSetFreeFunc( free );
102 PicoSetPrintFunc( PicoPrintFunc );
103 PicoSetLoadFileFunc( PicoLoadFileFunc );
104 PicoSetFreeFileFunc( PicoFreeFileFunc );
107 static void add_model_apis( CSynapseClient& client ){
108 const picoModule_t** modules = PicoModuleList( NULL );
109 while ( *modules != NULL )
111 const picoModule_t* module = *modules++;
112 if ( module->canload && module->load ) {
113 for ( unsigned int j = 0; module->defaultExts[j] != NULL; j++ )
114 client.AddAPI( MODEL_MAJOR, module->defaultExts[j], sizeof( _QERPlugModelTable ) );
119 static bool model_is_supported( const char* extension ){
120 const picoModule_t** modules = PicoModuleList( NULL );
121 while ( *modules != NULL )
123 const picoModule_t* module = *modules++;
124 if ( module->canload && module->load ) {
125 for ( unsigned int j = 0; module->defaultExts[j] != NULL; j++ )
126 if ( strcmp( extension, module->defaultExts[j] ) == 0 ) {
134 void init_filetypes(){
135 const picoModule_t **modules = PicoModuleList( NULL );
136 while ( *modules != NULL )
138 const picoModule_t* module = *modules++;
139 if ( module->canload && module->load ) {
140 for ( char*const* ext = module->defaultExts; *ext != NULL; ++ext )
145 strcpy( buf + 2, *ext );
146 GetFileTypeRegistry()->addType( MODEL_MAJOR, filetype_t( module->displayName, buf ) );
152 // plugin implementation
154 static const char *PLUGIN_NAME = "Model loading module";
155 static const char *PLUGIN_COMMANDS = "About;-;Flush & Reload Models;Flush & Reload Selected";
156 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";
158 extern "C" const char* QERPlug_Init( void *hApp, void* pMainWidget ){
160 return (char *) PLUGIN_NAME;
163 extern "C" const char* QERPlug_GetName(){
164 return (char *) PLUGIN_NAME;
167 extern "C" const char* QERPlug_GetCommandList(){
168 return (char *) PLUGIN_COMMANDS;
171 extern "C" void QERPlug_Dispatch( const char *p, vec3_t vMin, vec3_t vMax, bool bSingleBrush ){
172 if ( !strcmp( p, "Flush & Reload Selected" ) ) {
173 DoFlushReloadSelected();
175 else if ( !strcmp( p, "Flush & Reload Models" ) ) {
178 else if ( !strcmp( p, "About" ) ) {
179 const picoModule_t** modules = PicoModuleList( NULL );
180 char about_buf[1024];
181 strncpy( about_buf, PLUGIN_ABOUT, sizeof( about_buf ) - 1 );
182 while ( *modules != NULL ) {
183 const picoModule_t* module = *modules++;
184 strncat( about_buf, module->displayName, sizeof( about_buf ) - 1 );
185 strncat( about_buf, " (", sizeof( about_buf ) - 1 );
186 strncat( about_buf, module->defaultExts[0], sizeof( about_buf ) - 1 );
187 strncat( about_buf, ")\n\t", sizeof( about_buf ) - 1 );
188 strncat( about_buf, module->copyright, sizeof( about_buf ) - 1 );
189 strncat( about_buf, "\n", sizeof( about_buf ) - 1 );
191 g_FuncTable.m_pfnMessageBox( NULL, about_buf, "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 ) ) {
230 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
233 g_pSynapseServer = pServer;
234 g_pSynapseServer->IncRef();
235 Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
239 add_model_apis( g_SynapseClient );
240 g_SynapseClient.AddAPI( TOOLBAR_MAJOR, "model", sizeof( _QERPlugToolbarTable ) );
241 g_SynapseClient.AddAPI( PLUGIN_MAJOR, "model", sizeof( _QERPluginTable ) );
243 g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
244 g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
246 if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
250 return &g_SynapseClient;
253 bool CSynapseClientModel::RequestAPI( APIDescriptor_t *pAPI ){
254 if ( !strcmp( pAPI->major_name, MODEL_MAJOR ) ) {
255 _QERPlugModelTable* pTable = static_cast<_QERPlugModelTable*>( pAPI->mpTable );
257 if ( model_is_supported( pAPI->minor_name ) ) {
258 pTable->m_pfnLoadModel = &LoadModel;
262 else if ( !strcmp( pAPI->major_name, TOOLBAR_MAJOR ) ) {
263 _QERPlugToolbarTable* pTable = static_cast<_QERPlugToolbarTable*>( pAPI->mpTable );
265 pTable->m_pfnToolbarButtonCount = &ToolbarButtonCount;
266 pTable->m_pfnGetToolbarButton = &GetToolbarButton;
269 else if ( !strcmp( pAPI->major_name, PLUGIN_MAJOR ) ) {
270 _QERPluginTable* pTable = static_cast<_QERPluginTable*>( pAPI->mpTable );
272 pTable->m_pfnQERPlug_Init = QERPlug_Init;
273 pTable->m_pfnQERPlug_GetName = QERPlug_GetName;
274 pTable->m_pfnQERPlug_GetCommandList = QERPlug_GetCommandList;
275 pTable->m_pfnQERPlug_Dispatch = QERPlug_Dispatch;
279 Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
285 const char* CSynapseClientModel::GetInfo(){
286 return "picomodel loader module built " __DATE__ " " RADIANT_VERSION;
289 const char* CSynapseClientModel::GetName(){