Exemplo n.º 1
0
 void JustSummoned(Creature* pSummon)
 {
     SummonList.push_back(pSummon->GetGUID());
     AggroAllPlayers(pSummon);
 }
Exemplo n.º 2
0
        void DoSummonGrandChampion(uint32 uiBoss)
        {
            ++uiSummonTimes;
            uint32 VEHICLE_TO_SUMMON1 = 0;
            uint32 VEHICLE_TO_SUMMON2 = 0;
            switch(uiBoss)
            {
                case 0:
                    VEHICLE_TO_SUMMON1 = VEHICLE_MOKRA_SKILLCRUSHER_MOUNT;
                    VEHICLE_TO_SUMMON2 = VEHICLE_ORGRIMMAR_WOLF;
                    break;
                case 1:
                    VEHICLE_TO_SUMMON1 = VEHICLE_ERESSEA_DAWNSINGER_MOUNT;
                    VEHICLE_TO_SUMMON2 = VEHICLE_SILVERMOON_HAWKSTRIDER;
                    break;
                case 2:
                    VEHICLE_TO_SUMMON1 = VEHICLE_RUNOK_WILDMANE_MOUNT;
                    VEHICLE_TO_SUMMON2 = VEHICLE_THUNDER_BLUFF_KODO;
                    break;
                case 3:
                    VEHICLE_TO_SUMMON1 = VEHICLE_ZUL_TORE_MOUNT;
                    VEHICLE_TO_SUMMON2 = VEHICLE_DARKSPEAR_RAPTOR;
                    break;
                case 4:
                    VEHICLE_TO_SUMMON1 = VEHICLE_DEATHSTALKER_VESCERI_MOUNT;
                    VEHICLE_TO_SUMMON2 = VEHICLE_FORSAKE_WARHORSE;
                    break;
                default:
                    return;
            }

            if (Creature* pBoss = me->SummonCreature(VEHICLE_TO_SUMMON1,SpawnPosition))
            {
                switch(uiSummonTimes)
                {
                    case 1:
                    {
                        uiVehicle1GUID = pBoss->GetGUID();
                        uint64 uiGrandChampionBoss1 = 0;
                        if (Creature* pBoss = Unit::GetCreature(*me, uiVehicle1GUID))
                            if (Vehicle* pVehicle = pBoss->GetVehicleKit())
                                if (Unit* pUnit = pVehicle->GetPassenger(0))
                                    uiGrandChampionBoss1 = pUnit->GetGUID();
                        if (pInstance)
                        {
                            pInstance->SetData64(DATA_GRAND_CHAMPION_VEHICLE_1,uiVehicle1GUID);
                            pInstance->SetData64(DATA_GRAND_CHAMPION_1,uiGrandChampionBoss1);
                        }
                        pBoss->AI()->SetData(1,0);
                        break;
                    }
                    case 2:
                    {
                        uiVehicle2GUID = pBoss->GetGUID();
                        uint64 uiGrandChampionBoss2 = 0;
                        if (Creature* pBoss = Unit::GetCreature(*me, uiVehicle2GUID))
                            if (Vehicle* pVehicle = pBoss->GetVehicleKit())
                                if (Unit* pUnit = pVehicle->GetPassenger(0))
                                    uiGrandChampionBoss2 = pUnit->GetGUID();
                        if (pInstance)
                        {
                            pInstance->SetData64(DATA_GRAND_CHAMPION_VEHICLE_2,uiVehicle2GUID);
                            pInstance->SetData64(DATA_GRAND_CHAMPION_2,uiGrandChampionBoss2);
                        }
                        pBoss->AI()->SetData(2,0);
                        break;
                    }
                    case 3:
                    {
                        uiVehicle3GUID = pBoss->GetGUID();
                        uint64 uiGrandChampionBoss3 = 0;
                        if (Creature* pBoss = Unit::GetCreature(*me, uiVehicle3GUID))
                            if (Vehicle* pVehicle = pBoss->GetVehicleKit())
                                if (Unit* pUnit = pVehicle->GetPassenger(0))
                                    uiGrandChampionBoss3 = pUnit->GetGUID();
                        if (pInstance)
                        {
                            pInstance->SetData64(DATA_GRAND_CHAMPION_VEHICLE_3,uiVehicle3GUID);
                            pInstance->SetData64(DATA_GRAND_CHAMPION_3,uiGrandChampionBoss3);
                        }
                        pBoss->AI()->SetData(3,0);
                        break;
                    }
                    default:
                        return;
                }

                for (uint8 i = 0; i < 3; ++i)
                {
                    if (Creature* pAdd = me->SummonCreature(VEHICLE_TO_SUMMON2,SpawnPosition,TEMPSUMMON_CORPSE_DESPAWN))
                    {
                        switch(uiSummonTimes)
                        {
                            case 1:
                                Champion1List.push_back(pAdd->GetGUID());
                                break;
                            case 2:
                                Champion2List.push_back(pAdd->GetGUID());
                                break;
                            case 3:
                                Champion3List.push_back(pAdd->GetGUID());
                                break;
                        }

                        switch(i)
                        {
                            case 0:
                                pAdd->GetMotionMaster()->MoveFollow(pBoss,2.0f,M_PI);
                                break;
                            case 1:
                                pAdd->GetMotionMaster()->MoveFollow(pBoss,2.0f,M_PI / 2);
                                break;
                            case 2:
                                pAdd->GetMotionMaster()->MoveFollow(pBoss,2.0f,M_PI / 2 + M_PI);
                                break;
                        }
                    }

                }
            }
        }
Exemplo n.º 3
0
void Inventory::MarkDirty(ItemInst *inst) {
	if(inst) {
		dirty_inst.push_back(inst);
	}
}
Exemplo n.º 4
0
void processTree() {
    TriSet::iterator tit;
    ClassMap::iterator cit, cit2;
    int c, cOld;
    NTriangulation* t;

    for (NPacket* p = tree; p; p = p->nextTreePacket())
        if (p->type() == PACKET_TRIANGULATION) {
            // A triangulation to process.
            t = static_cast<NTriangulation*>(p);
            fprintf(stderr, "Processing %s ...\n", t->label().c_str());
            nTris++;

            nonMin = false;
            orig = static_cast<NTriangulation*>(p);
            equivs.clear();
            equivs.insert(orig);

            tryMovesUp(orig, argUp);

            if (nonMin) {
                allNonMin.push_back(orig);
                nNonMin++;
                continue;
            }

            // In equivs we now have a list of all triangulations
            // equivalent to orig.

            // Is this an equivalence class we're already seen?
            for (tit = equivs.begin(); tit != equivs.end(); tit++) {
                cit = eClass.find(*tit);
                if (cit != eClass.end())
                    break;
            }
            if (tit != equivs.end()) {
                // We found an equivalence class.  Insert everything we
                // haven't seen yet, and merge the classes of everything
                // we have.
                c = cit->second;
                for (tit = equivs.begin(); tit != equivs.end(); tit++) {
                    cit = eClass.find(*tit);
                    if (cit == eClass.end())
                        eClass.insert(std::make_pair(*tit, c));
                    else if (cit->second != c) {
                        // Merge the two equivalence classes.
                        cOld = cit->second;
                        for (cit = eClass.begin(); cit != eClass.end(); cit++)
                            if (cit->second == cOld)
                                cit->second = c;
                        nClasses--;
                    }
                }
            } else {
                // No such equivalence class.  Insert everything.
                c = nextClass++;
                for (tit = equivs.begin(); tit != equivs.end(); tit++)
                    eClass.insert(std::make_pair(*tit, c));
                nClasses++;
            }
        }

    // Finished progress reporting.
    fprintf(stderr, "\n");

    // Write the summary of results.
    if (! allNonMin.empty()) {
        printf("NON-MINIMAL TRIANGULATIONS:\n\n");
        for (std::list<NTriangulation*>::const_iterator it = allNonMin.begin();
                it != allNonMin.end(); it++)
            printf("    %s\n", (*it)->label().c_str());
        printf("\n");
    }

    if (nClasses) {
        printf("EQUIVALENCE CLASSES:\n\n");

        if (outFile) {
            newTree = new NContainer();
            newTree->setLabel("Equivalence Classes");
        }

        int classNum = 1;
        std::string className;
        NContainer* classCnt = 0;

        for (cit = eClass.begin(); cit != eClass.end(); cit++)
            if (cit->second >= 0) {
                // The first triangulation of a new equivalence class.
                c = cit->second;

                std::ostringstream s;
                s << "Class " << classNum << " : " <<
                  cit->first->homology().str();
                className = s.str();
                classNum++;

                printf("%s\n\n", className.c_str());
                if (outFile) {
                    classCnt = new NContainer();
                    classCnt->setLabel(className);
                    newTree->insertChildLast(classCnt);
                }

                // Find the triangulations in this class, and erase the
                // class as we go.
                for (cit2 = cit; cit2 != eClass.end(); cit2++)
                    if (cit2->second == c) {
                        printf("    %s\n",
                               cit2->first->label().c_str());
                        if (outFile) {
                            t = new NTriangulation(*(cit2->first));
                            t->setLabel(cit2->first->label());
                            classCnt->insertChildLast(t);
                        }

                        cit2->second = -1;
                    }

                printf("\n");
            }
    }

    printf("Final statistics:\n");
    printf("    Triangulations read:        %ld\n", nTris);
    printf("    Equivalence classes:        %ld\n", nClasses);
    printf("    New triangulations:         %ld\n", nNew);
    printf("    Non-minimal triangulations: %ld\n", nNonMin);
}
Exemplo n.º 5
0
 void SetGUID(uint64 const guid, int32 id/* = 0 */)
 {
     if (id == DATA_INTENSE_COLD)
         intenseColdList.push_back(guid);
 }
Exemplo n.º 6
0
void RTLInstDict::fixupParamsSub( std::string s, std::list<std::string>& funcParams, bool& haveCount, int mark )
{
  ParamEntry &param = DetParamMap[s];

  if ( param.params.size() == 0 )
    {
      std::cerr << "Error in SSL File: Variant operand " << s << " has no branches. Well that's really useful...\n";
      return;
    }
  if ( param.mark == mark )
    return; /* Already seen this round. May indicate a cycle, but may not */

  param.mark = mark;

  for ( std::list<std::string>::iterator it = param.params.begin();
        it != param.params.end(); it++ )
    {
      ParamEntry &sub = DetParamMap[*it];
      if (sub.kind == PARAM_VARIANT )
        {
          fixupParamsSub(*it, funcParams, haveCount, mark );
          if (!haveCount)
            { /* Empty branch? */
              continue;
            }
        }
      else if (!haveCount )
        {
          haveCount = true;
          char buf[10];
          for (unsigned i=1; i <= sub.funcParams.size(); i++ )
            {
              sprintf( buf, "__lp%d", i );
              funcParams.push_back(buf);
            }
        }

      if (funcParams.size() != sub.funcParams.size() )
        {
          std::cerr << "Error in SSL File: Variant operand " << s << " does not have a fixed number of functional "
          "parameters:\n" << "Expected " << funcParams.size() << ", but branch " << *it << " has " <<
          sub.funcParams.size() << ".\n";
        }
      else if (funcParams != sub.funcParams && sub.asgn != NULL )
        {
          /* Rename so all the parameter names match */
          std::list<std::string>::iterator i,j;
          for ( i = funcParams.begin(), j = sub.funcParams.begin(); i != funcParams.end(); i++, j++ )
            {
              Exp* match = Location::param(j->c_str());
              Exp* replace = Location::param(i->c_str());
              sub.asgn->searchAndReplace( match, replace );
            }
          sub.funcParams = funcParams;
        }
    }

//	  if( param.funcParams.size() != funcParams.size() )
//		  theSemTable.setItem( n, cFUNCTION, 0, 0, funcParams.size(),
//							   theSemTable[n].sName.c_str() );
  param.funcParams = funcParams;
}
Exemplo n.º 7
0
 void SetTarget(std::list<WorldObject*>& targets)
 {
     targets.clear();
     if (_target)
         targets.push_back(_target);
 }
Exemplo n.º 8
0
	void cnx_dolink(bt_session_cnx_t *cnx) 	throw()	{ cnx_db.push_back(cnx);	}
Exemplo n.º 9
0
 void JustSummoned(Creature* summoned)
 {
     lDwarfGUIDList.push_back(summoned->GetGUID());
     summoned->AddThreat(me, 0.0f);
     summoned->AI()->AttackStart(me);
 }
Exemplo n.º 10
0
void LineAccumulator::new_line()
{
    //std::cerr << "NEW LINE" << std::endl;
    Line line;
    m_lines.push_back(line);
}
Exemplo n.º 11
0
	void swarm_dolink(bt_swarm_t *swarm) 	throw()	{ swarm_db.push_back(swarm);	}
Exemplo n.º 12
0
int AStarPathFind::PathFind(int nStartX, int nStartY, int nEndX, int nEndY, std::list<Point>& oListPath)
{
    if (m_poMapConf == NULL)
    {
        return -1;
    }
    nStartX = XMath::Max(0, XMath::Min(nStartX, (int)m_poMapConf->nPixelWidth - 1));
    nStartY = XMath::Max(0, XMath::Min(nStartY, (int)m_poMapConf->nPixelHeight - 1));
    nEndX = XMath::Max(0, XMath::Min(nEndX, (int)m_poMapConf->nPixelWidth - 1));
    nEndY = XMath::Max(0, XMath::Min(nEndY , (int)m_poMapConf->nPixelHeight - 1));
    int nSX = nStartX / gnUnitWidth;
    int nSY = nStartY / gnUnitHeight;
    int nEX = nEndX / gnUnitWidth;
    int nEY = nEndY / gnUnitHeight;
    if (nSX == nEX && nSY == nEY)
    {
        return -2;
    }
    if (!CanWalk(nSX, nSY) || !CanWalk(nEX, nEY))
    {
        return -3;
    }
    m_uSearchVersion++;
    ASTAR_NODE* pNode = GetNode(nSX, nSY);
    ASTAR_NODE* pEnd = GetNode(nEX, nEY);
    if (pNode == NULL || pEnd == NULL)
    {
        return -4;
    }
    m_OpenedList.Clear();
    pNode->bOpened = true;
    m_OpenedList.Push(pNode);
    static int tDir[8][2] = { { -1, 1 }, { -1, 0 }, { -1, -1 }, { 0, 1 }, { 0, -1 }, { 1, 1 }, { 1, 0 }, { 1, -1 } };
    while (!pEnd->bClosed && m_OpenedList.Size() > 0)
    {
        pNode = m_OpenedList.Min();
        m_OpenedList.Remove(pNode);
        pNode->bOpened = false;
        pNode->bClosed = true;
        ASTAR_NODE* pTmpNode = NULL;
        for (int i = 0; i < 8; i++)
        {
            int nX = pNode->nX + tDir[i][0];
            int nY = pNode->nY + tDir[i][1];
            pTmpNode = GetNode(nX, nY);
            if (pTmpNode == NULL || !CanWalk(nX, nY)) 
            {
                continue;
            }
            if (!CanDiagonalWalk(pNode, pTmpNode))
            {
                continue;
            }
            int nG = pNode->nG + GetG(pNode->nX, pNode->nY, pTmpNode->nX, pTmpNode->nY);
            int nH = GetH(pTmpNode->nX, pTmpNode->nY, pEnd->nX, pEnd->nY);
			int nF = nG + nH;
            if (pTmpNode->bOpened || pTmpNode->bClosed)
            {
                if (pTmpNode->nKey > nF)
                {
                    pTmpNode->nG = nG;
                    pTmpNode->nH = nH;
					pTmpNode->nKey = nF;
                    pTmpNode->pParent = pNode;
					if (pTmpNode->bOpened)
					{
						m_OpenedList.Update(pTmpNode);
					}
                }
            }
            else
            {
				pTmpNode->nG = nG;
                pTmpNode->nH = nH;
				pTmpNode->nKey = nF;
                pTmpNode->pParent = pNode;
                m_OpenedList.Push(pTmpNode);
                pTmpNode->bOpened = true;
            }
        }
    }
    if (!pEnd->bClosed)
    {
        return -5;
    }
    m_oTmpListPath.clear();
    ASTAR_NODE* pTarNode = pNode;
	//XLog(LEVEL_DEBUG,"Robot path0:");
    while (pTarNode != NULL)
    {
        ASTAR_POINT oASPos;
        oASPos.nX = pTarNode->nX;
        oASPos.nY = pTarNode->nY;
		//XLog(LEVEL_DEBUG, "[%d,%d] ", oASPos.nX, 35 - oASPos.nY);
        m_oTmpListPath.push_front(oASPos);
        pTarNode = pTarNode->pParent;
    }
	//XLog(LEVEL_DEBUG,"\n");

    if (m_oTmpListPath.size() > 2)
    {
        Floyd(m_oTmpListPath);
    }
    ASLITER iter = m_oTmpListPath.begin();
    ASLITER iter_end = m_oTmpListPath.end();
	//XLog(LEVEL_DEBUG,"Robot path1:");
    for (; iter != iter_end; iter++)
    {
        ASTAR_POINT& oPos = *iter;
		int nPosX = (int)((oPos.nX + 0.5f) * gnUnitWidth);
		int nPosY = (int)((oPos.nY + 0.5f) * gnUnitHeight);
		oListPath.push_back(Point(nPosX, nPosY));
		//XLog(LEVEL_DEBUG,"[%d,%d](%d,%d) ", nPosX, nPosY, oPos.nX, 35-oPos.nY);
    }
	//XLog(LEVEL_DEBUG,"\n");
    return 0;
}
Exemplo n.º 13
0
void
StatsD::ParseMetrics( std::string const &stats_metrics_string, char const *param_name, std::list< classad::ClassAd * > &stats_metrics ) {

    // Parse a list of metrics.  The expected syntax is
    // a list of ClassAds, optionally delimited by commas and or
    // whitespace.

    int offset = 0;
    while(1) {
        if(offset >= (int)stats_metrics_string.size()) break;

        int this_offset = offset; //save offset before eating an ad.

        std::string error_msg;

        classad::ClassAdParser parser;
        classad::ClassAd *ad = new classad::ClassAd;
        bool failed = false;
        if(!parser.ParseClassAd(stats_metrics_string,*ad,offset)) {
            int final_offset = this_offset;
            std::string final_stats_metrics_string = stats_metrics_string;
            final_stats_metrics_string += "\n[]"; // add an empty ClassAd

            if(parser.ParseClassAd(final_stats_metrics_string,*ad,final_offset)) {
                // There must have been some trailing whitespace or
                // comments after the last ClassAd, so the only reason
                // ParseClassAd() failed was because there was no ad.
                // Therefore, we are done.
                delete ad;
                break;
            }
            failed = true;
        }

        if( failed ) {
            EXCEPT("CONFIGURATION ERROR: error in metrics defined in %s: %s, for entry starting here: %.80s\n",
                   param_name,error_msg.c_str(),stats_metrics_string.c_str() + this_offset);
        }

        classad::ClassAd *ad2 = new ClassAd(m_default_metric_ad);
        ad2->Update(*ad);
        delete ad;
        ad = ad2;

        int verbosity = 0;
        ad->EvaluateAttrInt(ATTR_VERBOSITY,verbosity);
        if( verbosity > m_verbosity ) {
            delete ad;
            continue;
        }

        // for efficient queries to the collector, keep track of
        // which type of ads we need
        std::string target_type;
        ad->EvaluateAttrString(ATTR_TARGET_TYPE,target_type);
        if( target_type.empty() ) {
            classad::ClassAdUnParser unparser;
            std::string ad_str;
            unparser.Unparse(ad_str,ad);
            EXCEPT("CONFIGURATION ERROR: no target type specified for metric defined in %s: %s\n",
                   param_name,
                   ad_str.c_str());
        }
        StringList target_types(target_type.c_str());
        m_target_types.create_union(target_types,true);

        stats_metrics.push_back(ad);
    }
}
Exemplo n.º 14
0
void TemplateSimplifier::expandTemplate(
    TokenList& tokenlist,
    const Token *tok,
    const std::string &name,
    std::vector<const Token *> &typeParametersInDeclaration,
    const std::string &newName,
    std::vector<const Token *> &typesUsedInTemplateInstantiation,
    std::list<Token *> &templateInstantiations)
{
    for (const Token *tok3 = tokenlist.front(); tok3; tok3 = tok3->next()) {
        if (tok3->str() == "{" || tok3->str() == "(" || tok3->str() == "[")
            tok3 = tok3->link();

        // Start of template..
        if (tok3 == tok) {
            tok3 = tok3->next();
        }

        // member function implemented outside class definition
        else if (TemplateSimplifier::instantiateMatch(tok3, name, typeParametersInDeclaration.size(), ":: ~| %var% (")) {
            tokenlist.addtoken(newName.c_str(), tok3->linenr(), tok3->fileIndex());
            while (tok3->str() != "::")
                tok3 = tok3->next();
        }

        // not part of template.. go on to next token
        else
            continue;

        int indentlevel = 0;
        std::stack<Token *> brackets; // holds "(", "[" and "{" tokens

        for (; tok3; tok3 = tok3->next()) {
            if (tok3->isName()) {
                // search for this token in the type vector
                unsigned int itype = 0;
                while (itype < typeParametersInDeclaration.size() && typeParametersInDeclaration[itype]->str() != tok3->str())
                    ++itype;

                // replace type with given type..
                if (itype < typeParametersInDeclaration.size()) {
                    unsigned int typeindentlevel = 0;
                    for (const Token *typetok = typesUsedInTemplateInstantiation[itype];
                         typetok && (typeindentlevel>0 || !Token::Match(typetok, ",|>|>>"));
                         typetok = typetok->next()) {
                        if (Token::Match(typetok, "%var% <") && templateParameters(typetok->next()) > 0)
                            ++typeindentlevel;
                        else if (typeindentlevel > 0 && typetok->str() == ">")
                            --typeindentlevel;
                        else if (typeindentlevel > 0 && typetok->str() == ">>") {
                            if (typeindentlevel == 1)
                                break;
                            typeindentlevel -= 2;
                        }
                        tokenlist.addtoken(typetok, tok3->linenr(), tok3->fileIndex());
                    }
                    continue;
                }
            }

            // replace name..
            if (Token::Match(tok3, (name + " !!<").c_str())) {
                tokenlist.addtoken(newName.c_str(), tok3->linenr(), tok3->fileIndex());
                continue;
            }

            // copy
            tokenlist.addtoken(tok3, tok3->linenr(), tok3->fileIndex());
            if (Token::Match(tok3, "%type% <")) {
                //if (!Token::simpleMatch(tok3, (name + " <").c_str()))
                //done = false;
                templateInstantiations.push_back(tokenlist.back());
            }

            // link() newly tokens manually
            else if (tok3->str() == "{") {
                brackets.push(tokenlist.back());
                indentlevel++;
            } else if (tok3->str() == "(") {
                brackets.push(tokenlist.back());
            } else if (tok3->str() == "[") {
                brackets.push(tokenlist.back());
            } else if (tok3->str() == "}") {
                assert(brackets.empty() == false && brackets.top()->str() == "{");
                Token::createMutualLinks(brackets.top(), tokenlist.back());
                brackets.pop();
                if (indentlevel <= 1 && brackets.empty()) {
                    // there is a bug if indentlevel is 0
                    // the "}" token should only be added if indentlevel is 1 but I add it always intentionally
                    // if indentlevel ever becomes 0, cppcheck will write:
                    // ### Error: Invalid number of character {
                    break;
                }
                --indentlevel;
            } else if (tok3->str() == ")") {
                assert(brackets.empty() == false && brackets.top()->str() == "(");
                Token::createMutualLinks(brackets.top(), tokenlist.back());
                brackets.pop();
            } else if (tok3->str() == "]") {
                assert(brackets.empty() == false && brackets.top()->str() == "[");
                Token::createMutualLinks(brackets.top(), tokenlist.back());
                brackets.pop();
            }
        }

        assert(brackets.empty());
    }
}
Exemplo n.º 15
0
// return number of faces and score
void detectFaces(const CxImage& img, std::list <Face>& lFaces, int nRot)
{
	if (cascade_el == NULL || cascade_er == NULL || cascade_f == NULL || cascade_m == NULL || cascade_n == NULL)
		init();
	CxImage imgRotated (img);
	imgRotated.Rotate180();
	IplImage *pIplImage = cvCreateImageHeader (cvSize (img.GetWidth(), img.GetHeight()), 8, img.GetBpp() / 8);
	pIplImage->imageDataOrigin = (char*)imgRotated.GetDIB();
	pIplImage->imageData = (char*)imgRotated.GetBits();

	CvMemStorage			*storage;

	/* setup memory storage, needed by the object detector */
	storage = cvCreateMemStorage(0);

	assert(cascade_f && cascade_el && cascade_er && cascade_m && cascade_n && storage);

	/* haar detection for faces */
	CvSeq *pFaces = cvHaarDetectObjects(
		pIplImage, cascade_f, storage,
		1.2, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize( 40, 40 ) );
	if (pFaces->total == 0)
		return;

	CvSeq seqFaces (*pFaces);
	list <CvRect> lrFaces;
	for(int idxFace = 0; idxFace < seqFaces.total; idxFace++ ) {
		CvRect *r = (CvRect*)cvGetSeqElem(&seqFaces, idxFace);
		if (r)
			lrFaces.push_back (*r);
	}

	/* haar detection for eyes */
	list<pair <RECT, RECT>> lpairEyes;
	detect_eyes (storage, pIplImage, lpairEyes);
	
	/* haar detection for mouths */
	list<RECT> lMouths;
	detect_mouths (storage, pIplImage, lMouths);
	
	/* haar detection for noses */
	list<RECT> lNoses;
	detect_noses (storage, pIplImage, lNoses);
	
	for(list <CvRect>::iterator itFace = lrFaces.begin(); itFace != lrFaces.end(); ++itFace) {
		CvRect r (*itFace);
		CvRect rFace (*itFace);
		rFace.x = img.GetWidth() - r.x - r.width;
		rFace.y = img.GetHeight() - r.y - r.height;
		RECT rcFace; 
		rcFace.left = img.GetWidth() - r.x - r.width - 10; rcFace.right = img.GetWidth() - r.x + 10;
		rcFace.top = img.GetHeight() - r.y - r.height - 10; rcFace.bottom = img.GetHeight() - r.y + 10;

		/* detect current eyes */
		pair <RECT, RECT> pairEyes;
		match_eyes_with_face (lpairEyes, rFace, pairEyes);

		/* detect current mouth */
		RECT rcMouth;
		match_mouths_with_face (lMouths, rFace, pairEyes, rcMouth);

		/* detect current nose */
		RECT rcNose;
		match_noses_with_face (lNoses, rFace, pairEyes, rcMouth, rcNose);

		lFaces.push_back (Face (rcFace, pairEyes, rcMouth, rcNose, nRot));
	}
	Face::adjustRectFaces(lFaces);

	cvReleaseMemStorage (&storage);

	cvReleaseImageHeader (&pIplImage);
}
 void FilterTargets(std::list<Unit*>& unitList)
 {
     unitList.remove_if(PactOfTheDarkfallenCheck(true));
     unitList.push_back(GetCaster());
 }
Exemplo n.º 17
0
void detect_eyes(CvMemStorage	*storage, IplImage* img, std::list <std::pair <RECT, RECT>>& lpairEyes)
{
	/* reset buffer for the next object detection */
	cvClearMemStorage (storage);

	/* Detect objects */
	CvSeq* pEyesLeft = cvHaarDetectObjects(
		img,
		cascade_el,
		storage,
		1.2,
		2,
		CV_HAAR_DO_CANNY_PRUNING,
		cvSize(40, 20)
		);
	CvSeq cvSeqEyeLeft (*pEyesLeft);
	cvClearMemStorage (storage);

	CvSeq* pEyesRight = cvHaarDetectObjects(
		img,
		cascade_er,
		storage,
		1.2,
		2,
		CV_HAAR_DO_CANNY_PRUNING,
		cvSize(40, 20)
		);
	CvSeq cvSeqEyeRight (*pEyesRight);

	std::list <CvRect*> lRectsEyeLeft;
	for(int i = 0; i < (pEyesLeft ? pEyesLeft->total : 0); i++ ) {
		bool bFound = false;
		CvRect* pRc = (CvRect*)cvGetSeqElem(&cvSeqEyeLeft, i);
		if (!pRc)
			continue;
		for(std::list <CvRect*>::iterator itEye = lRectsEyeLeft.begin(); itEye != lRectsEyeLeft.end(); ++itEye){
			RECT rcInt;
			rcInt.left = max ((int)(*itEye)->x, (int)pRc->x);
			rcInt.top = max ((int)(*itEye)->y, (int)pRc->y);
			rcInt.right = min ((int)((*itEye)->x + (*itEye)->width), (int)(pRc->x + pRc->width));
			rcInt.bottom = min ((int)((*itEye)->y + (*itEye)->height), (int)(pRc->y + pRc->height));			
			if ((rcInt.left < rcInt.right) && (rcInt.top < rcInt.bottom)){
				bFound = true;
				break;
			}
		}
		if (!bFound)
			lRectsEyeLeft.push_back (pRc);
	}
	std::list <CvRect*> lRectsEyeRight;
	for(int i = 0; i < (pEyesRight ? pEyesRight->total : 0); i++ ) {
		bool bFound = false;
		CvRect* pRc = (CvRect*)cvGetSeqElem(&cvSeqEyeRight, i);
		if (!pRc)
			continue;
		for(std::list <CvRect*>::iterator itEye = lRectsEyeRight.begin(); itEye != lRectsEyeRight.end(); ++itEye){
			RECT rcInt;
			rcInt.left = max ((int)(*itEye)->x, (int)pRc->x);
			rcInt.top = max ((int)(*itEye)->y, (int)pRc->y);
			rcInt.right = min ((int)((*itEye)->x + (*itEye)->width), (int)(pRc->x + pRc->width));
			rcInt.bottom = min ((int)((*itEye)->y + (*itEye)->height), (int)(pRc->y + pRc->height));			
			if ((rcInt.left < rcInt.right) && (rcInt.top < rcInt.bottom)){
				bFound = true;
				break;
			}
		}
		if (!bFound)
			lRectsEyeRight.push_back (pRc);
	}

	RECT rcNo = {-1,-1,-1,-1};
	for(std::list <CvRect*>::iterator itEyeLeft = lRectsEyeLeft.begin(); itEyeLeft != lRectsEyeLeft.end(); ++itEyeLeft){
		CvRect* rl = *itEyeLeft;
		RECT rcEyeLeft = rcNo;
		RECT rcEyeRight = rcNo;
		for(std::list <CvRect*>::iterator itEyeRight = lRectsEyeRight.begin(); itEyeRight != lRectsEyeRight.end(); ++itEyeRight){
			CvRect* rr = *itEyeRight;
			if (eye_match(rl,rr)){
				rcEyeLeft.left = img->width - rl->x - rl->width; rcEyeLeft.right = img->width - rl->x;
				rcEyeLeft.top = img->height - rl->y - rl->height; rcEyeLeft.bottom = img->height - rl->y;
				rcEyeRight.left = img->width - rr->x - rr->width; rcEyeRight.right = img->width - rr->x;
				rcEyeRight.top = img->height - rr->y - rr->height; rcEyeRight.bottom = img->height - rr->y;
				lpairEyes.push_back(pair<RECT,RECT> (rcEyeLeft, rcEyeRight));
			}
			else if (eye_match(rr,rl)){
				rcEyeLeft.left = img->width - rl->x - rl->width; rcEyeLeft.right = img->width - rl->x;
				rcEyeLeft.top = img->height - rl->y - rl->height; rcEyeLeft.bottom = img->height - rl->y;
				rcEyeRight.left = img->width - rr->x - rr->width; rcEyeRight.right = img->width - rr->x;
				rcEyeRight.top = img->height - rr->y - rr->height; rcEyeRight.bottom = img->height - rr->y;
				lpairEyes.push_back(pair<RECT,RECT> (rcEyeLeft, rcEyeRight));
			}
			else{
				rcEyeLeft.left = img->width - rl->x - rl->width; rcEyeLeft.right = img->width - rl->x;
				rcEyeLeft.top = img->height - rl->y - rl->height; rcEyeLeft.bottom = img->height - rl->y;
				rcEyeRight = rcNo;
			}
		}
		if ((rcEyeRight.left == rcNo.left) && (rcEyeRight.right == rcNo.right) && (rcEyeRight.top == rcNo.top) && (rcEyeRight.bottom == rcNo.bottom))
			lpairEyes.push_back(pair<RECT,RECT> (rcEyeLeft, rcEyeRight));
	}
	for(std::list <CvRect*>::iterator itEye = lRectsEyeRight.begin(); itEye != lRectsEyeRight.end(); ++itEye){
		RECT rcEyeRight; rcEyeRight.left = img->width - (*itEye)->x - (*itEye)->width; rcEyeRight.right = img->width - (*itEye)->x;
		rcEyeRight.top = img->height - (*itEye)->y - (*itEye)->height; rcEyeRight.bottom = img->height - (*itEye)->y;
		lpairEyes.push_back(pair<RECT,RECT> (rcNo, rcEyeRight));
	}
}
Exemplo n.º 18
0
void RetroshareDirModel::getFilePaths(const QModelIndexList &list, std::list<std::string> &fullpaths)
{
#ifdef RDM_DEBUG
	std::cerr << "RetroshareDirModel::getFilePaths()" << std::endl;
#endif
	if (RemoteMode)
	{
#ifdef RDM_DEBUG
		std::cerr << "No File Paths for remote files" << std::endl;
#endif
		return;
	}
	/* translate */
	QModelIndexList::const_iterator it;
	for(it = list.begin(); it != list.end(); it++)
	{
		void *ref = it -> internalPointer();

     		DirDetails details;
     		uint32_t flags = DIR_FLAGS_DETAILS;
     		flags |= DIR_FLAGS_LOCAL;

     		if (!requestDirDetails(ref, details, flags))
     		{
#ifdef RDM_DEBUG
			std::cerr << "getFilePaths() Bad Request" << std::endl;
#endif
			continue;
     		}

		if (details.type != DIR_TYPE_FILE)
		{
#ifdef RDM_DEBUG
			std::cerr << "getFilePaths() Not File" << std::endl;
#endif
			continue; /* not file! */
		}

#ifdef RDM_DEBUG
		std::cerr << "::::::::::::File Details:::: " << std::endl;
		std::cerr << "Name: " << details.name << std::endl;
		std::cerr << "Hash: " << details.hash << std::endl;
		std::cerr << "Size: " << details.count << std::endl;
		std::cerr << "Path: " << details.path << std::endl;
#endif

		std::string filepath = details.path + "/";
		filepath += details.name;

#ifdef RDM_DEBUG
		std::cerr << "Constructed FilePath: " << filepath << std::endl;
#endif
		if (fullpaths.end() == std::find(fullpaths.begin(), fullpaths.end(), filepath))
		{
			fullpaths.push_back(filepath);
		}
	}
#ifdef RDM_DEBUG
	std::cerr << "::::::::::::Done getFilePaths" << std::endl;
#endif
}
Exemplo n.º 19
0
bool SQLite3Backend::getBuddies(long id, std::list<BuddyInfo> &roster) {
//	SELECT id, uin, subscription, nickname, groups, flags FROM " + m_prefix + "buddies WHERE user_id=? ORDER BY id ASC
	BEGIN(m_getBuddies);
	BIND_INT(m_getBuddies, id);

// 	"SELECT buddy_id, type, var, value FROM " + m_prefix + "buddies_settings WHERE user_id=? ORDER BY buddy_id ASC"
	BEGIN(m_getBuddiesSettings);
	BIND_INT(m_getBuddiesSettings, id);

	SettingVariableInfo var;
	long buddy_id = -1;
	std::string key;

	int ret;
	int ret2 = -10;
	while((ret = sqlite3_step(m_getBuddies)) == SQLITE_ROW) {
		BuddyInfo b;
		RESET_GET_COUNTER(m_getBuddies);
		b.id = GET_INT(m_getBuddies);
		b.legacyName = GET_STR(m_getBuddies);
		b.subscription = GET_STR(m_getBuddies);
		b.alias = GET_STR(m_getBuddies);
		std::string groups = GET_STR(m_getBuddies);
		b.groups = StorageBackend::deserializeGroups(groups);
		b.flags = GET_INT(m_getBuddies);

		if (buddy_id == b.id) {
			std::cout << "Adding buddy info " << key << "\n";
			b.settings[key] = var;
			buddy_id = -1;
		}

		while(buddy_id == -1 && ret2 != SQLITE_DONE && ret2 != SQLITE_ERROR && (ret2 = sqlite3_step(m_getBuddiesSettings)) == SQLITE_ROW) {
			RESET_GET_COUNTER(m_getBuddiesSettings);
			buddy_id = GET_INT(m_getBuddiesSettings);
			
			var.type = GET_INT(m_getBuddiesSettings);
			key = GET_STR(m_getBuddiesSettings);
			std::string val = GET_STR(m_getBuddiesSettings);

			switch (var.type) {
				case TYPE_BOOLEAN:
					var.b = atoi(val.c_str());
					break;
				case TYPE_STRING:
					var.s = val;
					break;
				default:
					if (buddy_id == b.id) {
						buddy_id = -1;
					}
					continue;
					break;
			}
			if (buddy_id == b.id) {
				std::cout << "Adding buddy info " << key << "=" << val << "\n";
				b.settings[key] = var;
				buddy_id = -1;
			}
		}

// 		if (ret != SQLITE_DONE) {
// 			LOG4CXX_ERROR(logger, "getBuddiesSettings query"<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
// 			return false;
// 		}

		roster.push_back(b);
	}

	if (ret != SQLITE_DONE) {
		LOG4CXX_ERROR(logger, "getBuddies query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
		return false;
	}

	if (ret2 != SQLITE_DONE) {
		if (ret2 == SQLITE_ERROR) {
			LOG4CXX_ERROR(logger, "getBuddiesSettings query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
			return false;
		}

		while((ret2 = sqlite3_step(m_getBuddiesSettings)) == SQLITE_ROW) {
		}

		if (ret2 != SQLITE_DONE) {
			LOG4CXX_ERROR(logger, "getBuddiesSettings query "<< (sqlite3_errmsg(m_db) == NULL ? "" : sqlite3_errmsg(m_db)));
			return false;
		}
	}
	
	return true;
}
Exemplo n.º 20
0
void DpsHunterDebuffStrategy::InitTriggers(std::list<TriggerNode*> &triggers)
{
    triggers.push_back(new TriggerNode(
        "no stings",
        NextAction::array(0, new NextAction("serpent sting", 50.0f), NULL)));
}
Exemplo n.º 21
0
 void JustSummoned(Creature* summon)
 {
     SummonList.push_back(summon->GetGUID());
 }
Exemplo n.º 22
0
 void FilterTargets(std::list<WorldObject*>& unitList)
 {
     unitList.remove_if(Trinity::UnitAuraCheck(true, SPELL_COUNTDOWN));
     unitList.push_back(GetCaster());
 }
 void add_player(int _pid) {
   mtx_all_games.lock();
   players.push_back(_pid);
   mtx_all_games.unlock();
 }
Exemplo n.º 24
0
void DoActionTag::execute(MovieClip* parent, std::list < std::pair<PlaceInfo, DisplayObject*> >& ls)
{
    Depth=0x20000;
    ls.push_back(make_pair(PlaceInfo(),this));
}
Exemplo n.º 25
0
void mapbuffer::save_quad( const std::string &filename, const tripoint &om_addr,
                           std::list<tripoint> &submaps_to_delete, bool delete_after_save )
{
    std::ofstream fout;
    fopen_exclusive(fout, filename.c_str());
    if(!fout.is_open()) {
        return;
    }

    std::vector<point> offsets;
    offsets.push_back( point(0, 0) );
    offsets.push_back( point(0, 1) );
    offsets.push_back( point(1, 0) );
    offsets.push_back( point(1, 1) );
    JsonOut jsout( fout );
    jsout.start_array();
    for( std::vector<point>::iterator offset = offsets.begin();
         offset != offsets.end(); ++offset ) {
        tripoint submap_addr = overmapbuffer::omt_to_sm_copy( om_addr );
        submap_addr.x += offset->x;
        submap_addr.y += offset->y;

        if (submaps.count(submap_addr) == 0) {
            continue;
        }
        submap *sm = submaps[submap_addr];
        if( sm == NULL ) {
            continue;
        }

        jsout.start_object();

        jsout.member( "version", savegame_version);

        jsout.member( "coordinates" );
        jsout.start_array();
        jsout.write( submap_addr.x );
        jsout.write( submap_addr.y );
        jsout.write( submap_addr.z );
        jsout.end_array();

        jsout.member( "turn_last_touched", sm->turn_last_touched );
        jsout.member( "temperature", sm->temperature );

        jsout.member( "terrain" );
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save terrains
                jsout.write( terlist[sm->ter[i][j]].id );
            }
        }
        jsout.end_array();

        // Write out the radiation array in a simple RLE scheme.
        // written in intensity, count pairs
        jsout.member( "radiation" );
        jsout.start_array();
        int lastrad = -1;
        int count = 0;
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save radiation, re-examine this because it doesnt look like it works right
                int r = sm->get_radiation(i, j);
                if (r == lastrad) {
                    count++;
                } else {
                    if (count) {
                        jsout.write( count );
                    }
                    jsout.write( r );
                    lastrad = r;
                    count = 1;
                }
            }
        }
        jsout.write( count );
        jsout.end_array();

        jsout.member("furniture");
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save furniture
                if( sm->get_furn( i, j ) != f_null ) {
                    jsout.start_array();
                    jsout.write( i );
                    jsout.write( j );
                    jsout.write( furnlist[ sm->get_furn( i, j ) ].id );
                    jsout.end_array();
                }
            }
        }
        jsout.end_array();

        jsout.member( "items" );
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                if( sm->itm[i][j].empty() ) {
                    continue;
                }
                jsout.write( i );
                jsout.write( j );
                jsout.write( sm->itm[i][j] );
            }
        }
        jsout.end_array();

        jsout.member( "traps" );
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save traps
                if (sm->get_trap( i, j ) != tr_null) {
                    jsout.start_array();
                    jsout.write( i );
                    jsout.write( j );
                    jsout.write( traplist[ sm->get_trap( i, j ) ]->id );
                    jsout.end_array();
                }
            }
        }
        jsout.end_array();

        jsout.member( "fields" );
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save fields
                if (sm->fld[i][j].fieldCount() > 0) {
                    jsout.write( i );
                    jsout.write( j );
                    jsout.start_array();
                    for(std::map<field_id, field_entry *>::iterator it = sm->fld[i][j].getFieldStart();
                        it != sm->fld[i][j].getFieldEnd(); ++it) {
                        if(it->second != NULL) {
                            // We don't seem to have a string identifier for fields anywhere.
                            jsout.write( it->second->getFieldType() );
                            jsout.write( it->second->getFieldDensity() );
                            jsout.write( it->second->getFieldAge() );
                        }
                    }
                    jsout.end_array();
                }
            }
        }
        jsout.end_array();

        jsout.member( "graffiti" );
        jsout.start_array();
        for(int j = 0; j < SEEY; j++) {
            for(int i = 0; i < SEEX; i++) {
                // Save graffiti
                if (sm->get_graffiti(i, j).contents) {
                    jsout.start_array();
                    jsout.write( i );
                    jsout.write( j );
                    jsout.write( *sm->get_graffiti(i, j).contents );
                    jsout.end_array();
                }
            }
        }
        jsout.end_array();

        jsout.member("cosmetics");
        jsout.start_array();
        for (int j = 0; j < SEEY; j++) {
            for (int i = 0; i < SEEX; i++) {
                if (sm->cosmetics[i][j].size() > 0) {
                    jsout.start_array();
                    jsout.write(i);
                    jsout.write(j);
                    jsout.write(sm->cosmetics[i][j]);
                    jsout.end_array();
                }
            }
        }
        jsout.end_array();

        // Output the spawn points
        jsout.member( "spawns" );
        jsout.start_array();
        for( std::vector<spawn_point>::iterator spawn_it = sm->spawns.begin();
             spawn_it != sm->spawns.end(); ++spawn_it ) {
            jsout.start_array();
            jsout.write( spawn_it->type );
            jsout.write( spawn_it->count );
            jsout.write( spawn_it->posx );
            jsout.write( spawn_it->posy );
            jsout.write( spawn_it->faction_id );
            jsout.write( spawn_it->mission_id );
            jsout.write( spawn_it->friendly );
            jsout.write( spawn_it->name );
            jsout.end_array();
        }
        jsout.end_array();

        jsout.member( "vehicles" );
        jsout.start_array();
        for( std::vector<vehicle *>::iterator vehicle_it = sm->vehicles.begin();
             vehicle_it != sm->vehicles.end(); ++vehicle_it ) {
            // json lib doesn't know how to turn a vehicle * into a vehicle,
            // so we have to iterate manually.
            jsout.write( **vehicle_it );
        }
        jsout.end_array();

        // Output the computer
        if (sm->comp.name != "") {
            jsout.member( "computers", sm->comp.save_data() );
        }

        // Output base camp if any
        if (sm->camp.is_valid()) {
            jsout.member( "camp" );
            jsout.write( sm->camp.save_data() );
        }
        if( delete_after_save ) {
            submaps_to_delete.push_back( submap_addr );
        }
        jsout.end_object();
    }
    jsout.end_array();
    fclose_exclusive(fout, filename.c_str());
}
Exemplo n.º 26
0
void MainClass::init()
{
	Scene2D& scene2D = Engine::instance().getScene2DMgr();

	Int2 winSize = scene2D.getWindowSize();

	Engine::instance().startRender();
	//Engine::instance().clearScreen(Color(57,155,230, 255));
	Engine::instance().getScene2DMgr().drawRectangle(Int2(0,0), winSize, Color(57,155,230, 255), true);//clearScreen(Color(57,155,230, 255));
	Bitmap* loading = new Bitmap("data/loading.png");
	Int2 bitmapPos = winSize*0.5f - loading->size()*0.5f;
	loading->draw(winSize*0.5f-loading->size()*0.5f, 1.f, Float2(1.f, 1.f));
#if defined(USES_WINDOWS8_METRO)
	Engine::instance().getScene2DMgr().drawRectangle(bitmapPos + Int2(362, 411), bitmapPos + Int2(463, 440), CoreUtils::colorWhite, true);// hide "Esc: quit"
#endif
	delete loading;
	Engine::instance().endRender();

	//-----

	m_isHelpOpened = true;

	m_help = new Sprite("data/help.png");
	m_help->setPosition(winSize*0.5f-m_help->getScaledSize()*0.5f);

	m_pressF1Help = new Sprite("data/pressf1help.png");
	m_pressF1Help->setPosition(Int2(10, winSize.height()-30));

	m_background = new Sprite("data/background.png");
	m_background->setPosition(Int2(0,0));

	m_collisionImage = new Image("data/collision.png");
	m_structure = new Bitmap("data/structure.png");

	m_structureForeground = new Bitmap("data/structure_foreground.png");

	m_engineSystem = new EngineSystem;

	m_chara = new Chara();

	m_cannon = new Cannon();

	m_clouds.push_back(new Cloud);
	m_clouds.push_back(new Cloud);
	m_clouds.push_back(new Cloud);
	m_clouds.push_back(new Cloud);

	m_burning = new Burning;
	m_waterSystem = new WaterSystem;

	m_swarm = new Swarm;

	m_gameOver = new Bitmap("data/game_over.png");
	
#if defined(USES_WINDOWS_OPENGL) || defined(USES_LINUX)
	m_music = Engine::instance().getSoundMgr().loadSound("data/sounds/opengameart_cynicmusic_battleThemeA.ogg");
#else
	m_music = Engine::instance().getSoundMgr().loadSound("data/sounds/opengameart_cynicmusic_battleThemeA.wav");
#endif
	m_music->setVolume(m_musicVolume);
	m_music->play();
}
Exemplo n.º 27
0
 void add_runtime_data(RuntimeData* rd) {
   runtime_data_.push_back(rd);
 }
CASE_TEST(channel, io_stream_tcp_basic)
{
    atbus::adapter::loop_t loop;
    uv_loop_init(&loop);

    atbus::channel::io_stream_channel svr, cli;
    atbus::channel::io_stream_init(&svr, &loop, NULL);
    atbus::channel::io_stream_init(&cli, &loop, NULL);
    CASE_EXPECT_EQ(&loop, svr.ev_loop);
    CASE_EXPECT_EQ(&loop, cli.ev_loop);

    g_check_flag = 0;

    int inited_fds = 0;
    inited_fds += setup_channel(svr, "ipv6://:::16387", NULL);
    CASE_EXPECT_EQ(1, g_check_flag);
    CASE_EXPECT_NE(NULL, svr.ev_loop);
    
    if (0 == inited_fds) {
        uv_loop_close(&loop);
        return;
    }

    inited_fds = 0;
    inited_fds += setup_channel(cli, NULL, "ipv4://127.0.0.1:16387");
    inited_fds += setup_channel(cli, NULL, "dns://localhost:16387");
    inited_fds += setup_channel(cli, NULL, "ipv6://::1:16387");

    int check_flag = g_check_flag;
    while (g_check_flag - check_flag < 2 * inited_fds) {
        uv_run(&loop, UV_RUN_ONCE);
    }

    svr.evt.callbacks[atbus::channel::io_stream_callback_evt_t::EN_FN_RECVED] = recv_callback_check_fn;
    cli.evt.callbacks[atbus::channel::io_stream_callback_evt_t::EN_FN_RECVED] = recv_callback_check_fn;
    char* buf = get_test_buffer();

    check_flag = g_check_flag;
    // small buffer
    atbus::channel::io_stream_send(cli.conn_pool.begin()->second.get(), buf, 13);
    g_check_buff_sequence.push_back(std::make_pair(0, 13));
    atbus::channel::io_stream_send(cli.conn_pool.begin()->second.get(), buf + 13, 28);
    g_check_buff_sequence.push_back(std::make_pair(13, 28));
    atbus::channel::io_stream_send(cli.conn_pool.begin()->second.get(), buf + 13 + 28, 100);
    g_check_buff_sequence.push_back(std::make_pair(13 + 28, 100));

    // big buffer
    atbus::channel::io_stream_send(cli.conn_pool.begin()->second.get(), buf + 1024, 56 * 1024 + 3);
    g_check_buff_sequence.push_back(std::make_pair(1024, 56 * 1024 + 3));

    while (g_check_flag - check_flag < 4) {
        uv_run(&loop, UV_RUN_ONCE);
    }

    // many big buffer
    {
        check_flag = g_check_flag;
        atbus::channel::io_stream_channel::conn_pool_t::iterator it = svr.conn_pool.begin();
        // 跳过listen的socket
        if (it->second->addr.address == "ipv6://:::16387") {
            ++it;
        }

        size_t sum_size = 0;
        g_recv_rec = std::make_pair(0, 0);
        for (int i = 0; i < 153; ++ i) {
            size_t s = static_cast<size_t>(rand() % 2048);
            size_t l = static_cast<size_t>(rand() % 10240) + 20 * 1024;
            atbus::channel::io_stream_send(it->second.get(), buf + s, l);
            g_check_buff_sequence.push_back(std::make_pair(s, l));
            sum_size += l;
        }

        CASE_MSG_INFO() << "send " << sum_size << " bytes data with " << g_check_buff_sequence.size() << " packages done." << std::endl;

        while (g_check_flag - check_flag < 153) {
            uv_run(&loop, UV_RUN_ONCE);
        }

        CASE_MSG_INFO() << "recv " << g_recv_rec.second << " bytes data with " << g_recv_rec.first << " packages and checked done." << std::endl;
    }

    atbus::channel::io_stream_close(&svr);
    atbus::channel::io_stream_close(&cli);
    CASE_EXPECT_EQ(0, svr.conn_pool.size());
    CASE_EXPECT_EQ(0, cli.conn_pool.size());

    uv_loop_close(&loop);
}
Exemplo n.º 29
0
/**
* Pretty basic lexical analyzer
* Breaks up the input character stream into tokens and puts them into the list provided.
* Ignores # as a line comment
*/
void Config::Tokenize(FILE *input, std::list<std::string> &tokens)
{
	char c = fgetc(input);
	std::string lexeme;

	while(c != EOF)
	{
		if(isspace(c))
		{
			if(lexeme.size() > 0)
			{
				tokens.push_back(lexeme);
				lexeme.clear();
			}
			c = fgetc(input);
			continue;
		}

		if(isalnum(c))
		{
			lexeme.append((const char *)&c, 1);
			c = fgetc(input);
			continue;
		}

		switch(c)
		{
		case '#':
			{
				if(lexeme.size() > 0)
				{
					tokens.push_back(lexeme);
					lexeme.clear();
				}

				while(c != '\n' && c != EOF)
				{
					c = fgetc(input);
				}
				break;
			}
		case '[':
		case ']':
		case '=':
			{
				if(lexeme.size() > 0)
				{
					tokens.push_back(lexeme);
					lexeme.clear();
				}

				lexeme.append((const char *)&c, 1);
				tokens.push_back(lexeme);
				lexeme.clear();
				break;
			}
		default:
			{
				lexeme.append((const char *)&c, 1);
			}
		}

		c = fgetc(input);
	}

	if(lexeme.size() > 0)
	{
		tokens.push_back(lexeme);
	}
}
Exemplo n.º 30
0
 void Summon(uint8 uiCase)
 {
     switch(uiCase)
     {
         case 1:
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[1], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[2], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[3], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[4], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[5], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[6], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[7], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[8], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[9], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             break;
         case 2:
             if (GameObject* pGo = me->SummonGameObject(183410, -533.140f, -105.322f, -156.016f, 0, 0, 0, 0, 0, 1000))
             {
                 GoSummonList.push_back(pGo->GetGUID());
                 pGo->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1); //We can't use it!
             }
             Summon(3);
             break;
         case 3:
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[1], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[2], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[3], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             DoScriptText(SAY_BLASTMASTER_19, me);
             break;
         case 4:
             if (GameObject* pGo = me->SummonGameObject(183410, -542.199f, -96.854f, -155.790f, 0, 0, 0, 0, 0, 1000))
             {
                 GoSummonList.push_back(pGo->GetGUID());
                 pGo->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1);
             }
             break;
         case 5:
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[0], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[1], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[2], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             DoScriptText(SAY_BLASTMASTER_15, me);
             break;
         case 6:
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[10], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[11], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[12], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[13], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             me->SummonCreature(NPC_CAVERNDEEP_AMBUSHER, SpawnPosition[14], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             break;
         case 7:
             if (GameObject* pGo = me->SummonGameObject(183410, -507.820f, -103.333f, -151.353f, 0, 0, 0, 0, 0, 1000))
             {
                 GoSummonList.push_back(pGo->GetGUID());
                 pGo->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1); //We can't use it!
                 Summon(6);
             }
             break;
         case 8:
             if (GameObject* pGo = me->SummonGameObject(183410, -511.829f, -86.249f, -151.431f, 0, 0, 0, 0, 0, 1000))
             {
                 GoSummonList.push_back(pGo->GetGUID());
                 pGo->SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_UNK1); //We can't use it!
             }
             break;
         case 9:
             if (Creature* pGrubbis = me->SummonCreature(NPC_GRUBBIS, SpawnPosition[15], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000))
                 DoScriptText(SAY_GRUBBIS, pGrubbis);
             me->SummonCreature(NPC_CHOMPER, SpawnPosition[16], TEMPSUMMON_CORPSE_TIMED_DESPAWN, 1800000);
             break;
     }
 }