Esempio n. 1
0
void Instrument::InstrumentLoadStore(const Instruction* instr) {
    static Counter* load_int_counter = GetCounter("Load Integer");
    static Counter* store_int_counter = GetCounter("Store Integer");
    static Counter* load_fp_counter = GetCounter("Load FP");
    static Counter* store_fp_counter = GetCounter("Store FP");

    switch (instr->Mask(LoadStoreOpMask)) {
    case STRB_w:    // Fall through.
    case STRH_w:    // Fall through.
    case STR_w:     // Fall through.
    case STR_x:
        store_int_counter->Increment();
        break;
    case STR_s:     // Fall through.
    case STR_d:
        store_fp_counter->Increment();
        break;
    case LDRB_w:    // Fall through.
    case LDRH_w:    // Fall through.
    case LDR_w:     // Fall through.
    case LDR_x:     // Fall through.
    case LDRSB_x:   // Fall through.
    case LDRSH_x:   // Fall through.
    case LDRSW_x:   // Fall through.
    case LDRSB_w:   // Fall through.
    case LDRSH_w:
        load_int_counter->Increment();
        break;
    case LDR_s:     // Fall through.
    case LDR_d:
        load_fp_counter->Increment();
        break;
    }
}
Esempio n. 2
0
void
Control::Substitute(map<string,string>* __mapping){
switch(GetControlKind()){
   case ADaAn_FOR      :
            if(__mapping->find(GetCounter()) != __mapping->end())
               SetCounterName(__mapping->operator[](GetCounter()));
            GetForLowerBound()->Substitute(__mapping);
            GetForUpperBound()->Substitute(__mapping);
            return;
   case ADaAn_WHILE   :
            if(__mapping->find(GetCounter()) != __mapping->end())
               SetCounterName(__mapping->operator[](GetCounter()));
            GetCondition()->Substitute(__mapping);
            return;
   case ADaAn_IF      :
            GetCondition()->Substitute(__mapping);
            return;
   case ADaAn_IF_ELSE   :
            GetCondition()->Substitute(__mapping);
            return;
   }

cerr<<"Control::Rename, Fatal error(unhandled operator)";
throw(UNHANDLED_CASE);
exit(EXIT_FAILURE);
}
Esempio n. 3
0
	void Run()
	{
		LOG_INFO("Thread [%s] Start...", m_threadName);
		int ret = 0;
		for(int i= GetCounter(); i <= m_requestCount; i= GetCounter()){
			ClientCtx* ctx = GetCtx();

			ret = m_requestCb(i, ctx, m_args);
			
			if(ret== 0){
				AtomInt_Inc(&g_errors[0]);
			}else{
				if(ret < 0){
					AtomInt_Inc(&g_errors[ERRNO_UNKNOW]);
				}else{
					AtomInt_Inc(&g_errors[ret%0xFFFF]);
				}
			}

			if(i % m_num == 0){
				double usedtime = g_now_second -g_start;
				//LOG_DEBUG("start:%.3f - now:%.3f", g_start, g_now_second);
				printf("Request %d time:%.3f\n", i, usedtime);
			}
			if(g_stop) break;
		}
		
		LOG_INFO("Thread [%s] Stop...", m_threadName);
	}
Esempio n. 4
0
/****************************************************************************
REMARKS:
If processor does not support time stamp reading, but is at least a 386 or
above, utilize method of timing a loop of BSF instructions which take a
known number of cycles to run on i386(tm), i486(tm), and Pentium(R)
processors.
****************************************************************************/
static ulong GetBSFCpuSpeed(
    ulong cycles)
{
    CPU_largeInteger t0,t1,count_freq;
    ulong   ticks;              /* Microseconds elapsed during test     */
    ulong   current;            /* Variable to store time elapsed       */
    int     i,j,iPriority;
    ulong   lowest  = (ulong)-1;

    iPriority = SetMaxThreadPriority();
    GetCounterFrequency(&count_freq);
    for (i = 0; i < SAMPLINGS; i++) {
	GetCounter(&t0);
	for (j = 0; j < INNER_LOOPS; j++)
	    _CPU_runBSFLoop(ITERATIONS);
	GetCounter(&t1);
	current = t1.low - t0.low;
	if (current < lowest)
	    lowest = current;
	}
    RestoreThreadPriority(iPriority);

    /* Compute frequency */
    ticks = _CPU_mulDiv(lowest,1000000,count_freq.low);
    if ((ticks % count_freq.low) > (count_freq.low/2))
	ticks++;            /* Round up if necessary */
    if (ticks == 0)
	return 0;
    return ((cycles*INNER_LOOPS)/ticks);
}
Esempio n. 5
0
void Instrument::InstrumentLoadStorePair(const Instruction* instr) {
    static Counter* load_pair_counter = GetCounter("Load Pair");
    static Counter* store_pair_counter = GetCounter("Store Pair");

    if (instr->Mask(LoadStorePairLBit) != 0) {
        load_pair_counter->Increment();
    } else {
        store_pair_counter->Increment();
    }
}
Esempio n. 6
0
 uint32_t operator()()
 {
     uint32_t const counter = GetCounter();
     if ((counter % 3) == 0)
         return m_startIndex;
     return m_startIndex + counter - 2 * (counter / 3);
 }
Esempio n. 7
0
/* Initialize OpenGL Graphics */
void InitGL()
{
	StartCounter();
	gLastTime = GetCounter();
	// Set "clearing" or background color
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque
}
Esempio n. 8
0
unsigned int HighPerfTick::Tick()
{
	__int64 counter = GetCounter();
	unsigned int elapsed = (unsigned int)(counter - lastTick);
	lastTick = counter;
	return elapsed;
}
Esempio n. 9
0
//---------------------------------------------------------------------------------
// Update from glut. Called when no more event handling.
//---------------------------------------------------------------------------------
void Idle()
{	
	static double prevTime = GetCounter();
	double tick = GetCounter() - prevTime;
	double currentTime = GetCounter();
	double deltaTime = currentTime - gLastTime;
	// Update.
	if (deltaTime > (UPDATE_MAX))
	{	
		gUpdateDeltaTime.Stop();
		glutPostRedisplay(); //everytime you are done 
		CSimpleControllers::GetInstance().Update();

		gUserUpdateProfiler.Start();
		if (gEditorMode)
		{
			EditorUpdate((float)deltaTime);			// Call user defined update.
		}
		else
		{
			Update((float)deltaTime);				// Call user defined update.
		}
		gUserUpdateProfiler.Stop();
		
		gLastTime = currentTime;		
		RECT tileClientArea;
		if (GetClientRect( MAIN_WINDOW_HANDLE, &tileClientArea))
		{
			WINDOW_WIDTH = tileClientArea.right - tileClientArea.left;
			WINDOW_HEIGHT = tileClientArea.bottom - tileClientArea.top;
		}

		if (App::GetController().CheckButton(APP_ENABLE_DEBUG_INFO_BUTTON) )
		{
			gRenderUpdateTimes = !gRenderUpdateTimes;
		}

		if (App::IsKeyPressed(APP_QUIT_KEY))
		{		
			glutLeaveMainLoop();
		}
		gUpdateDeltaTime.Start();
	}
	
}
Esempio n. 10
0
std::string ObjectGuid::GetString() const
{
    std::ostringstream str;
    str << GetTypeName() << " (";
    if (HasEntry())
        str << "Entry: " << GetEntry() << " ";
    str << "Guid: " << GetCounter() << ")";
    return str.str();
}
Esempio n. 11
0
// ****************************************************
// ******************* Group System *******************
// ****************************************************
Group* Battlefield::GetFreeBfRaid(TeamId TeamId)
{
    for (auto itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
        if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
            if (!group->IsFull())
                return group;

    return nullptr;
}
Esempio n. 12
0
Group* Battlefield::GetGroupPlayer(ObjectGuid guid, TeamId TeamId)
{
    for (auto itr = m_Groups[TeamId].begin(); itr != m_Groups[TeamId].end(); ++itr)
        if (Group* group = sGroupMgr->GetGroupByGUID(itr->GetCounter()))
            if (group->IsMember(guid))
                return group;

    return nullptr;
}
Esempio n. 13
0
  uint32_t operator()()
  {
    uint32_t const counter = GetCounter();
    uint32_t const result = m_startIndex + m_counter;
    if (counter % 2 == 0)
      m_counter++;

    return result;
  }
Esempio n. 14
0
void Instrument::VisitMoveWideImmediate(const Instruction* instr) {
    Update();
    static Counter* counter = GetCounter("Move Immediate");

    if (instr->IsMovn() && (instr->Rd() == kZeroRegCode)) {
        unsigned imm = instr->ImmMoveWide();
        HandleInstrumentationEvent(imm);
    } else {
        counter->Increment();
    }
}
Esempio n. 15
0
std::string ObjectGuid::ToString() const
{
    std::ostringstream str;
    str << "GUID Full: 0x" << std::hex << std::setw(16) << std::setfill('0') << _guid << std::dec;
    str << " Type: " << GetTypeName();
    if (HasEntry())
        str << (IsPet() ? " Pet number: " : " Entry: ") << GetEntry() << " ";

    str << " Low: " << GetCounter();
    return str.str();
}
Esempio n. 16
0
File: main.c Progetto: klkn/w1209
void Pwm_Step(void)
{
	unsigned long cur = GetCounter();
	unsigned long delta_timer = cur - gs_pwm_timer;
	unsigned int vkl_time = gs_current_percent <= 0 ? 0 :(gs_current_percent >= 100 ? g_settings.pwm_mlsec : gs_current_percent * g_settings.pwm_mlsec / 100);
	if(delta_timer >= g_settings.pwm_mlsec)
	{
		delta_timer = 0;
		gs_pwm_timer = cur;
	}
	SetRelayState(delta_timer < vkl_time);
}
Esempio n. 17
0
    uint32_t operator()()
    {
        uint32_t const counter = GetCounter();
        uint32_t const result = m_startIndex + m_base + counter - 2 * (counter / 3) + GetCWNormalizer();
        if (counter + 1 == m_indexPerStrip)
        {
            m_base += m_vertexStride;
            ResetCounter();
        }

        return result;
    }
Esempio n. 18
0
void Down_Task(void)
{
	switch(GetGrapCount())//层次
	{
		case 1:
			AddCounter();
			if(GetCounter() > 4)
				SetCounter(1);
			GetMainGrap(GetCounter());
			break;
		case 2:
			Level2_Down();
			break;
		case 3:
			Level3_Down();
			break;
		case 4:
			Level4_Down();
			break;
		default:break;
	}

}
Esempio n. 19
0
File: main.c Progetto: klkn/w1209
void Pid_Step(void)
{
	float pid_value;
	unsigned long cur = GetCounter();
	float delta_temperature = gs_current_temperature - g_settings.pid_level; 
	if((cur - gs_pid_timer) < g_settings.pid_mlsec)
		return;
	gs_pid_timer = cur;
	gs_intergrator_value += delta_temperature*g_settings.pid_I;
	if(gs_intergrator_value > g_settings.pid_I_limit)
		gs_intergrator_value = g_settings.pid_I_limit;
	pid_value = gs_current_percent + g_settings.pid_P*delta_temperature + gs_intergrator_value + g_settings.pid_D*delta_temperature;
	gs_current_percent = (pid_value > 100) ? 100 : pid_value;
}
Esempio n. 20
0
void Up_Task(void)
{
	switch(GetGrapCount())//层次
	{
		case 1:
			if(GetCounter() > 1)
				SubCounter();	
			else
				SetCounter(4);				
			GetMainGrap(GetCounter());
			break;
		case 2:
			Level2_Up();
			break;
		case 3:
			Level3_Up();
			break;
		case 4:
			Level4_Up();
			break;
		default:break;
	}
	
}
Esempio n. 21
0
std::string ObjectGuid::GetString() const
{
    std::ostringstream str;
    str << GetTypeName();

    if (IsPlayer())
    {
        std::string name;
        if (sObjectMgr.GetPlayerNameByGUID(*this, name))
            str << " " << name;
    }

    str << " (";
    if (HasEntry())
        str << (IsPet() ? "Petnumber: " : "Entry: ") << GetEntry() << " ";
    str << "Guid: " << GetCounter() << ")";
    return str.str();
}
Esempio n. 22
0
double get_sort_time(int *pa, int len, void (fsort)(int * , int   ))
{
# if 0 //  计时方法1
	const clock_t begin = clock();
	 fsort(pa, len);
	 const clock_t end = clock();
	 return  (double)(end-begin)/CLOCKS_PER_SEC  ;
#endif
#if 0 // 计时方法2
	 DWORD begin = GetTickCount();
	 fsort(pa, len);
	 DWORD end = GetTickCount();

	 return end - begin;
#endif

	 StartCounter();
     fsort(pa, len);
     return  GetCounter() ;
 
}
Esempio n. 23
0
Condition*
Control::GetRegularDomain(void){
Condition* result;
if(IsIf() || IsIfElse() || IsWhileLoop())
   {
   if(IsWhileLoop()){
      Inequation* ineq=new Inequation(new Expression(GetCounter()),FADA_GREATER_EQ,new Expression(1));
      Condition* count_ge_0 = new Condition (ineq);
      result=new Condition(count_ge_0,FADA_AND,GetCondition());
      return result;
      }
   return GetCondition();
   }
if(IsForLoop()){
   Inequation* ineq1=new Inequation ( new Expression(GetLoopCounter( )),FADA_GREATER_EQ,GetForLowerBound( ));
   Inequation* ineq2=new Inequation ( new Expression(GetLoopCounter( )),FADA_LESS_EQ,GetForUpperBound( ));
   result = new Condition( new Condition(ineq1), FADA_AND , new Condition(ineq2));
   return result;
   }
cout<<"\nControl::GetRegularDomain(void) .... inappropriate case \n";
throw(10);
}
Esempio n. 24
0
// Use the object index to find the object in the performance data. Then, use the
// counter index to find the counter definition. The definition contains the offset
// to the counter data in the counter block. The location of the counter block 
// depends on whether the counter is a single instance counter or multiple instance counter.
// After finding the counter block, retrieve the counter data.
BOOL GetCounterValues(DWORD dwObjectIndex, DWORD dwCounterIndex, LPWSTR pInstanceName, RAW_DATA* pRawData)
{
	PERF_OBJECT_TYPE* pObject = NULL;
	PERF_COUNTER_DEFINITION* pCounter = NULL;
	PERF_COUNTER_BLOCK* pCounterDataBlock = NULL;
	BOOL fSuccess = FALSE;

	pObject = GetObject(dwObjectIndex);
	if (NULL == pObject)
	{
		wprintf(L"Object  %d not found.\n", dwObjectIndex);
		goto cleanup;
	}

	pCounter = GetCounter(pObject, dwCounterIndex);
	if (NULL == pCounter)
	{
		wprintf(L"Counter %d not found.\n", dwCounterIndex);
		goto cleanup;
	}

	// Retrieve a pointer to the beginning of the counter data block. The counter data
	// block contains all the counter data for the object.
	pCounterDataBlock = GetCounterBlock(pObject, pInstanceName);
	if (NULL == pCounterDataBlock)
	{
		wprintf(L"Instance %s not found.\n", pInstanceName);
		goto cleanup;
	}

	ZeroMemory(pRawData, sizeof(RAW_DATA));
	pRawData->CounterType = pCounter->CounterType;
	fSuccess = GetValue(pObject, pCounter, pCounterDataBlock, pRawData);

cleanup:

	return fSuccess;
}
Esempio n. 25
0
OP_STATUS Counters::SetCounters(HTML_Element* element, CSS_decl* cp, BOOL reset)
{
	if (cp && cp->GetDeclType() == CSS_DECL_GEN_ARRAY)
	{
		short gen_arr_len = cp->ArrayValueLen();
		const CSS_generic_value* gen_arr = cp->GenArrayValue();

		for (int i = 0; i < gen_arr_len; i++)
		{
			if (gen_arr[i].value_type == CSS_STRING_LITERAL && gen_arr[i].value.string)
			{
				OP_ASSERT(*gen_arr[i].value.string || !"Only non-empty strings (identifiers) should be allowed by the css parser");
				Counter* counter = GetCounter(gen_arr[i].value.string, uni_strlen(gen_arr[i].value.string));

				if (!counter)
				{
					counter = OP_NEW(Counter, (gen_arr[i].value.string));

					if (counter)
						counter->Into(&counter_list);
					else
						return OpStatus::ERR_NO_MEMORY;
				}

				if (!counter->GetName() ||
					!counter->SetCounter(element, reset ? COUNTER_RESET : COUNTER_INCREMENT, i + 1 < gen_arr_len && gen_arr[i + 1].value_type == CSS_INT_NUMBER ? gen_arr[++i].value.number : (reset ? 0 : 1), add_only))
				{
					counter->Out();
					OP_DELETE(counter);
					return OpStatus::ERR_NO_MEMORY;
				}
			}
		}
	}

	return OpStatus::OK;
}
Esempio n. 26
0
File: main.c Progetto: klkn/w1209
void MenuOnKey(void)
{
	keys_t cur_key = GetKeys();
	unsigned long cur = GetCounter();
	if(cur_key == KEY_NONE && gs_menu_level != 0)
	{
		if((cur - gs_menu_timer) > 5000)
			gs_menu_level = 0;
		return;
	}
	gs_menu_timer = cur;
	switch(gs_menu_level)
	{
	case 1:
	{
		if(cur_key & KEY_SET)
			gs_menu_level = cur_key & KEY_LONG ? 0 : 2;
		else if(cur_key == KEY_MINUS)
		{
			if(--gs_menu_param >= MENU_END) gs_menu_param = MENU_END-1;
		}
		else if(cur_key == KEY_PLUS)
		{
			if(++gs_menu_param >= MENU_END) gs_menu_param = 0;
		}
		break;
	}
	case 2:
	{
		switch(gs_menu_param)
		{
			case MENU_PID_LEVEL:
				MenuFloatOnKey(cur_key, &g_settings.pid_level, 0.1, 0, 100);
				break;
			case MENU_PID_DEFAULT_PERCENT:
				MenuUIntOnKey(cur_key, &g_settings.pid_default_percent, 1, 0, 100);
				break;
			case MENU_PID_MLSEC:
				MenuUIntOnKey(cur_key, &g_settings.pid_mlsec, 100, 100, 60000);
				break;
			case MENU_PID_P:
				MenuFloatOnKey(cur_key, &g_settings.pid_P, 0.1, 0.1, 100);
				break;
			case MENU_PID_I:
				MenuFloatOnKey(cur_key, &g_settings.pid_I, 0.1, 0.1, 1);
				break;
			case MENU_PID_D:
				MenuFloatOnKey(cur_key, &g_settings.pid_D, 0.1, 0.1, 10);
				break;
			case MENU_PID_I_LIMIT:
				MenuFloatOnKey(cur_key, &g_settings.pid_I_limit, 1, 1, 40);
				break;
			case MUNU_PWM_MLSEC:
				MenuUIntOnKey(cur_key, &g_settings.pwm_mlsec, 100, 100, 60000);
				break;
			case MENU_CALIBR:
				if(cur_key == KEY_MINUS || cur_key == KEY_PLUS)
					gs_menu_param_2 = !gs_menu_param_2;
				else if(cur_key == KEY_SET)
				{
					if(gs_menu_param_2)
						g_settings.calibr_100 = gs_current_adc;
					else
						g_settings.calibr_0 = gs_current_adc;
				}
				break;
		}
		break;
	}
	default:
		if(cur_key & (KEY_SET | KEY_LONG))
		{
			gs_menu_level = 1;
		}
	break;
	}
}
Esempio n. 27
0
Condition*
Control::GetRegularDomain(int __id, vector<string>* __loop_counters, vector<string>* __param,LDemonstrator* __loop_ppts){
vector<string> variables=*__loop_counters;
if(IsLoop())
   variables.push_back(GetLoopCounter());
NormalizeConditions(__id,&variables,__param);
switch(GetNonAffineDomain()->size()){
   case 0:   goto simple_case;
      
   case 1:   {
      vector<Inequation*> v=*GetNonAffineDomain()->begin();
      if(v.size() <= 1)
         goto simple_case;
      }
   default:
      goto complicated_case;
   }

simple_case:
cout<<"\nSimple case";
exit(0);

if(IsIf() || IsIfElse() || IsWhileLoop())
   {
   if(IsWhileLoop()){
      cout<<"\nComplicated domain";
      exit(0);

      Inequation* ineq=new Inequation(new Expression(GetCounter()),FADA_GREATER_EQ,new Expression(0));
      Condition* count_ge_0 = new Condition (ineq);
      return new Condition(GetCondition(),FADA_AND,count_ge_0);
      }

   return GetCondition();
   }

if(IsForLoop()){
   Inequation* ineq1=new Inequation ( new Expression(GetLoopCounter( )),FADA_GREATER_EQ,GetForLowerBound( ));
   Inequation* ineq2=new Inequation ( new Expression(GetLoopCounter( )),FADA_LESS_EQ,GetForUpperBound( ));
   return new Condition( new Condition(ineq1), FADA_AND , new Condition(ineq2));
   }

cout<<"\nControl::GetRegularDomain ... inappropriate case 1";
exit(0);

complicated_case:
      cout<<"\nComplicated domain";
      exit(0);
Condition* result=new Condition(new Inequation(true));
for(vector<vector<Inequation*> >::iterator it=GetAffineDomain()->begin(); it != GetAffineDomain()->end(); ++it){
   result=new Condition(ToDNFTerm(&(*it)),FADA_AND,result);
   }
if(IsWhileLoop()){
   Inequation* ineq=new Inequation(new Expression(GetCounter()),FADA_GREATER_EQ,new Expression(1));
   Condition* count_ge_0 = new Condition (ineq);
   result=new Condition(count_ge_0,FADA_AND,result);
   }
ostringstream ch;
ch<<"domain_"<<__id;
Expression* non_affine=new Expression(ch.str());
for(vector<string>::iterator it=__loop_counters->begin(); it != __loop_counters->end();++it)
   non_affine->AddArgument(new Expression(*it));
if(IsLoop())
   non_affine->AddArgument(new Expression(GetLoopCounter()));
if(non_affine->IsVariable())
   __param->push_back(non_affine->GetVariableName());
return new Condition(new Condition(new Inequation(non_affine,FADA_NEQ,new Expression(0))),FADA_AND,result);
}
Esempio n. 28
0
void ExclusivePoolMgr::ExecuteEvent(ExclusivePool& pool)
{
    sLog.outBasic("ExclusivePool: Shuffling pool %u...", pool.poolID);

    // Get the spawn points and shuffle them.
    std::vector<ExclusivePoolSpot> poolSpotList;
    poolSpotList.insert(poolSpotList.begin(), m_poolSpots[pool.poolID].begin(), m_poolSpots[pool.poolID].end());
    std::random_shuffle(poolSpotList.begin(), poolSpotList.end());
    
    for (std::pair<const uint32, std::list<ObjectGuid> >& poolPair : pool.m_objects)
    {
        // If we have run out of spawn positions we stop spawning creatures.
        if (poolSpotList.empty())
            break;
        
        std::list<ObjectGuid> poolObjectList = poolPair.second;

        // Check if any creatures in the current group are alive.
        // If they are the group should be skipped.
        bool foundAlive = false;
        for (ObjectGuid currentCreature : poolObjectList)
        {
            const CreatureData* pData = sObjectMgr.GetCreatureData(currentCreature.GetCounter());
            if (pData)
            {
                Map* pMap = sMapMgr.FindMap(pData->mapid);
                if (pMap)
                {
                    if (!pMap->IsLoaded(pData->posX, pData->posY))
                    {
                        MaNGOS::ObjectUpdater updater(0);
                        // for creature
                        TypeContainerVisitor<MaNGOS::ObjectUpdater, GridTypeMapContainer  > grid_object_update(updater);
                        // for pets
                        TypeContainerVisitor<MaNGOS::ObjectUpdater, WorldTypeMapContainer > world_object_update(updater);
                        // Make sure that the creature is loaded before checking its status.
                        CellPair cellPair = MaNGOS::ComputeCellPair(pData->posX, pData->posY);
                        Cell cell(cellPair);
                        pMap->Visit(cell, grid_object_update);
                        pMap->Visit(cell, world_object_update);
                    }


                    Creature* pCreature = pMap->GetCreature(currentCreature);
                    if (pCreature)
                    {
                        // If the creature is alive or being looted we don't include it in the randomisation.
                        if (pCreature->isAlive() || pCreature->HasFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE))
                        {
                            sLog.outBasic("ExclusivePool: Skipping creature with guid %u.", currentCreature.GetCounter());
                            auto itr = std::find_if(poolSpotList.begin(), poolSpotList.end(),
                            [&](const ExclusivePoolSpot& spot)
                            {
                                if (spot.x == pData->posX && spot.y == pData->posY && 
                                    spot.z == pData->posZ && spot.mapID == pData->mapid)
                                {
                                    return true;
                                }
                                else
                                    return false;
                            });

                            // If we found the spot on which the living creature is standing
                            // we remove that spot since it's occupied.
                            if (itr != poolSpotList.end())
                            {
                                poolSpotList.erase(itr);
                                foundAlive = true;
                            }
                            else
                            {
                                sLog.outBasic("ExclusivePool: Could not find the pool position for creature %u. Moving it to avoid double spawns!", currentCreature.GetCounter());
                            }

                            DespawnAllExcept(poolObjectList, currentCreature);

                            break;
                        }
                    }
                }
            }
        }

        // If a creature in the current group was alive we skip it.
        if (foundAlive)
            continue;

        
        // Pick a random creature from the current group.
        auto itr = poolObjectList.begin();
        std::advance(itr, urand(0, poolObjectList.size() - 1));
        
        // Get a spawn point for the creature.
        ExclusivePoolSpot spot = poolSpotList.back();
        poolSpotList.pop_back();

        CreatureData& rData = sObjectMgr.mCreatureDataMap[itr->GetCounter()];
        
        // If the creature is already in the correct spot we skip it.
        if (rData.posX == spot.x && rData.posY == spot.y && 
            rData.posZ == spot.z && rData.mapid == spot.mapID)
        {
            continue;
        }
        
        // Do the actual spawning.
        sObjectMgr.RemoveCreatureFromGrid(itr->GetCounter(), &rData);
        Creature::AddToRemoveListInMaps(itr->GetCounter(), &rData);
        
        rData.posX = spot.x;
        rData.posY = spot.y;
        rData.posZ = spot.z;
        rData.orientation = spot.orientation;
        rData.mapid = spot.mapID;
        
        // Update the creature entry in the database.
        WorldDatabase.PQuery("UPDATE creature SET map=%u, position_x=%f, position_y=%f, position_z=%f, orientation=%f WHERE guid=%u",
                             spot.mapID, spot.x, spot.y, spot.z, spot.orientation, itr->GetCounter());

        // Make sure that all other creatures in the group are despawned.
        DespawnAllExcept(poolObjectList, *itr);
    }
    
    SaveRespawnTime(pool);

    sLog.outBasic("ExclusivePool: Finished shuffling pool %u.", pool.poolID);
}
Esempio n. 29
0
double WaitCounter(double _time)
{
	while ((double)((GetCounter() - i64CounterStart)/PCFreq) < _time);
	return ((double)GetCounter());

} // end WaitCounter()
Esempio n. 30
0
/*******************************************************************************
**                                                                            **
** FUNC-NAME     :                                                            **
**                                                                            **
** DESCRIPTION   :                                                            **
**                                                                            **
** PRECONDITIONS :                                                            **
**                                                                            **
** PARAMETER     :                                                            **
**                                                                            **
** RETURN        :                                                            **
**                                                                            **
** REMARKS       :                                                            **
**                                                                            **
*******************************************************************************/
StatusType SetAbsAlarm
(
	AlarmType AlarmID,
	TickType Start,
	TickType Cycle
)
{
	/* \req OSEK_SYS_3.22 The system service StatusType
	 ** SetAbsAlarm ( AlarmType AlarmID, TickType Start, TickType Cycle )
	 ** shall be defined */

	/* \req OSEK_SYS_3.22.3-1/2 Possible return values in Standard mode are E_OK,
	 ** E_OS_STATE */
	StatusType ret = E_OK;

#if (ERROR_CHECKING_TYPE == ERROR_CHECKING_EXTENDED)
	/* check if the alarm id is in range */
	if(AlarmID >= ALARMS_COUNT)
	{
		/* \req OSEK_SYS_3.22.4-1/2 Extra possible return values in Extended mode
		 ** are E_OS_ID, E_OS_VALUE */
		ret = E_OS_ID;
	}
	/* check that increment and cycle are in range */
	else if( (Start > CountersConst[AlarmsConst[AlarmID].Counter].MaxAllowedValue) ||
				( ( Cycle != 0 ) &&
					( (Cycle > CountersConst[AlarmsConst[AlarmID].Counter].MaxAllowedValue) ||
						(Cycle < CountersConst[AlarmsConst[AlarmID].Counter].MinCycle) ) ) )
	{
		/* \req OSEK_SYS_3.22.4-2/2 Extra possible return values in Extended mode
		 ** are E_OS_ID, E_OS_VALUE */
		ret = E_OS_VALUE;
	}
	else
#endif
	/* check if the alarm is disable */
	if(AlarmsVar[AlarmID].AlarmState != 0)
   {
		/* \req OSEK_SYS_3.22.3-2/2 Possible return values in Standard mode are E_OK,
		 ** E_OS_STATE */
      ret = E_OS_STATE;
   }
	else
	{

		IntSecure_Start();

		/* enable alarm */
		AlarmsVar[AlarmID].AlarmState = 1;

		/* set abs alarm */
		AlarmsVar[AlarmID].AlarmTime = GetCounter(AlarmsConst[AlarmID].Counter) + Start;
		AlarmsVar[AlarmID].AlarmCycleTime = Cycle;

		IntSecure_End();
	}

#if (HOOK_ERRORHOOK == ENABLE)
	/* \req OSEK_ERR_1.3-14/xx The ErrorHook hook routine shall be called if a
	 ** system service returns a StatusType value not equal to E_OK.*/
	/* \req OSEK_ERR_1.3.1-14/xx The hook routine ErrorHook is not called if a
	 ** system service is called from the ErrorHook itself. */
   if ( ( ret != E_OK ) && (ErrorHookRunning != 1))
	{
		SetError_Api(OSServiceId_SetAbsAlarm);
		SetError_Param1(AlarmID);
		SetError_Param2(Start);
		SetError_Param3(Cycle);
		SetError_Ret(ret);
		SetError_Msg("SetAbsAlarm returns != than E_OK");
		SetError_ErrorHook();
	}
#endif

	return ret;
}