static void cxHashRootReadDB(cxDBEnv env,cxHashRoot root,xmlTextReaderPtr reader) { cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, root, env); int depth = xmlTextReaderDepth(reader); while(xmlTextReaderRead(reader) && depth != xmlTextReaderDepth(reader)){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(!ELEMENT_IS_TYPE(cxDB)){ continue; } cxConstChars file = cxXMLAttr(reader,"file"); cxConstChars table = cxXMLAttr(reader,"table"); cxConstChars type = cxXMLAttr(reader,"type"); cxConstChars sid = cxXMLAttr(reader,"id"); cxConstChars path = cxXMLAttr(reader,"path"); //assert file copy ->to document cxBool copy = cxXMLReadBoolAttr(info, "copy", false); if(copy && file != NULL){ cxCopyFile(file, NULL, NULL); } cxBool rdonly = cxXMLReadBoolAttr(info, "rdonly", false); if(sid == NULL){ CX_WARN("db id not set,will can't add dataset"); } cxString sfile = NULL; if(cxConstCharsEqu(path, "assert")){ sfile = cxAssetsPath(file); //assert must set true rdonly = true; }else if(cxConstCharsEqu(path, "document")){ sfile = cxDocumentPath(file); }else{ CX_ERROR("must set path assert or document"); } cxAny db = NULL; if(file != NULL && table != NULL && type != NULL){ db = cxDBCreate(env, cxStringBody(sfile), table, type, rdonly); } if(db != NULL && sid != NULL){ cxHashSet(root->items, cxHashStrKey(sid), cxDBTypesCreate(db)); }else{ CX_ERROR("open dbenv type %s,db %s:%s failed",cxStringBody(env->type),file,table); } } }
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 cxEngineLuaLoader(lua_State *L) { cxChar path[PATH_MAX] = {0}; cxConstChars file = luaL_checkstring(L, 1); cxConstChars ext = strrchr(file, '.'); cxString data = NULL; if(ext == NULL || !cxConstCharsEqu(ext, ".lua")){ snprintf(path, PATH_MAX, "%s.lua",file); data = cxEngineGetLuaScript(path); } if(data == NULL){ snprintf(path, PATH_MAX, "%s",file); data = cxEngineGetLuaScript(path); } if(data != NULL){ luaL_loadbuffer(L, cxStringBody(data), cxStringLength(data), file); return 1; } luaL_error(L, "error loading file %s error",path); return 1; }
static cxAny cxReadValues(cxHashRoot root,cxConstChars temp,xmlTextReaderPtr reader) { cxNumberValue vm={0}; cxInt b4[4] = {255,255,255,255}; cxString text = cxXMLReadString(reader); CX_RETURN(text == NULL, NULL); cxConstChars value = cxStringBody(text); cxAny rv = NULL; if(ELEMENT_IS_TYPE(cxPoint) && cxReadFloats(value, &vm.vp.vertices.x) == 9){ rv = cxNumberPoint(vm.vp); }else if(ELEMENT_IS_TYPE(cxBool)){ rv = cxNumberBool(cxConstCharsEqu(value, "true")); }else if(ELEMENT_IS_TYPE(cxInt)){ rv = cxNumberInt(atoi(value)); }else if(ELEMENT_IS_TYPE(cxFloat)){ rv = cxNumberFloat(atof(value)); }else if (ELEMENT_IS_TYPE(cxDouble)){ rv = cxNumberDouble(atof(value)); }else if (ELEMENT_IS_TYPE(cxVec2f) && cxReadFloats(value, &vm.vec2f.x) == 2){ rv = cxNumberVec2f(vm.vec2f); }else if (ELEMENT_IS_TYPE(cxSize2f) && cxReadFloats(value, &vm.size2f.w) == 2){ rv = cxNumberSize2f(vm.size2f); }else if(ELEMENT_IS_TYPE(cxColor4f) && cxReadFloats(value, &vm.color4f.r) >= 3){ rv = cxNumberColor4f(vm.color4f); }else if(ELEMENT_IS_TYPE(cxVec2i) && cxReadInts(value, &vm.vec2i.x) == 2){ rv = cxNumberVec2i(vm.vec2i); }else if(ELEMENT_IS_TYPE(cxColor4b) && cxReadInts(value, b4) >= 3){ vm.color4f.r = ((cxFloat)b4[0])/255.0f; vm.color4f.g = ((cxFloat)b4[1])/255.0f; vm.color4f.b = ((cxFloat)b4[2])/255.0f; vm.color4f.a = ((cxFloat)b4[3])/255.0f; rv = cxNumberColor4f(vm.color4f); }else if(ELEMENT_IS_TYPE(cxHash)){ rv = cxHashRootReadHash(root,reader); } return rv; }