]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/imagem8/imagem8.cpp
uncrustify! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / plugins / imagem8 / imagem8.cpp
1 /*
2    Copyright (c) 2001, Loki software, inc.
3    All rights reserved.
4
5    Redistribution and use in source and binary forms, with or without modification,
6    are permitted provided that the following conditions are met:
7
8    Redistributions of source code must retain the above copyright notice, this list
9    of conditions and the following disclaimer.
10
11    Redistributions in binary form must reproduce the above copyright notice, this
12    list of conditions and the following disclaimer in the documentation and/or
13    other materials provided with the distribution.
14
15    Neither the name of Loki software nor the names of its contributors may be used
16    to endorse or promote products derived from this software without specific prior
17    written permission.
18
19    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
20    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22    DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
23    DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 //
32 // Image loading plugin
33 //
34 // Leonardo Zide (leo@lokigames.com)
35 //
36
37 #include <stdio.h>
38 #include "imagem8.h"
39
40 // =============================================================================
41 // global tables
42
43 _QERFuncTable_1 g_FuncTable; // Radiant function table
44 _QERFileSystemTable g_FileSystemTable;
45
46 // =============================================================================
47 // SYNAPSE
48
49 CSynapseServer* g_pSynapseServer = NULL;
50 CSynapseClientImage g_SynapseClient;
51
52 #if __GNUC__ >= 4
53 #pragma GCC visibility push(default)
54 #endif
55 extern "C" CSynapseClient * SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces( const char *version, CSynapseServer *pServer ) {
56 #if __GNUC__ >= 4
57 #pragma GCC visibility pop
58 #endif
59         if ( strcmp( version, SYNAPSE_VERSION ) ) {
60                 Syn_Printf( "ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version );
61                 return NULL;
62         }
63         g_pSynapseServer = pServer;
64         g_pSynapseServer->IncRef();
65         Set_Syn_Printf( g_pSynapseServer->Get_Syn_Printf() );
66
67         g_SynapseClient.AddAPI( IMAGE_MAJOR, "m8", sizeof( _QERPlugImageTable ) );
68         g_SynapseClient.AddAPI( IMAGE_MAJOR, "m32", sizeof( _QERPlugImageTable ) );
69         g_SynapseClient.AddAPI( RADIANT_MAJOR, NULL, sizeof( _QERFuncTable_1 ), SYN_REQUIRE, &g_FuncTable );
70
71         Syn_Printf( "Dynamic APIs for client '%s'\n", g_SynapseClient.GetInfo() );
72         if ( !g_pSynapseServer->SelectClientConfig( g_SynapseClient.GetName() ) ) {
73                 Syn_Printf( "ERROR: Failed to select synapse client config in '%s'\n", g_SynapseClient.GetInfo() );
74                 return NULL;
75         }
76         char *api, *minor;
77         while ( g_pSynapseServer->GetNextConfig( &api, &minor ) )
78         {
79                 Syn_Printf( "api: '%s' minor: '%s'\n", api, minor );
80                 if ( !strcmp( api, VFS_MAJOR ) ) {
81                         g_SynapseClient.AddAPI( VFS_MAJOR, minor, sizeof( _QERFileSystemTable ), SYN_REQUIRE, &g_FileSystemTable );
82                 }
83                 else
84                 {
85                         Syn_Printf( "WARNING: unknown API node '%s' in synapse config from module '%s'\n", api, g_SynapseClient.GetInfo() );
86                 }
87         }
88         return &g_SynapseClient;
89 }
90
91 bool CSynapseClientImage::RequestAPI( APIDescriptor_t *pAPI ){
92         if ( !strcmp( pAPI->major_name, IMAGE_MAJOR ) ) {
93                 _QERPlugImageTable* pTable = static_cast<_QERPlugImageTable*>( pAPI->mpTable );
94                 if ( !strcmp( pAPI->minor_name, "m8" ) ) {
95                         pTable->m_pfnLoadImage = &LoadM8;
96                         return true;
97                 }
98                 if ( !strcmp( pAPI->minor_name, "m32" ) ) {
99                         pTable->m_pfnLoadImage = &LoadM32;
100                         return true;
101                 }
102         }
103
104         Syn_Printf( "ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo() );
105         return false;
106 }
107
108 bool CSynapseClientImage::OnActivate() {
109         if ( !g_FileSystemTable.m_nSize ) {
110                 Syn_Printf( "ERROR: VFS_MAJOR table was not initialized before OnActivate in '%s' - incomplete synapse.config?\n", GetInfo() );
111                 return false;
112         }
113         return true;
114 }
115
116 #include "version.h"
117
118 const char* CSynapseClientImage::GetInfo(){
119         return "M8 M32 formats module built " __DATE__ " " RADIANT_VERSION;
120 }