naev 0.12.5
nxml.c
Go to the documentation of this file.
1
9#include "nxml.h"
10#include <inttypes.h>
11
12#include "ndata.h"
13
25glTexture *xml_parseTexture( xmlNodePtr node, const char *path, int defsx,
26 int defsy, const unsigned int flags )
27{
28 int sx, sy;
29 char *buf, filename[PATH_MAX];
30 glTexture *tex;
31
32 xmlr_attr_int_def( node, "sx", sx, defsx );
33 xmlr_attr_int_def( node, "sy", sy, defsy );
34
35 /* Get graphic to load. */
36 buf = xml_get( node );
37 if (buf == NULL)
38 return NULL;
39
40 /* Check for absolute pathe. */
41 if (( buf[0] == '/' ) || ( path == NULL ))
42 snprintf( filename, sizeof( filename ), "%s", buf );
43 else
44 snprintf( filename, sizeof( filename ), path, buf );
45
46 /* Load the graphic. */
47 if (( sx == 1 ) && ( sy == 1 ))
48 tex = gl_newImage( filename, flags );
49 else
50 tex = gl_newSprite( filename, sx, sy, flags );
51
52 /* Return result. */
53 return tex;
54}
55
59void xmlw_setParams( xmlTextWriterPtr writer )
60{
61 xmlTextWriterSetIndentString( writer, (const xmlChar *)" " );
62 xmlTextWriterSetIndent( writer, 1 );
63}
64
70xmlDocPtr xml_parsePhysFS( const char *filename )
71{
72 char *buf;
73 size_t bufsize;
74 xmlDocPtr doc;
75
76 /* @TODO: Don't slurp?
77 * Can we directly create an InputStream backed by PHYSFS_*, or use SAX? */
78 buf = ndata_read( filename, &bufsize );
79 if (buf == NULL) {
80 WARN( _( "Unable to read data from '%s'" ), filename );
81 return NULL;
82 }
83 /* Empty file, we ignore these. */
84 if (bufsize == 0) {
85 free( buf );
86 return NULL;
87 }
88 doc = xmlParseMemory( buf, bufsize );
89 if (doc == NULL)
90 WARN( _( "Unable to parse document '%s'" ), filename );
91 free( buf );
92 return doc;
93}
94
95int xmlw_saveTime( xmlTextWriterPtr writer, const char *name, time_t t )
96{
97 xmlw_elem( writer, name, "%lld", (long long)t );
98 return 0;
99}
100
101int xmlw_saveNTime( xmlTextWriterPtr writer, const char *name, ntime_t t )
102{
103 xmlw_elem( writer, name, "%" PRIu64, t );
104 return 0;
105}
106
107int xml_parseTime( xmlNodePtr node, time_t *t )
108{
109 *t = xml_getULong( node );
110 return 0;
111}
112int xml_parseNTime( xmlNodePtr node, ntime_t *t )
113{
114 *t = xml_getULong( node );
115 return 0;
116}
#define PATH_MAX
Definition naev.h:57
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
Definition ndata.c:207
glTexture * xml_parseTexture(xmlNodePtr node, const char *path, int defsx, int defsy, const unsigned int flags)
Parses a texture handling the sx and sy elements.
Definition nxml.c:25
void xmlw_setParams(xmlTextWriterPtr writer)
Sets up the standard xml write parameters.
Definition nxml.c:59
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
Definition nxml.c:70
glTexture * gl_newSprite(const char *path, const int sx, const int sy, const unsigned int flags)
Loads the texture immediately, but also sets it as a sprite.
Definition opengl_tex.c:785
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:587
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43