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