void LibxmlParser::parseXMLFile(XMLHandler& handler, const String& filename, const String&, const String& resourceGroup) { // load xml file data into buffer using resource provider CEGUI::RawDataContainer rawXMLData; CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup); xmlDocPtr doc = xmlParseMemory( reinterpret_cast<char*>(rawXMLData.getDataPtr()), rawXMLData.getSize()); // release loaded xml data. System::getSingleton().getResourceProvider()-> unloadRawDataContainer(rawXMLData); if (!doc) { xmlError* err = xmlGetLastError(); throw GenericException( String("LibxmlParser::parseXMLFile - xmlParseMemory failed in file: '") + err->file + "' at line number" + PropertyHelper::uintToString(err->line) + ". Error is:" + err->message); } // get root element xmlNode* root = xmlDocGetRootElement(doc); // process all elements from root to end of doc processXMLElement(handler, root); // release the xmlDoc xmlFreeDoc(doc); }
void ExpatParser::parseXMLFile(CEGUI::XMLHandler& handler, const CEGUI::String& filename, const CEGUI::String& schemaName, const CEGUI::String& resourceGroup) { // All stuff goes here XML_Parser parser = XML_ParserCreate(0); // Create a parser if (! parser) { throw CEGUI::GenericException("ExpatParser::parseXMLFile - Unable to create a new Expat Parser"); } XML_SetUserData(parser, (void*)&handler); // Initialise user data XML_SetElementHandler(parser, startElement, endElement); // Register callback for elements // Aquire resource using CEGUI ResourceProvider CEGUI::RawDataContainer rawXMLData; CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup); // Parse the data (note that the last true parameter tels Expat that this is the last chunk of the document if ( ! XML_Parse(parser, reinterpret_cast<const char*>(rawXMLData.getDataPtr()), rawXMLData.getSize(), true)) { CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData); throw CEGUI::GenericException(CEGUI::String((CEGUI::utf8*)"ExpatParser::parseXMLFile( ") + CEGUI::String(filename)+ CEGUI::String((CEGUI::utf8*)" ) - XML Parsing error '\r\n") + CEGUI::String((CEGUI::utf8*)XML_ErrorString(XML_GetErrorCode(parser))) + CEGUI::String((CEGUI::utf8*)"' at line ") + XML_GetCurrentLineNumber(parser)); } // Release resource CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData); // Free parser XML_ParserFree(parser); }
void CEGUILuaBindScriptModule::executeScriptFile(const CEGUI::String &filename, const CEGUI::String &resourceGroup) { // load file CEGUI::RawDataContainer raw; CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, raw, resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup); lua_State * lua_vm = LuaScript::Instance( ).GetLuaVM( ); // load code into lua int top = lua_gettop( lua_vm ); int loaderr = luaL_loadbuffer( lua_vm, (char*)raw.getDataPtr(), raw.getSize(), filename.c_str()); CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer( raw ); if (loaderr) { CEGUI::String errMsg = lua_tostring(lua_vm,-1); lua_settop(lua_vm,top); throw CEGUI::ScriptException("Unable to execute Lua script file: '"+filename+"'\n\n"+errMsg+"\n"); } // call it if (lua_pcall(lua_vm,0,0,0)) { CEGUI::String errMsg = lua_tostring(lua_vm,-1); lua_settop(lua_vm,top); throw CEGUI::ScriptException("Unable to execute Lua script file: '"+filename+"'\n\n"+errMsg+"\n"); } lua_settop(lua_vm,top); // just in case :P }
void CLuaManager::executeScriptFile(const CEGUI::String& filename, const CEGUI::String& resourceGroup) { // load file CEGUI::RawDataContainer raw; CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, raw, resourceGroup.empty() ? d_defaultResourceGroup : resourceGroup); // load code into lua int loaderr = luaL_loadbuffer(m_luaVM, (char*)raw.getDataPtr(), raw.getSize(), filename.c_str()); CEGUI::System::getSingleton().getResourceProvider()->unloadRawDataContainer(raw); // call it if (loaderr==0) { // run the file int result = lua_pcall(m_luaVM,0,0,0); switch (result) { case LUA_ERRRUN: CLog::getInstance()->error("Runtime error in %s", filename.c_str()); break; case LUA_ERRMEM: CLog::getInstance()->error("Memory alocation error in %s", filename.c_str()); break; case LUA_ERRERR: CLog::getInstance()->error("Error handler error in %s", filename.c_str()); break; default: break; } } else { CLog::getInstance()->error("Unable to load %s", filename.c_str()); } }
void GuiTexture::loadFromFile( const CEGUI::String& filename, const CEGUI::String& resourceGroup ) { glBindTexture( GL_TEXTURE_2D, _ogltexture ); // load file to memory via resource provider CEGUI::RawDataContainer texFile; CEGUI::System::getSingleton().getResourceProvider()->loadRawDataContainer( filename, texFile, resourceGroup ); if ( !texFile.getDataPtr() ) return; tImageTGA* img = LoadTGA( texFile.getDataPtr(), texFile.getSize() ); if (img != 0) { _width = static_cast<CEGUI::ushort>(img->sizeX); _height = static_cast<CEGUI::ushort>(img->sizeY); // flip the image... flipImageTGA(img); // If the image is 32-bit (4 channels), then we need to specify GL_RGBA for an alpha, else we use GL_RGB. int textureType = (img->channels == 4) ? GL_RGBA : GL_RGB; glTexImage2D(GL_TEXTURE_2D, 0, textureType, _width, _height, 0, textureType, GL_UNSIGNED_BYTE, img->data); // Free texture data, we don't need it anymore if ( img->data ) { delete[] img->data; } // Free the image structure delete img; } else { throw CEGUI::RendererException("GuiTexture::loadFromFile - internal Targa loader failed to load image '" + filename + "'."); } }