void StatisticsHistory::TimeAndValueQueue::ResizeSampleSet( int maxSamples, DataStructures::Queue<StatisticsHistory::TimeAndValue> &histogram, SHDataCategory dataCategory, Time timeClipStart, Time timeClipEnd )
{
	histogram.Clear(_FILE_AND_LINE_);
	if (maxSamples==0)
		return;
	Time timeRange = GetTimeRange();
	if (timeRange==0)
		return;
	if (maxSamples==1)
	{
		StatisticsHistory::TimeAndValue tav;
		tav.time = timeRange;
		tav.val = GetRecentSum();
		histogram.Push(tav, _FILE_AND_LINE_);
		return;
	}
	Time interval = timeRange / maxSamples;
	if (interval==0)
		interval=1;
	unsigned int dataIndex;
	Time timeBoundary;
	StatisticsHistory::TimeAndValue currentSum;
	Time currentTime;
	SHValueType numSamples;
	Time endTime;
	
	numSamples=0;
	endTime = values[values.Size()-1].time;
	dataIndex=0;
	currentTime=values[0].time;
	currentSum.val=0;
	currentSum.time=values[0].time + interval / 2;
	timeBoundary = values[0].time + interval;
	while (timeBoundary <= endTime)
	{
		while (dataIndex < values.Size() && values[dataIndex].time <= timeBoundary)
		{
			currentSum.val += values[dataIndex].val;
			dataIndex++;
			numSamples++;
		}

		if (dataCategory==DC_CONTINUOUS)
		{
			if (dataIndex > 0 &&
				dataIndex < values.Size() &&
				values[dataIndex-1].time < timeBoundary &&
				values[dataIndex].time > timeBoundary)
			{
				SHValueType interpolatedValue = Interpolate(values[dataIndex-1], values[dataIndex], timeBoundary);
				currentSum.val+=interpolatedValue;
				numSamples++;
			}

			if (numSamples > 1)
			{
				currentSum.val /= numSamples;
			}
		}

		histogram.Push(currentSum, _FILE_AND_LINE_);
		currentSum.time=timeBoundary + interval / 2;
		timeBoundary += interval;
		currentSum.val=0;
		numSamples=0;
	}

	
	if ( timeClipStart!=0 && histogram.Size()>=1)
	{
		timeClipStart = histogram.Peek().time+timeClipStart;
		if (histogram.PeekTail().time < timeClipStart)
		{
			histogram.Clear(_FILE_AND_LINE_);
		}
		else if (histogram.Size()>=2 && histogram.Peek().time < timeClipStart)
		{
			StatisticsHistory::TimeAndValue tav;

			do
			{
				tav = histogram.Pop();

				if (histogram.Peek().time == timeClipStart)
				{
					break;
				}
				else if (histogram.Peek().time > timeClipStart)
				{
					StatisticsHistory::TimeAndValue tav2;
					tav2.val = StatisticsHistory::TimeAndValueQueue::Interpolate(tav, histogram.Peek(), timeClipStart);
					tav2.time=timeClipStart;
					histogram.PushAtHead(tav2, 0, _FILE_AND_LINE_);
					break;
				}
			} while (histogram.Size()>=2);
		}
	}

	if ( timeClipEnd!=0 && histogram.Size()>=1)
	{
		timeClipEnd = histogram.PeekTail().time-timeClipEnd;
		if (histogram.Peek().time > timeClipEnd)
		{
			histogram.Clear(_FILE_AND_LINE_);
		}
		else if (histogram.Size()>=2 && histogram.PeekTail().time > timeClipEnd)
		{
			StatisticsHistory::TimeAndValue tav;

			do
			{
				tav = histogram.PopTail();

				if (histogram.PeekTail().time == timeClipEnd)
				{
					break;
				}
				else if (histogram.PeekTail().time < timeClipEnd)
				{
					StatisticsHistory::TimeAndValue tav2;
					tav2.val = StatisticsHistory::TimeAndValueQueue::Interpolate(tav, histogram.PeekTail(), timeClipEnd);
					tav2.time=timeClipEnd;
					histogram.Push(tav2, _FILE_AND_LINE_);
					break;
				}
			} while (histogram.Size()>=2);
		}
	}
}
Exemple #2
0
bool RPC4::CallBlocking( const char* uniqueID, RakNet::BitStream * bitStream, PacketPriority priority, PacketReliability reliability, char orderingChannel, const AddressOrGUID systemIdentifier, RakNet::BitStream *returnData )
{
	RakNet::BitStream out;
	out.Write((MessageID) ID_RPC_PLUGIN);
	out.Write((MessageID) ID_RPC4_CALL);
	out.WriteCompressed(uniqueID);
	out.Write(true); // Blocking
	if (bitStream)
	{
		bitStream->ResetReadPointer();
        out.AlignWriteToByteBoundary();
		out.Write(bitStream);
	}
	RakAssert(returnData);
	RakAssert(rakPeerInterface);
	ConnectionState cs;
	cs = rakPeerInterface->GetConnectionState(systemIdentifier);
	if (cs!=IS_CONNECTED && cs!=IS_LOOPBACK)
		return false;

	SendUnified(&out,priority,reliability,orderingChannel,systemIdentifier,false);

	returnData->Reset();
	blockingReturnValue.Reset();
	gotBlockingReturnValue=false;
	Packet *packet;
	DataStructures::Queue<Packet*> packetQueue;
	while (gotBlockingReturnValue==false)
	{
		// TODO - block, filter until gotBlockingReturnValue==true or ID_CONNECTION_LOST or ID_DISCONNECTION_NOTIFICXATION or ID_RPC_REMOTE_ERROR/RPC_ERROR_FUNCTION_NOT_REGISTERED
		RakSleep(30);

		packet=rakPeerInterface->Receive();

		if (packet)
		{
			if (
				(packet->data[0]==ID_CONNECTION_LOST || packet->data[0]==ID_DISCONNECTION_NOTIFICATION) &&
				((systemIdentifier.rakNetGuid!=UNASSIGNED_RAKNET_GUID && packet->guid==systemIdentifier.rakNetGuid) ||
				(systemIdentifier.systemAddress!=UNASSIGNED_SYSTEM_ADDRESS && packet->systemAddress==systemIdentifier.systemAddress))
				)
			{
				// Push back to head in reverse order
				rakPeerInterface->PushBackPacket(packet,true);
				while (packetQueue.Size())
					rakPeerInterface->PushBackPacket(packetQueue.Pop(),true);
				return false;
			}
			else if (packet->data[0]==ID_RPC_REMOTE_ERROR && packet->data[1]==RPC_ERROR_FUNCTION_NOT_REGISTERED)
			{
				RakNet::RakString functionName;
				RakNet::BitStream bsIn(packet->data,packet->length,false);
				bsIn.IgnoreBytes(2);
				bsIn.Read(functionName);
				if (functionName==uniqueID)
				{
					// Push back to head in reverse order
					rakPeerInterface->PushBackPacket(packet,true);
					while (packetQueue.Size())
						rakPeerInterface->PushBackPacket(packetQueue.Pop(),true);
					return false;
				}
				else
				{
					packetQueue.PushAtHead(packet,0,_FILE_AND_LINE_);
				}
			}
			else
			{
				packetQueue.PushAtHead(packet,0,_FILE_AND_LINE_);
			}
		}
	}

	returnData->Read(blockingReturnValue);
	return true;
}