cxTexture cxTextureCreate(cxConstChars file) { cxTexture texture = NULL; CX_ASSERT(file != NULL, "file args error"); cxStream stream = cxAssetsStreamCreate(file); if(stream == NULL){ CX_ERROR("create stream from file %s failed",file); return NULL; } char *ext = strrchr(file, '.'); if(ext == NULL){ CX_ERROR("unknow file ext name"); return NULL; } if(cxConstCharsEqu(ext, ".png")){ texture = cxTexturePNGLoadStream(stream); }else if(cxConstCharsEqu(ext, ".pvr")){ texture = cxTexturePVRLoadStream(stream); }else if(cxConstCharsEqu(ext, ".xml")){ texture = cxTextureXMLLoadStream(stream); }else if(cxConstCharsEqu(ext, ".pkm")){ texture = cxTexturePKMLoadStream(stream); }else if(cxConstCharsEqu(ext, ".jpg") || cxConstCharsEqu(ext, ".jpeg")){ texture = cxTextureJPGLoadStream(stream); }else{ CX_ERROR("load texture failed %s",file); } return texture; }
static cxInt cxStreamLuaMakeAssets(lua_State *L) { cxConstChars file = luaL_checkstring(L, 1); cxStream this = cxAssetsStreamCreate(file); CX_LUA_PUSH_OBJECT(this); return 1; }
cxTypes cxHashRootReadString(cxHashRoot root,xmlTextReaderPtr reader) { cxTypes types = cxStringTypesCreate(); cxString bytes = NULL; cxConstChars src = cxXMLAttr(reader, "src"); if(src != NULL){ cxStream stream = cxAssetsStreamCreate(src); bytes = cxStreamAllBytes(stream); }else if(!xmlTextReaderIsEmptyElement(reader)) { bytes = cxXMLReadString(reader); }else{ bytes = NULL; } if(bytes == NULL){ return NULL; } CX_RETAIN_SWAP(types->any, bytes); return types; }
cxXMLScript cxEngineGetXMLScript(cxConstChars file) { cxEngine this = cxEngineInstance(); CX_RETURN(file == NULL,NULL); cxXMLScript script = cxHashGet(this->scripts, cxHashStrKey(file)); if(script != NULL){ return script; } script = CX_CREATE(cxXMLScript); cxStream stream = cxAssetsStreamCreate(file); CX_RETURN(stream == NULL, NULL); CX_RETAIN_SWAP(script->bytes, cxStreamAllBytes(stream)); CX_RETURN(script->bytes == NULL, NULL); cxHashSet(this->scripts, cxHashStrKey(file), script); return script; }