Exemplo n.º 1
0
void L1FramedTcpConnection::LengthReadCallback(concurrency::task<Result<SocketReadResult>> resultTask)
{
	auto result = resultTask.get();

	if (!result.HasSucceeded())
	{
		// TODO: propagate error

	}
	else
	{
		auto byteArray = result.GetDetail().GetBuffer();

		// if the size is sufficient for a length header
		if (byteArray.size() == 8)
		{
			struct
			{
				uint32_t signature;
				uint32_t length;
			} lengthHeader;

			memcpy(&lengthHeader, &byteArray[0], sizeof(lengthHeader));

			// if the signature is valid
			if (lengthHeader.signature == 0xDEADC0DE)
			{
				// read the expected data
				size_t readLength = lengthHeader.length + 8;

				m_socket->Read(readLength).then(std::bind(&L1FramedTcpConnection::PacketReadCallback, this, readLength, std::placeholders::_1));
			}
		}
	}
}
Exemplo n.º 2
0
//--------------------------------------------------------------------------------------
// Updates the manoeuvre. This mostly consists of processing any messages received from
// the participating entities and reacting accordingly. This can include the sending
// out of follow-up orders for entities that have completed a stage of the manoeuvre. Eventually
// the function should also check whether the goal of the manoeuvre has been achieved in 
// order to initiate termination.
// Param1: The time passed since the last update.
// Returns a behaviour status representing the state of the manoeuvre.
//--------------------------------------------------------------------------------------
BehaviourStatus GuardedFlagCapture::Update(float deltaTime)
{
	// Keep track of who has reached the target and let those defend until all have arrived
	SortOutProcessedMessages();
	ProcessMessages();

	m_timer += deltaTime;

	if(m_updateMovementTargetsInterval != 0.0f && m_timer >= m_updateMovementTargetsInterval)
	{
		UpdateMovementTargets();
		m_timer = 0.0f;
	}

	if(!IsActive() || HasFailed() || (GetNumberOfParticipants() < GetMinNumberOfParticipants()))
	{
		// The manoeuvre will fail if something failed during the initiation or if it wasn't
		// initiated at all.
		return StatusFailure;
	}else if(HasSucceeded())
	{
		return StatusSuccess;
	}

	return StatusRunning;
}
Exemplo n.º 3
0
//--------------------------------------------------------------------------------------
// Updates the manoeuvre. This mostly consists of processing any messages received from
// the participating entities and reacting accordingly. This can include the sending
// out of follow-up orders for entities that have completed a stage of the manoeuvre. Eventually
// the function should also check whether the goal of the manoeuvre has been achieved in 
// order to initiate termination.
// Param1: The time passed since the last update.
// Returns a behaviour status representing the state of the manoeuvre.
//--------------------------------------------------------------------------------------
BehaviourStatus SimpleBaseAttack::Update(float deltaTime)
{
	// Keep track of who has reached the target and let those defend until all have arrived
	SortOutProcessedMessages();
	ProcessMessages();

	if(!IsActive() || HasFailed() || (GetNumberOfParticipants() < GetMinNumberOfParticipants()))
	{
		// The manoeuvre will fail if something failed during the initiation or if it wasn't
		// initiated at all.
		return StatusFailure;
	}else if(HasSucceeded())
	{
		return StatusSuccess;
	}

	return StatusRunning;
}
Exemplo n.º 4
0
void L1FramedTcpConnection::PacketReadCallback(uint32_t expectedLength, concurrency::task<Result<SocketReadResult>> resultTask)
{
	auto result = resultTask.get();

	if (!result.HasSucceeded())
	{
		// TODO: propagate error
	}
	else
	{
		auto byteArray = result.GetDetail().GetBuffer();

		// if the size is as expected
		if (byteArray.size() == expectedLength)
		{
			// pass it on to the parser (ha!)
			m_parser->HandleIncomingMessage(byteArray);
		}

		// continue reading the stream
		m_socket->Read(8).then(std::bind(&L1FramedTcpConnection::LengthReadCallback, this, std::placeholders::_1));
	}
}