]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/map/plugin.cpp
Merge pull request #47 from mrwonko/MapLoading
[xonotic/netradiant.git] / plugins / map / plugin.cpp
1 /*
2    Copyright (C) 1999-2007 id Software, Inc. and contributors.
3    For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 #include "plugin.h"
23
24 // =============================================================================
25 // Globals
26
27 // function tables
28 _QERFuncTable_1 g_FuncTable;
29 _QERScripLibTable g_ScripLibTable;
30 _QERShadersTable g_ShadersTable;
31 _QEREntityTable __ENTITYTABLENAME;
32 _QERBrushTable g_BrushTable;
33 _QERPatchTable g_PatchTable;
34 _QERFileSystemTable g_FileSystemTable;
35 /*!
36    the map version we have been initialized with: Q1/Q2/Q3
37    we provide all three formats in the same module
38  */
39 int g_MapVersion;
40
41 // =============================================================================
42 // SYNAPSE
43
44 CSynapseServer* g_pSynapseServer = NULL;
45 CSynapseClientMap g_SynapseClient;
46
47 static const XMLConfigEntry_t entries[] =
48 {
49         { SHADERS_MAJOR, SYN_REQUIRE, sizeof( g_ShadersTable ), &g_ShadersTable },
50         { NULL, SYN_UNKNOWN, 0, NULL }
51 };
52
53 #if __GNUC__ >= 4
54 #pragma GCC visibility push(default)
55 #endif
56 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
57 #if __GNUC__ >= 4
58 #pragma GCC visibility pop
59 #endif
60         if ( strcmp( version, SYNAPSE_VERSION ) ) {
61                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
62                 return NULL;
63         }
64         g_pSynapseServer = pServer;
65         g_pSynapseServer->IncRef();
66         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
67
68         g_SynapseClient.AddAPI( MAP_MAJOR, "mapq3", sizeof( _QERPlugMapTable ) );
69         g_SynapseClient.AddAPI( MAP_MAJOR, "maphl", sizeof( _QERPlugMapTable ) );
70         g_SynapseClient.AddAPI( MAP_MAJOR, "mapq2", sizeof( _QERPlugMapTable ) );
71         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
72         g_SynapseClient.AddAPI( SCRIPLIB_MAJOR, NULL, sizeof( g_ScripLibTable ), SYN_REQUIRE, &g_ScripLibTable );
73
74         // same trick as bobtoolz, see bug #828
75         g_SynapseClient.AddAPI( VFS_MAJOR, "*", sizeof( g_FileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
76
77         if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
78                 return NULL;
79         }
80
81         g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( __ENTITYTABLENAME ), SYN_REQUIRE, &__ENTITYTABLENAME );
82         g_SynapseClient.AddAPI( BRUSH_MAJOR, NULL, sizeof( g_BrushTable ), SYN_REQUIRE, &g_BrushTable );
83         g_SynapseClient.AddAPI( PATCH_MAJOR, NULL, sizeof( g_PatchTable ), SYN_REQUIRE, &g_PatchTable );
84
85         return &g_SynapseClient;
86 }
87
88 bool CSynapseClientMap::RequestAPI( APIDescriptor_t *pAPI ){
89         if ( !strcmp( pAPI->major_name, MAP_MAJOR ) ) {
90                 _QERPlugMapTable* pTable = static_cast<_QERPlugMapTable*>( pAPI->mpTable );
91                 if ( !strcmp( pAPI->minor_name, "mapq3" ) ) {
92                         pTable->m_pfnMap_Read = &Map_ReadQ3;
93                         pTable->m_pfnMap_Write = &Map_WriteQ3;
94                         return true;
95                 }
96                 if ( !strcmp( pAPI->minor_name, "maphl" ) ) {
97                         pTable->m_pfnMap_Read = &Map_ReadHL;
98                         pTable->m_pfnMap_Write = &Map_WriteHL;
99                         mbMapHL = true;
100                         return true;
101                 }
102                 if ( !strcmp( pAPI->minor_name, "mapq2" ) ) {
103                         pTable->m_pfnMap_Read = &Map_ReadQ2;
104                         pTable->m_pfnMap_Write = &Map_WriteQ2;
105                         return true;
106                 }
107                 Syn_Printf( "ERROR: RequestAPI( Major: '%s' Minor: '%s' ) not found in '%s'\n", pAPI->major_name, pAPI->minor_name, GetInfo() );
108                 return false;
109         }
110
111         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
112         return false;
113 }
114
115 bool CSynapseClientMap::OnActivate() {
116         return true;
117 }
118
119 #include "version.h"
120
121 const char* CSynapseClientMap::GetInfo(){
122         return "MAP format module built " __DATE__ " " RADIANT_VERSION;
123 }
124
125 const char* CSynapseClientMap::GetName(){
126         return "map";
127 }