cxAny cxPlayEffect(cxConstChars file,cxBool loop) { cxPlayer this = cxPlayerInstance(); JniMethodInfo methodInfo; cxBool ret = cxGetStaticMethodInfo(&methodInfo, CLASS_NAME, "cxEnginePlayEffect","(Ljava/lang/String;Z)I"); CX_ASSERT(ret, "get static method info failed"); CX_UNUSED_PARAM(ret); jstring path = (*methodInfo.env)->NewStringUTF(methodInfo.env,file); cxInt soundId = (*methodInfo.env)->CallStaticIntMethod(methodInfo.env, methodInfo.classID, methodInfo.methodID, path, loop); (*methodInfo.env)->DeleteLocalRef(methodInfo.env,path); if(soundId <= 0){ CX_ERROR("play file failed %s",file); return NULL; } cxTrack track = cxHashGet(this->tracks, cxHashStrKey(file)); //add or replace if(track == NULL || track->soundId != soundId){ track = CX_ALLOC(cxTrack); track->file = cxStringAllocChars(file); track->soundId = soundId; cxHashSet(this->tracks, cxHashStrKey(file), track); CX_RELEASE(track); } return track; }
cxAny cxActionRootCreate(cxConstChars xml) { cxEngine engine = cxEngineInstance(); cxActionRoot this = cxHashGet(engine->actions, cxHashStrKey(xml)); if(this != NULL){ return this; } cxXMLScript script = cxEngineGetXMLScript(xml); if(script == NULL || script->bytes == NULL){ CX_ERROR("%s script not register",xml); return NULL; } this = CX_CREATE(cxActionRoot); xmlTextReaderPtr reader = cxXMLReaderForScript(script,cxActionRootReaderError, this); if(reader == NULL){ CX_ERROR("create xml reader failed"); return NULL; } CX_EVENT_FIRE(this, onBegin); cxActionRootLoadCodesWithReader(this, reader); cxHashKey key = cxHashStrKey(xml); cxHashSet(this->codes, key, script->bytes); cxHashSet(engine->actions, key, this); CX_EVENT_FIRE(this, onEnd); return this; }
cxAny cxEngineTypes(cxConstChars url) { CX_RETURN(url == NULL, NULL); cxEngine this = cxEngineInstance(); cxUrlPath path = cxUrlPathParse(url); CX_RETURN(path == NULL, NULL); cxHashRoot sets = cxHashGet(this->datasets, cxHashStrKey(path->path)); if(sets == NULL){ sets = cxHashRootCreate(path->path); CX_RETURN(sets == NULL, NULL); cxHashSet(this->datasets, cxHashStrKey(path->path), sets); } cxAny ret = NULL; if(path->count >= 2){ ret = cxHashGet(sets->items, cxHashStrKey(path->key)); } return ret; }
//use global cached cxTexture cxTextureFactoryLoadFile(cxConstChars file) { cxTextureFactory factory = cxTextureFactoryInstance(); cxTexture texture = cxHashGet(factory->caches, cxHashStrKey(file)); if(texture != NULL){ return texture; } if((texture = cxTextureCreate(file)) != NULL){ cxHashSet(factory->caches, cxHashStrKey(file), texture); } return texture; }
cxBMPFont cxEngineLoadBMPFont(cxConstChars file) { cxEngine this = cxEngineInstance(); cxBMPFont font = cxHashGet(this->bmpfonts, cxHashStrKey(file)); if(font != NULL){ return font; } font = cxBMPFontCreate(file); if(font == NULL){ return NULL; } cxHashSet(this->bmpfonts, cxHashStrKey(file), font); return font; }
cxAny cxEventBaseHttpConnect(cxConstChars host,cxInt port) { cxEventBase this = cxEventBaseInstance(); cxConstChars key = CX_CONST_STRING("%s:%d",host,port); cxHttpConn conn = cxHashGet(this->conns, cxHashStrKey(key)); if(conn != NULL){ return conn; } conn = cxHttpConnectOpen(host, port); if(conn == NULL){ CX_ERROR("http open %s:%d failed",host,port); return NULL; } cxHashSet(this->conns, cxHashStrKey(key), conn); return conn; }
cxString cxEngineLocalizedText(cxConstChars url) { cxEngine this = cxEngineInstance(); cxUrlPath path = cxUrlPathParse(url); cxTypes langTypes= cxEngineTypes("appConfig.xml?lang"); CX_ASSERT(langTypes != NULL, "appConfig.xml must set lang filed"); cxString dir = cxHashGet(langTypes->any, cxHashStrKey(cxStringBody(this->lang))); if(dir == NULL){ dir = cxHashFirst(langTypes->any); } CX_ASSERT(dir != NULL, "get lang dir error"); cxConstChars file = CX_CONST_STRING("%s/%s",cxStringBody(dir),path->path); cxTypes types = cxEngineTypes(CX_CONST_STRING("%s?%s",file,path->key)); CX_RETURN(types == NULL || !cxTypesIsType(types, cxTypesString), NULL); return types->any; }
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; }
cxAny cxActionRootGet(cxConstChars src) { cxUrlPath path = cxUrlPathParse(src); CX_RETURN(path == NULL, NULL); cxActionRoot this = cxActionRootCreate(path->path); CX_RETURN(this == NULL, NULL); cxString code = cxHashGet(this->codes, (path->count == 1) ? cxHashStrKey(path->path) : cxHashStrKey(path->key)); CX_RETURN(code == NULL, NULL); //create by code xmlTextReaderPtr reader = cxXMLReaderForString(code, NULL, NULL); cxReaderAttrInfo *info = cxReaderAttrInfoMake(reader, this, NULL); while(xmlTextReaderRead(reader)){ CX_CONTINUE(xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT); cxConstChars temp = cxXMLReadElementName(reader); info->object = CX_METHOD_FIRE(NULL, this->Make,temp,reader); CX_CONTINUE(info->object == NULL); //save root cxObjectSetRoot(info->object, this); cxObjectReadAttrRun(info); } return info->object; }
cxAny cxViewGetCache(cxAny pview,cxConstChars key) { cxView this = pview; return cxHashGet(this->caches, cxHashStrKey(key)); }
cxConvert cxGetConvert(cxConstChars name) { CX_ASSERT(convertFuncs != NULL, "global cxjson not init"); CX_ASSERT(cxConstCharsOK(name), "name error"); return cxHashGet(convertFuncs, cxHashStrKey(name)); }
cxTexture cxTextureMTFGet(cxAny pthis,cxInt idx) { CX_ASSERT_THIS(pthis, cxTextureMTF); CX_ASSERT(idx >= 0 && idx < this->header.count, "idx range"); return cxHashGet(this->caches, cxHashIntKey(idx)); }
cxType cxTypesGet(cxConstType typeName) { return cxHashGet(types, cxHashStrKey(typeName)); }