//---------------------------------------------------------------------------------------------- Matrix IDrawInterface::CalcWorldTransform() const { Matrix OutMatrix; std::vector<const IDrawInterface*> TmpActorList; TNodeMap<class CActor, class IDrawInterface> *IterActor = m_pNode->GetRootNode(); while (IterActor) // do not allow top level root processing { // use it as origin for child nodes TmpActorList.push_back(IterActor->m_pValue); IterActor = IterActor->GetRootNode(); } // build global space matrix for (std::vector<const IDrawInterface*>::reverse_iterator Iter = TmpActorList.rbegin(); Iter != TmpActorList.rend(); ++Iter) { OutMatrix = OutMatrix * (*Iter)->GetPivot_(); } return OutMatrix; }
Node ITESimplifier::substitute(TNode e, TNodeMap& substTable, TNodeMap& cache) { TNodeMap::iterator it = cache.find(e), iend = cache.end(); if (it != iend) { return it->second; } // do substitution? it = substTable.find(e); iend = substTable.end(); if (it != iend) { Node result = substitute(it->second, substTable, cache); cache[e] = result; return result; } size_t sz = e.getNumChildren(); if (sz == 0) { cache[e] = e; return e; } NodeBuilder<> builder(e.getKind()); if (e.getMetaKind() == kind::metakind::PARAMETERIZED) { builder << e.getOperator(); } for (unsigned i = 0; i < e.getNumChildren(); ++ i) { builder << substitute(e[i], substTable, cache); } Node result = builder; // it = substTable.find(result); // if (it != iend) { // result = substitute(it->second, substTable, cache); // } cache[e] = result; return result; }
//================================================================= void CHTimer::display(CLog *log, TSortCriterion criterion, bool displayInline /*= true*/, bool displayEx) { CSimpleClock benchClock; benchClock.start(); if(!_BenchStartedOnce) // should have done at least one bench { benchClock.stop(); _CurrNode->SonsPreambule += benchClock.getNumTicks(); return; } log->displayNL("HTIMER: ========================================================================="); log->displayRawNL("HTIMER: Bench cumuled results"); typedef std::map<CHTimer *, TNodeVect> TNodeMap; TNodeMap nodeMap; TNodeVect nodeLeft; nodeLeft.push_back(&_RootNode); /// 1 ) walk the tree to build the node map (well, in a not very optimal way..) while (!nodeLeft.empty()) { CNode *currNode = nodeLeft.back(); nodeMap[currNode->Owner].push_back(currNode); nodeLeft.pop_back(); nodeLeft.insert(nodeLeft.end(), currNode->Sons.begin(), currNode->Sons.end()); } // 2 ) build statistics typedef std::vector<CTimerStat> TTimerStatVect; typedef std::vector<CTimerStat *> TTimerStatPtrVect; TTimerStatVect stats(nodeMap.size()); TTimerStatPtrVect statsPtr(stats.size()); // uint k = 0; for(TNodeMap::iterator it = nodeMap.begin(); it != nodeMap.end(); ++it) { statsPtr[k] = &stats[k]; stats[k].Timer = it->first; stats[k].buildFromNodes(&(it->second[0]), (uint)it->second.size(), _MsPerTick); ++k; } // 3 ) sort statistics if (criterion != NoSort) { CStatSorter sorter(criterion); std::sort(statsPtr.begin(), statsPtr.end(), sorter); } // 4 ) get root total time. CStats rootStats; rootStats.buildFromNode( &_RootNode, _MsPerTick); // 5 ) display statistics uint maxNodeLength = 0; std::string format; if (displayInline) { for(TTimerStatPtrVect::iterator statIt = statsPtr.begin(); statIt != statsPtr.end(); ++statIt) { maxNodeLength = std::max(maxNodeLength, (uint)strlen((*statIt)->Timer->_Name)); } format = "HTIMER: %-" + NLMISC::toString(maxNodeLength + 1) + "s %s"; } std::string statsInline; log->displayRawNL(format.c_str(), "", " | total | local | visits | loc%/ glb% | sessn max | min | max | mean"); for(TTimerStatPtrVect::iterator statIt = statsPtr.begin(); statIt != statsPtr.end(); ++statIt) { if (!displayInline) { log->displayRawNL("HTIMER: ================================="); log->displayRawNL("HTIMER: Node %s", (*statIt)->Timer->_Name); (*statIt)->display(log, displayEx, _WantStandardDeviation); } else { (*statIt)->getStats(statsInline, displayEx, rootStats.TotalTime, _WantStandardDeviation); char out[4096]; NLMISC::smprintf(out, 2048, format.c_str(), (*statIt)->Timer->_Name, statsInline.c_str()); log->displayRawNL(out); } } benchClock.stop(); _CurrNode->SonsPreambule += benchClock.getNumTicks(); }
Node ITESimplifier::simplifyWithCare(TNode e) { TNodeMap substTable; CareMap queue; CareMap::iterator it; ITESimplifier::CareSetPtr cs = getNewSet(); ITESimplifier::CareSetPtr cs2; queue[e] = cs; TNode v; bool done; unsigned i; while (!queue.empty()) { it = queue.end(); --it; v = it->first; cs = it->second; set<Node>& css = cs.getCareSet(); queue.erase(v); done = false; set<Node>::iterator iCare, iCareEnd = css.end(); switch (v.getKind()) { case kind::ITE: { iCare = css.find(v[0]); if (iCare != iCareEnd) { Assert(substTable.find(v) == substTable.end()); substTable[v] = v[1]; updateQueue(queue, v[1], cs); done = true; break; } else { iCare = css.find(v[0].negate()); if (iCare != iCareEnd) { Assert(substTable.find(v) == substTable.end()); substTable[v] = v[2]; updateQueue(queue, v[2], cs); done = true; break; } } updateQueue(queue, v[0], cs); cs2 = getNewSet(); cs2.getCareSet() = css; cs2.getCareSet().insert(v[0]); updateQueue(queue, v[1], cs2); cs2 = getNewSet(); cs2.getCareSet() = css; cs2.getCareSet().insert(v[0].negate()); updateQueue(queue, v[2], cs2); done = true; break; } case kind::AND: { for (i = 0; i < v.getNumChildren(); ++i) { iCare = css.find(v[i].negate()); if (iCare != iCareEnd) { Assert(substTable.find(v) == substTable.end()); substTable[v] = d_false; done = true; break; } } if (done) break; Assert(v.getNumChildren() > 1); updateQueue(queue, v[0], cs); cs2 = getNewSet(); cs2.getCareSet() = css; cs2.getCareSet().insert(v[0]); for (i = 1; i < v.getNumChildren(); ++i) { updateQueue(queue, v[i], cs2); } done = true; break; } case kind::OR: { for (i = 0; i < v.getNumChildren(); ++i) { iCare = css.find(v[i]); if (iCare != iCareEnd) { Assert(substTable.find(v) == substTable.end()); substTable[v] = d_true; done = true; break; } } if (done) break; Assert(v.getNumChildren() > 1); updateQueue(queue, v[0], cs); cs2 = getNewSet(); cs2.getCareSet() = css; cs2.getCareSet().insert(v[0].negate()); for (i = 1; i < v.getNumChildren(); ++i) { updateQueue(queue, v[i], cs2); } done = true; break; } default: break; } if (done) { continue; } for (unsigned i = 0; i < v.getNumChildren(); ++i) { updateQueue(queue, v[i], cs); } } while (!d_usedSets.empty()) { delete d_usedSets.back(); d_usedSets.pop_back(); } TNodeMap cache; return substitute(e, substTable, cache); }