예제 #1
0
    void ByteSpeedMeter::SubmitBytes(boost::uint32_t bytes)
    {
        if (is_running_ == false)
            return ;

        UpdateTickCount();

        total_bytes_ += bytes;
        history_bytes_[ GetPositionFromSeconds(last_sec_) ] += bytes;
    }
예제 #2
0
    void ByteSpeedMeter::Start()
    {
        if (is_running_ == true)
            return ;
    
        Clear();

        UpdateTickCount();
        start_time_ = last_tick_count_;

        is_running_ = true;
    }
예제 #3
0
    double ByteSpeedMeter::RecentMinuteByteSpeed() // 1 minute
    {
        if (is_running_ == false)
            return 0.0;

        UpdateTickCount();

        double bytes_in_minute = 0.0;
        for (boost::uint32_t i = 0; i < HISTORY_INTERVAL_IN_SEC; i++)
            bytes_in_minute += history_bytes_[i];

        boost::uint32_t elapsed_time = GetElapsedTimeInMilliSeconds();
        if (elapsed_time > HISTORY_INTERVAL_IN_SEC * 1000)
            return 1.0 * bytes_in_minute / HISTORY_INTERVAL_IN_SEC;
        else
            return 1000.0 * bytes_in_minute / elapsed_time;
    }
예제 #4
0
    double ByteSpeedMeter::CurrentByteSpeed() // 5 seconds
    {
        if (is_running_ == false)
            return 0.0;

        UpdateTickCount();

        double bytes_in_recent = 0.0;
        for (boost::uint32_t i = last_sec_; i > last_sec_ - SECONDS_IN_RECENT; i--)
            bytes_in_recent += history_bytes_[ GetPositionFromSeconds(i) ];

        boost::uint32_t elapsed_time = GetElapsedTimeInMilliSeconds();
        if (elapsed_time > SECONDS_IN_RECENT * 1000)
            return 1.0 * bytes_in_recent / SECONDS_IN_RECENT;
        else
            return 1000.0 * bytes_in_recent / elapsed_time;
    }
예제 #5
0
/**\brief SpriteManager update function.
 * \details Update the sprites inside each quadrant
 * \param lowFps If true, forces the wave-update method to be used rather than the full-update
 */
void SpriteManager::Update( lua_State *L, bool lowFps) {
	//this will contain every quadrant that we will potentially want to update
	list<QuadTree*> quadList;
	
	//if update-all is given then we update every quadrant
	//we do the same if tickCount == 0 even if update-all is not given
	// (in wave update mode, tickCount == 0 is when we want to update all quadrants)
	if( ! lowFps || tickCount == 0) {
		//need to get all of the quadrants in our map
		GetAllQuadrants(&quadList);
	}
	else
	{
		//wave update mode with tickCount != 0 -- update some quadrants
		Camera* camera = Simulation_Lua::GetSimulation(L)->GetCamera();
		Coordinate currentPoint (camera->GetFocusCoordinate());	//always update centered on where we're at

		quadList.push_back (GetQuadrant (currentPoint)); //we ALWAYS update the current quadrant

		//we also ALWAYS update the 'regular' bands
		//	the first band is at index 1 - index 0 would be the single quadrant in the middle
		//	when we get the list of quadrants back we splice them onto the end of our overall list
		for (int i = 1; i <= numRegularBands; i ++) {
			list<QuadTree*> tempBandList = GetQuadrantsInBand (currentPoint, i);
			quadList.splice (quadList.end(), tempBandList);
		}

		//now - we SOMETIMES update the semi-regular bands
		//   the ticks that each band is updated in is stored in the map
		//   so we get our semiRegular update modulus of the ticks and then check the map
		//    - the map has the tick index as the key and the band to update as the value
		int semiRegularTick = tickCount % semiRegularPeriod;
		map<int,int>::iterator findBand = ticksToBandNum.find (semiRegularTick);
		if (findBand != ticksToBandNum.end()) {		//found the key
			//cout << "tick = " << tickCount << ", semiRegularTick = " << semiRegularTick << ", band = " << findBand->second << endl;
			list<QuadTree*> tempBandList = GetQuadrantsInBand (currentPoint, findBand->second);
			quadList.splice (quadList.end(), tempBandList);
		}
		else {
			//no semi-regular bands to update at this tick, do nothing
		}
	}

	// Find and Fix any Sprites that have moved out of bounds.
	list<Sprite *> all_oob;
	list<QuadTree*>::iterator iter;
	for ( iter = quadList.begin(); iter != quadList.end(); ++iter ) {
		(*iter)->Update(L);
		list<Sprite *>* oob = (*iter)->FixOutOfBounds();
		all_oob.splice(all_oob.end(), *oob );
		delete oob;
	}

	// Move sprites to adjacent Quadrants as they cross boundaries
	list<Sprite *>::iterator i;
	for( i = all_oob.begin(); i != all_oob.end(); ++i ) {
		GetQuadrant( (*i)->GetWorldPosition() )->Insert( *i );
	}

	// Delete all sprites queued to be deleted
	if (!spritesToDelete.empty()) {
		spritesToDelete.sort(); // The list has to be sorted or unique doesn't work correctly.
		spritesToDelete.unique();
	
		// Tell the AI that they've been killed
		for( i = spritesToDelete.begin(); i != spritesToDelete.end(); ++i ) {
			if( (*i)->GetDrawOrder() == DRAW_ORDER_SHIP ) {
				((AI*)(*i))->Killed(L);
			}
		}

		for( i = spritesToDelete.begin(); i != spritesToDelete.end(); ++i ) {
			DeleteSprite(*i);
		}
		spritesToDelete.clear();
	}

	for ( iter = quadList.begin(); iter != quadList.end(); ++iter ) {
		(*iter)->ReBallance();
	}

	DeleteEmptyQuadrants();

	// Update the tick count after all updates for this tick are done
	UpdateTickCount ();
}