示例#1
0
void CBuffer::UpdateInfo(tstring& s)
{
	tstring p;

	s = "";
	s += "MACRO-BUFFER INFO\n";
	s += "Network extender\n \n";

	if (GetPlayerOwner())
	{
		s += "Team: " + GetPlayerOwner()->GetPlayerName() + "\n";
		if (GetDigitanksPlayer() == DigitanksGame()->GetCurrentLocalDigitanksPlayer())
			s += " Friendly\n \n";
		else
			s += " Hostile\n \n";
	}
	else
	{
		s += "Team: Neutral\n \n";
	}

	if (IsConstructing())
	{
		s += "(Constructing)\n";
		s += tsprintf(tstring("Turns left: %d\n"), GetTurnsRemainingToConstruct());
		return;
	}

	s += tsprintf(tstring("Fleet Points: %d\n"), FleetPoints());
	s += tsprintf(tstring("Bandwidth: %.1f/turn\n"), Bandwidth());
	s += tsprintf(tstring("Network Size: %d\n"), (int)GetDataFlowRadius());
	s += tsprintf(tstring("Efficiency: %d\n"), (int)(GetChildEfficiency() * 100));
}
示例#2
0
文件: cpu.cpp 项目: BSVino/Digitanks
void CCPU::UpdateInfo(tstring& s)
{
	tstring p;
	s = "";
	s += "CENTRAL PROCESSING UNIT\n";
	s += "Command center\n \n";

	if (GetDigitanksPlayer())
	{
		s += "Team: " + GetDigitanksPlayer()->GetPlayerName() + "\n";
		if (GetDigitanksPlayer() == DigitanksGame()->GetCurrentLocalDigitanksPlayer())
			s += " Friendly\n \n";
		else
			s += " Hostile\n \n";
	}
	else
	{
		s += "Team: Neutral\n \n";
	}

	if (IsProducing())
	{
		s += "[Producing Rogue]\n";
		s += tsprintf(tstring("Turns left: %d\n \n"), m_iTurnsToProduceRogue.Get());
	}

	s += tsprintf(tstring("Power: %.1f/turn\n"), Power());
	s += tsprintf(tstring("Fleet Points: %d\n"), FleetPoints());
	s += tsprintf(tstring("Bandwidth: %.1f/turn\n"), Bandwidth());
	s += tsprintf(tstring("Network Size: %d\n"), (int)GetDataFlowRadius());
	s += tsprintf(tstring("Efficiency: %d\n"), (int)(GetChildEfficiency() * 100));
}
示例#3
0
Bandwidth Module::getBandwidth(){
	std::ifstream streamUp("/sys/kernel/bandwidth/up");
	std::ifstream streamDown("/sys/kernel/bandwidth/down");
	ULong up = 0;
	streamUp >> up;

	ULong down = 0;
	streamDown >> down;

	return Bandwidth(down, up);
}
示例#4
0
void Window::update(){
	Module module;

	const ULong seconds = module.getSeconds();
	
	if(seconds != seconds_){
		seconds_ = seconds;
		const Bandwidth moduleBandwidth = module.getBandwidth();

		const time_t currentTime = time(0);
		const tm * timeData = localtime(&currentTime);
		const int currentWeekDay = timeData->tm_wday;

		if(currentWeekDay != prevWeekDay_){
			prevWeekDay_ = currentWeekDay;
			moduleStartBandwidth_ = moduleBandwidth;
			startBandwidth_ = Bandwidth(0ul, 0ul);
		}
	
		const Bandwidth bandwidth = (moduleBandwidth - moduleStartBandwidth_) + startBandwidth_;

		const ULong total = bandwidth.down + bandwidth.up;
		const ULong limit = 4ul * 1024ul * 1024ul * 1024ul; // 4GB.
		const ULong maxTransferRate = (limit > total ? limit - total : 0ul) / 60ul;
	
		BandwidthFile file;
		file.save(bandwidth);
	
		module.setLimit(maxTransferRate);
		
		const double usage = total < limit ? double(total) / double(limit) : 1.0;

		progress_->setValue(usage * 100000.0);
	
		std::ostringstream stream;
		stream << "Bandwidth Limit: " << displayDataSize(limit) << std::endl;
		stream << "Bandwidth Used (Total): " << displayDataSize(total) << std::endl;
		stream << "Bandwidth Used (Down): " << displayDataSize(bandwidth.down) << std::endl;
		stream << "Bandwidth Used (Up): " << displayDataSize(bandwidth.up) << std::endl;
		stream << "Current max transfer rate: " << displayDataSize(maxTransferRate) << "/s";
	
		label_->setText(tr(stream.str().c_str()));

		trayIcon_.update(bandwidth);
	}
}
示例#5
0
void CStructure::DrawSchema(int x, int y, int w, int h)
{
	CRenderingContext c(GameServer()->GetRenderer(), true);
	c.SetBlend(BLEND_ALPHA);
	c.SetColor(Color(255, 255, 255));

	float flYPosition = (float)y + h;
	float flXPosition = (float)x + w + 20;

	int iIconFontSize = 11;
	tstring sFont = "text";
	float flIconFontHeight = glgui::RootPanel()->GetFontHeight(sFont, iIconFontSize) + 2;

	if (IsConstructing())
	{
		tstring sTurns = tsprintf(tstring("Turns To Construct: %d"), GetTurnsRemainingToConstruct());
		float flWidth = glgui::RootPanel()->GetTextWidth(sTurns, sTurns.length(), sFont, iIconFontSize);
		glgui::CLabel::PaintText(sTurns, sTurns.length(), sFont, iIconFontSize, flXPosition - flWidth, (float)y);
		return;
	}

	if (IsUpgrading())
	{
		tstring sTurns = tsprintf(tstring("Turns To Upgrade: %d"), GetTurnsRemainingToUpgrade());
		float flWidth = glgui::RootPanel()->GetTextWidth(sTurns, sTurns.length(), sFont, iIconFontSize);
		glgui::CLabel::PaintText(sTurns, sTurns.length(), sFont, iIconFontSize, flXPosition - flWidth, (float)y);
		return;
	}

	if (GetUnitType() == STRUCTURE_CPU)
	{
		CCPU* pCPU = static_cast<CCPU*>(this);
		if (pCPU->IsProducing())
		{
			tstring sTurns = "Rogue: 1";	// It only ever takes one turn to make a rogue.
			float flWidth = glgui::RootPanel()->GetTextWidth(sTurns, sTurns.length(), sFont, iIconFontSize);
			glgui::CLabel::PaintText(sTurns, sTurns.length(), sFont, iIconFontSize, flXPosition - flWidth, (float)y);
		}
	}
	else if (GetUnitType() == STRUCTURE_TANKLOADER || GetUnitType() == STRUCTURE_INFANTRYLOADER || GetUnitType() == STRUCTURE_ARTILLERYLOADER)
	{
		CLoader* pLoader = static_cast<CLoader*>(this);
		if (pLoader->IsProducing())
		{
			tstring sUnit;
			if (pLoader->GetBuildUnit() == UNIT_INFANTRY)
				sUnit = "Resistor";
			else if (pLoader->GetBuildUnit() == UNIT_ARTILLERY)
				sUnit = "Artillery";
			else
				sUnit = "Digitank";

			tstring sTurns = tsprintf(sUnit + ": %d", pLoader->GetTurnsRemainingToProduce());
			float flWidth = glgui::RootPanel()->GetTextWidth(sTurns, sTurns.length(), sFont, iIconFontSize);
			glgui::CLabel::PaintText(sTurns, sTurns.length(), sFont, iIconFontSize, flXPosition - flWidth, (float)y);
		}
	}

	if (Bandwidth() > 0)
	{
		tstring sBandwidth = tsprintf(tstring(": %.1f"), Bandwidth());
		float flWidth = glgui::RootPanel()->GetTextWidth(sBandwidth, sBandwidth.length(), sFont, iIconFontSize);

		DigitanksWindow()->GetHUD()->PaintHUDSheet("BandwidthIcon", flXPosition - flWidth - flIconFontHeight, flYPosition - flIconFontHeight + 5, flIconFontHeight, flIconFontHeight);

		glgui::CLabel::PaintText(sBandwidth, sBandwidth.length(), sFont, iIconFontSize, flXPosition - flWidth, flYPosition);

		flYPosition -= flIconFontHeight;
	}

	if (FleetPoints() > 0)
	{
		tstring sFleetPoints = tsprintf(tstring(": %d"), FleetPoints());
		float flWidth = glgui::RootPanel()->GetTextWidth(sFleetPoints, sFleetPoints.length(), sFont, iIconFontSize);

		DigitanksWindow()->GetHUD()->PaintHUDSheet("FleetPointsIcon", flXPosition - flWidth - flIconFontHeight, flYPosition - flIconFontHeight + 5, flIconFontHeight, flIconFontHeight);

		glgui::CLabel::PaintText(sFleetPoints, sFleetPoints.length(), sFont, iIconFontSize, flXPosition - flWidth, flYPosition);

		flYPosition -= flIconFontHeight;
	}

	if (Power() > 0)
	{
		tstring sPower = tsprintf(tstring(": %.1f"), Power());
		float flWidth = glgui::RootPanel()->GetTextWidth(sPower, sPower.length(), sFont, iIconFontSize);

		DigitanksWindow()->GetHUD()->PaintHUDSheet("PowerIcon", (flXPosition - flWidth - flIconFontHeight), (flYPosition - flIconFontHeight) + 5, flIconFontHeight, flIconFontHeight);

		glgui::CLabel::PaintText(sPower, sPower.length(), sFont, iIconFontSize, flXPosition - flWidth, flYPosition);

		flYPosition -= flIconFontHeight;
	}
}
示例#6
0
void ReportDialog::OnTimer( wxTimerEvent& event )
{
	if( m_dummy > 99 )
		m_dummy = 0;

	TestMarshall *tm = TestMarshall::GetInstance();

	wxString title;

	if( m_step == 0 ) // Init and OS Info
	{
		if( NextStep() )
		{
		  this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
		  Run(1);
		}
	}
	else if( m_step == 1 ) // TCP window size
	{
		if( NextStep() )
		{
		  this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
		  Run(2);
		}
	}
	else if( m_step == 2 ) // External IP
	{
	  title << wxT("Kontrollerar extern IP");
	  if( NextStep() )
	    {
	      this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
	      Run(3);
	    }

	}
	else if( m_step == 3 )
	{
	  title << wxT("Kontrollerar dina n�tverksinst�llningar");

	  if( NextStep() )
		{
		  this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
		  Run(4);
		  return;
		}

		if( m_proc_running ) {
			this->OutputBuffer();
		}
		else {
			while( this->OutputBuffer() );
		}

		m_stepDone = !m_proc_running;

	}
	else if( m_step == 4 ) // netstat 
	{
	  title << wxT("Kontrollerar din nuvarande n�tverkskopplingar");
	  if( NextStep() )
	    {
	      this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
	      Run(5);
	      return;
	    }

		if( m_proc_running ) {
			this->OutputBuffer();
		}
		else {
			while( this->OutputBuffer() );
		}

		m_stepDone = !m_proc_running;

	}
	else if( m_step == 5 ) // tptest downstream
	{
	  title << FROMCSTR(tm->GetProgressString());
	  if( NextStep() )
	    {
	      this->m_Output->AppendText( wxT("\n\n----------------------------\n\n") );
	      Run(6);
	      return;
	    }

		if( tm->GetCompletedStatus() )
		{
			// TCP nedstr�ms
			TPEngine *engp = tm->GetDownstreamTPEngineStruct(0);
			wxString Bandwidth( FROMCSTR( Int32ToString( (int)engp->bestTCPRecvRate*8) ) );
			m_Output->AppendText( wxT("\n\nTCP nedstr�ms : ") );
			m_Output->AppendText( Bandwidth );
			m_Output->AppendText( wxT("\n") );
			Bandwidth.Clear();

			// TCP uppstr�ms
			engp = tm->GetUpstreamTPEngineStruct(0);
			Bandwidth << FROMCSTR( Int32ToString( (int)engp->bestTCPSendRate*8) );
			m_Output->AppendText( wxT("\nTCP uppstr�ms : ") );
			m_Output->AppendText( Bandwidth );
			m_Output->AppendText( wxT("\n") );
			Bandwidth.Clear();


			// UDP nedstr�ms
			engp = tm->GetDownstreamTPEngineStruct(1);
			Bandwidth << FROMCSTR( Int32ToString( (int)engp->bestUDPRecvRate*8 ) );
			m_Output->AppendText( wxT("\nUDP nedstr�ms : ") );
			m_Output->AppendText( Bandwidth );
			m_Output->AppendText( wxT("\n") );
			Bandwidth.Clear();

			// UDP uppstr�ms
			engp = tm->GetUpstreamTPEngineStruct(1);
			Bandwidth << FROMCSTR( Int32ToString( (int)engp->bestUDPSendRate*8) );
			m_Output->AppendText( wxT("\nUDP uppstr�ms : ") );
			m_Output->AppendText( Bandwidth );
			m_Output->AppendText( wxT("\n") );
			Bandwidth.Clear();

			m_stepDone = true;
		}

	}
	else if( m_step == 6 )
	{
	  title << wxT("Utf�r traceroute");

		if( m_proc_running ) {
			this->OutputBuffer();
		}
		else {
			while( this->OutputBuffer() );
		}

		m_stepDone = !m_proc_running;
	}
	
	bool Ok = this->m_dlgProgress->Update( m_dummy++, title );

	if( !m_Closed && (m_step == 6 && m_stepDone) || !Ok )
	{
	  TestMarshall *tm = TestMarshall::GetInstance();

	  this->m_Output->AppendText( wxT("\n\n----------- END --------------\n\n") );

	  this->m_timer->Stop();

	  if( m_TPTestInitialized )
	    tm->DeinitTestEngine(!Ok);

	  this->SetCursor( *wxSTANDARD_CURSOR );
	  this->m_dlgProgress->Show(false);
	  this->m_ButtonSaveToFile->Enable(true);
	  m_Done = true;
	}
}