bool SoccerBase::GetActiveScene(const Leaf& base, boost::shared_ptr<Scene>& active_scene) { static boost::shared_ptr<SceneServer> sceneServer; if (sceneServer.get() == 0) { if (! GetSceneServer(base,sceneServer)) { base.GetLog()->Error() << "(SoccerBase) ERROR: " << base.GetName() << ", could not get SceneServer\n"; return false; } } active_scene = sceneServer->GetActiveScene(); if (active_scene.get() == 0) { base.GetLog()->Error() << "ERROR: (SoccerBase: " << base.GetName() << ", SceneServer reports no active scene\n"; return false; } return true; }
void Level::checkTouchLeaf(Point point) { if (this->hanged || this->done) { return; } if (this->frog->getJumping()) { return; } __Array* allLeavesKey = this->getLeaves()->allKeys(); for (int i = 0; i < allLeavesKey->count(); i++) { __Integer* key = (__Integer*) allLeavesKey->getObjectAtIndex(i); Leaf* leaf = (Leaf*) this->getLeaves()->objectForKey(key->getValue()); if (leaf->getDrowning()) { continue; } RectBody* leafBody = (RectBody*) leaf->getBody(); if (CPointUtil::isPointInRectangle(point, leaf->getPosition(), leafBody->getWidth(), leafBody->getHeight())) { ViewDirection willingDirection = this->checkJumpable(leaf); if (willingDirection != VIEW_NONE) { this->frog->setViewDirection(willingDirection); this->frogJump(leaf); } break; } } }
bool SoccerBase::GetGameControlServer(const Leaf& base, boost::shared_ptr<GameControlServer> & game_control_server) { static boost::shared_ptr<GameControlServer> gameControlServer; if (gameControlServer.get() == 0) { gameControlServer = shared_dynamic_cast<GameControlServer> (base.GetCore()->Get("/sys/server/gamecontrol")); if (gameControlServer.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << " found no GameControlServer\n"; return false; } } game_control_server = gameControlServer; return true; }
bool Db::insertLeafData(const Leaf& leaf, const Data& data) { if (leaf.getDataSeqNo() != m_nextLeafSeqNo) return false; sqlite3_stmt* statement; sqlite3_prepare_v2(m_db, "INSERT INTO leaves (dataSeqNo, dataName, signerSeqNo, timestamp, isCert, cert)\ VALUES (?, ?, ?, ?, 1, ?)", -1, &statement, nullptr); sqlite3_bind_int(statement, 1, leaf.getDataSeqNo()); sqlite3_bind_block(statement, 2, leaf.getDataName().wireEncode(), SQLITE_TRANSIENT); sqlite3_bind_int(statement, 3, leaf.getSignerSeqNo()); sqlite3_bind_int(statement, 4, leaf.getTimestamp()); sqlite3_bind_block(statement, 5, data.wireEncode(), SQLITE_TRANSIENT); int result = sqlite3_step(statement); sqlite3_finalize(statement); if (result == SQLITE_OK || result == SQLITE_DONE) { m_nextLeafSeqNo++; return true; } return false; }
void CipherText::compute_node(element_t& v, Node* node){//v amounts to s if(node->getType() == LEAF){ Leaf* leaf = (Leaf*)node; leaf->compute(&v, this->pub, this->p); // printf("leaf: %d, %d, computed\n", leaf->getK(), leaf->getNum()); } else if (node->getType() == INTERNAL_NODE){ InternalNode* internalNode = (InternalNode*)node; int num = internalNode->getNum(); int k = internalNode->getK(); Node** sons = internalNode->getSons();//?? // printf("internal Node: %d, %d\n", k, num); element_t* ys = (element_t*)malloc(sizeof(element_t) * (num + 1)); element_init_Zr(ys[0], *(this->p)); element_set(ys[0], v); //set ys[0] to v computePoints(ys, k, num); //compute other num point, int i = 1; for (i = 1; i <= num; i++){ compute_node(ys[i], sons[i - 1]); } } }
void GraphmlParser::parseXmlNodes(Element* xml, ProcessNetwork* processnetwork) throw(InvalidArgumentException, ParseException, IOException, RuntimeException) { if (!xml) { THROW_EXCEPTION(InvalidArgumentException, "\"xml\" must not be NULL"); } if (!processnetwork) { THROW_EXCEPTION(InvalidArgumentException, "\"processnetwork\" must not be NULL"); } list<Element*> elements = getElementsByName(xml, "node"); list<Element*>::iterator it; for (it = elements.begin(); it != elements.end(); ++it) { logger_.logMessage(Logger::DEBUG, string("Analyzing line " + tools::toString((*it)->Row()) + "...")); Leaf* process = generateLeaf(*it); try { if (!processnetwork->addProcess(process)) { THROW_EXCEPTION(ParseException, file_, (*it)->Row(), (*it)->Column(), string("Multiple processs with ID \"") + process->getId()->getString() + "\""); } } catch (bad_alloc&) { THROW_EXCEPTION(OutOfMemoryException); } } }
void TabuSearch::adaptLeafs(LSMove* aMove) { leafs.remove(aMove->out); Leaf* toRemove = NULL; for (list<Leaf*>::iterator aLeaf = leafs.begin(); aLeaf != leafs.end(); aLeaf++) { Vertex* other = ((aMove->in)->getEdge())->otherVertex((aMove->in)->getVertex()); if ((*aLeaf)->getVertex() == other) { toRemove = *aLeaf; break; } } if (toRemove != NULL) { leafs.remove(toRemove); delete(toRemove); } Vertex* ov = ((aMove->out)->getEdge())->otherVertex((aMove->out)->getVertex()); if (((*currentSol).incidentEdges(ov))->size() == 1) { Edge* le = *(((*currentSol).incidentEdges(ov))->begin()); if ((*currentSol).isLeave(ov)) { bool inserted = false; list<Leaf*>::iterator aLeaf; for (aLeaf = leafs.begin(); aLeaf != leafs.end(); aLeaf++) { Edge* cle = (*aLeaf)->getEdge(); if (le->weight() >= cle->weight()) { break; inserted = true; } } if (inserted == true) { leafs.insert(aLeaf,new Leaf(le,ov)); } else { leafs.push_back(new Leaf(le,ov)); } } } Leaf* newLeaf = (aMove->in)->copy(); Edge* le = newLeaf->getEdge(); bool inserted = false; list<Leaf*>::iterator aLeaf; for (aLeaf = leafs.begin(); aLeaf != leafs.end(); aLeaf++) { Edge* cle = (*aLeaf)->getEdge(); if (le->weight() >= cle->weight()) { break; inserted = true; } } if (inserted == true) { leafs.insert(aLeaf,newLeaf); } else { leafs.push_back(newLeaf); } }
Leaf *find(StrItr begin, StrItr end) { if(children.find(*begin) == children.end()) { return NULL; } Leaf *leaf = children[*begin]; if(end-begin == 1) { return leaf; } return leaf->find(begin+1, end); };
void Level::updateLeaves(float dt) { GameModel* gameModel = GameModel::getInstance(); for (auto iter = this->drowningLeaves->begin(); iter != this->drowningLeaves->end(); iter++) { Leaf* drowningLeaf = (Leaf*) *iter; if (drowningLeaf->getDrowning()) { if (drowningLeaf->getCurrentDrownDuration() != -1) { drowningLeaf->setCurrentDrownDuration(drowningLeaf->getCurrentDrownDuration() - dt); if (drowningLeaf->getCurrentDrownDuration() < 0) { drowningLeaf->setCurrentDrownDuration(-1); DataEvent* dataEvent = new DataEvent(); dataEvent->setEventCode(EVT_LEAF_DROWN); dataEvent->setArgumentReference(drowningLeaf); gameModel->fireEvent(dataEvent); this->leaves->removeObjectForKey(drowningLeaf->getPositionIndex()); this->drowningLeaves->eraseObject(drowningLeaf); if (this->leaves->count() == 1) { this->done = true; } break; } } drowningLeaf->play(SPRITE_TYPE_MAIN, FRAME_LEAF_FALL); } } }
//-------------------------------------------------------------- void ofApp::setup(){ ofEnableAlphaBlending(); //allows you to use transparent colors ofEnableSmoothing(); //make lines smoooooooooth... numLeaves = (int)ofRandom(5,15); for (int i = 0; i < numLeaves; i++){ Leaf tempLeaf; tempLeaf.setup(); leaves.push_back(tempLeaf); } }
void VolumeTextureAtlasBuilder::addTexture(const Leaf& leaf) { int x = m_itemCount % m_maxItemCountPerDimension.x; int y = (m_itemCount / m_maxItemCountPerDimension.x) % m_maxItemCountPerDimension.y; int z = m_itemCount / (m_maxItemCountPerDimension.x * m_maxItemCountPerDimension.y); assert(leaf.getVoxelCountPerDimension() == m_itemTextureWidth); leaf.toImageBuffer(*m_imageBuffer, glm::ivec3(x * m_itemTextureWidth, y * m_itemTextureWidth, z * m_itemTextureWidth)); ++m_itemCount; }
///Composite 组合模式通过和 Decorator 模式有着类似的结构图,但是 Composite 模式旨在构造 类,而 Decorator 模式重在不生成子类即可给对象添加职责。Decorator 模式重在修饰,而 Composite 模式重在表示 void CompositeTest() { Leaf* l = new Leaf(); l->Operation(); Composite* com = new Composite(); com->Add(l); com->Operation(); NS_Composite::Component* ll = com->GetChild(0); ll->Operation(); }
void test_composite() { Leaf* l = new Leaf; l->Operation(); ComponentComposite* com = new Composite; com->Add(l); com->Operation(); ComponentComposite* l1 = com->GetChild(0); l1->Operation(); }
void MainWindow::testComposition() { Leaf *pLeaf = new Leaf(); pLeaf->operation(); Composition *pComposion = new Composition(); pComposion->add(pLeaf); pComposion->operation(); Component *pCom2 = pComposion->child(0); pCom2->operation(); }
void append(QueryResult &result, StrItr begin, StrItr end) { Leaf *leaf = NULL; if(children.find(*begin) == children.end()) { leaf = new Leaf(); children[*begin] = leaf; } else { leaf = children[*begin]; } leaf->queryResults.insert(result); if(end-begin > 1) leaf->append(result, begin+1, end); };
void Tree::Divis(const Point* begin, const Point* end, const int& color) { double* dl = new double(begin->Range(end)); if(*dl < kleafrate*size/33.3) { delete dl; return; } Point middle; double* rnd = new double(RND()); if(begin->GetX() == end->GetX() || begin->GetY() == end->GetY()) { int krnd = (*rnd <= 0.5) ? 1 : -1; if(begin->GetX() == end->GetX()) middle.SetXY(begin->GetX() + ((begin->GetX() + krnd * *dl/2 > 0.0) ? krnd : -krnd) * *dl/2, min(begin->GetY(), end->GetY()) + *dl/2); if(begin->GetY() == end->GetY()) middle.SetXY(min(begin->GetX(), end->GetX()) + *dl/2, begin->GetY() + ((begin->GetY() + krnd * *dl/2 > 0.0) ? krnd : -krnd) * *dl/2); } else if(*rnd <= 0.5) middle.SetXY(begin->GetX(), end->GetY()); else middle.SetXY(end->GetX(), begin->GetY()); delete dl; double *chance = new double(center.Range(&sun)/middle.Range(&sun)); if(sflowers != 0 && *rnd < 0.025 * *chance) { f = middle; f.Draw(color); } else { l = middle; if(*rnd < Fi / *chance / 0.8) l.Draw(color3); else l.Draw(color4); } delete chance; delete rnd; Divis(begin, &middle, color); Divis(&middle, end, color); }
bool SoccerBase::GetTransformParent(const Leaf& base, boost::shared_ptr<Transform>& transform_parent) { transform_parent = shared_dynamic_cast<Transform> ((base.FindParentSupportingClass<Transform>()).lock()); if (transform_parent.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") parent node is not derived from TransformNode\n"; return false; } return true; }
QuerySet find(vector<string> &tokens, vector<Boost> &boosts, int max = 20) { QuerySet result; vector<Leaf *> leafs; for(vector<string>::iterator token = tokens.begin(); token != tokens.end(); token++) { transform(token->begin(), token->end(), token->begin(), ::tolower); Leaf *leaf = NULL; leaf = root.find(token->begin(), token->end()); if(leaf == NULL) return result; leafs.push_back(leaf); } if(leafs.size() == 0) return result; sort(leafs.begin(), leafs.end(), sortLeafs); for(QuerySet::reverse_iterator queryResult = leafs[0]->queryResults.rbegin(); queryResult != leafs[0]->queryResults.rend(); queryResult++) { bool inAll = true; for(int i=1; i!=leafs.size(); i++) { if(leafs[i]->queryResults.find(*queryResult) == leafs[i]->queryResults.end()) { inAll = false; break; } } if(inAll) result.insert(queryResult->boost(boosts)); if(boosts.size() == 0 && result.size() == max) return result; } return result; };
void SetLeaf(const double& angle, const double ksize=1.0, const double krate=1.0) { l.SetAngleWidth(angle); kleafsize = ksize; kleafrate = krate; }
void DefaultSize() { center.SetXY(x, y-size*Fi); l.SetSize(kleafsize*size/35); f.SetSize(size/25); }
//-------------------------------------------------------------- void ofApp::setup(){ numLeaves = 40; for(int i=0; i<numLeaves; i++){ Leaf tempLeaf; tempLeaf.setup(); leaves.push_back(tempLeaf); } numCircles = 100; for(int i=0; i<numCircles; i++){ Circle tempCircle; tempCircle.setup(); circles.push_back(tempCircle); } ofSetRectMode(OF_RECTMODE_CENTER); ofEnableSmoothing(); ofEnableAlphaBlending(); }
bool SoccerBase::GetSceneServer(const Leaf& base, boost::shared_ptr<SceneServer>& scene_server) { scene_server = shared_static_cast<SceneServer> (base.GetCore()->Get("/sys/server/scene")); if (scene_server.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") scene server not found.\n"; return false; } return true; }
bool SoccerBase::GetGameState(const Leaf& base, boost::shared_ptr<GameStateAspect>& game_state) { game_state = shared_dynamic_cast<GameStateAspect> (base.GetCore()->Get("/sys/server/gamecontrol/GameStateAspect")); if (game_state.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << ") found no GameStateAspect\n"; return false; } return true; }
void Level::placeLeaves() { Size winSize = Director::getInstance()->getWinSize(); float holeHeight = 110 / 2; float holeWidth = 110 / 2; float originPositionX = (winSize.width - (holeWidth * 2 * CONFIG_LAGOON_WIDTH)) / 2; float originPositionY = (winSize.height - (holeHeight * 2 * CONFIG_LAGOON_HEIGHT)) / 2; int sizeOfLagoon = CONFIG_LAGOON_HEIGHT * CONFIG_LAGOON_WIDTH; for (int i = 0; i < sizeOfLagoon; i++) { Leaf* leaf = (Leaf*) this->leaves->objectForKey(i + 1); if (leaf != NULL) { float height = (i / CONFIG_LAGOON_WIDTH) * holeHeight * 2; float width = (i % CONFIG_LAGOON_WIDTH) * holeWidth * 2; leaf->setPosition(Point(originPositionX + width + holeWidth, originPositionY + height + holeHeight)); } } }
/* Create a leaf. If the "above" parameter is true, it will create the leaf in a random location above the screen. If it's false, the leaf will be created just above the screen, ready to come it. */ Leaf* FallLeaves::_CreateLeaf(BView* view, bool above) { // The Z axis (how far away the leaf is) // determines the size and speed int32 z = RAND_NUM(40, 100); // Use this array to ensure unique Z values. while (fZUsed[z]) { z++; if (z > 100) z = 40; } fZUsed[z] = true; // The lower the Z axis number, the smaller the leaf int32 size = (fSize * z) / 100; // Create the leaf Leaf* leaf = new Leaf(_RandomBitmap(size)); leaf->SetZ(z); // The lower the Z axis number, the slower the leaf int32 maxSpeedFromScreenSize = view->Bounds().IntegerHeight(); int32 maxSpeed = (maxSpeedFromScreenSize * fSpeed) / kMaxSpeed; int32 speed = (maxSpeed * z) / 100; leaf->SetSpeed(speed); BRect boundary(-(size / 2), -view->Bounds().Height(), view->Bounds().Width() - (size / 2), view->Bounds().Height()); leaf->SetBoundary(boundary); // Set it to a random position BPoint pos; pos.x = RAND_NUM((int32)boundary.left, boundary.IntegerWidth()); pos.y = -size; if (above) pos.y = -(RAND_NUM(size, boundary.IntegerHeight())); leaf->SetPos(pos); return leaf; }
int main() { Component* cmp; Leaf* lfp; Leaf lf; Composite cs; cmp = &lf; cmp->Add(cmp); cmp->Remove(cmp); lfp = &lf; lfp->Add(cmp); //compile error lf.Add(cmp); //compile error return 0; }
bool SoccerBase::GetSoccerRuleAspect(const Leaf& base, boost::shared_ptr<SoccerRuleAspect> & soccer_rule_aspect) { soccer_rule_aspect = shared_dynamic_cast<SoccerRuleAspect> (base.GetCore()->Get("/sys/server/gamecontrol/SoccerRuleAspect")); if (soccer_rule_aspect.get() == 0) { base.GetLog()->Error() << "Error: (SoccerBase: " << base.GetName() << " found no SoccerRuleAspect\n"; return false; } return true; }
CNode* VariableEliminator::expand_neq_constraints(Clause& cl, set<Leaf*>& neqs) { set<Leaf*>::iterator it = neqs.begin(); for(; it!= neqs.end(); it++) { Leaf* l = *it; if(l->get_type() == ILP) cl.neg_ilp.erase((ILPLeaf*)l); else cl.neg_eq.erase((EqLeaf*)l); } CNode* node = cl.to_cnode(); set<CNode*> to_and; to_and.insert(node); for(it=neqs.begin(); it!=neqs.end(); it++) { Leaf* l = *it; CNode* lt = NULL; CNode* gt = NULL; if(l->get_type() == ILP) { ILPLeaf* ilp = (ILPLeaf*) l; lt = ILPLeaf::make(ILP_LT, ilp->get_elems(), ilp->get_constant()); lt = lt->fold_negated_ilps(); gt = ILPLeaf::make(ILP_GT, ilp->get_elems(), ilp->get_constant()); gt = gt->fold_negated_ilps(); } else { EqLeaf* eq = (EqLeaf*) l; map<Term*, long int> elems; elems[eq->get_lhs()] = 1; elems[eq->get_rhs()] = -1; lt = ILPLeaf::make(ILP_LT, elems, 0); lt = lt->fold_negated_ilps(); gt = ILPLeaf::make(ILP_GT, elems, 0); gt = gt->fold_negated_ilps(); } CNode* disjunct = Connective::make(OR, lt, gt); to_and.insert(disjunct); } return Connective::make_and(to_and); }
void Level::loadMap() { char mapPath[200]; int chapter = ((this->level - 1) / CONFIG_LEVELS_PER_CHAPTER) + 1; int chapterLevel = ((this->level - 1) % CONFIG_LEVELS_PER_CHAPTER) + 1; sprintf(mapPath, DOC_MAP, this->getLevelIndex(chapter, chapterLevel)); // load water holes Json* root; log("begin read file"); string fileData = CStringUtil::readFile(mapPath, false, true, false); root = Json_create(fileData.data()); if (root) { Json* data = Json_getItem(root, "data"); Json* data_platform = Json_getItem(data, "data_platform"); Json* platform = Json_getItem(data_platform, "platform"); if (platform != NULL) { int size = platform->size; for (int i = 0; i < size; i++) { Json* item = Json_getItemAt(platform, i); int instructionIndex = atoi(Json_getString(item, "_id", "")); int positionIndex = atoi(Json_getString(item, "position", "")); Leaf* leaf = new Leaf(); leaf->setInstructionIndex(instructionIndex); leaf->setPositionIndex(positionIndex); this->leaves->setObject(leaf, positionIndex); } } } // load frog this->frog = new Frog(); CC_SAFE_RETAIN(this->frog); this->frog->setPosition(Point(0, 0)); // place leaves this->placeLeaves(); // place frog this->placeFrog(); }
void FallLeaves::Draw(BView* view, int32 frame) { if (fBackBitmap->Lock()) { // Clear the offscreen buffer fBackView->FillRect(fBackView->Bounds()); // Update and draw the leaves for (int32 i = fLeaves->CountItems() - 1; ; i--) { Leaf* leaf = fLeaves->ItemAt(i); if (leaf == NULL) break; leaf->Update(TICKS_PER_SECOND); leaf->Draw(fBackView); // If the leaf is dead, remove it if (leaf->IsDead()) { fZUsed[leaf->Z()] = false; fLeaves->RemoveItem(leaf); delete leaf; } } fBackBitmap->Unlock(); } bool sort = false; // Add some new leaves if necessary // to replace any dead ones while (fLeaves->CountItems() < fAmount) { fLeaves->AddItem(_CreateLeaf(view, false)); sort = true; } // Keep the leaves sorted by Z axis if (sort) fLeaves->SortItems(cmpz); view->DrawBitmap(fBackBitmap); }