string ParamSet::FindOneFilename(const string &name, const string &d) const { string filename = FindOneString(name, ""); if (filename == "") return d; filename = AbsolutePath(ResolveFilename(filename)); return filename; }
bool ParseArgs(const CompilerInstance &CI, const std::vector<std::string> &Args) override { StringRef DB = "yaml"; StringRef Input; // Parse the extra command line args. // FIXME: This is very limited at the moment. for (StringRef Arg : Args) { if (Arg.startswith("-db=")) DB = Arg.substr(strlen("-db=")); else if (Arg.startswith("-input=")) Input = Arg.substr(strlen("-input=")); } llvm::ErrorOr<std::unique_ptr<include_fixer::YamlSymbolIndex>> SymbolIdx( nullptr); if (DB == "yaml") { if (!Input.empty()) { SymbolIdx = include_fixer::YamlSymbolIndex::createFromFile(Input); } else { // If we don't have any input file, look in the directory of the first // file and its parents. const FrontendOptions &FO = CI.getFrontendOpts(); SmallString<128> AbsolutePath( tooling::getAbsolutePath(FO.Inputs[0].getFile())); StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); SymbolIdx = include_fixer::YamlSymbolIndex::createFromDirectory( Directory, "find_all_symbols_db.yaml"); } } SymbolIndexMgr->addSymbolIndex(std::move(*SymbolIdx)); return true; }
void ParamSet::AddSampledSpectrumFiles(const string &name, const char **names, int nItems) { EraseSpectrum(name); Spectrum *s = new Spectrum[nItems]; for (int i = 0; i < nItems; ++i) { string fn = AbsolutePath(ResolveFilename(names[i])); if (cachedSpectra.find(fn) != cachedSpectra.end()) { s[i] = cachedSpectra[fn]; continue; } vector<float> vals; if (!ReadFloatFile(fn.c_str(), &vals)) { Warning("Unable to read SPD file \"%s\". Using black distribution.", fn.c_str()); s[i] = Spectrum(0.); } else { if (vals.size() % 2) { Warning("Extra value found in spectrum file \"%s\". " "Ignoring it.", fn.c_str()); } vector<float> wls, v; for (uint32_t j = 0; j < vals.size() / 2; ++j) { wls.push_back(vals[2*j]); v.push_back(vals[2*j+1]); } s[i] = Spectrum::FromSampled(&wls[0], &v[0], wls.size()); } cachedSpectra[fn] = s[i]; } spectra.push_back(new ParamSetItem<Spectrum>(name, s, nItems)); delete[] s; }
string DaemonConfig::RunDirectory( void ) { string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "run_directory" ) ); if( Data.empty() ) CRITICAL_LOG_RETURN( Data, "DaemonConfig::RunDirectory; No data in run_directory tag found" ) else { Data = AbsolutePath( Data ); VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::RunDirectory; Returned " << Data ); } }
string DaemonConfigProjectApplication::Check_System_Limits_Script( void ) { string Data = NormalizeString( Parse_XML( ApplicationCache, "check_system_limits_script" ) ); if( Data.empty() ) { CRITICAL_LOG_RETURN( Data, "DaemonConfigProjectApplication::Check_System_Limits_Script; No data in check_system_limits_script tag found" ) } else { Data = AbsolutePath( Data ); VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Check_System_Limits_Script; Returned " << Data ); } }
string DaemonConfigProjectApplication::Job_Abort_Script( void ) { string Data = NormalizeString( Parse_XML( ApplicationCache, "job_abort_script" ) ); if( Data.empty() ) { CRITICAL_LOG_RETURN( Data, "DaemonConfigProjectApplication::Job_Abort_Script; No data in job_abort_script tag found" ) } else { Data = AbsolutePath( Data ); VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfigProjectApplication::Job_Abort_Script; Returned " << Data ); } }
string DaemonConfig::Resource_Certificate_File( void ) { string Data = NormalizeString( Parse_XML( Parse_XML( ConfigurationXML, "resource" ), "resource_certificate_file" ) ); if( Data.empty() ) { CRITICAL_LOG_RETURN( Data, "DaemonConfig::Resource_Certificate_File; No data in resource_certificate_file tag found" ) } else { Data = AbsolutePath( Data ); VERBOSE_DEBUG_LOG_RETURN( Data, "DaemonConfig::Resource_Certificate_File; Returned " << Data ); } }
EncryptionInfoPtr ManifestItem::GetEncryptionInfo() const { ContainerPtr container = GetPackage()->GetContainer(); string abs = AbsolutePath(); if (abs.at(0) == '/') { abs = abs.substr(1, abs.length()-1); } return container->EncryptionInfoForPath(abs); }
unique_ptr<AsyncByteStream> ManifestItem::AsyncReader() const { auto package = GetPackage(); if ( !package ) return nullptr; auto container = package->GetContainer(); if ( !container ) return nullptr; return container->GetArchive()->AsyncByteStreamAtPath(AbsolutePath()); }
CompilationDatabase * CompilationDatabase::autoDetectFromDirectory(StringRef SourceDir, std::string &ErrorMessage) { SmallString<1024> AbsolutePath(getAbsolutePath(SourceDir)); CompilationDatabase *DB = findCompilationDatabaseFromDirectory(AbsolutePath, ErrorMessage); if (!DB) ErrorMessage = ("Could not auto-detect compilation database from directory \"" + SourceDir + "\"\n" + ErrorMessage).str(); return DB; }
CompilationDatabase * CompilationDatabase::autoDetectFromSource(StringRef SourceFile, std::string &ErrorMessage) { SmallString<1024> AbsolutePath(getAbsolutePath(SourceFile)); StringRef Directory = llvm::sys::path::parent_path(AbsolutePath); CompilationDatabase *DB = findCompilationDatabaseFromDirectory(Directory, ErrorMessage); if (!DB) ErrorMessage = ("Could not auto-detect compilation database for file \"" + SourceFile + "\"\n" + ErrorMessage).str(); return DB; }
SEARCH_STACK* PROJECT::SchSearchS() { SEARCH_STACK* ss = (SEARCH_STACK*) GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ); wxASSERT( !ss || dynamic_cast<SEARCH_STACK*>( GetElem( PROJECT::ELEM_SCH_SEARCH_STACK ) ) ); if( !ss ) { ss = new SEARCH_STACK(); // Make PROJECT the new SEARCH_STACK owner. SetElem( PROJECT::ELEM_SCH_SEARCH_STACK, ss ); // to the empty SEARCH_STACK for SchSearchS(), add project dir as first ss->AddPaths( m_project_name.GetPath() ); // next add the paths found in *.pro, variable "LibDir" wxString libDir; try { PART_LIBS::LibNamesAndPaths( this, false, &libDir ); } catch( const IO_ERROR& DBG( ioe ) ) { DBG(printf( "%s: %s\n", __func__, TO_UTF8( ioe.What() ) );) } if( !!libDir ) { wxArrayString paths; SEARCH_STACK::Split( &paths, libDir ); for( unsigned i =0; i<paths.GetCount(); ++i ) { wxString path = AbsolutePath( paths[i] ); ss->AddPaths( path ); // at the end } } // append all paths from aSList add_search_paths( ss, Kiface().KifaceSearch(), -1 ); // addLibrarySearchPaths( SEARCH_STACK* aSP, wxConfigBase* aCfg ) // This is undocumented, but somebody wanted to store !schematic! // library search paths in the .kicad_common file? add_search_paths( ss, Pgm().CommonSettings(), -1 ); }
/// \brief Returns the absolute path of 'File', by prepending it with /// 'BaseDirectory' if 'File' is not absolute. /// /// Otherwise returns 'File'. /// If 'File' starts with "./", the returned path will not contain the "./". /// Otherwise, the returned path will contain the literal path-concatenation of /// 'BaseDirectory' and 'File'. /// /// \param File Either an absolute or relative path. /// \param BaseDirectory An absolute path. static std::string getAbsolutePath( StringRef File, StringRef BaseDirectory) { assert(llvm::sys::path::is_absolute(BaseDirectory)); if (llvm::sys::path::is_absolute(File)) { return File; } StringRef RelativePath(File); if (RelativePath.startswith("./")) { RelativePath = RelativePath.substr(strlen("./")); } llvm::SmallString<1024> AbsolutePath(BaseDirectory); llvm::sys::path::append(AbsolutePath, RelativePath); return AbsolutePath.str(); }
/// \brief Returns the absolute path of 'File', by prepending it with /// 'BaseDirectory' if 'File' is not absolute. /// /// Otherwise returns 'File'. /// If 'File' starts with "./", the returned path will not contain the "./". /// Otherwise, the returned path will contain the literal path-concatenation of /// 'BaseDirectory' and 'File'. /// /// \param File Either an absolute or relative path. /// \param BaseDirectory An absolute path. static std::string getAbsolutePath( StringRef File, StringRef BaseDirectory) { SmallString<1024> PathStorage; assert(llvm::sys::path::is_absolute(BaseDirectory)); if (llvm::sys::path::is_absolute(File)) { llvm::sys::path::native(File, PathStorage); return PathStorage.str(); } StringRef RelativePath(File); // FIXME: Should '.\\' be accepted on Win32? if (RelativePath.startswith("./")) { RelativePath = RelativePath.substr(strlen("./")); } llvm::SmallString<1024> AbsolutePath(BaseDirectory); llvm::sys::path::append(AbsolutePath, RelativePath); llvm::sys::path::native(Twine(AbsolutePath), PathStorage); return PathStorage.str(); }
std::string getAbsolutePath(StringRef File) { SmallString<1024> BaseDirectory; if (const char *PWD = ::getenv("PWD")) BaseDirectory = PWD; else llvm::sys::fs::current_path(BaseDirectory); SmallString<1024> PathStorage; if (llvm::sys::path::is_absolute(File)) { llvm::sys::path::native(File, PathStorage); return PathStorage.str(); } StringRef RelativePath(File); // FIXME: Should '.\\' be accepted on Win32? if (RelativePath.startswith("./")) { RelativePath = RelativePath.substr(strlen("./")); } SmallString<1024> AbsolutePath(BaseDirectory); llvm::sys::path::append(AbsolutePath, RelativePath); llvm::sys::path::native(Twine(AbsolutePath), PathStorage); return PathStorage.str(); }
void ParamSet::AddSampledSpectrumFiles(const std::string &name, const char **names, int nValues) { EraseSpectrum(name); std::unique_ptr<Spectrum[]> s(new Spectrum[nValues]); for (int i = 0; i < nValues; ++i) { std::string fn = AbsolutePath(ResolveFilename(names[i])); if (cachedSpectra.find(fn) != cachedSpectra.end()) { s[i] = cachedSpectra[fn]; continue; } std::vector<Float> vals; if (!ReadFloatFile(fn.c_str(), &vals)) { Warning( "Unable to read SPD file \"%s\". Using black distribution.", fn.c_str()); s[i] = Spectrum(0.); } else { if (vals.size() % 2) { Warning( "Extra value found in spectrum file \"%s\". " "Ignoring it.", fn.c_str()); } std::vector<Float> wls, v; for (size_t j = 0; j < vals.size() / 2; ++j) { wls.push_back(vals[2 * j]); v.push_back(vals[2 * j + 1]); } s[i] = Spectrum::FromSampled(&wls[0], &v[0], wls.size()); } cachedSpectra[fn] = s[i]; } std::shared_ptr<ParamSetItem<Spectrum>> psi( new ParamSetItem<Spectrum>(name, std::move(s), nValues)); spectra.push_back(psi); }
bool ManifestItem::CanLoadDocument() const { return GetPackage()->GetContainer()->FileExistsAtPath(AbsolutePath()); }
int main(void) { int i; bool bPonderTime; UcciCommStruct UcciComm; const char *szEngineName; PositionStruct posProbe; #ifdef _WIN32 HMODULE hModule; #else void *hModule; #endif int mv, stat; char fen[1024]; /* disable stdio buffering */ if (setvbuf(stdin, NULL, _IONBF, 0) != 0) perror("setvbuf"); if (setvbuf(stdout, NULL, _IONBF, 0) != 0) perror("setvbuf"); // myfp = fopen("test", "w+"); // fputs("test\n", myfp); xb_mv_left = 40; xb_mv_ctrl = 40; xb_tm_left = 30000; xb_tm_ctrl = 30000; xb_tm_incr = 0; xb_post = 0; xb_ponder = 0; xb_depth = UCCI_MAX_DEPTH; xb_force = 0; Search.nHashSize = 4; Search.nRandom = 0; Search.nRandomSave = 2; /* if not working with autotools */ #ifndef PKGDATADIR #define PKGDATADIR "." #endif LocatePath(Search.szBookFile, PKGDATADIR "/book.dat"); //LocatePath(Search.szBookFile, "book.dat"); LocatePath(Search.szLibEvalFile, cszLibEvalFile); hModule = LoadEvalApi(Search.szLibEvalFile); bPonderTime = false; PreGenInit(); NewHash(24); // 24=16MB, 25=32MB, 26=64MB, ... Search.pos.FromFen(cszStartFen); Search.pos.nDistance = 0; Search.PreEvaluate(&Search.pos, &PreEval); Search.nBanMoves = 0; Search.bQuit = Search.bBatch = Search.bDebug = Search.bAlwaysCheck = false; Search.bUseHash = Search.bUseBook = Search.bNullMove = Search.bKnowledge = true; Search.bIdle = false; Search.nCountMask = INTERRUPT_COUNT - 1; Search.nRandomMask = 0; Search.rc4Random.InitRand(); szEngineName = Search.GetEngineName(); if (szEngineName == NULL) { PrintLn("id name ElephantEye"); } else { printf("id name %s / ElephantEye\n", szEngineName); fflush(stdout); } PrintLn("id version 3.15"); PrintLn("id copyright 2004-2008 www.elephantbase.net"); PrintLn("id author Morning Yellow"); PrintLn("id user ElephantEye Test Team"); while (BootLine() != UCCI_COMM_XBOARD); // PrintLn("option usemillisec type check default true"); // PrintLn("option promotion type check default false"); // PrintLn("option batch type check default false"); // PrintLn("option debug type check default false"); // PrintLn("option ponder type check default false"); // PrintLn("option alwayscheck type check default false"); // PrintLn("option usehash type check default true"); // PrintLn("option usebook type check default true"); // printf("option bookfiles type string default %s\n", Search.szBookFile); // fflush(stdout); // printf("option evalapi type string default %s\n", szLibEvalFile); // fflush(stdout); // PrintLn("option hashsize type spin min 16 max 1024 default 16"); // PrintLn("option idle type combo var none var small var medium var large default none"); // PrintLn("option pruning type combo var none var small var medium var large default large"); // PrintLn("option knowledge type combo var none var small var medium var large default large"); // PrintLn("option randomness type combo var none var small var medium var large default none"); // PrintLn("option newgame type button"); // PrintLn("ucciok"); // 以下是接收指令和提供对策的循环体 while (!Search.bQuit) { switch (IdleLine(UcciComm, Search.bDebug)) { case UCCI_COMM_STOP: PrintLn("nobestmove"); break; case UCCI_COMM_POSITION: BuildPos(Search.pos, UcciComm); Search.pos.nDistance = 0; Search.PreEvaluate(&Search.pos, &PreEval); Search.nBanMoves = 0; hint_mv = 0; break; case UCCI_COMM_NEW: Search.pos.FromFen(cszStartFen); Search.pos.nDistance = 0; Search.PreEvaluate(&Search.pos, &PreEval); Search.nBanMoves = 0; xb_force = 0; xb_tm_left = xb_tm_ctrl; xb_mv_left = xb_mv_ctrl; xb_depth = UCCI_MAX_DEPTH; hint_mv = 0; break; case UCCI_COMM_BANMOVES: Search.nBanMoves = UcciComm.nBanMoveNum; for (i = 0; i < UcciComm.nBanMoveNum; i ++) { Search.wmvBanList[i] = COORD_MOVE(UcciComm.lpdwBanMovesCoord[i]); } break; case UCCI_COMM_SETOPTION: switch (UcciComm.Option) { case UCCI_OPTION_PROMOTION: PreEval.bPromotion = UcciComm.bCheck; break; case UCCI_OPTION_ALWAYSCHECK: Search.bAlwaysCheck = UcciComm.bCheck; break; case UCCI_OPTION_USEHASH: Search.bUseHash = UcciComm.bCheck; break; case UCCI_OPTION_USEBOOK: Search.bUseBook = UcciComm.bCheck; break; case UCCI_OPTION_BOOKFILES: if (AbsolutePath(UcciComm.szOption)) { strcpy(Search.szBookFile, UcciComm.szOption); } else { LocatePath(Search.szBookFile, UcciComm.szOption); } break; case UCCI_OPTION_EVALAPI: if (AbsolutePath(UcciComm.szOption)) { strcpy(Search.szLibEvalFile, UcciComm.szOption); } else { LocatePath(Search.szLibEvalFile, UcciComm.szOption); } FreeEvalApi(hModule); hModule = LoadEvalApi(Search.szLibEvalFile); break; case UCCI_OPTION_HASHSIZE: DelHash(); Search.nHashSize = UcciComm.nSpin; NewHash(UcciComm.nSpin + 20); break; case UCCI_OPTION_PRUNING: Search.bNullMove = UcciComm.bCheck; break; case UCCI_OPTION_KNOWLEDGE: Search.bKnowledge = UcciComm.bCheck; break; case UCCI_OPTION_RANDOMNESS: Search.nRandom = UcciComm.nSpin; if (UcciComm.nSpin) Search.nRandomSave = UcciComm.nSpin; Search.nRandomMask = (1 << Search.nRandom) - 1; break; default: break; } break; case UCCI_COMM_GO: // Search.bPonder = UcciComm.bPonder; // Search.bDraw = UcciComm.bDraw; // switch (UcciComm.Go) { // case UCCI_GO_DEPTH: // Search.nGoMode = GO_MODE_INFINITY; // Search.nNodes = 0; // SearchMain(UcciComm.nDepth); // break; // case UCCI_GO_NODES: // Search.nGoMode = GO_MODE_NODES; // Search.nNodes = UcciComm.nNodes; // SearchMain(UCCI_MAX_DEPTH); // break; // case UCCI_GO_TIME_MOVESTOGO: // case UCCI_GO_TIME_INCREMENT: // Search.nGoMode = GO_MODE_TIMER; // if (UcciComm.Go == UCCI_GO_TIME_MOVESTOGO) { // // 对于时段制,把剩余时间平均分配到每一步,作为适当时限。 // // 剩余步数从1到5,最大时限依次是剩余时间的100%、90%、80%、70%和60%,5以上都是50% // Search.nProperTimer = UcciComm.nTime / UcciComm.nMovesToGo; // Search.nMaxTimer = UcciComm.nTime * MAX(5, 11 - UcciComm.nMovesToGo) / 10; // } else { // // 对于加时制,假设棋局会在20回合内结束,算出平均每一步的适当时限,最大时限是剩余时间的一半 // Search.nProperTimer = UcciComm.nTime / 20 + UcciComm.nIncrement; // Search.nMaxTimer = UcciComm.nTime / 2; // } // // 如果是后台思考的时间分配策略,那么适当时限设为原来的1.25倍 // Search.nProperTimer += (bPonderTime ? Search.nProperTimer / 4 : 0); // Search.nMaxTimer = MIN(Search.nMaxTimer, Search.nProperTimer * 10); // SearchMain(UCCI_MAX_DEPTH); // break; // default: // break; // } xb_force = 0; Search.nGoMode = GO_MODE_TIMER; prepare_clock(); SearchMain(xb_depth); update_clock(); break; case UCCI_COMM_PROBE: BuildPos(posProbe, UcciComm); if (!PopHash(posProbe)) { PopLeaf(posProbe); } break; case UCCI_COMM_QUIT: Search.bQuit = true; break; case UCCI_COMM_UNDO: if (Search.pos.nDistance >= 1) Search.pos.UndoMakeMove(); hint_mv = 0; break; case UCCI_COMM_REMOVE: if (Search.pos.nDistance >= 2) { Search.pos.UndoMakeMove(); Search.pos.UndoMakeMove(); } hint_mv = 0; break; case UCCI_COMM_USERMOVE: mv = COORD_MOVE(UcciComm.dwMoveCoord); TryMove(Search.pos, stat, mv); switch (stat) { case MOVE_ILLEGAL: printf("Illegal move: %.4s\n", (char *)&UcciComm.dwMoveCoord); break; case MOVE_INCHECK: printf("Illegal move (in check): %.4s\n", (char *)&UcciComm.dwMoveCoord); break; case MOVE_DRAW: puts("1/2-1/2 {Draw by rule}\n"); break; case MOVE_PERPETUAL_LOSS: printf("Illegal move (perpetual attack): %.4s\n", (char *)&UcciComm.dwMoveCoord); break; case MOVE_PERPETUAL: puts("1/2-1/2 {Draw by repetition}\n"); break; case MOVE_MATE: if (Search.pos.sdPlayer == 0) puts("1-0 {checkmate or stalemate}\n"); else puts("0-1 {checkmate or stalemate}\n"); break; default: Search.pos.MakeMove(mv); if (!xb_force) { prepare_clock(); SearchMain(xb_depth); update_clock(); } break; } break; default: break; } } DelHash(); FreeEvalApi(hModule); return 0; }
int start(void) { int i; bool bPonderTime; UcciCommStruct UcciComm; char szLibEvalFile[1024]; const char *szEngineName; PositionStruct posProbe; #ifdef _WIN32 HMODULE hModule; #else void *hModule; #endif if (BootLine() != UCCI_COMM_UCCI) { return 0; } LocatePath(Search.szBookFile, "BOOK.DAT"); LocatePath(szLibEvalFile, cszLibEvalFile); hModule = LoadEvalApi(szLibEvalFile); bPonderTime = false; PreGenInit(); NewHash(24); // 24=16MB, 25=32MB, 26=64MB, ... Search.pos.FromFen("rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR b - - 0 1"); Search.pos.nDistance = 0; Search.PreEvaluate(&Search.pos, &PreEval); Search.nBanMoves = 0; Search.bQuit = Search.bBatch = Search.bDebug = Search.bAlwaysCheck = false; Search.bUseHash = Search.bUseBook = Search.bNullMove = Search.bKnowledge = true; Search.bIdle = false; Search.nCountMask = INTERRUPT_COUNT - 1; Search.nRandomMask = 0; Search.rc4Random.InitRand(); szEngineName = Search.GetEngineName(); if (szEngineName == NULL) { PrintLn("#id name ElephantEye"); } else { //printf("id name %s / ElephantEye\n", szEngineName); //fflush(stdout); pipeOutputWrite("id name %s / ElephantEye\n", szEngineName); } PrintLn("#id version 3.15"); PrintLn("#id copyright 2004-2008 www.elephantbase.net"); PrintLn("#id author Morning Yellow"); PrintLn("#id user ElephantEye Test Team"); PrintLn("#option usemillisec type check default true"); PrintLn("#option promotion type check default false"); PrintLn("#option batch type check default false"); PrintLn("#option debug type check default false"); PrintLn("#option ponder type check default false"); PrintLn("#option alwayscheck type check default false"); PrintLn("#option usehash type check default true"); PrintLn("#option usebook type check default true"); //printf("option bookfiles type string default %s\n", Search.szBookFile); //fflush(stdout); pipeOutputWrite("#option bookfiles type string default %s\n", Search.szBookFile); //printf("option evalapi type string default %s\n", szLibEvalFile); //fflush(stdout); pipeOutputWrite("#option evalapi type string default %s\n", szLibEvalFile); PrintLn("#option hashsize type spin min 16 max 1024 default 16"); PrintLn("#option idle type combo var none var small var medium var large default none"); PrintLn("#option pruning type combo var none var small var medium var large default large"); PrintLn("#option knowledge type combo var none var small var medium var large default large"); PrintLn("#option randomness type combo var none var small var medium var large default none"); PrintLn("#option newgame type button"); PrintLn("#ucciok"); // 以下是接收指令和提供对策的循环体 while (!Search.bQuit) { switch (IdleLine(UcciComm, Search.bDebug)) { case UCCI_COMM_ISREADY: PrintLn("#readyok"); break; case UCCI_COMM_STOP: PrintLn("#nobestmove"); break; case UCCI_COMM_POSITION: BuildPos(Search.pos, UcciComm); Search.pos.nDistance = 0; Search.PreEvaluate(&Search.pos, &PreEval); Search.nBanMoves = 0; break; case UCCI_COMM_BANMOVES: Search.nBanMoves = UcciComm.nBanMoveNum; for (i = 0; i < UcciComm.nBanMoveNum; i ++) { Search.wmvBanList[i] = COORD_MOVE(UcciComm.lpdwBanMovesCoord[i]); } break; case UCCI_COMM_SETOPTION: switch (UcciComm.Option) { case UCCI_OPTION_PROMOTION: PreEval.bPromotion = UcciComm.bCheck; break; case UCCI_OPTION_BATCH: Search.bBatch = UcciComm.bCheck; break; case UCCI_OPTION_DEBUG: Search.bDebug = UcciComm.bCheck; break; case UCCI_OPTION_PONDER: bPonderTime = UcciComm.bCheck; break; case UCCI_OPTION_ALWAYSCHECK: Search.bAlwaysCheck = UcciComm.bCheck; break; case UCCI_OPTION_USEHASH: Search.bUseHash = UcciComm.bCheck; break; case UCCI_OPTION_USEBOOK: Search.bUseBook = UcciComm.bCheck; break; case UCCI_OPTION_BOOKFILES: if (AbsolutePath(UcciComm.szOption)) { strcpy(Search.szBookFile, UcciComm.szOption); } else { LocatePath(Search.szBookFile, UcciComm.szOption); } break; case UCCI_OPTION_EVALAPI: if (AbsolutePath(UcciComm.szOption)) { strcpy(szLibEvalFile, UcciComm.szOption); } else { LocatePath(szLibEvalFile, UcciComm.szOption); } FreeEvalApi(hModule); hModule = LoadEvalApi(szLibEvalFile); break; case UCCI_OPTION_HASHSIZE: DelHash(); i = 19; // 小于1,分配0.5M置换表 while (UcciComm.nSpin > 0) { UcciComm.nSpin /= 2; i ++; } NewHash(MAX(i, 24)); // 最小的置换表设为16M break; case UCCI_OPTION_IDLE: switch (UcciComm.Grade) { case UCCI_GRADE_NONE: Search.bIdle = false; Search.nCountMask = INTERRUPT_COUNT - 1; break; case UCCI_GRADE_SMALL: Search.bIdle = true; Search.nCountMask = INTERRUPT_COUNT / 4 - 1; break; case UCCI_GRADE_MEDIUM: Search.bIdle = true; Search.nCountMask = INTERRUPT_COUNT / 16 - 1; break; case UCCI_GRADE_LARGE: Search.bIdle = true; Search.nCountMask = INTERRUPT_COUNT / 64 - 1; break; default: break; } break; case UCCI_OPTION_PRUNING: Search.bNullMove = (UcciComm.Grade != UCCI_GRADE_NONE); break; case UCCI_OPTION_KNOWLEDGE: Search.bKnowledge = (UcciComm.Grade != UCCI_GRADE_NONE); break; case UCCI_OPTION_RANDOMNESS: switch (UcciComm.Grade) { case UCCI_GRADE_NONE: Search.nRandomMask = 0; break; case UCCI_GRADE_SMALL: Search.nRandomMask = 1; break; case UCCI_GRADE_MEDIUM: Search.nRandomMask = 3; break; case UCCI_GRADE_LARGE: Search.nRandomMask = 7; break; default: break; } break; default: break; } break; case UCCI_COMM_GO: Search.bPonder = UcciComm.bPonder; Search.bDraw = UcciComm.bDraw; switch (UcciComm.Go) { case UCCI_GO_DEPTH: Search.nGoMode = GO_MODE_INFINITY; Search.nNodes = 0; SearchMain(UcciComm.nDepth); break; case UCCI_GO_NODES: Search.nGoMode = GO_MODE_NODES; Search.nNodes = UcciComm.nNodes; SearchMain(UCCI_MAX_DEPTH); break; case UCCI_GO_TIME_MOVESTOGO: case UCCI_GO_TIME_INCREMENT: Search.nGoMode = GO_MODE_TIMER; if (UcciComm.Go == UCCI_GO_TIME_MOVESTOGO) { // 对于时段制,把剩余时间平均分配到每一步,作为适当时限。 // 剩余步数从1到5,最大时限依次是剩余时间的100%、90%、80%、70%和60%,5以上都是50% Search.nProperTimer = UcciComm.nTime / UcciComm.nMovesToGo; Search.nMaxTimer = UcciComm.nTime * MAX(5, 11 - UcciComm.nMovesToGo) / 10; } else { // 对于加时制,假设棋局会在20回合内结束,算出平均每一步的适当时限,最大时限是剩余时间的一半 Search.nProperTimer = UcciComm.nTime / 20 + UcciComm.nIncrement; Search.nMaxTimer = UcciComm.nTime / 2; } // 如果是后台思考的时间分配策略,那么适当时限设为原来的1.25倍 Search.nProperTimer += (bPonderTime ? Search.nProperTimer / 4 : 0); Search.nMaxTimer = MIN(Search.nMaxTimer, Search.nProperTimer * 10); SearchMain(UCCI_MAX_DEPTH); break; default: break; } break; case UCCI_COMM_PROBE: BuildPos(posProbe, UcciComm); if (!PopHash(posProbe)) { PopLeaf(posProbe); } break; case UCCI_COMM_QUIT: Search.bQuit = true; break; default: break; } } DelHash(); FreeEvalApi(hModule); PrintLn("#bye"); return 0; }
int main( int argc, char **argv ) { struct stat fstat; int c, err, maxsize_set, maxlife_set; int do_rescan, do_expire, do_list, print_stat, do_update_param, print_books, is_profile, nfsen_format; char *maxsize_string, *lifetime_string, *datadir; uint64_t maxsize, lifetime, low_water; uint32_t runtime; channel_t *channel, *current_channel; maxsize_string = lifetime_string = NULL; datadir = NULL; maxsize = lifetime = 0; do_rescan = 0; do_expire = 0; do_list = 0; do_update_param = 0; is_profile = 0; print_stat = 0; print_books = 0; maxsize_set = 0; maxlife_set = 0; low_water = 0; nfsen_format = 0; runtime = 0; while ((c = getopt(argc, argv, "e:hl:L:T:Ypr:s:t:u:w:")) != EOF) { switch (c) { case 'h': usage(argv[0]); exit(0); break; case 'l': CheckDataDir(datadir); datadir = optarg; do_list = 1; print_stat = 1; break; case 'L': CheckDataDir(datadir); datadir = optarg; print_stat = 1; print_books = 1; break; case 'p': is_profile = 1; break; case 'r': CheckDataDir(datadir); do_rescan = 1; print_stat = 1; datadir = optarg; break; case 'e': CheckDataDir(datadir); datadir = optarg; do_expire = 1; print_stat = 1; break; case 's': if ( ParseSizeDef(optarg, &maxsize ) == 0 ) exit(250); maxsize_set = 1; break; case 't': if ( ParseTimeDef(optarg, &lifetime ) == 0 ) exit(250); maxlife_set = 1; break; case 'u': CheckDataDir(datadir); datadir = optarg; do_update_param = 1; break; case 'w': low_water = strtoll(optarg, NULL, 10); if ( low_water > 100 ) { fprintf(stderr, "Water mark > 100%%\n"); exit(250); } if ( low_water == 0 ) low_water = 100; break; case 'T': runtime = strtoll(optarg, NULL, 10); if ( runtime > 3600 ) { fprintf(stderr, "Runtime > 3600 (1h)\n"); exit(250); } break; case 'Y': nfsen_format = 1; break; default: usage(argv[0]); exit(250); } } datadir = AbsolutePath(datadir); if ( !datadir ) { fprintf(stderr, "Missing data directory\n"); usage(argv[0]); exit(250); } err = stat(datadir, &fstat); if ( !(fstat.st_mode & S_IFDIR) ) { fprintf(stderr, "No such directory: %s\n", datadir); exit(250); } channel = GetChannelList(datadir, is_profile, do_rescan); // GetChannelList(datadir, is_profile, do_rescan); if ( !channel ) { exit(250); } // printf("Size: %llu, time: %llu\n", maxsize, lifetime); // update water mark only, when not listing if ( !is_profile && !do_list && low_water ) channel->dirstat->low_water = low_water; /* process do_list first: if the UpdateBookStat results in a FORCE_REBUILD, * this will immediately done afterwards * do_expire will need accurate books as well, so update the books here as well */ if ( do_list || do_expire ) { current_channel = channel; while ( current_channel ) { if ( current_channel->books_stat == BOOKKEEPER_OK ) { bookkeeper_t tmp_books; printf("Include nfcapd bookeeping record in %s\n", current_channel->datadir); ClearBooks(current_channel->books, &tmp_books); UpdateBookStat(current_channel->dirstat, &tmp_books); if ( current_channel->dirstat->status == FORCE_REBUILD ) current_channel->do_rescan = 1; } current_channel = current_channel->next; } } // process do_rescan: make sure stats are up to date, if required current_channel = channel; while ( current_channel ) { if ( current_channel->do_rescan ) { int i; uint64_t last_sequence; /* detect new files: If nfcapd adds a new file while we are rescanning the directory * this results in inconsistent data for the rescan. Therefore check at the begin and end * of the rescan for the sequence number, which reflects the accesss/change to the bookkeeping record * It's assumed, that such an event does not occure more than once. However, loop 3 times max */ for ( i=0; i<3; i++ ) { last_sequence = BookSequence(current_channel->books); printf("Scanning files in %s .. ", current_channel->datadir); RescanDir(current_channel->datadir, current_channel->dirstat); if ( current_channel->dirstat->numfiles == 0 ) { //nothing found current_channel->status = NOFILES; } if ( BookSequence(current_channel->books) == last_sequence ) break; printf("Rescan again, due to file changes in directory!\n"); } if ( BookSequence(current_channel->books) != last_sequence ) { fprintf(stderr, "Could not savely rescan the directory. Data is not consistent.\n"); ReleaseBookkeeper(current_channel->books, DETACH_ONLY); if ( current_channel->status == OK ) WriteStatInfo(current_channel->dirstat); exit(250); } printf("done.\n"); if ( current_channel->books_stat == BOOKKEEPER_OK ) { printf("Updating nfcapd bookeeping records\n"); ClearBooks(channel->books, NULL); } } current_channel = current_channel->next; } // now process do_expire if required if ( do_expire ) { dirstat_t old_stat, current_stat; if ( is_profile ) { current_stat.status = 0; current_stat.max_lifetime = lifetime; current_stat.max_size = maxsize; current_stat.low_water = low_water ? low_water : 98; // sum up all channels in the profile current_channel = channel; current_stat.numfiles = current_channel->dirstat->numfiles; current_stat.filesize = current_channel->dirstat->filesize; current_stat.first = current_channel->dirstat->first; current_stat.last = current_channel->dirstat->last; current_channel = current_channel->next; while ( current_channel ) { current_stat.numfiles += current_channel->dirstat->numfiles; current_stat.filesize += current_channel->dirstat->filesize; if ( current_channel->dirstat->first && (current_channel->dirstat->first < current_stat.first) ) current_stat.first = current_channel->dirstat->first; if ( current_channel->dirstat->last > current_stat.last ) current_stat.last = current_channel->dirstat->last; current_channel = current_channel->next; } old_stat = current_stat; ExpireProfile(channel, ¤t_stat, maxsize, lifetime, runtime); } else { // cmd args override dirstat values if ( maxsize_set ) channel->dirstat->max_size = maxsize; else maxsize = channel->dirstat->max_size; if ( maxlife_set ) channel->dirstat->max_lifetime = lifetime; else lifetime = channel->dirstat->max_lifetime; old_stat = *(channel->dirstat); ExpireDir(channel->datadir, channel->dirstat, maxsize, lifetime, runtime); current_stat = *(channel->dirstat); } // Report, what we have done printf("Expired files: %llu\n", (unsigned long long)(old_stat.numfiles - current_stat.numfiles)); printf("Expired file size: %s\n", ScaleValue(old_stat.filesize - current_stat.filesize)); printf("Expired time range: %s\n\n", ScaleTime(current_stat.first - old_stat.first)); } if ( !is_profile && do_update_param ) { switch (channel->books_stat) { case BOOKKEEPER_OK: if ( maxsize_set ) channel->dirstat->max_size = maxsize; else maxsize = channel->dirstat->max_size; if ( maxlife_set ) channel->dirstat->max_lifetime = lifetime; else lifetime = channel->dirstat->max_lifetime; printf("Update collector process running for directory: '%s'\n", datadir); UpdateBooksParam(channel->books, (time_t)lifetime, maxsize); print_stat = 1; break; case ERR_NOTEXISTS: if ( maxsize_set ) channel->dirstat->max_size = maxsize; if ( maxlife_set ) channel->dirstat->max_lifetime = lifetime; print_stat = 1; break; default: // should never be reached as already cought earlier printf("Error %i while connecting to collector\n", channel->books_stat); } if ( channel->status == OK || channel->status == NOFILES ) WriteStatInfo(channel->dirstat); } if ( !is_profile && print_books ) { switch (channel->books_stat) { case BOOKKEEPER_OK: PrintBooks(channel->books); break; case ERR_NOTEXISTS: printf("No collector process running for directory: '%s'\n", channel->datadir); break; default: // should never be reached as already cought earlier printf("Error %i while connecting to collector\n", channel->books_stat); } } if ( print_stat ) { if ( is_profile ) { dirstat_t current_stat; current_stat.status = 0; current_stat.max_lifetime = lifetime; current_stat.max_size = maxsize; current_stat.low_water = low_water ? low_water : 98; // sum up all channels in the profile current_channel = channel; current_stat.numfiles = current_channel->dirstat->numfiles; current_stat.filesize = current_channel->dirstat->filesize; current_stat.first = current_channel->dirstat->first; current_stat.last = current_channel->dirstat->last; current_channel = current_channel->next; while ( current_channel ) { current_stat.numfiles += current_channel->dirstat->numfiles; current_stat.filesize += current_channel->dirstat->filesize; if ( current_channel->dirstat->first && (current_channel->dirstat->first < current_stat.first) ) current_stat.first = current_channel->dirstat->first; if ( current_channel->dirstat->last > current_stat.last ) current_stat.last = current_channel->dirstat->last; current_channel = current_channel->next; } if ( nfsen_format ) { printf("Stat|%llu|%llu|%llu\n", (unsigned long long)current_stat.filesize, (unsigned long long)current_stat.first, (unsigned long long)current_stat.last); } else PrintDirStat(¤t_stat); } else if ( nfsen_format ) printf("Stat|%llu|%llu|%llu\n", (unsigned long long)channel->dirstat->filesize, (unsigned long long)channel->dirstat->first, (unsigned long long)channel->dirstat->last ); else PrintDirStat(channel->dirstat); } current_channel = channel; while ( current_channel ) { ReleaseBookkeeper(current_channel->books, DETACH_ONLY); if ( current_channel->status == OK ) WriteStatInfo(current_channel->dirstat); current_channel = current_channel->next; } return 0; }
//------------------------------------------------------------- //- Load //- Loads an MF1 model from a file //------------------------------------------------------------- uint8* CSGPModelMF1::LoadMF1(CSGPModelMF1* &pOutModelMF1, const String& WorkingDir, const String& Filename) { uint8 * ucpBuffer = 0; uint32 iFileSize = 0; String AbsolutePath(Filename); // Identify by their absolute filenames if possible. if( !File::isAbsolutePath(AbsolutePath) ) { AbsolutePath = WorkingDir + File::separatorString + String(Filename); } { ScopedPointer<FileInputStream> MF1FileStream( File(AbsolutePath).createInputStream() ); if( MF1FileStream == nullptr ) { Logger::getCurrentLogger()->writeToLog(String("Could not open MF1 File:") + Filename, ELL_ERROR); return NULL; } iFileSize = (uint32)MF1FileStream->getTotalLength(); ucpBuffer = new uint8 [iFileSize]; MF1FileStream->read(ucpBuffer, iFileSize); } //Make sure header is valid pOutModelMF1 = (CSGPModelMF1 *)ucpBuffer; if(pOutModelMF1->m_Header.m_iId != 0xCAFE2BEE || pOutModelMF1->m_Header.m_iVersion != 1) { Logger::getCurrentLogger()->writeToLog(Filename + String(" is not a valid MF1 File!"), ELL_ERROR); delete [] ucpBuffer; ucpBuffer = NULL; return NULL; } // Skin { if( pOutModelMF1->m_Header.m_iSkinOffset ) { pOutModelMF1->m_pSkins = (SGPMF1Skin *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iSkinOffset); for( uint32 i=0; i<pOutModelMF1->m_Header.m_iNumSkins; i++ ) { if( pOutModelMF1->m_pSkins[i].m_pMatKeyFrame ) pOutModelMF1->m_pSkins[i].m_pMatKeyFrame = (SGPMF1MatKeyFrame *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pSkins[i].m_pMatKeyFrame); } } else pOutModelMF1->m_pSkins = NULL; } //Mesh { if( pOutModelMF1->m_Header.m_iLod0MeshOffset ) { pOutModelMF1->m_pLOD0Meshes = (SGPMF1Mesh *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iLod0MeshOffset); for( uint32 i=0; i<pOutModelMF1->m_Header.m_iNumMeshes; i++ ) { if( pOutModelMF1->m_pLOD0Meshes[i].m_pVertex ) pOutModelMF1->m_pLOD0Meshes[i].m_pVertex = (SGPMF1Vertex *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pVertex); if( pOutModelMF1->m_pLOD0Meshes[i].m_pIndices ) pOutModelMF1->m_pLOD0Meshes[i].m_pIndices = (uint16 *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pIndices); if( pOutModelMF1->m_pLOD0Meshes[i].m_pVertexBoneGroupID ) pOutModelMF1->m_pLOD0Meshes[i].m_pVertexBoneGroupID = (uint16 *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pVertexBoneGroupID); if( pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords0 ) pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords0 = (SGPMF1TexCoord *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords0); if( pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords1 ) pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords1 = (SGPMF1TexCoord *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pTexCoords1); if( pOutModelMF1->m_pLOD0Meshes[i].m_pVertexColor ) pOutModelMF1->m_pLOD0Meshes[i].m_pVertexColor = (SGPMF1VertexColor *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pLOD0Meshes[i].m_pVertexColor); } } else pOutModelMF1->m_pLOD0Meshes = NULL; if( pOutModelMF1->m_Header.m_iLod1MeshOffset ) {} else pOutModelMF1->m_pLOD1Meshes = NULL; if( pOutModelMF1->m_Header.m_iLod2MeshOffset ) {} else pOutModelMF1->m_pLOD2Meshes = NULL; } // Bone File name { if( pOutModelMF1->m_Header.m_iBoneAnimFileOffset ) pOutModelMF1->m_pBoneFileNames = (SGPMF1BoneFileName *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iBoneAnimFileOffset); else pOutModelMF1->m_pBoneFileNames = NULL; } // ActionList { if( pOutModelMF1->m_Header.m_iActionListOffset ) pOutModelMF1->m_pActionLists = (SGPMF1ActionList *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iActionListOffset); else pOutModelMF1->m_pActionLists = NULL; } //Attachment { if( pOutModelMF1->m_Header.m_iAttachOffset ) pOutModelMF1->m_pAttachTags = (SGPMF1AttachmentTag *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iAttachOffset); else pOutModelMF1->m_pAttachTags = NULL; if( pOutModelMF1->m_Header.m_iEttachOffset ) pOutModelMF1->m_pEffectTags = (SGPMF1AttachmentTag *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iEttachOffset); else pOutModelMF1->m_pEffectTags = NULL; } // Particle { if( pOutModelMF1->m_Header.m_iParticleOffset ) { pOutModelMF1->m_pParticleEmitter = (SGPMF1ParticleTag *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iParticleOffset); for( uint32 i=0; i < pOutModelMF1->m_Header.m_iNumParticles; ++i ) { // Particle System ParticleSystemParam& systemParam = pOutModelMF1->m_pParticleEmitter[i].m_SystemParam; systemParam.m_pGroupParam = (ParticleGroupParam *)(ucpBuffer + (intptr_t)systemParam.m_pGroupParam); for( uint32 j=0; j < systemParam.m_groupCount; ++j ) { // Particle Group ParticleGroupParam& groupParam = systemParam.m_pGroupParam[j]; // Particle Model ParticleModelParam& modelParam = groupParam.m_ModelParam; modelParam.m_pRegularParam = (ParticleRegularParam *)(ucpBuffer + (intptr_t)modelParam.m_pRegularParam); modelParam.m_pInterpolatorParam = (ParticleInterpolatorParam *)(ucpBuffer + (intptr_t)modelParam.m_pInterpolatorParam); // interpolator for(uint32 k=0; k < modelParam.m_InterpolatorCount; ++k) { ParticleInterpolatorParam& interpolatorParam = modelParam.m_pInterpolatorParam[k]; if(interpolatorParam.m_InterpolatorType == Interpolator_SelfDefine) { ParticleSelfDefInterpolatorData& selfDefData = interpolatorParam.m_SelfDefData; selfDefData.m_pEntry = (ParticleEntryParam *)(ucpBuffer + (intptr_t)selfDefData.m_pEntry); } } // Particle Emitter groupParam.m_pEmitterParam = (ParticleEmitterParam *)(ucpBuffer + (intptr_t)groupParam.m_pEmitterParam); // Particle Modifier groupParam.m_pModifierParam = (ParticleModifierParam *)(ucpBuffer + (intptr_t)groupParam.m_pModifierParam); } } } } //Ribbon { } //Config Setting { if( pOutModelMF1->m_Header.m_iConfigsOffset ) { pOutModelMF1->m_pConfigSetting = (SGPMF1ConfigSetting *)(ucpBuffer + (intptr_t)pOutModelMF1->m_Header.m_iConfigsOffset); for( uint32 i=0; i<pOutModelMF1->m_Header.m_iNumConfigs; i++ ) { if( pOutModelMF1->m_pConfigSetting[i].pMeshConfigList ) pOutModelMF1->m_pConfigSetting[i].pMeshConfigList = (SGPMF1ConfigSetting::MeshConfig *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pConfigSetting[i].pMeshConfigList); if( pOutModelMF1->m_pConfigSetting[i].pReplaceTextureConfigList ) pOutModelMF1->m_pConfigSetting[i].pReplaceTextureConfigList = (SGPMF1ConfigSetting::ReplaceTextureConfig *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pConfigSetting[i].pReplaceTextureConfigList); if( pOutModelMF1->m_pConfigSetting[i].pParticleConfigList ) pOutModelMF1->m_pConfigSetting[i].pParticleConfigList = (SGPMF1ConfigSetting::ParticleConfig *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pConfigSetting[i].pParticleConfigList); if( pOutModelMF1->m_pConfigSetting[i].pRibbonConfigList ) pOutModelMF1->m_pConfigSetting[i].pRibbonConfigList = (SGPMF1ConfigSetting::RibbonConfig *)(ucpBuffer + (intptr_t)pOutModelMF1->m_pConfigSetting[i].pRibbonConfigList); } } else pOutModelMF1->m_pConfigSetting = NULL; } pOutModelMF1->m_iNumBones = 0; pOutModelMF1->m_iNumBoneGroup = 0; pOutModelMF1->m_pBones = NULL; pOutModelMF1->m_pBoneGroup = NULL; return ucpBuffer; }
//Load an MF1 bone animation file uint8* CSGPModelMF1::LoadBone(CSGPModelMF1* &pOutModelMF1, const String& WorkingDir, const String& BoneFilename, uint16 BoneFileIndex) { uint8 * ucpBuffer = 0; uint32 iFileSize = 0; String AbsolutePath(BoneFilename); // Identify by their absolute filenames if possible. if( !File::isAbsolutePath(AbsolutePath) ) { AbsolutePath = WorkingDir + File::separatorString + String(BoneFilename); } if( BoneFileIndex > 0 ) AbsolutePath = AbsolutePath + String(BoneFileIndex); { ScopedPointer<FileInputStream> BF1FileStream( File(AbsolutePath).createInputStream() ); if( BF1FileStream == nullptr ) { Logger::getCurrentLogger()->writeToLog(String("Could not open BF1 File:") + BoneFilename, ELL_ERROR); return NULL; } iFileSize = (uint32)BF1FileStream->getTotalLength(); ucpBuffer = new uint8 [iFileSize]; BF1FileStream->read(ucpBuffer, iFileSize); } SGPMF1BoneHeader *pBoneHeader = (SGPMF1BoneHeader *)ucpBuffer; if(pBoneHeader->m_iId != 0xCAFEBBEE || pBoneHeader->m_iVersion != 1) { Logger::getCurrentLogger()->writeToLog(BoneFilename + String(" is not a valid BF1 File!"), ELL_ERROR); delete [] ucpBuffer; ucpBuffer = NULL; return NULL; } if( BoneFileIndex == 0 ) { pOutModelMF1->m_iNumBones = pBoneHeader->m_iNumBones; pOutModelMF1->m_iNumBoneGroup = pBoneHeader->m_iNumBoneGroup; pOutModelMF1->m_pBones = (SGPMF1Bone *)(ucpBuffer + (intptr_t)pBoneHeader->m_iBonesOffset); for(uint32 i=0; i<pOutModelMF1->m_iNumBones; i++) { pOutModelMF1->m_pBones[i].m_ChildIds = (uint16*)(ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_ChildIds); pOutModelMF1->m_pBones[i].m_TransKeyFrames = (KeyFrameBlock*)(ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_TransKeyFrames); pOutModelMF1->m_pBones[i].m_RotsKeyFrames = (KeyFrameBlock*)(ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_RotsKeyFrames); pOutModelMF1->m_pBones[i].m_ScaleKeyFrames = (ScaleKeyFrameBlock*)(ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_ScaleKeyFrames); pOutModelMF1->m_pBones[i].m_VisibleKeyFrames = (VisibleKeyFrameBlock*)(ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_VisibleKeyFrames); pOutModelMF1->m_pBones[i].m_TransKeyFrames->m_KeyFrames = (SGPMF1KeyFrame*) (ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_TransKeyFrames->m_KeyFrames); pOutModelMF1->m_pBones[i].m_RotsKeyFrames->m_KeyFrames = (SGPMF1KeyFrame*) (ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_RotsKeyFrames->m_KeyFrames); pOutModelMF1->m_pBones[i].m_ScaleKeyFrames->m_KeyFrames = (SGPMF1ScaleKeyFrame*) (ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_ScaleKeyFrames->m_KeyFrames); pOutModelMF1->m_pBones[i].m_VisibleKeyFrames->m_KeyFrames = (SGPMF1VisibleKeyFrame*) (ucpBuffer + (intptr_t)pOutModelMF1->m_pBones[i].m_VisibleKeyFrames->m_KeyFrames); } pOutModelMF1->m_pBoneGroup = (SGPMF1BoneGroup *)(ucpBuffer + (intptr_t)pBoneHeader->m_iBoneGroupOffset); } else if( BoneFileIndex > 0 ) { // Some check jassert(pOutModelMF1->m_iNumBones == pBoneHeader->m_iNumBones); jassert(pOutModelMF1->m_iNumBoneGroup == pBoneHeader->m_iNumBoneGroup); // Relocate Pointer SGPMF1Bone* pBones = (SGPMF1Bone *)(ucpBuffer + (intptr_t)pBoneHeader->m_iBonesOffset); for(uint32 i=0; i<pOutModelMF1->m_iNumBones; i++) { KeyFrameBlock* pTransBlock = (KeyFrameBlock*)(ucpBuffer + (intptr_t)pBones[i].m_TransKeyFrames); KeyFrameBlock* pRotsBlock = (KeyFrameBlock*)(ucpBuffer + (intptr_t)pBones[i].m_RotsKeyFrames); ScaleKeyFrameBlock* pScalesBlock = (ScaleKeyFrameBlock*)(ucpBuffer + (intptr_t)pBones[i].m_ScaleKeyFrames); VisibleKeyFrameBlock* pVisibleBlock = (VisibleKeyFrameBlock*)(ucpBuffer + (intptr_t)pBones[i].m_VisibleKeyFrames); pTransBlock->m_KeyFrames = (SGPMF1KeyFrame*) (ucpBuffer + (intptr_t)pTransBlock->m_KeyFrames); pRotsBlock->m_KeyFrames = (SGPMF1KeyFrame*) (ucpBuffer + (intptr_t)pRotsBlock->m_KeyFrames); pScalesBlock->m_KeyFrames = (SGPMF1ScaleKeyFrame*) (ucpBuffer + (intptr_t)pScalesBlock->m_KeyFrames); pVisibleBlock->m_KeyFrames = (SGPMF1VisibleKeyFrame*) (ucpBuffer + (intptr_t)pVisibleBlock->m_KeyFrames); pTransBlock->m_BoneFileID = BoneFileIndex; pRotsBlock->m_BoneFileID = BoneFileIndex; pScalesBlock->m_BoneFileID = BoneFileIndex; pVisibleBlock->m_BoneFileID = BoneFileIndex; // Find next free Block KeyFrameBlock** ppNextTransBlock = &pOutModelMF1->m_pBones[i].m_TransKeyFrames->m_nextBlock; KeyFrameBlock** ppNextRotsBlock = &pOutModelMF1->m_pBones[i].m_RotsKeyFrames->m_nextBlock; ScaleKeyFrameBlock** ppNextScaleBlock = &pOutModelMF1->m_pBones[i].m_ScaleKeyFrames->m_nextBlock; VisibleKeyFrameBlock** ppNextVisibleBlock = &pOutModelMF1->m_pBones[i].m_VisibleKeyFrames->m_nextBlock; while(*ppNextTransBlock != NULL) { ppNextTransBlock = &((*ppNextTransBlock)->m_nextBlock); ppNextRotsBlock = &((*ppNextRotsBlock)->m_nextBlock); ppNextScaleBlock = &((*ppNextScaleBlock)->m_nextBlock); ppNextVisibleBlock = &((*ppNextVisibleBlock)->m_nextBlock); } *ppNextTransBlock = pTransBlock; *ppNextRotsBlock = pRotsBlock; *ppNextScaleBlock = pScalesBlock; *ppNextVisibleBlock = pVisibleBlock; } } return ucpBuffer; }
bool JSONCompilationDatabase::parse(std::string &ErrorMessage) { llvm::yaml::document_iterator I = YAMLStream.begin(); if (I == YAMLStream.end()) { ErrorMessage = "Error while parsing YAML."; return false; } llvm::yaml::Node *Root = I->getRoot(); if (Root == NULL) { ErrorMessage = "Error while parsing YAML."; return false; } llvm::yaml::SequenceNode *Array = llvm::dyn_cast<llvm::yaml::SequenceNode>(Root); if (Array == NULL) { ErrorMessage = "Expected array."; return false; } for (llvm::yaml::SequenceNode::iterator AI = Array->begin(), AE = Array->end(); AI != AE; ++AI) { llvm::yaml::MappingNode *Object = llvm::dyn_cast<llvm::yaml::MappingNode>(&*AI); if (Object == NULL) { ErrorMessage = "Expected object."; return false; } llvm::yaml::ScalarNode *Directory = NULL; llvm::yaml::ScalarNode *Command = NULL; llvm::yaml::ScalarNode *File = NULL; for (llvm::yaml::MappingNode::iterator KVI = Object->begin(), KVE = Object->end(); KVI != KVE; ++KVI) { llvm::yaml::Node *Value = (*KVI).getValue(); if (Value == NULL) { ErrorMessage = "Expected value."; return false; } llvm::yaml::ScalarNode *ValueString = llvm::dyn_cast<llvm::yaml::ScalarNode>(Value); if (ValueString == NULL) { ErrorMessage = "Expected string as value."; return false; } llvm::yaml::ScalarNode *KeyString = llvm::dyn_cast<llvm::yaml::ScalarNode>((*KVI).getKey()); if (KeyString == NULL) { ErrorMessage = "Expected strings as key."; return false; } llvm::SmallString<8> KeyStorage; if (KeyString->getValue(KeyStorage) == "directory") { Directory = ValueString; } else if (KeyString->getValue(KeyStorage) == "command") { Command = ValueString; } else if (KeyString->getValue(KeyStorage) == "file") { File = ValueString; } else { ErrorMessage = ("Unknown key: \"" + KeyString->getRawValue() + "\"").str(); return false; } } if (!File) { ErrorMessage = "Missing key: \"file\"."; return false; } if (!Command) { ErrorMessage = "Missing key: \"command\"."; return false; } if (!Directory) { ErrorMessage = "Missing key: \"directory\"."; return false; } llvm::SmallString<8> FileStorage; StringRef FileName = File->getValue(FileStorage); llvm::SmallString<128> NativeFilePath; if (llvm::sys::path::is_relative(FileName)) { llvm::SmallString<8> DirectoryStorage; llvm::SmallString<128> AbsolutePath( Directory->getValue(DirectoryStorage)); llvm::sys::path::append(AbsolutePath, FileName); llvm::sys::path::native(AbsolutePath.str(), NativeFilePath); } else { llvm::sys::path::native(FileName, NativeFilePath); } IndexByFile[NativeFilePath].push_back( CompileCommandRef(Directory, Command)); MatchTrie.insert(NativeFilePath.str()); } return true; }