bool AStar::Save(IFileSystem *filesystem, const char *Filename) { CUtlBuffer buf; AStarNode *Node; NodeList_t Links; int TotalNumLinks = 0; int NodeTotal = Nodes.Count(); ////////////////////////////////////////////// // Nodes buf.PutInt(NodeTotal); for(int i = 0; i < NodeTotal; i++) { Node = Nodes[i]; buf.PutFloat(Node->GetPos().x); buf.PutFloat(Node->GetPos().y); buf.PutFloat(Node->GetPos().z); TotalNumLinks += Node->GetLinks().Count(); } ////////////////////////////////////////////// ////////////////////////////////////////////// // Links buf.PutInt(TotalNumLinks); for(int i = 0; i < NodeTotal; i++) { Node = Nodes[i]; Links = Node->GetLinks(); for(int li = 0; li < Links.Count(); li++) { buf.PutInt(Node->GetID()); buf.PutInt(Links[li]->GetID()); } } ////////////////////////////////////////////// ////////////////////////////////////////////// // Write File FileHandle_t fh = filesystem->Open(Filename, "wb"); if(!fh) { return false; } filesystem->Write(buf.Base(), buf.TellPut(), fh); filesystem->Close(fh); ////////////////////////////////////////////// return true; }
void COleFileSystem::GetAllNodesList(NodeList_t& node_list, COleProp* base_node) { if(!(base_node->m_Child_List).empty()) { for(Tree_Level_Itor_t child_node = (base_node->m_Child_List).begin(); child_node != (base_node->m_Child_List).end(); child_node++ ) { GetAllNodesList(node_list, (*child_node)); node_list.push_back((*child_node)); } } else { return; } }
void COleFileSystem::SortList(NodeList_t& node_list) { //printf("sort len = %d\n", node_list.size() ); sort(node_list.begin(), node_list.end(), oleCompare); // stable_sort Compare }
// =========================================================== //! Fixes up references in a block to point to alternative symbols. // based on an existing symbol-to-symbol map // Also called variable substitution. static void remapVarSyms (const VarSymRemap_t& vsym_remap, // regular shared variables const ASTtools::VarSymSet_t& pdSyms, // special shared variables const VarSymRemap_t& private_remap, // variables using private copies SgBasicBlock* b) { // Check if variable remapping is even needed. if (vsym_remap.empty() && private_remap.empty()){ //cout << "no remapping " << endl ; return; } // Find all variable references typedef Rose_STL_Container<SgNode *> NodeList_t; NodeList_t refs = NodeQuery::querySubTree (b, V_SgVarRefExp); // For each of the references , for (NodeList_t::iterator i = refs.begin (); i != refs.end (); ++i) { // Reference possibly in need of fix-up. SgVarRefExp* ref_orig = isSgVarRefExp (*i); ROSE_ASSERT (ref_orig); // Search for a symbol which needs to be replaced. // cout << "this is the symbol " <<ref_orig->get_symbol()->get_name().str() << endl ; VarSymRemap_t::const_iterator ref_new = vsym_remap.find (ref_orig->get_symbol ()); VarSymRemap_t::const_iterator ref_private = private_remap.find (ref_orig->get_symbol ()); // a variable could be both a variable needing passing original value and private variable // such as OpenMP firstprivate, lastprivate and reduction variable // For variable substitution, private remap has higher priority // remapping private variables if (ref_private != private_remap.end()) { // get the replacement variable SgVariableSymbol* sym_new = ref_private->second; // Do the replacement ref_orig->set_symbol (sym_new); } else if (ref_new != vsym_remap.end ()) // Needs replacement, regular shared variables { if(Outliner::enable_debug) { cout << "replace this " << "variable with that " << endl ; } SgVariableSymbol* sym_new = ref_new->second; if (Outliner::temp_variable || Outliner::useStructureWrapper) // uniform handling if temp variables of the same type are used {// two cases: variable using temp vs. variables using pointer dereferencing! if (pdSyms.find(ref_orig->get_symbol())==pdSyms.end()) //using temp ref_orig->set_symbol(sym_new); else { SgPointerDerefExp * deref_exp = SageBuilder::buildPointerDerefExp(buildVarRefExp(sym_new)); deref_exp->set_need_paren(true); SageInterface::replaceExpression(isSgExpression(ref_orig),isSgExpression(deref_exp)); } } else // no variable cloning is used { if (is_C_language()) // old method of using pointer dereferencing indiscriminately for C input // TODO compare the orig and new type, use pointer dereferencing only when necessary { SgPointerDerefExp * deref_exp = SageBuilder::buildPointerDerefExp(buildVarRefExp(sym_new)); deref_exp->set_need_paren(true); SageInterface::replaceExpression(isSgExpression(ref_orig),isSgExpression(deref_exp)); } else ref_orig->set_symbol (sym_new); } } //find an entry } // for every refs }
NodeList_t& AStar::FindPath() { Reset(); FoundPath = false; //Msg("Reset Variables: %i, %i, %i\n", Path.Count(), Opened.Count(), Closed.Count()); if(GetStart() == GetEnd()) { //Msg("Start Is End\n"); return Path; } // 1) Add the starting node to the open list. AddOpenedNode(Start); Start->SetStatus(NULL, 0, 0, 0); float CurrentScoreG; float ScoreF, ScoreG, ScoreH; NodeList_t Links; AStarNode *Current = NULL, *LastNode = NULL, *Link = NULL; //Msg("Added Node\n"); // 2) Repeat the following: while(true) { // a) Look for the lowest F cost square on the open list. We refer to this as the current square. Current = FindLowestF(); if(Current != NULL) { LastNode = Current; if(Current->GetPos() == End->GetPos()) { FoundPath = true; break; } else { CurrentScoreG = Current->GetScoreG(); // b) Switch it to the closed list. AddClosedNode(Current); // c) For each of the nodes linked to this node... Links = Current->GetLinks(); ScoreH = HeuristicDistance(Current->GetPos(), End->GetPos()); //Msg("Found Lowest F: %i | %f, %f, %f\n", Links.Count(), Current->GetPos().x, Current->GetPos().y, Current->GetPos().z); for(int i = 0; i < Links.Count(); i++) { Link = Links[i]; if(Link != NULL) { // If it is not walkable or if it is on the closed list, ignore it. if(!Link->IsClosed()) { // If it isn’t on the open list, add it to the open list. Make the current node the parent of this node. Record the F, G, and H costs of the node. if(!Link->IsOpened()) { //Msg("SetStatus\n"); AddOpenedNode(Link); ScoreG = CurrentScoreG + HeuristicDistance(Current->GetPos(), Link->GetPos()); ScoreF = ScoreG + ScoreH; Link->SetStatus(Current, ScoreF, ScoreG, ScoreH); } //if(Link->Opened()) Always true? //{ if(CurrentScoreG > ScoreG) { Link->SetParent(Current); //Msg("Set Parent\n"); } else { //Msg("%f | %f\n", CurrentScoreG, ScoreG); } //} } } } } } else { //Msg("Failed to find Lowest F\n"); break; } } return CalcPath(LastNode); }