]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/entity/plugin.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / plugins / entity / 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 //
23 // Model Plugin
24 //
25
26 #include "plugin.h"
27 #include "entity.h"
28 #include "entity_entitymodel.h"
29 #include "light.h"
30
31 // =============================================================================
32 // Globals
33
34 // function tables
35 _QERFuncTable_1 g_FuncTable;
36 _QERQglTable g_QglTable;
37 _QERBrushTable __BRUSHTABLENAME;
38 _QERUndoTable __UNDOTABLENAME;
39 _EClassManagerTable __ECLASSMANAGERTABLENAME;
40
41 // =============================================================================
42 // SYNAPSE
43
44 class CSynapseClientEntity : public CSynapseClient
45 {
46 public:
47 // CSynapseClient API
48 bool RequestAPI( APIDescriptor_t *pAPI );
49 const char* GetInfo();
50
51 CSynapseClientEntity() { }
52 virtual ~CSynapseClientEntity() { }
53 };
54
55
56 CSynapseServer* g_pSynapseServer = NULL;
57 CSynapseClientEntity g_SynapseClient;
58
59 #if __GNUC__ >= 4
60 #pragma GCC visibility push(default)
61 #endif
62 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
63 #if __GNUC__ >= 4
64 #pragma GCC visibility pop
65 #endif
66         if ( strcmp( version, SYNAPSE_VERSION ) ) {
67                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
68                 return NULL;
69         }
70         g_pSynapseServer = pServer;
71         g_pSynapseServer->IncRef();
72         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
73
74         g_SynapseClient.AddAPI( ENTITY_MAJOR, NULL, sizeof( _QEREntityTable ) );
75         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( g_FuncTable ), SYN_REQUIRE, &g_FuncTable );
76         g_SynapseClient.AddAPI( QGL_MAJOR, NULL, sizeof( g_QglTable ), SYN_REQUIRE, &g_QglTable );
77         g_SynapseClient.AddAPI( BRUSH_MAJOR, NULL, sizeof( __BRUSHTABLENAME ), SYN_REQUIRE, &__BRUSHTABLENAME );
78         g_SynapseClient.AddAPI( UNDO_MAJOR, NULL, sizeof( __UNDOTABLENAME ), SYN_REQUIRE, &__UNDOTABLENAME );
79         g_SynapseClient.AddAPI( ECLASSMANAGER_MAJOR, NULL, sizeof( __ECLASSMANAGERTABLENAME ), SYN_REQUIRE, &__ECLASSMANAGERTABLENAME );
80
81         return &g_SynapseClient;
82 }
83
84 bool CSynapseClientEntity::RequestAPI( APIDescriptor_t *pAPI ){
85         if ( !strcmp( pAPI->major_name, ENTITY_MAJOR ) ) {
86                 _QEREntityTable* pTable = static_cast<_QEREntityTable*>( pAPI->mpTable );
87                 pTable->m_pfnEntity_Alloc = &Entity_Alloc;
88                 pTable->m_pfnEntity_Free = &Entity_Free;
89                 pTable->m_pfnEntity_Clone = &Entity_Clone;
90                 pTable->m_pfnSetKeyValue = &SetKeyValue;
91                 pTable->m_pfnDeleteKey = &DeleteKey;
92                 pTable->m_pfnValueForKey = &ValueForKey;
93                 pTable->m_pfnFloatForKey = &FloatForKey;
94                 pTable->m_pfnIntForKey = &IntForKey;
95                 pTable->m_pfnGetVectorForKey = &GetVectorForKey;
96                 pTable->m_pfnEntity_AddToList = &Entity_AddToList;
97                 pTable->m_pfnEntity_RemoveFromList = &Entity_RemoveFromList;
98                 pTable->m_pfnEntity_LinkBrush = &Entity_LinkBrush;
99                 pTable->m_pfnEntity_UnlinkBrush = &Entity_UnlinkBrush;
100                 pTable->m_pfnDrawLight = &DrawLight;
101                 pTable->m_pfnEntity_MemorySize = &Entity_MemorySize;
102                 pTable->m_pfnAllocateEpair = &Entity_AllocateEpair;
103                 pTable->m_pfnGetEntityKeyValList = &Entity_GetKeyValList;
104                 pTable->m_pfnSetEntityKeyValList = &Entity_SetKeyValList;
105
106                 return true;
107         }
108
109         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
110         return false;
111 }
112
113 #include "version.h"
114
115 const char* CSynapseClientEntity::GetInfo(){
116         return "Entity module built " __DATE__ " " RADIANT_VERSION;
117 }