transfer from internal tree r5311 branches/1.4-gpl
git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/ZeroRadiant@177 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
8
plugins/mapxml/mapxml.def
Normal file
8
plugins/mapxml/mapxml.def
Normal file
@@ -0,0 +1,8 @@
|
||||
; mapxml.def : Declares the module parameters for the DLL.
|
||||
|
||||
LIBRARY "MAPXML"
|
||||
DESCRIPTION 'MAPXML Windows Dynamic Link Library'
|
||||
|
||||
EXPORTS
|
||||
; Explicit exports can go here
|
||||
Synapse_EnumerateInterfaces @1
|
||||
85
plugins/mapxml/mapxml.vcproj
Normal file
85
plugins/mapxml/mapxml.vcproj
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" ?><VisualStudioProject Name="mapxml" ProjectGUID="{DDBF170A-42DF-4836-9006-816422E08493}" ProjectType="Visual C++" RootNamespace="mapxml" Version="8.00">
|
||||
<Platforms>
|
||||
<Platform Name="Win32"/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration CharacterSet="2" ConfigurationType="2" IntermediateDirectory="$(SolutionDir)\build\intermediate\$(ConfigurationName)\$(ProjectName)" Name="Debug|Win32" OutputDirectory="$(SolutionDir)\build\$(ConfigurationName)\modules">
|
||||
<Tool Name="VCPreBuildEventTool"/>
|
||||
<Tool Name="VCCustomBuildTool"/>
|
||||
<Tool Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool Name="VCMIDLTool"/>
|
||||
<Tool AdditionalIncludeDirectories=""$(SolutionDir)\include";"$(SolutionDir)\libs";"$(SolutionDir)\..\STLPort\stlport";"$(SolutionDir)\..\gtk2\include";"$(SolutionDir)\..\gtk2\include\glib-2.0";"$(SolutionDir)\..\gtk2\lib\glib-2.0\include";"$(SolutionDir)\..\libxml2\include"" BasicRuntimeChecks="3" DebugInformationFormat="4" Detect64BitPortabilityProblems="true" DisableSpecificWarnings="4996;4244;4267" MinimalRebuild="true" Name="VCCLCompilerTool" Optimization="0" PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="3" WarningLevel="3"/>
|
||||
<Tool Name="VCManagedResourceCompilerTool"/>
|
||||
<Tool Name="VCResourceCompilerTool"/>
|
||||
<Tool Name="VCPreLinkEventTool"/>
|
||||
<Tool AdditionalDependencies="cmdlib.lib synapse.lib libxml2.lib glib-2.0.lib gobject-2.0.lib" AdditionalLibraryDirectories=""$(SolutionDir)\..\libxml2\lib";"$(SolutionDir)\..\gtk2\lib";"$(SolutionDir)\build\$(ConfigurationName)\libs"" GenerateDebugInformation="true" ModuleDefinitionFile="mapxml.def" Name="VCLinkerTool" TargetMachine="1"/>
|
||||
<Tool Name="VCALinkTool"/>
|
||||
<Tool Name="VCManifestTool"/>
|
||||
<Tool Name="VCXDCMakeTool"/>
|
||||
<Tool Name="VCBscMakeTool"/>
|
||||
<Tool Name="VCFxCopTool"/>
|
||||
<Tool Name="VCAppVerifierTool"/>
|
||||
<Tool Name="VCWebDeploymentTool"/>
|
||||
<Tool Name="VCPostBuildEventTool"/>
|
||||
</Configuration>
|
||||
<Configuration CharacterSet="2" ConfigurationType="2" IntermediateDirectory="$(SolutionDir)\build\intermediate\$(ConfigurationName)\$(ProjectName)" Name="Release|Win32" OutputDirectory="$(SolutionDir)\build\$(ConfigurationName)\modules" WholeProgramOptimization="1">
|
||||
<Tool Name="VCPreBuildEventTool"/>
|
||||
<Tool Name="VCCustomBuildTool"/>
|
||||
<Tool Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool Name="VCMIDLTool"/>
|
||||
<Tool AdditionalIncludeDirectories=""$(SolutionDir)\include";"$(SolutionDir)\libs";"$(SolutionDir)\..\STLPort\stlport";"$(SolutionDir)\..\gtk2\include";"$(SolutionDir)\..\gtk2\include\glib-2.0";"$(SolutionDir)\..\gtk2\lib\glib-2.0\include";"$(SolutionDir)\..\libxml2\include"" DebugInformationFormat="3" Detect64BitPortabilityProblems="true" DisableSpecificWarnings="4996;4244;4267" Name="VCCLCompilerTool" PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS" RuntimeLibrary="2" WarningLevel="3"/>
|
||||
<Tool Name="VCManagedResourceCompilerTool"/>
|
||||
<Tool Name="VCResourceCompilerTool"/>
|
||||
<Tool Name="VCPreLinkEventTool"/>
|
||||
<Tool AdditionalDependencies="cmdlib.lib synapse.lib libxml2.lib glib-2.0.lib gobject-2.0.lib" AdditionalLibraryDirectories=""$(SolutionDir)\..\libxml2\lib";"$(SolutionDir)\..\gtk2\lib";"$(SolutionDir)\build\$(ConfigurationName)\libs"" EnableCOMDATFolding="2" GenerateDebugInformation="true" ModuleDefinitionFile="mapxml.def" Name="VCLinkerTool" OptimizeReferences="2" TargetMachine="1"/>
|
||||
<Tool Name="VCALinkTool"/>
|
||||
<Tool Name="VCManifestTool"/>
|
||||
<Tool Name="VCXDCMakeTool"/>
|
||||
<Tool Name="VCBscMakeTool"/>
|
||||
<Tool Name="VCFxCopTool"/>
|
||||
<Tool Name="VCAppVerifierTool"/>
|
||||
<Tool Name="VCWebDeploymentTool"/>
|
||||
<Tool Name="VCPostBuildEventTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" Name="Source Files">
|
||||
<File RelativePath=".\mapxml.def">
|
||||
</File>
|
||||
<File RelativePath=".\plugin.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\xmlparse.cpp">
|
||||
</File>
|
||||
<File RelativePath=".\xmlwrite.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter Filter="h;hpp;hxx;hm;inl" Name="Header Files">
|
||||
<File RelativePath=".\plugin.h">
|
||||
</File>
|
||||
<Filter Filter="*.h" Name="API">
|
||||
<File RelativePath="..\..\include\ifilesystem.h">
|
||||
</File>
|
||||
<File RelativePath="..\..\include\ipatch.h">
|
||||
</File>
|
||||
<File RelativePath="..\..\include\iscriplib.h">
|
||||
</File>
|
||||
<File RelativePath="..\..\include\qerplugin.h">
|
||||
</File>
|
||||
<File RelativePath="..\..\include\qertypes.h">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" Name="Resource Files">
|
||||
</Filter>
|
||||
<File RelativePath=".\Conscript">
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
73
plugins/mapxml/plugin.cpp
Normal file
73
plugins/mapxml/plugin.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "plugin.h"
|
||||
|
||||
// =============================================================================
|
||||
// Globals
|
||||
|
||||
// function tables
|
||||
_QERFuncTable_1 g_FuncTable;
|
||||
_QERShadersTable g_ShadersTable;
|
||||
_QEREntityTable g_EntityTable;
|
||||
_QERBrushTable g_BrushTable;
|
||||
_QERPatchTable g_PatchTable;
|
||||
|
||||
// =============================================================================
|
||||
// SYNAPSE
|
||||
|
||||
CSynapseServer* g_pSynapseServer = NULL;
|
||||
CSynapseClientXMap g_SynapseClient;
|
||||
|
||||
static const XMLConfigEntry_t entries[] =
|
||||
{
|
||||
{ SHADERS_MAJOR, SYN_REQUIRE, sizeof(g_ShadersTable), &g_ShadersTable },
|
||||
{ NULL, SYN_UNKNOWN, 0, NULL } };
|
||||
|
||||
extern "C" CSynapseClient* SYNAPSE_DLL_EXPORT Synapse_EnumerateInterfaces (const char *version, CSynapseServer *pServer)
|
||||
{
|
||||
if (strcmp(version, SYNAPSE_VERSION))
|
||||
{
|
||||
Syn_Printf("ERROR: synapse API version mismatch: should be '" SYNAPSE_VERSION "', got '%s'\n", version);
|
||||
return NULL;
|
||||
}
|
||||
g_pSynapseServer = pServer;
|
||||
g_pSynapseServer->IncRef();
|
||||
Set_Syn_Printf(g_pSynapseServer->Get_Syn_Printf());
|
||||
|
||||
g_SynapseClient.AddAPI(MAP_MAJOR, "mapxml", sizeof(_QERPlugMapTable));
|
||||
g_SynapseClient.AddAPI(RADIANT_MAJOR, NULL, sizeof(_QERFuncTable_1), SYN_REQUIRE, &g_FuncTable);
|
||||
g_SynapseClient.AddAPI(ENTITY_MAJOR, NULL, sizeof(g_EntityTable), SYN_REQUIRE, &g_EntityTable);
|
||||
g_SynapseClient.AddAPI(BRUSH_MAJOR, NULL, sizeof(g_BrushTable), SYN_REQUIRE, &g_BrushTable);
|
||||
g_SynapseClient.AddAPI(PATCH_MAJOR, NULL, sizeof(g_PatchTable), SYN_REQUIRE, &g_PatchTable);
|
||||
|
||||
if ( !g_SynapseClient.ConfigXML( pServer, NULL, entries ) ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return &g_SynapseClient;
|
||||
}
|
||||
|
||||
bool CSynapseClientXMap::RequestAPI(APIDescriptor_t *pAPI)
|
||||
{
|
||||
if (!strcmp(pAPI->major_name, MAP_MAJOR))
|
||||
{
|
||||
_QERPlugMapTable* pTable= static_cast<_QERPlugMapTable*>(pAPI->mpTable);
|
||||
pTable->m_pfnMap_Read = &Map_Read;
|
||||
pTable->m_pfnMap_Write = &Map_Write;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Syn_Printf("ERROR: RequestAPI( '%s' ) not found in '%s'\n", pAPI->major_name, GetInfo());
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "version.h"
|
||||
|
||||
const char* CSynapseClientXMap::GetInfo()
|
||||
{
|
||||
return "XMAP module built " __DATE__ " " RADIANT_VERSION;
|
||||
}
|
||||
|
||||
const char* CSynapseClientXMap::GetName()
|
||||
{
|
||||
return "xmap";
|
||||
}
|
||||
49
plugins/mapxml/plugin.h
Normal file
49
plugins/mapxml/plugin.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef _PLUGIN_H_
|
||||
#define _PLUGIN_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libxml/parser.h"
|
||||
|
||||
#include "synapse.h"
|
||||
#define USE_QERTABLE_DEFINE
|
||||
#include "qerplugin.h"
|
||||
#include "imap.h"
|
||||
#include "ishaders.h"
|
||||
#define USE_ENTITYTABLE_DEFINE
|
||||
#include "ientity.h"
|
||||
#define USE_BRUSHTABLE_DEFINE
|
||||
#include "ibrush.h"
|
||||
#define USE_PATCHTABLE_DEFINE
|
||||
#include "ipatch.h"
|
||||
|
||||
extern _QERFuncTable_1 g_FuncTable;
|
||||
extern _QERShadersTable g_ShadersTable;
|
||||
extern _QEREntityTable g_EntityTable;
|
||||
extern _QERBrushTable g_BrushTable;
|
||||
extern _QERPatchTable g_PatchTable;
|
||||
|
||||
#define Error g_FuncTable.m_pfnError
|
||||
#define QERApp_Shader_ForName g_ShadersTable.m_pfnShader_ForName
|
||||
|
||||
extern void *g_pRadiantWnd;
|
||||
|
||||
void Map_Read (IDataStream *in, CPtrArray *map);
|
||||
void Map_Write (CPtrArray *map, IDataStream *out);
|
||||
|
||||
extern CSynapseServer* g_pSynapseServer;
|
||||
|
||||
class CSynapseClientXMap : public CSynapseClient
|
||||
{
|
||||
public:
|
||||
// CSynapseClient API
|
||||
bool RequestAPI(APIDescriptor_t *pAPI);
|
||||
const char* GetInfo();
|
||||
const char* GetName(); ///< required for XML runtime config
|
||||
|
||||
CSynapseClientXMap() { }
|
||||
virtual ~CSynapseClientXMap() { }
|
||||
};
|
||||
|
||||
#endif // _PLUGIN_H_
|
||||
295
plugins/mapxml/xmlparse.cpp
Normal file
295
plugins/mapxml/xmlparse.cpp
Normal file
@@ -0,0 +1,295 @@
|
||||
//
|
||||
// parses xml tree format into internal objects
|
||||
//
|
||||
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
void Patch_XMLParse(patchMesh_t *pPatch, xmlNodePtr surface)
|
||||
{
|
||||
char *str, *content;
|
||||
int i, j;
|
||||
|
||||
for(xmlNodePtr current = surface->children; current != NULL; current = current->next)
|
||||
{
|
||||
if(current->type != XML_ELEMENT_NODE) continue;
|
||||
if(!strcmp((char *)current->name, "matrix"))
|
||||
{
|
||||
str = (char *)xmlGetProp(current, (xmlChar *)"width");
|
||||
pPatch->width = atoi(str);
|
||||
xmlFree(str);
|
||||
str = (char *)xmlGetProp(current, (xmlChar *)"height");
|
||||
pPatch->height = atoi(str);
|
||||
xmlFree(str);
|
||||
|
||||
content = Q_StrDup((char *)current->children->content);
|
||||
|
||||
str = strtok(content, " \n\r\t\v\0");
|
||||
for(i=0; i<pPatch->width; i++)
|
||||
{
|
||||
for(j=0; j<pPatch->height; j++)
|
||||
{
|
||||
pPatch->ctrl[i][j].xyz[0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
pPatch->ctrl[i][j].xyz[1] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
pPatch->ctrl[i][j].xyz[2] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
pPatch->ctrl[i][j].st[0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
pPatch->ctrl[i][j].st[1] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
}
|
||||
}
|
||||
|
||||
delete [] content;
|
||||
}
|
||||
else if(!strcmp((char *)current->name, "shader")) {
|
||||
pPatch->pShader = QERApp_Shader_ForName((char*)current->children->content);
|
||||
pPatch->d_texture = pPatch->pShader->getTexture();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Face_XMLParse (face_t *face, xmlNodePtr surface)
|
||||
{
|
||||
char *str, *content;
|
||||
int i, j;
|
||||
|
||||
for(xmlNodePtr current = surface->children; current != NULL; current = current->next)
|
||||
{
|
||||
if(current->type != XML_ELEMENT_NODE) continue;
|
||||
if(!strcmp((char *)current->name, "planepts"))
|
||||
{
|
||||
content = Q_StrDup((char *)current->children->content);
|
||||
|
||||
str = strtok(content, " \n\r\t\v\0");
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
face->planepts[i][j] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
}
|
||||
}
|
||||
|
||||
delete [] content;
|
||||
}
|
||||
else if(!strcmp((char *)current->name, "texdef"))
|
||||
{
|
||||
content = Q_StrDup((char *)current->children->content);
|
||||
|
||||
str = strtok(content, " \n\r\t\v\0");
|
||||
face->texdef.shift[0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.shift[1] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.rotate = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.scale[0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.scale[1] = atof(str);
|
||||
|
||||
delete [] content;
|
||||
}
|
||||
else if(!strcmp((char *)current->name, "bpmatrix"))
|
||||
{
|
||||
content = Q_StrDup((char *)current->children->content);
|
||||
|
||||
str = strtok(content, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[0][0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[0][1] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[0][2] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[1][0] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[1][1] = atof(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->brushprimit_texdef.coords[1][2] = atof(str);
|
||||
|
||||
delete [] content;
|
||||
}
|
||||
else if(!strcmp((char *)current->name, "flags"))
|
||||
{
|
||||
content = Q_StrDup((char *)current->children->content);
|
||||
|
||||
str = strtok(content, " \n\r\t\v\0");
|
||||
face->texdef.contents = atoi(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.flags = atoi(str);
|
||||
str = strtok(NULL, " \n\r\t\v\0");
|
||||
face->texdef.value = atoi(str);
|
||||
|
||||
delete [] content;
|
||||
}
|
||||
else if(!strcmp((char *)current->name, "shader"))
|
||||
{
|
||||
face->texdef.SetName((char *)current->children->content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Brush_XMLParse (brush_t *pBrush, xmlNodePtr primitive)
|
||||
{
|
||||
face_t *f;
|
||||
|
||||
for(xmlNodePtr current = primitive->children; current != NULL; current = current->next)
|
||||
{
|
||||
if(current->type != XML_ELEMENT_NODE) continue;
|
||||
f = pBrush->brush_faces;
|
||||
pBrush->brush_faces = Face_Alloc();
|
||||
Face_XMLParse(pBrush->brush_faces, current);
|
||||
pBrush->brush_faces->next = f;
|
||||
}
|
||||
}
|
||||
|
||||
void Entity_XMLParse(entity_t *pEntity, xmlNodePtr entity)
|
||||
{
|
||||
brush_t *pBrush;
|
||||
|
||||
for(xmlNodePtr current = entity->children; current != NULL; current = current->next)
|
||||
{
|
||||
if(current->type != XML_ELEMENT_NODE) continue;
|
||||
if(!strcmp((char *)current->name, "epair"))
|
||||
{
|
||||
char *key = (char *)xmlGetProp(current, (xmlChar *)"key");
|
||||
char *value = (char *)xmlGetProp(current, (xmlChar *)"value");
|
||||
SetKeyValue(pEntity, key, value);
|
||||
xmlFree(key);
|
||||
xmlFree(value);
|
||||
}
|
||||
else if(strcmp((char *)current->name, "brush") == 0)
|
||||
{
|
||||
pBrush = Brush_Alloc();
|
||||
Brush_XMLParse(pBrush, current);
|
||||
((CPtrArray*)pEntity->pData)->Add(pBrush);
|
||||
}
|
||||
else if(strcmp((char *)current->name, "patch") == 0)
|
||||
{
|
||||
pBrush = Brush_Alloc();
|
||||
pBrush->patchBrush = true;
|
||||
pBrush->pPatch = Patch_Alloc();
|
||||
pBrush->pPatch->pSymbiot = pBrush;
|
||||
Patch_XMLParse(pBrush->pPatch, current);
|
||||
((CPtrArray*)pEntity->pData)->Add(pBrush);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map_XMLRead(CPtrArray *map, xmlNodePtr map_node)
|
||||
{
|
||||
entity_t *pEntity;
|
||||
xmlNodePtr current;
|
||||
|
||||
for(current = map_node->children; current != NULL; current = current->next)
|
||||
{
|
||||
if(current->type != XML_ELEMENT_NODE) continue;
|
||||
pEntity = Entity_Alloc();
|
||||
pEntity->pData = new CPtrArray;
|
||||
Entity_XMLParse(pEntity, current);
|
||||
map->Add(pEntity);
|
||||
}
|
||||
}
|
||||
|
||||
// SPoG
|
||||
// temporarily copied from qe3.cpp
|
||||
// duplicate code starts here (note: g_strAppPath swapped for g_FuncTable.m_pfnGetQERPath())
|
||||
|
||||
void HandleXMLError( void* ctxt, const char* text, ... )
|
||||
{
|
||||
va_list argptr;
|
||||
static char buf[32768];
|
||||
|
||||
va_start (argptr,text);
|
||||
vsprintf (buf, text, argptr);
|
||||
Sys_FPrintf (SYS_ERR, "XML %s\n", buf);
|
||||
va_end (argptr);
|
||||
}
|
||||
|
||||
#define DTD_BUFFER_LENGTH 1024
|
||||
xmlDocPtr ParseXMLStream(IDataStream *stream, bool validate = false)
|
||||
{
|
||||
xmlDocPtr doc = NULL;
|
||||
bool wellFormed = false, valid = false;
|
||||
int res, size = 1024;
|
||||
char chars[1024];
|
||||
xmlParserCtxtPtr ctxt;
|
||||
|
||||
// SPoG
|
||||
// HACK: use AppPath to resolve DTD location
|
||||
// do a buffer-safe string copy and concatenate
|
||||
int i;
|
||||
char* w;
|
||||
const char* r;
|
||||
char buf[DTD_BUFFER_LENGTH];
|
||||
|
||||
w = buf;
|
||||
i = 0;
|
||||
// copy
|
||||
//assert(g_FuncTable.m_pfnGetQERPath() != NULL);
|
||||
for(r = g_FuncTable.m_pfnGetQERPath(); i<DTD_BUFFER_LENGTH && *r != '\0'; i++, r++) w[i] = *r;
|
||||
// concatenate
|
||||
for(r = "dtds/"; i<DTD_BUFFER_LENGTH && *r != '\0'; i++, r++) w[i] = *r;
|
||||
// terminate
|
||||
w[i] = '\0';
|
||||
|
||||
if(i == DTD_BUFFER_LENGTH)
|
||||
{
|
||||
HandleXMLError(NULL, "ERROR: buffer overflow: DTD path length too large\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//if(validate)
|
||||
// xmlDoValidityCheckingDefaultValue = 1;
|
||||
//else
|
||||
xmlDoValidityCheckingDefaultValue = 0;
|
||||
|
||||
xmlSetGenericErrorFunc(NULL, HandleXMLError);
|
||||
|
||||
res = stream->Read(chars, 4);
|
||||
if (res > 0)
|
||||
{
|
||||
ctxt = xmlCreatePushParserCtxt(NULL, NULL, chars, res, buf);
|
||||
|
||||
while ((res = stream->Read(chars, size)) > 0)
|
||||
{
|
||||
xmlParseChunk(ctxt, chars, res, 0);
|
||||
}
|
||||
xmlParseChunk(ctxt, chars, 0, 1);
|
||||
doc = ctxt->myDoc;
|
||||
|
||||
wellFormed = (ctxt->wellFormed == 1);
|
||||
valid = (ctxt->valid == 1);
|
||||
|
||||
xmlFreeParserCtxt(ctxt);
|
||||
}
|
||||
|
||||
if(wellFormed && (!validate || (validate && valid)))
|
||||
return doc;
|
||||
|
||||
if(doc != NULL)
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// duplicate code ends here
|
||||
|
||||
void Map_Read (IDataStream *in, CPtrArray *map)
|
||||
{
|
||||
xmlDocPtr doc;
|
||||
|
||||
doc = ParseXMLStream(in, false ); // quick hack while dtd validation is broken
|
||||
|
||||
if(doc != NULL)
|
||||
{
|
||||
xmlNodePtr node=doc->children;
|
||||
while(node != NULL && node->type != XML_ELEMENT_NODE) node=node->next;
|
||||
if(node != NULL)
|
||||
Map_XMLRead(map, node);
|
||||
}
|
||||
|
||||
xmlFreeDoc(doc);
|
||||
}
|
||||
217
plugins/mapxml/xmlwrite.cpp
Normal file
217
plugins/mapxml/xmlwrite.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
//
|
||||
// writes xml tree format from internal objects
|
||||
//
|
||||
|
||||
|
||||
#include "plugin.h"
|
||||
|
||||
char *str_append_token(char *str1, const char *str2)
|
||||
{
|
||||
char *str;
|
||||
if(str1 != NULL)
|
||||
{
|
||||
str = new char[strlen(str1)+strlen(str2)+2];
|
||||
sprintf(str, "%s %s", str1, str2);
|
||||
delete [] str1;
|
||||
}
|
||||
else
|
||||
{
|
||||
str = new char[strlen(str2)+1];
|
||||
strcpy(str, str2);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
void str_from_float(char *buf, float f)
|
||||
{
|
||||
if(f == (int)f) sprintf(buf, "%i", (int)f);
|
||||
else sprintf(buf, "%f", f);
|
||||
}
|
||||
|
||||
void Patch_XMLWrite(patchMesh_t *pPatch, xmlNodePtr surface)
|
||||
{
|
||||
char buf[16];
|
||||
char *str;
|
||||
int i, j;
|
||||
xmlNodePtr node;
|
||||
|
||||
// write shader
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"shader", (xmlChar *)pPatch->pShader->getName());
|
||||
|
||||
// write matrix
|
||||
str = NULL;
|
||||
for(i=0; i<pPatch->width; i++)
|
||||
{
|
||||
for(j=0; j<pPatch->height; j++)
|
||||
{
|
||||
str_from_float(buf, pPatch->ctrl[i][j].xyz[0]);
|
||||
str = str_append_token(str, buf);
|
||||
str_from_float(buf, pPatch->ctrl[i][j].xyz[1]);
|
||||
str = str_append_token(str, buf);
|
||||
str_from_float(buf, pPatch->ctrl[i][j].xyz[2]);
|
||||
str = str_append_token(str, buf);
|
||||
str_from_float(buf, pPatch->ctrl[i][j].st[0]);
|
||||
str = str_append_token(str, buf);
|
||||
str_from_float(buf, pPatch->ctrl[i][j].st[1]);
|
||||
str = str_append_token(str, buf);
|
||||
}
|
||||
}
|
||||
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"matrix", (xmlChar *)str);
|
||||
delete [] str;
|
||||
sprintf(buf, "%i", pPatch->width);
|
||||
xmlSetProp(node, (xmlChar *)"width", (xmlChar *)buf);
|
||||
sprintf(buf, "%i", pPatch->height);
|
||||
xmlSetProp(node, (xmlChar *)"height", (xmlChar *)buf);
|
||||
}
|
||||
|
||||
void Face_XMLWrite (face_t *face, xmlNodePtr surface, bool bAlternateTexdef = false)
|
||||
{
|
||||
char buf[16];
|
||||
xmlNodePtr node;
|
||||
int i, j;
|
||||
char *str;
|
||||
|
||||
// write shader
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"shader", (xmlChar *)face->texdef.GetName());
|
||||
|
||||
// write planepts
|
||||
str = NULL;
|
||||
for (i=0 ; i<3 ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
str_from_float(buf, face->planepts[i][j]);
|
||||
str = str_append_token(str, buf);
|
||||
}
|
||||
}
|
||||
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"planepts", (xmlChar *)str);
|
||||
delete [] str;
|
||||
|
||||
if(!bAlternateTexdef)
|
||||
{
|
||||
// write texdef
|
||||
sprintf(buf, "%i", (int)face->texdef.shift[0]);
|
||||
str = str_append_token(NULL, buf);
|
||||
sprintf(buf, "%i", (int)face->texdef.shift[1]);
|
||||
str = str_append_token(str, buf);
|
||||
sprintf(buf, "%i", (int)face->texdef.rotate);
|
||||
str = str_append_token(str, buf);
|
||||
sprintf(buf, "%f", face->texdef.scale[0]);
|
||||
str = str_append_token(str, buf);
|
||||
sprintf(buf, "%f", face->texdef.scale[1]);
|
||||
str = str_append_token(str, buf);
|
||||
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"texdef", (xmlChar *)str);
|
||||
delete [] str;
|
||||
}
|
||||
else
|
||||
{
|
||||
// write matrix texdef
|
||||
str = NULL;
|
||||
for (i=0 ; i<2 ; i++)
|
||||
{
|
||||
for (j=0 ; j<3 ; j++)
|
||||
{
|
||||
str_from_float(buf, face->brushprimit_texdef.coords[i][j]);
|
||||
str = str_append_token(str, buf);
|
||||
}
|
||||
}
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"bpmatrix", (xmlChar *)str);
|
||||
delete [] str;
|
||||
}
|
||||
|
||||
// write flags
|
||||
sprintf(buf, "%i", face->texdef.contents);
|
||||
str = str_append_token(NULL, buf);
|
||||
sprintf(buf, "%i", face->texdef.flags);
|
||||
str = str_append_token(str, buf);
|
||||
sprintf(buf, "%i", face->texdef.value);
|
||||
str = str_append_token(str, buf);
|
||||
|
||||
node = xmlNewChild(surface, NULL, (xmlChar *)"flags", (xmlChar *)str);
|
||||
delete [] str;
|
||||
}
|
||||
|
||||
void Brush_XMLWrite (brush_t *brush, xmlNodePtr primitive)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
|
||||
for(face_t *face = brush->brush_faces; face != NULL; face = face->next)
|
||||
{
|
||||
node = xmlNewChild(primitive, NULL, (xmlChar *)"plane", NULL);
|
||||
Face_XMLWrite (face, node, brush->bBrushDef);
|
||||
}
|
||||
}
|
||||
|
||||
void Epair_XMLWrite(epair_t *pEpair, xmlNodePtr epair)
|
||||
{
|
||||
xmlSetProp(epair, (xmlChar *)"key", (xmlChar *)pEpair->key);
|
||||
xmlSetProp(epair, (xmlChar *)"value", (xmlChar *)pEpair->value);
|
||||
}
|
||||
|
||||
void Entity_XMLWrite(entity_t *pEntity, xmlNodePtr entity)
|
||||
{
|
||||
brush_t *pBrush;
|
||||
epair_t *pEpair;
|
||||
xmlNodePtr node;
|
||||
|
||||
CPtrArray *brushes = (CPtrArray*)pEntity->pData;
|
||||
|
||||
for(pEpair = pEntity->epairs; pEpair != NULL; pEpair = pEpair->next)
|
||||
{
|
||||
node = xmlNewChild(entity, NULL, (xmlChar *)"epair", NULL);
|
||||
Epair_XMLWrite(pEpair, node);
|
||||
}
|
||||
|
||||
for(int i=0; i<brushes->GetSize(); i++)
|
||||
{
|
||||
pBrush = (brush_t*)brushes->GetAt(i);
|
||||
|
||||
if(pBrush->patchBrush)
|
||||
{
|
||||
node = xmlNewChild(entity, NULL, (xmlChar *)"patch", NULL);
|
||||
Patch_XMLWrite(pBrush->pPatch, node);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = xmlNewChild(entity, NULL, (xmlChar *)"brush", NULL);
|
||||
Brush_XMLWrite(pBrush, node);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Map_XMLWrite (CPtrArray *map, xmlNodePtr map_node)
|
||||
{
|
||||
entity_t *pEntity;
|
||||
xmlNodePtr node;
|
||||
|
||||
for(int i=0; i<map->GetSize(); i++)
|
||||
{
|
||||
pEntity = (entity_t*)map->GetAt(i);
|
||||
|
||||
node = xmlNewChild(map_node, NULL, (xmlChar *)"entity", NULL);
|
||||
Entity_XMLWrite(pEntity, node);
|
||||
}
|
||||
}
|
||||
|
||||
void Map_Write (CPtrArray *map, IDataStream *out)
|
||||
{
|
||||
xmlChar* buf;
|
||||
int len;
|
||||
|
||||
xmlDocPtr doc = xmlNewDoc((xmlChar *)"1.0");
|
||||
xmlCreateIntSubset(doc, (xmlChar *)"mapq3", NULL, (xmlChar *)"mapq3.dtd");
|
||||
doc->children->next = xmlNewDocNode(doc, NULL, (xmlChar *)"mapq3", NULL);
|
||||
|
||||
Map_XMLWrite(map, doc->children->next);
|
||||
|
||||
// xmlDocDumpMemory(doc, &buf, &len);
|
||||
xmlDocDumpFormatMemory(doc, &buf, &len, 1);
|
||||
xmlFreeDoc(doc);
|
||||
|
||||
out->Write(buf, len);
|
||||
|
||||
xmlFree(buf);
|
||||
}
|
||||
Reference in New Issue
Block a user