void fetchDir(const char *dirname) { DIR *dir; struct dirent *entry; if (!(dir = opendir(dirname))) return; if (!(entry = readdir(dir))) return; do { checkbusy(); char path[PATH_MAX]; if (entry->d_type == DT_DIR) { int len = snprintf(path, sizeof(path) - 1, "%s/%s", dirname, entry->d_name); path[len] = 0; if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; fetchDir(path); } else if(entry->d_type == DT_REG) { sprintf(path, "%s/%s", dirname, entry->d_name); ReadFileToCache(path, 0); } printf("%s\n", path); // usleep(200); } while ( (entry = readdir(dir)) != NULL); closedir(dir); }
void SpriteManagerBaseNonTemplate::handleImageIDChange(fm::Size spriteIndex,const fg::Glyph &shape) { if (useInstancing()) { fm::vec2 uvsPos = shape.pos; fm::vec2 uvsSiz = shape.size; fm::vec2 frameS = shape.leftdown; m_uvpProp.update(spriteIndex,&uvsPos.x); m_uvsProp.update(spriteIndex,&uvsSiz.x); if (m_useFrames) m_frmProp.update(spriteIndex,&frameS.x); } else { fm::vec2 *uvs; buildVertices(nullptr,&uvs,nullptr, fetchPos(spriteIndex),fetchSize(spriteIndex), shape,fetchDir(spriteIndex),fetchColor(spriteIndex)); m_vertUVsProp.update(spriteIndex,&uvs[0].x); delete[] uvs; } if (!fetchSize(spriteIndex).area()) handleSizeChange(spriteIndex,shape.size); }
void SpriteManagerBaseNonTemplate::handleSizeChange(fm::Size spriteIndex,fm::vec2 size) { fm::vec2 cpySize = size; if (m_useFrames) { fg::Glyph shape = m_glyphGetterFunc(this,spriteIndex); cpySize.w = std::max<float>(cpySize.w,shape.leftdown.w*2); cpySize.h = std::max<float>(cpySize.h,shape.leftdown.h*2); } if (useInstancing()) { m_sizProp.update(spriteIndex,&cpySize.x); } else { fm::vec3 *pts; buildVertices(&pts,nullptr,nullptr, fetchPos(spriteIndex),cpySize, m_glyphGetterFunc(this,spriteIndex),fetchDir(spriteIndex),fetchColor(spriteIndex)); m_vertPtsProp.update(spriteIndex,&pts[0].x); delete[] pts; } }
void SpriteManagerBaseNonTemplate::handleColorChange(fm::Size spriteIndex,fm::vec4 clr) { if (useInstancing()) { m_clrProp.update(spriteIndex,&clr.x); } else { fm::vec4 *clrP; buildVertices(nullptr,nullptr,&clrP, fetchPos(spriteIndex),fetchSize(spriteIndex), m_glyphGetterFunc(this,spriteIndex),fetchDir(spriteIndex),clr); m_vertClrProp.update(spriteIndex,&clrP[0].x); delete[] clrP; } }
void SpriteManagerBaseNonTemplate::handlePosChange(fm::Size spriteIndex,fm::vec3 pos) { if (useInstancing()) { m_posProp.update(spriteIndex,&pos.x); } else { fm::vec3 *pts; buildVertices(&pts,nullptr,nullptr, pos,fetchSize(spriteIndex), m_glyphGetterFunc(this,spriteIndex),fetchDir(spriteIndex),fetchColor(spriteIndex)); m_vertPtsProp.update(spriteIndex,&pts[0].x); delete[] pts; } }
static void* fetchworker(void* arg) { pthread_attr_t thAttr; int policy = 0; pthread_attr_init(&thAttr); pthread_attr_getschedpolicy(&thAttr, &policy); pthread_setschedprio(pthread_self(), sched_get_priority_min(policy)); PX_ASSERT(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL)==0); FetchWorker* fw = (FetchWorker*)arg; // PathEntry* pe = NULL; while(!fw->exit) { FetchQueue* mfsitem; PX_LOCK(&fw->mt); while(fw->head == NULL) { pthread_cond_wait(&fw->cv, &fw->mt); if(fw->exit) { PX_UNLOCK(&fw->mt); break; } } mfsitem = fw->head; if (mfsitem != NULL) { fw->head = fw->head->next; PX_UNLOCK(&fw->mt); /*---------process write back queue---------*/ ReadFileToCache(mfsitem->rscpath, mfsitem->filesize); // *(mfsitem->flag) = '1' ; free(mfsitem); } else { fw->tail = NULL; PX_UNLOCK(&fw->mt); } continue; #ifdef USEFETCHCONF pe = readfetchconf(); while (pe != NULL) { if (pe->pt == PATHDIR_T) { fetchDir(pe->path); } else if (pe->pt == PATHFILE_T) { ReadFileToCache(pe->path); } PathEntry* freepe = pe; pe = pe->next; free(freepe); } printf("done fetchworker!\n"); sleep(FETCHWORKERSLEEPTIME); #endif } pthread_exit(NULL); }