/* Check if a single square is accessable. */ int CMoveMath::SquareIsBlocked(const MoveData& moveData, int xSquare, int zSquare) { //Error-check if(xSquare < 0 || zSquare < 0 || xSquare >= gs->mapx || zSquare >= gs->mapy) return true; CSolidObject* obstacle = readmap->GroundBlocked(xSquare + zSquare * gs->mapx); if(obstacle) { if(obstacle->mobility) { if(obstacle->isMoving) { return BLOCK_MOVING; } else { if(!((CUnit*)obstacle)->beingBuilt && ((CUnit*)obstacle)->commandAI->commandQue.empty()) { return BLOCK_MOBILE; } else { return BLOCK_MOBILE_BUSY; } } } else { if(IsBlocking(moveData, obstacle)) return BLOCK_STRUCTURE; } } return 0; }
BOOL CTCPSocketAsync::IsAsyncClass() const { try { //Check if we are blocking if (IsBlocking() || m_bDisabledConnect) return FALSE; else //Not blocking return TRUE; } ERROR_HANDLER_RETURN("IsAsyncClass",FALSE) }
void ConvertQueryOverlap(const PxShape* PShape, const PxRigidActor* PActor, FOverlapResult& OutOverlap, const PxFilterData& QueryFilter) { const bool bBlock = IsBlocking(PShape, QueryFilter); const FBodyInstance* BodyInst = FPhysxUserData::Get<FBodyInstance>(PActor->userData); const FDestructibleChunkInfo* ChunkInfo = FPhysxUserData::Get<FDestructibleChunkInfo>(PActor->userData); // Grab actor/component const UPrimitiveComponent* OwnerComponent = nullptr; // Try body instance if (BodyInst) { BodyInst = BodyInst->GetOriginalBodyInstance(PShape); OwnerComponent = BodyInst->OwnerComponent.Get(); // cache weak pointer object, avoid multiple derefs below. if (OwnerComponent) { OutOverlap.Actor = OwnerComponent->GetOwner(); OutOverlap.Component = BodyInst->OwnerComponent; // Copying weak pointer is faster than assigning raw pointer. OutOverlap.ItemIndex = OwnerComponent->bMultiBodyOverlap ? BodyInst->InstanceBodyIndex : INDEX_NONE; } } if (!OwnerComponent) { // Try chunk info if (ChunkInfo) { OwnerComponent = ChunkInfo->OwningComponent.Get(); // cache weak pointer object, avoid multiple derefs below. if (OwnerComponent) { OutOverlap.Actor = OwnerComponent->GetOwner(); OutOverlap.Component = ChunkInfo->OwningComponent; // Copying weak pointer is faster than assigning raw pointer. OutOverlap.ItemIndex = OwnerComponent->bMultiBodyOverlap ? UDestructibleComponent::ChunkIdxToBoneIdx(ChunkInfo->ChunkIndex) : INDEX_NONE; } } } // Other info OutOverlap.bBlockingHit = bBlock; }
BOOL CTCPSocketAsync::LocalConnect(unsigned short usSourcePort, IP aDestinationAddress, unsigned short usDestinationPort, BOOL bDisableAsync, BOOL bForceErrorEvent) { try { //Quit if not ok if (!CheckSocketValid()) return FALSE; //Set the async notification if (!bDisableAsync) { int iResult; iResult=InternalWSAAsyncSelect(WM_SOCKET_CONNECT, FD_CONNECT); if (iResult) { //Get the error code int iErrorCode; iErrorCode=GetSystemLastError(); //Report it SetLastError("Connect"); //Do we need to call event? if (bForceErrorEvent) SocketConnected(iErrorCode); //Exit return FALSE; } //Set our timeout if (m_ulTimeout && !IsBlocking()) if (!SetSystemTimeout(m_ulTimeout)) { //Report it ReportError("LocalConnect","Failed to set timer!"); //Do we need to call event? if (bForceErrorEvent) SocketConnected(GetErrorCode()); //Exit return FALSE; } } //Set to non blocking! else if (!Block()) return FALSE; //Set the flag m_bDisabledConnect=bDisableAsync; //Call the original connect BOOL bResult; bResult=CTCPSocket::Connect(usSourcePort, aDestinationAddress, usDestinationPort); //Reset the flag m_bDisabledConnect=FALSE; if (bResult) { //Call event, but only if in async if (!bDisableAsync && !IsBlocking()) //Call user, will add socket automatically return SocketConnected(0); else //Set as async return SetAsync(); } else if (GetSystemLastError()!=WSAEWOULDBLOCK || bDisableAsync || IsBlocking()) { if (m_ulTimeout) //Kill the timer KillSystemTimer(); //Get the error code int iErrorCode; iErrorCode=GetSystemLastError(); //Report it SetLastError("Connect"); //Do we need to call event? if (bForceErrorEvent && !bDisableAsync) SocketConnected(iErrorCode); //Exit return FALSE; } else return TRUE; } ERROR_HANDLER_RETURN("LocalConnect",FALSE) }
Socket::Status TcpSocket::Connect(const IpAddress& remoteAddress, unsigned short remotePort, Uint32 timeout) { // Create the internal socket if it doesn't exist Create(); // Create the remote address sockaddr_in address = priv::SocketImpl::CreateAddress(remoteAddress.ToInteger(), remotePort); if (timeout == 0) { // ----- We're not using a timeout: just try to connect ----- // Connect the socket if (connect(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) == -1) return priv::SocketImpl::GetErrorStatus(); // Connection succeeded return Done; } else { // ----- We're using a timeout: we'll need a few tricks to make it work ----- // Save the previous blocking state bool blocking = IsBlocking(); // Switch to non-blocking to enable our connection timeout if (blocking) SetBlocking(false); // Try to connect to the remote address if (connect(GetHandle(), reinterpret_cast<sockaddr*>(&address), sizeof(address)) >= 0) { // We got instantly connected! (it may no happen a lot...) return Done; } // Get the error status Status status = priv::SocketImpl::GetErrorStatus(); // If we were in non-blocking mode, return immediatly if (!blocking) return status; // Otherwise, wait until something happens to our socket (success, timeout or error) if (status == Socket::NotReady) { // Setup the selector fd_set selector; FD_ZERO(&selector); FD_SET(GetHandle(), &selector); // Setup the timeout timeval time; time.tv_sec = timeout / 1000; time.tv_usec = (timeout - time.tv_sec * 1000) * 1000; // Wait for something to write on our socket (which means that the connection request has returned) if (select(static_cast<int>(GetHandle() + 1), NULL, &selector, NULL, &time) > 0) { // At this point the connection may have been either accepted or refused. // To know whether it's a success or a failure, we must check the address of the connected peer if (GetRemoteAddress() != sf::IpAddress::None) { // Connection accepted status = Done; } else { // Connection refused status = priv::SocketImpl::GetErrorStatus(); } } else { // Failed to connect before timeout is over status = priv::SocketImpl::GetErrorStatus(); } } // Switch back to blocking mode SetBlocking(true); return status; } }
sfBool sfTcpSocket_IsBlocking(const sfTcpSocket* socket) { CSFML_CALL_RETURN(socket, IsBlocking(), sfFalse); }