void Node::AddChild(PNode node) { CHECK_ASSERT(node && node.get() != this); children_.push_back(node); childrenHash_.insert(std::make_pair(node->name_, node)); PNode thisNode = SharedFromPointerNode(this); node->parent_ = thisNode; PScene scene = scene_.lock(); if (!scene) scene = std::dynamic_pointer_cast<Scene>(thisNode); node->scene_ = scene; if (scene) { PLight light = std::dynamic_pointer_cast<Light>(node); if (light) scene->AddLight(light.get()); else { PCamera camera = std::dynamic_pointer_cast<Camera>(node); if (camera) scene->AddCamera(camera.get()); else { auto ps = std::dynamic_pointer_cast<ParticleSystem>(node); if (ps) scene->AddParticleSystem(ps.get()); } } } node->MarkAsDirty(); }
int Node :: RunNode(const Options & oOptions, Node *& poNode) { if (oOptions.bIsLargeValueMode) { InsideOptions::Instance()->SetAsLargeBufferMode(); } poNode = nullptr; NetWork * poNetWork = nullptr; Breakpoint::m_poBreakpoint = nullptr; BP->SetInstance(oOptions.poBreakpoint); PNode * poRealNode = new PNode(); int ret = poRealNode->Init(oOptions, poNetWork); if (ret != 0) { return ret; } //step1 set node to network //very important, let network on recieve callback can work. poNetWork->m_poNode = poRealNode; //step2 run network. //start recieve message from network, so all must init before this step. //must be the last step. poNetWork->RunNetWork(); poNode = poRealNode; return 0; }
void PScene::render(PRenderState *renderState) { // Update the world transform of each node in the scene. PNode::iterator ni(m_root); PNode *node = *ni; while (node != P_NULL) { // Update the transformation of each node. node->updateWorldTransform(); // Update the bounding box in the world space. node->updateBBox(); // Call customized update routing of each node. node->update(); node = *(++ni); } // Do the rendering. m_renderer->render(renderState); // Apply the post processing effects to the scene. PList<PAbstractEffect *>::iterator it = m_effects.begin(); PList<PAbstractEffect *>::iterator ie = m_effects.end(); while (it != ie) { (*it)->render(renderState); ++it; } }
PNode* SLRParser::reduceRepeatstmt(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Repeatstmt"; //Exp auto q_exp = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //UNTIL reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); //StSeq auto q_stseq = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //REPEAT reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); res->addChild(q_stseq); res->addChild(q_exp); return res; }
void Node::Update() const { if (!dirty_ || hide_) return; dirty_ = false; PNode parent = parent_.lock(); if (parent) { globalModel_ = parent->GetGlobalModelMatrix() * GetTransform(); globalPosition_ = Translation(globalModel_); globalOrientation_ = parent->GetGlobalOrientation() * q_; globalScale_ = Scale(globalModel_); } else { globalModel_ = GetTransform(); globalPosition_ = position_; globalOrientation_ = q_; globalScale_ = scale_; } isScaleUniform_ = NSG::IsScaleUniform(globalScale_); globalModelInv_ = Inverse(globalModel_); globalModelInvTransp_ = Transpose(Inverse(Matrix3(globalModel_))); lookAtDirection_ = globalOrientation_ * VECTOR3_LOOKAT_DIRECTION; upDirection_ = globalOrientation_ * VECTOR3_UP; signalUpdated_->Run(); }
PNode* SLRParser::reduceExp(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Exp"; //Simple-exp auto q_simpleexp = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); if(parsing_stack.top().cell.row.id == "Comparison-op") { //Comparison-op auto q_comparisonop = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //Simple-exp auto q_simpleexp2 = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); res->addChild(q_simpleexp2); res->addChild(q_comparisonop); res->addChild(q_simpleexp); }else{ res->addChild(q_simpleexp); } return res; }
void Node::RemoveChild(Node* node) { int idx = 0; for (auto& child : children_) { if (child.get() == node) { children_.erase(children_.begin() + idx); auto range = childrenHash_.equal_range(node->name_); auto it = range.first; while (it != range.second) { PNode child = it->second.lock(); if (!child) it = childrenHash_.erase(it); else if (child.get() == node) it = childrenHash_.erase(it); else ++it; } break; } ++idx; } }
PNode* SLRParser::reduceTerm(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Term"; //Factor auto q_factor = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); if(parsing_stack.top().cell.row.id == "Mulop") { //Mulop auto q_mulop = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //Term auto q_term = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); res->addChild(q_term); res->addChild(q_mulop); res->addChild(q_factor); }else { res->addChild(q_factor); } return res; }
PNode* SLRParser::reduceFactor(std::stack<stackElement>& parsing_stack) { stackElement e= parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Factor"; if(e.cell.row.id == "OPEN_PAREN") { //OPEN_PAREN //res->addChild(reduceMatch(parsing_stack)); auto q_openparen = reduceMatch(parsing_stack); //Exp res->addChild(parsing_stack.top().node); parsing_stack.pop(); //CLOSE_PAREN //res->addChild(reduceMatch(parsing_stack)); auto q_closeparen = reduceMatch(parsing_stack); }else if(e.cell.row.id == "NUMBER") { //NUMBER res->addChild(reduceMatch(parsing_stack)); }else if(e.cell.row.id == "ID") { //ID res->addChild(reduceID(parsing_stack)); } return res; }
PNode* SLRParser::reduceIFstmt(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "IFstmt"; //END reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); //StSeq auto q_stseq1 = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); if(parsing_stack.top().cell.row.id == "THEN") { //THEN reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); //Exp auto q_exp = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //IF reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); res->addChild(q_exp); res->addChild(q_stseq1); }else if(parsing_stack.top().cell.row.id == "ELSE") { //ELSE reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); //StSeq auto q_stseq2 = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //THEN reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); //Exp auto q_exp = parsing_stack.top().node; //res->addChild(parsing_stack.top().node); parsing_stack.pop(); //IF reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); res->addChild(q_exp); res->addChild(q_stseq2); res->addChild(q_stseq1); } return res; }
PNode* SLRParser::reduceStatement(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = ""; res->addChild(parsing_stack.top().node); parsing_stack.pop(); return res; }
PNode* SLRParser::reduceReadstmt(std::stack<stackElement>& parsing_stack) { PNode* id = reduceID(parsing_stack); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "read-stmt"; res->addChild(id); parsing_stack.pop(); return res; }
void PScene::pause() { PNode::iterator ni(m_root); PNode *node = *(++ni); // Skip the root while (node != P_NULL) { node->pause(); node = *(++ni); } }
//----<DFS nodes of the tree for test>-- void WalkTree(PNode<std::string >* pPNode) { pPNode->clearMarks(); std::cout <<"\n "<<pPNode->value(); PNode<std::string >* pTemp; while (pTemp = pPNode->nextUnmarkedChild()) { pTemp->setMarkState(true); WalkTree(pTemp); } }
bool DataList::Remove(PNode node) { if (!node.Ok()) return false; if (nodes.erase(BA::to_lower_copy(node->Name())) <= 0) return false; node->parent = NULL; node->ListRemove(); return true; }
PNode* SLRParser::reduceAddop(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Addop"; //ADD_OP || MINUS_OP res->addChild(reduceMatch(parsing_stack)); return res; }
PNode* SLRParser::reduceComparison(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Comparison-op"; //LESS_THAN || EQUAL res->addChild(reduceMatch(parsing_stack)); return res; }
bool DataList::Insert(PNode node) /// return false if such entry already exists. { if (!node.Ok()) return false; bool inserted = nodes.insert(std::pair<std::string, PNode>(BA::to_lower_copy(node->name), node)).second; if (!inserted) return false; node->parent = this; node->ListInsertAfter(list_loop.list_prev); return true; }
bool DataList::Remove(const std::string& str) { //PNode node=nodes.find(str.Lower())->last; PNode node = Find(str); if (!node.Ok()) return false; if (nodes.erase(BA::to_lower_copy(str)) <= 0) return false; node->parent = NULL; node->ListRemove(); return true; }
void Node::SetGlobalOrientation(const Quaternion& q) { PNode parent = parent_.lock(); if (parent == nullptr) { SetOrientation(q); } else { SetOrientation(Normalize(Quaternion(parent->GetGlobalModelInvMatrix()) * q)); } }
void Node::SetGlobalPosition(const Vertex3& position) { PNode parent = parent_.lock(); if (parent == nullptr) { SetPosition(position); } else { SetPosition(Vertex3(parent->GetGlobalModelInvMatrix() * Vertex4(position, 1))); } }
LightSpeed::JSON::PNode dbResultToJsonObject( LightSpeed::JSON::IFactory& factory, LightMySQL::Row& row, bool strDate) { using namespace LightSpeed::JSON; using namespace LightSpeed; PNode obj = factory.newClass(); natural c = row.size(); for (natural i = 0; i < c; i++) { const MYSQL_FIELD *fld = row.getResultObject().getFieldInfo(i); ConstStrA name(fld->name,fld->name_length); PNode nd = nil; if (row[i].isNull()) { nd = factory.newNullNode(); } else { switch (fld->type) { case MYSQL_TYPE_TINY: case MYSQL_TYPE_SHORT: case MYSQL_TYPE_LONG: case MYSQL_TYPE_LONGLONG: case MYSQL_TYPE_INT24: nd = factory.newValue(row[i].as<integer>());break; case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DATE: case MYSQL_TYPE_TIME: case MYSQL_TYPE_DATETIME: case MYSQL_TYPE_NEWDATE: nd = parseDateTime(factory,row[i].as<ConstStrA>(),strDate);break; case MYSQL_TYPE_FLOAT: case MYSQL_TYPE_DOUBLE: nd = factory.newValue(row[i].as<double>());break; /* case MYSQL_TYPE_TINY_BLOB: case MYSQL_TYPE_MEDIUM_BLOB: case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_BLOB:nd = factory.newValue(base64_encode(row[i].as<ConstStrA>())); break;*/ case MYSQL_TYPE_SET: nd = createArrayFromSet(factory,row[i].as<ConstStrA>());break; default: nd = factory.newValue(row[i].as<ConstStrA>()); break; } } obj->add(name,nd); } return obj; }
bool DataList::InsertAt(PNode node, PNode where) /// return false if such entry already exists. { if (!node.Ok()) return false; if (!(where->list_prev)) return false; bool inserted = nodes.insert(std::pair<std::string, PNode>((*node).name, node)).second; if (!inserted) return false; node->parent = this; node->ListInsertAfter(where->list_prev); return true; }
PNode DataList::FindByPath(const std::string& str) { if (str.empty()) return this; int i = 0; std::string buff; PDataList current_dir(this); if (str[i] == '/') { // go to root PDataList tmp = Parent(); while (tmp.Ok()) { current_dir = tmp; tmp = tmp->Parent(); } } else { buff += str[0]; } i = 1; while ((unsigned int)(i) < str.size()) { if (str[i] == '/') { if (buff == "..") { current_dir = current_dir->Parent(); if (!current_dir.Ok()) return NULL; } else if (buff != "." && !buff.empty()) { // PNode node = current_dir->Find(buff); if (!node.Ok()) return NULL; PDataList datalist(node); if (datalist.Ok()) { current_dir = datalist; } else return NULL; } buff = ""; } else { buff += str[i]; } ++i; } if (current_dir.Ok()) { if (!buff.empty()) { return current_dir->Find(buff); } else return PNode(current_dir); } else { return NULL; } }
void Node::SetParent(PNode parent) { RemoveFromParent(); if (parent) parent->AddChild(SharedFromPointerNode(this)); MarkAsDirty(); }
PNode* SLRParser::reduceWritestmt(std::stack<stackElement>& parsing_stack) { stackElement e = parsing_stack.top(); PNode* res = Services::memory->alloc<PNode>(); new (res) PNode(); res->Tag = "Writestmt"; //Exp res->addChild(parsing_stack.top().node); parsing_stack.pop(); //WRITE reduceMatch(parsing_stack); //res->addChild(reduceMatch(parsing_stack)); return res; }
void Node::SetGlobalLookAtDirection(const Vertex3& direction) { float length = Length(direction); if (length > 0) { auto rot = QuaternionFromLookRotation(-direction, GetUpDirection()); PNode parent = parent_.lock(); if (parent) { Quaternion q = Inverse(parent->GetGlobalOrientation()); SetOrientation(q * rot); } else { SetOrientation(rot); } } }
void Node::SetGlobalScale(const Vertex3& scale) { PNode parent = parent_.lock(); if (parent == nullptr) { SetScale(scale); } else { Vertex3 globalScale(parent->GetGlobalScale()); globalScale.x = 1 / globalScale.x; globalScale.y = 1 / globalScale.y; globalScale.z = 1 / globalScale.z; SetScale(globalScale * scale); } }
bool DataList::Rename(const std::string& old_name, const std::string& new_name) { // check that new name is not used up. if (nodes.find(BA::to_lower_copy(new_name)) != nodes.end()) return false; nodes_iterator i = nodes.find(BA::to_lower_copy(old_name)); if (i == nodes.end()) return false; PNode node = i->second; ASSERT_LOGIC(node.Ok(), "Internal TDF tree consistency (1)"); ASSERT_LOGIC(node->Name().Lower() == old_name.Lower(), "Internal TDF tree consistency (2)"); node->name = BA::to_lower_copy(new_name); nodes.erase(i); bool inserted = nodes.insert(std::pair<std::string, PNode>(BA::to_lower_copy(node->name), node)).second; ASSERT_LOGIC(inserted, "DataList::Rename failed"); return inserted; }
void DataList::InsertRenameAt(PNode node, PNode where) { // rename if such entry already exists. str contains new name. if (!node.Ok()) return; if (!where->list_prev) return; if (!InsertAt(node, where)) { for (int n = 0; n < 10000; ++n) { std::ostringstream os; os << node->Name() << rename_prefix << n; node->name = os.str(); if (InsertAt(node, where)) { return; } } LslError("insertRename: iterated over 10 000 names, way too many"); } }