cxTypes cxHashRootReadHash(cxHashRoot root,xmlTextReaderPtr reader) { cxTypes types = cxHashTypesCreate(); int depth = xmlTextReaderDepth(reader); while(xmlTextReaderRead(reader) && depth != xmlTextReaderDepth(reader)){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars key = cxXMLAttr(reader,"key"); if(key == NULL){ continue; } cxAny value = NULL; cxConstChars temp = cxXMLReadElementName(reader); if(ELEMENT_IS_TYPE(cxString)){ cxTypes types = cxHashRootReadString(root, reader); value = types != NULL ? types->any : NULL; } else if(ELEMENT_IS_TYPE(cxHash)){ cxTypes types = cxHashRootReadHash(root, reader); value = types != NULL ? types->any : NULL; } else if(ELEMENT_IS_TYPE(cxArray)){ cxTypes types = cxHashRootReadArray(root, reader); value = types != NULL ? types->any : NULL; } else { value = cxReadValues(root, temp, reader); } if(value != NULL){ cxHashSet(types->any, cxHashStrKey(key), value); } } return types; }
void cxActionReadAttr(cxReaderAttrInfo *info) { cxAction this = info->object; // cxActionSetStepHide(this, cxXMLReadBoolAttr(info, "cxAction.stepHide", this->stepHide)); //delay cxActionSetDelay(this, cxXMLReadFloatAttr(info, "cxAction.delay", this->delay)); //time cxActionSetDuration(this, cxXMLReadFloatAttr(info, "cxAction.time", this->duration)); //init time cxActionSetDurationInit(this, cxXMLReadFloatAttr(info, "cxAction.initTime", this->durationInit)); //curve cxConstChars scurve = cxXMLAttr(info->reader, "cxAction.curve"); cxCurveItem curve = cxCurveGet(scurve); if(curve != NULL){ CX_METHOD_OVERRIDE(this->Curve, curve->func); } // cxActionSetSplit(this, cxXMLReadIntAttr(info, "cxAction.split", this->split)); // cxActionSetSpeed(this, cxXMLReadFloatAttr(info, "cxAction.speed", this->speed)); //actionId cxActionSetId(this, cxXMLReadIntAttr(info, "cxAction.id", this->actionId)); //forever if(cxXMLReadBoolAttr(info, "cxAction.forever", false)){ CX_METHOD_OVERRIDE(this->Exit, cxActionForever); } //assist this->assist = cxXMLReadAssist4fAttr(info, "cxAction.assist", this->assist); //event cxXMLAppendEvent(info, this, cxAction, onStart); cxXMLAppendEvent(info, this, cxAction, onStop); cxXMLAppendEvent(info, this, cxAction, onSplit); cxXMLAppendEvent(info, this, cxAction, onStep); }
static void cxActionRootLoadCodesWithReader(cxAny pav,xmlTextReaderPtr reader) { cxActionRoot this = pav; cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, pav, pav); while(xmlTextReaderRead(reader) && !this->isError){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(!ELEMENT_IS_TYPE(cxActionRoot)){ continue; } cxObjectReadAttrRun(info); break; } while(xmlTextReaderRead(reader)){ CX_CONTINUE(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT); cxConstChars id = cxXMLAttr(reader, "id"); CX_CONTINUE(id == NULL); cxString code = cxXMLReaderReadOuterXml(reader); cxHashSet(this->codes, cxHashStrKey(id), code); } }
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); } } }
void cxHashRootReadDBEnv(cxHashRoot root,xmlTextReaderPtr reader) { cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, root, NULL); cxConstChars type = cxXMLAttr(reader, "type"); cxBool logger = cxXMLReadBoolAttr(info, "logger", false); cxDBEnv env = cxDBEnvCreate(type, logger); if(env != NULL){ cxHashRootReadDB(env, root, reader); } }
static void cxPolygonReadAttr(cxReaderAttrInfo *info) { cxSpriteReadAttr(info); cxConstChars points = cxXMLAttr(info->reader, "cxPolygon.points"); CX_RETURN(points == NULL); cxTypes type = cxEngineTypes(points); CX_ASSERT(cxTypesIsType(type, cxTypesArray), "must is array"); cxArray list = type->any; CX_ARRAY_FOREACH(list, ele){ cxNumber bp = cxArrayObject(ele); cxPolygonAppend(info->object, cxNumberToPoint(bp)); }
cxBool cxHashRootLoadWithReader(cxHashRoot root,xmlTextReaderPtr reader) { cxBool ret = false; while(xmlTextReaderRead(reader)){ if(root->isError){ break; } if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(ELEMENT_IS_TYPE(cxHashRoot)){ ret = true; break; } } CX_RETURN(!ret,false); cxAutoPoolPush(); while(xmlTextReaderRead(reader)){ if(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT){ continue; } cxConstChars temp = cxXMLReadElementName(reader); if(ELEMENT_IS_TYPE(cxDBEnv)){ cxHashRootReadDBEnv(root,reader); continue; } cxConstChars sid = cxXMLAttr(reader, "id"); if(sid == NULL){ CX_WARN("element %s:not set id,data not save to hash table",temp); continue; } cxAny object = NULL; if(ELEMENT_IS_TYPE(cxString)){ //cxTypesString object = cxHashRootReadString(root,reader); }else if(ELEMENT_IS_TYPE(cxHash)){ //cxTypesHash object = cxHashRootReadHash(root,reader); }else if(ELEMENT_IS_TYPE(cxArray)){ //cxTypesArray object = cxHashRootReadArray(root,reader); }else{ //cxTypesNumber object = cxHashRootReadNumber(root, temp, reader); } if(object != NULL){ cxHashSet(root->items, cxHashStrKey(sid), object); } } cxAutoPoolPop(); return ret; }
static cxBool cxRotateXMLReadAttr(cxAny xmlAction,cxAny mAction, xmlTextReaderPtr reader) { cxActionXMLReadAttr(xmlAction, mAction, reader); cxRotate this = mAction; cxChar *sx = cxXMLAttr("cxRotate.x"); cxChar *sy = cxXMLAttr("cxRotate.y"); cxChar *sz = cxXMLAttr("cxRotate.z"); if(sx != NULL){ this->raxis = cxVec3fv(1.0f, 0.0f, 0.0f); this->newRadians = kmDegreesToRadians(atof(sx)); }else if(sy != NULL){ this->raxis = cxVec3fv(0.0f, 1.0f, 0.0f); this->newRadians = kmDegreesToRadians(atof(sy)); }else if(sz != NULL){ this->raxis = cxVec3fv(0.0f, 0.0f, 1.0f); this->newRadians = kmDegreesToRadians(atof(sz)); } xmlFree(sx); xmlFree(sy); xmlFree(sz); return true; }
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; }