void OnLMBClick()
{
	if (ms.y < gun->cy - 10)
	{
		double a;
		int j = -1;
		for (int i = 0; i < R_COUNT; i++)
		{
			if (crosses[i]->IsEnabled() == 0)
			{
				if (j >= -1) j = i;
			}
			else if (ms.x > crosses[i]->x - 10 && ms.x < crosses[i]->x + 10 && ms.y > crosses[i]->y - 10 && ms.y < crosses[i]->y + 10)
			{
				j = -2;
				break;
			}
		}
		if (j >= 0)
		{
			if (score > 0) score -= 1;
			crosses[j]->Enable(ms.x, ms.y);
			if (gun->cx - ms.x == 0)
			{
				a = M_PI/2;
			}
			else
			{
				a = atan((double)gun->cy - ms.y / (double) gun->cx - ms.x);
				if (gun->cx - ms.x < 0) a += M_PI;
			}
			rockets[j]->Enable(round_int(gun->cx - 15 * cos(a)) - 2, round_int(gun->cy - 15 * sin(a)) - 5, 3, 6, round_int(gun->cx - 15 * cos(a)), round_int(gun->cy - 15 * sin(a)));
		}
	}
}
示例#2
0
void DungeonUtil::drawLine(double x1, double y1, double x2, double y2, float brushSize, int steps, const SelectiveDungeonTile& tile) {
  double x = x1;
  double y = y1;
  double deltaX = (x2 - x1);
  double deltaY = (y2 - y1);

  for(int i = 0; i < steps; i++) {
    double percent = (double)i / (double)(MACRO_MAX(steps - 1, 1));
    drawFilledCircle(round_int(x + (percent * deltaX)), round_int(y + (percent * deltaY)), brushSize, tile);
  }
}
示例#3
0
void Script :: logic(float t)
{
    const unsigned int time_between_ticks = round_int(1000.0f / m_TickFrames);
    // accumualate time
    m_TickTime.logic(t);
    //std::cout << m_TickTime.milliseconds() << std::endl;
    if(m_TickTime.milliseconds() < time_between_ticks) {
        return;
    }
    
    unsigned int remaining_frames = (unsigned int)(m_TickTime.milliseconds() / time_between_ticks - 1);
    unsigned int remaining_time = (unsigned int)m_TickTime.milliseconds() % time_between_ticks;
    
    // DEBUG{
        //Log::get().write(str("Remaining Frames: ") + str(remaining_frames));
        //assert(remaining_frames < 5);
    // }DEBUG
    
    m_TickTime.reset();
    m_TickTime.logic(((remaining_frames)*time_between_ticks) + remaining_time);

    // need to sleep?
    if(m_SleepFrames > 0)
    {
        // sleep this frame
        m_SleepFrames -= 1;
        return;
    }

    int status = lua_resume(m_pThread, 0);
    if(status != LUA_YIELD)
    {
        // either error or done with script
        if(status == LUA_ERRRUN && lua_isstring(m_pThread, -1))
        {
            Log::get().error(str(lua_tostring(m_pThread, -1)));
            return; // bail
        }
        else
        {
            // script is finished
            m_bDone = true;
        }
    }
    
    // figure out how many frames to sleep before resuming script
    if(lua_isnumber(m_pThread, 1))
    {
        m_SleepFrames = round_int(lua_tonumber(m_pThread, 1) - 1.0);
        if(m_SleepFrames < 0)
            m_SleepFrames = 0;
    }
}
void	ClockCycleCounter::compute_clk_mul ()
{
	assert (! _init_flag);

#if defined (__MACOS__)

	long				clk_speed_mhz = CurrentProcessorSpeed ();
	const Int64		clk_speed =
		static_cast <Int64> (clk_speed_mhz) * (1000L*1000L);

	const double	start_time_s = stopwatch_ClockCycleCounter_get_time_s ();
	start ();

	const double	duration = 0.01;	// Seconds
	while (stopwatch_ClockCycleCounter_get_time_s () - start_time_s < duration)
	{
		continue;
	}

	const double	stop_time_s = stopwatch_ClockCycleCounter_get_time_s ();
	stop ();

	const double	diff_time_s = stop_time_s - start_time_s;
	const double	nbr_cycles = diff_time_s * static_cast <double> (clk_speed);

	const Int64		diff_time_c = _state - _start_time;
	const double	clk_mul = nbr_cycles / static_cast <double> (diff_time_c);

	_clk_mul = round_int (clk_mul);

#endif	// __MACOS__
}
示例#5
0
int filterer::commonDiff(scan *s1)
{
	int common = 0;
	if (s1->charge[0] == 1){
		vector <int> dists;
		dists.assign(300,0);
		vector <peakData *> r;
		for (unsigned int i = 0; i < s1->peaks.size(); ++i){
			if (s1->peaks.at(i).rank == 1 || s1->peaks.at(i).rank == 2){
				r.push_back(&s1->peaks.at(i));
			}
		}
		for (unsigned int i = 0 ; i < r.size(); ++i){
			for (unsigned int j = i; j < r.size() && j < i+5; ++j){
				double diff = fabs(r.at(i)->exact_mz-r.at(j)->exact_mz);
				if (diff > 20 && diff < 300){
					dists[round_int(diff)]++;
				}
			}
		}
		for (unsigned int i = 0; i < dists.size(); ++i){
			if (dists.at(i) >= 2){
				common += dists.at(i)-1;
				cout << dists.at(i) << " ";
			}
		}
		cout << endl;
	}
	s1->commonDiff = common;
	return common;
}
void DrawRocketsAndCrosses()
{
	double a;
	for (int i = 0; i < R_COUNT; i++)
	{
		if (crosses[i]->IsEnabled() == 1)
		{
			if (sqrt(((long int) (crosses[i]->x - rockets[i]->cx) * (crosses[i]->x - rockets[i]->cx)) + ((long int) (crosses[i]->y - rockets[i]->cy) * (crosses[i]->y - rockets[i]->cy))) < 5)
			{
				if (explodes[i]->IsEnabled() == 1)
				{
					explodes[i]->Disable(BG_COLOR);
				}
				explodes[i]->Enable(crosses[i]->x, crosses[i]->y);
				crosses[i]->Disable(BG_COLOR);
				rockets[i]->Disable(BG_COLOR);
			}
			else
			{
				crosses[i]->Draw(CROSS_COLOR);
				if (rockets[i]->cx - crosses[i]->x == 0)
				{
					a = M_PI / 2;
				}
				else
				{
					a = atan((double)(rockets[i]->cy - crosses[i]->y) / (double)(rockets[i]->cx - crosses[i]->x));
					if (rockets[i]->cx - crosses[i]->x < 0) a += M_PI;
				}
				rockets[i]->cx = round_int(rockets[i]->cx - R_SPEED * cos(a));
				rockets[i]->cy = round_int(rockets[i]->cy - R_SPEED * sin(a));
				rockets[i]->DrawAngle(crosses[i]->x, crosses[i]->y, R_COLOR);
			}
		}
	}
}
示例#7
0
文件: create.c 项目: balanx/vbpp
/**************************************************************************
 *
 * Function Name : 
 * Parameters :
 * Return Value :
 * Purpose :
 *
 **************************************************************************/
int
is_an_integer(double value)
{
    double abs_value;

    if (value < 0.0) abs_value = value * -1.0;
    else abs_value = value;

    abs_value = round_int(abs_value) - abs_value;
    if (abs_value < 0.0) abs_value = abs_value * -1.0;

    if (abs_value <= DELTA) {
	return (TRUE);
    }
    else {
	return (FALSE);
    }
}
示例#8
0
void DungeonUtil::drawCrookedLine(double x1, double y1, double x2, double y2, int subdivisons, float maxDisplacement, float brushSize, const SelectiveDungeonTile& tile) {
  // we'll use a midpoint displacement algorithm here
  // we need to allow variance in the brushSize probably
  // WARNING: precision might be too bad like this


  if (subdivisons > 0) {
    // find the perpendicular to the line
    v2d_t offset = v2d_normalize(v2d_v(x2 - x1, y2 - y1));
    // not done yet...
    double temp = offset.vec[0];
    offset.vec[0] = offset.vec[1];
    offset.vec[1] = -temp;

    // scale it
    offset = v2d_scale(r_num(-maxDisplacement, maxDisplacement), offset);

    double offsetMidpointX = avg(x1, x2) + offset.x;
    double offsetMidpointY = avg(y1, y2) + offset.y;

    maxDisplacement *= DISPLACEMENT_SCALE;

    drawCrookedLine(x1, y1, offsetMidpointX, offsetMidpointY, subdivisons - 1, maxDisplacement, brushSize, tile);
    drawCrookedLine(offsetMidpointX, offsetMidpointY, x2, y2, subdivisons - 1, maxDisplacement, brushSize, tile);
  }
  else {
    // WARNING: is this really an acceptable way to draw this line?
//    float lineLength = dist(x1, y1, x2, y2);

    double lineLength = v2d_dist(v2d_v(x1, y1), v2d_v (x2, y2));

    int steps = MACRO_MAX(round_int(lineLength / (brushSize * 0.5f)), 1);

//    drawLine(round_int(x1), round_int(y1), round_int(x2), round_int(y2), brushSize, steps, tile);
    drawLine(x1, y1, x2, y2, brushSize, steps, tile);
  }
}
示例#9
0
void CharacterInfo::reload() {
	// update attributes
	std::string attributes = "";
	attributes.append(std::to_string(m_attributes->currentHealthPoints));
	attributes.append("/");
	attributes.append(std::to_string(m_attributes->maxHealthPoints));
	attributes.append("\n");

	// health regeneration
	attributes.append(std::to_string(m_attributes->healthRegenerationPerS));
	attributes.append("/s\n");

	// crit
	attributes.append(std::to_string(m_attributes->criticalHitChance));
	attributes.append("%\n");

	// cooldown reduction
	attributes.append(std::to_string(m_attributes->haste));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->cooldownMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("CooldownReduction"));
	attributes.append("\n\n");

	// dmg 
	attributes.append(std::to_string(m_attributes->damagePhysical) + "\n");
	attributes.append(std::to_string(m_attributes->damageFire) + "\n");
	attributes.append(std::to_string(m_attributes->damageIce) + "\n");
	attributes.append(std::to_string(m_attributes->damageShadow) + "\n");
	attributes.append(std::to_string(m_attributes->damageLight) + "\n\n");

	// resistance
	attributes.append(std::to_string(m_attributes->resistancePhysical));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->physicalMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("Reduction"));
	attributes.append("\n");

	attributes.append(std::to_string(m_attributes->resistanceFire));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->fireMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("Reduction"));
	attributes.append("\n");

	attributes.append(std::to_string(m_attributes->resistanceIce));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->iceMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("Reduction"));
	attributes.append("\n");

	attributes.append(std::to_string(m_attributes->resistanceShadow));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->shadowMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("Reduction"));
	attributes.append("\n");

	attributes.append(std::to_string(m_attributes->resistanceLight));
	attributes.append(" - ");
	attributes.append(std::to_string(-round_int(m_attributes->lightMultiplier * 100.f - 100.f)));
	attributes.append("% " + g_textProvider->getText("Reduction"));
	attributes.append("\n");
	m_attributeText.setString(attributes);

	m_window->setWidth(3 * GUIConstants::TEXT_OFFSET + m_namesText.getLocalBounds().width + m_attributeText.getLocalBounds().width);
}
示例#10
0
void filterer::analyze(vector<scan*> &sec, parameters &params)
{
	for (unsigned int i = 0; i < sec.size();++i){
		sec.at(i)->TICFore = 0;
		sec.at(i)->TICBack = 0;
		sec.at(i)->sumPeaksIntn = 0;
		if (i % 500 == 0){
			cout <<".";
			cout.flush();
		}
		if (sec.at(i)->mz.size() != 0){		
			peakData p;
			for (unsigned int j = 0; j < sec.at(i)->mz.size(); ++j){
				p.has_a = false;
				p.has_comp = false;
				p.has_h2o_nh3 = false;
				p.has_iso = false;
				p.posi = j;
				p.intn = sec.at(i)->intn.at(j);
				p.exact_mz = sec.at(i)->mz.at(j);
				p.mz = round_int(sec.at(i)->mz.at(j));
				sec.at(i)->peaks.push_back(p);
			}
			sec.at(i)->num_peaks = sec.at(i)->peaks.size();
			sec.at(i)->charge[0] = 0;
			sec.at(i)->charge[1] = 0;
			sec.at(i)->TIC = 0;
			float sumP = 0;
			double maxFore = 0;
			double maxBack = 0;
			double maxPeak = 0;
			double secondPeak = 0;
			for (unsigned int k = 0; k < sec.at(i)->peaks.size(); ++k){
				sec.at(i)->TIC += sec.at(i)->peaks.at(k).intn;
				sumP += sec.at(i)->peaks.at(k).intn;
				if (sec.at(i)->peaks.at(k).mz <= sec.at(i)->preMZ){
					sec.at(i)->TICFore+=sec.at(i)->peaks.at(k).intn;
					if (sec.at(i)->peaks.at(k).intn > maxFore)
						maxFore = sec.at(i)->peaks.at(k).intn;
				}
				else{
					sec.at(i)->TICBack+=sec.at(i)->peaks.at(k).intn;
					if (sec.at(i)->peaks.at(k).intn > maxBack)
						maxBack = sec.at(i)->peaks.at(k).intn;
				}
				if (sec.at(i)->peaks.at(k).intn>maxPeak){
					secondPeak = maxPeak;
					maxPeak=sec.at(i)->peaks.at(k).intn;
				}
				else if (sec.at(i)->peaks.at(k).intn>secondPeak && sec.at(i)->peaks.at(k).intn<maxPeak){
					secondPeak = sec.at(i)->peaks.at(k).intn;
				}
			}
			sec.at(i)->TICFore -= maxFore;
			sec.at(i)->TICBack -= maxBack;
			sec.at(i)->sumPeaksIntn=sumP;
			
			if (sec.at(i)->TICFore*0.125 > sec.at(i)->TICBack){
				sec.at(i)->charge[0]=1;
				sec.at(i)->charge[1]=0;
				for (unsigned int j = 0; j < sec.at(i)->peaks.size(); ++j){
					if (sec.at(i)->peaks.at(j).mz > sec.at(i)->preMZ){
						sec.at(i)->peaks.erase(sec.at(i)->peaks.begin()+j);
						j--;
					}
				}
			}
			sec.at(i)->num_peaks = sec.at(i)->peaks.size();
			sec.at(i)->basePeakIntensity= maxPeak;
			sec.at(i)->secBasePeakIntn = secondPeak;
			
			calIntnRatio(sec.at(i));
			goodSegments(sec.at(i));
			neutralPeaks(sec.at(i));
			calculateParents(sec.at(i));
			complement(sec.at(i));
			int num_r_peaks = 0;
			for (unsigned int j = 0; j < sec.at(i)->peaks.size(); ++j){
				if (sec.at(i)->peaks.at(j).rank<4)
					num_r_peaks++;
			}
			sec.at(i)->num_r_peaks = num_r_peaks;
			sec.at(i)->iso_ratio = 0;
			if (num_r_peaks != 0)
				sec.at(i)->iso_ratio = (double)sec.at(i)->num_iso/(double)sec.at(i)->num_r_peaks;
			if (num_r_peaks != 0)
				sec.at(i)->h2o_ratio = (double)sec.at(i)->num_h2o/(double)sec.at(i)->num_r_peaks;
		}
//tout << endl;
	}
	calNormTIC(sec);	
	for (unsigned int i = 0; i < sec.size();++i){		
		sec.at(i)->discrim=discrim_m(*sec.at(i),params);
	
//		if (sec.at(i)->discrim>cutoff)
//			sec.at(i)->good = true;
//		else
//			sec.at(i)->good = false;
//		evalCharge(sec.at(i));
	}
	cout <<"Done"<<endl;
}
示例#11
0
void filterer::calculateParents(scan *s1)
{
	int pCounts[5000];
	double pSum[5000];
	for (unsigned int k = 0; k < 5000; ++k){
		pCounts[k] = 0;
		pSum[k] = 0;
	}

	for (unsigned int k = 0; k <s1->peaks.size(); ++k){
		if (s1->peaks.at(k).rank < 10){
			for (unsigned int l = 0; l <s1->peaks.size(); ++l){
				double sumval = s1->peaks.at(k).exact_mz+s1->peaks.at(l).exact_mz;
				double sum2val = s1->peaks.at(k).exact_mz*2+s1->peaks.at(l).exact_mz;
				if ((sumval > s1->preMZ-3 &&sumval < s1->preMZ+3) || (sumval > s1->preMZ*2-1-3 && sumval < s1->preMZ*2-1+3)){
					int roundVal = round_int(sumval);
					if (roundVal < 5000){
					pCounts[roundVal]++;
					pSum[roundVal]+=sumval;
					}
				}
				if ((sumval > s1->preMZ*3-1-3 &&sumval < s1->preMZ*3-1+3)){
					int roundVal = round_int(sum2val);
					if (roundVal < 5000){
					pCounts[roundVal]++;
					pSum[roundVal]+=sum2val;
					}
				}
			}
		}
	}
  int maxP1 = 0;
  int maxP2 = 0;
  int maxP3 = 0;
  int pos1 = 0;
  int pos2 = 0;
  int pos3 = 0;
  unsigned int pre = round_int(s1->preMZ);
  for (unsigned int k =pre-3; k <= pre+3; ++k){
    if (k > 0 && k < 5000 && pCounts[k] > maxP1){
      maxP1 = pCounts[k];
      pos1 = k;
    }
  }
  pre = round_int(s1->preMZ*2-1);
  for (unsigned int k =pre-3; k <= pre+3; ++k){
    if (k > 0 && k < 5000 && pCounts[k] > maxP2){
      maxP2 = pCounts[k];
      pos2 = k;
    }
  }
  pre = round_int(s1->preMZ*3-1);
  for (unsigned int k =pre-3; k <= pre+3; ++k){
    if (k > 0 && k < 5000 && pCounts[k] > maxP3){
      maxP3 = pCounts[k];
      pos3 = k;
    }
  }
  if (maxP1 == 0)
    s1->parent1 = s1->preMZ;					// stored as parent+H
  else
    s1->parent1 = pSum[pos1]/pCounts[pos1];
  if (maxP2 == 0)
    s1->parent2 = s1->preMZ*2-1;					// stored as parent+H
  else
    s1->parent2 = pSum[pos2]/pCounts[pos2];
  if (maxP3 == 0)
    s1->parent3 = s1->preMZ*3-1;					// stored as parent+H
  else
    s1->parent3 = pSum[pos3]/pCounts[pos3];
}
示例#12
0
v2di_t DungeonUtil::arcLerp(int x, int y, float radius, float startAngle, float rotation, float percent) const {
  float finalAngle = startAngle + (percent * rotation);
  return v2di_v(x + round_int(radius * cos(finalAngle)), y + round_int(radius * sin(finalAngle)));
}