Lephisto/src/lxml.c
Allanis 1abb2c117d [Add] Added flags to image creation to control transparency mapping.
Should speed up the loading and reduce memory usage.
2014-05-17 11:19:15 +01:00

64 lines
1.3 KiB
C

/**
* @file lxml.c
*
* Handles some complex xml parsing.
*/
#include "lephisto.h"
#include "lxml.h"
/**
* @brief Parses a texture handling the sx and sy elements.
* @param node Node to parse.
* @param path Path to get file from, should be in the format of
* "PREFIX%sSUFFIX".
* @param defsx Default X sprites.
* @param defsy Default Y sprites.
* @param flags Image parameter control flags.
* @return The texture from the node or NULL if an error occurred.
*/
glTexture* xml_parseTexture(xmlNodePtr node,
const char* path, int defsx, int defsy,
const unsigned int flags) {
int sx, sy;
char* buf, filename[PATH_MAX];
glTexture* tex;
/* Sane defaults. */
sx = defsx;
sy = defsy;
/* Read x sprites. */
xmlr_attr(node, "sx", buf);
if(buf != NULL) {
sx = atoi(buf);
free(buf);
}
/* Read y sprites. */
xmlr_attr(node, "sy", buf);
if(buf != NULL) {
sy = atoi(buf);
free(buf);
}
/* Get graphic to load. */
buf = xml_get(node);
if(buf == NULL)
return NULL;
/* Convert name. */
snprintf(filename, PATH_MAX, (path != NULL) ? path : "%s", buf);
/* Load the graphic. */
if((sx == 1) && (sy == 1))
tex = gl_newImage(filename, flags);
else
tex = gl_newSprite(filename, sx, sy, flags);
/* Return result. */
return tex;
}