Esempio n. 1
0
void gxViewElement::Validate()
{
    // Keep whether I was invalid before validating the children.
    bool iWasInvalid = IsInvalid();
    
    // Mark me as valid - notice the comment below. If MarkValid() would come
    // after the validation of the descendants, it would override them possibly
    // setting this view element to invalid.
    MarkValid();
    
    
    Iterator iChildren( GetChildren() );
    
    // Ask all children to validate themselves in case they are invalid.
    // Notice that validate on descendants may trigger invalidation and will
    // mark this view element as invalid again.
    for ( iChildren.First(); iChildren.Current(); iChildren.Next() )
    {
        if ( iChildren.Current()->IsntValid() )
            iChildren.Current()->Validate();
    }

    // If I was invalid before validating the descendants, and if I'm not
    // invalid now (because my descendants have marked me as such) - validate
    // me and perform the layout. (If I am invalid now, then the next validation
    // event will lead to my validation.
    if ( iWasInvalid && IsntInvalid() )
    {
        DoValidate();
        Layout();
    }
}
Esempio n. 2
0
int ServerSocket::Listen(int backlog) {
    if (IsInvalid()) return -2;
    if (listen(my_socket, backlog) == SOCKET_ERROR) {
        error_code = ErrorCode::LISTEN_ERROR;
        return -1;
    }
    return 0;
}
Esempio n. 3
0
void Socket::ThrowIfInvalid(const char* message) const
{
	if (IsInvalid())
	{
		const DWORD error = WSAGetLastError();
		std::stringstream stream;
		stream << message;
		stream << "; WSAGetLastError() = " << error;
		std::string st = stream.str();
		throw std::runtime_error(st);
	}
}
Esempio n. 4
0
int ServerSocket::Bind(std::string ip_address, int port) {
    if (IsInvalid()) return -2;
    memset(&my_address, 0, sizeof(my_address));
    my_address.sin_family = AF_INET;
    my_address.sin_port = htons(port);
    my_address.sin_addr.s_addr = htonl(INADDR_ANY);

    if (bind(my_socket, (struct sockaddr*)&my_address, sizeof(my_address)) == -1) {
        error_code = ErrorCode::BIND_ERROR;
        return -1;
    }
    return 0;
}
Esempio n. 5
0
void gxViewElement::Invalidate()
{
    // No point invalidating if I'm already invalid.
    if ( IsInvalid() )
        return;
    
    MarkInvalid();
    
    if ( GetParent() != NULL )
    {
        // Invalidate further up the hierarchy tree.
        GetParent()->InvalidateUp( this );
    }

    InvalidateDown();
}
Esempio n. 6
0
VisualSystem::VisualAction VisualSystem::GetBestVisualActionWithViewWidth(ViewWidth view_width, bool force)
{
	if (force || GetSenseBallCycle() >= NewSightComeCycle(view_width)) {
		AngleDeg max_turn_ang = mCanTurn? mpSelfState->GetMaxTurnAngle(): 0.0;
		AngleDeg half_view_angle = sight::ViewAngle(view_width) * 0.5;
		AngleDeg neck_left_most = ServerParam::instance().minNeckAngle() - max_turn_ang; //脖子可以到达的极限角度(相对于当前身体正前方而言)
		AngleDeg neck_right_most = ServerParam::instance().maxNeckAngle() + max_turn_ang;
		AngleDeg left_most = neck_left_most - half_view_angle;
		AngleDeg right_most = neck_right_most + half_view_angle;

		VisualAction best_visual_action = mVisualRing.GetBestVisualAction(left_most, right_most, half_view_angle * 2.0);

		best_visual_action.mScore /= NewSightWaitCycle(view_width);

		Assert(!IsInvalid(best_visual_action.mScore));

		return best_visual_action;
	}
	else {
		return VisualAction();
	}
}
Esempio n. 7
0
 constexpr
 static bool IsWater(short h) {
   return h <= TERRAIN_WATER_THRESHOLD && !IsInvalid(h);
 }
Esempio n. 8
0
Move Notation::value(const Board & board, ColorType side, InputFormat format, const string &image) 
{
    int rank = 0;
    int file = 0;

    PieceType piece = Empty;
    PieceType promotion = Empty;
    Square dest = InvalidSquare, start = InvalidSquare;
    int capture = 0;

    stringstream s(image);
    string::const_iterator it = image.begin();
    int i = 0;
    while (it != image.end() && isspace(*it)) {
        it++;
        i++;
    }
    if (it == image.end() || !isalpha(*it)) return NullMove;
    string img(image,i); // string w/o leading spaces
    ASSERT(img.length());
    it = img.begin();
    if (*it == 'O' || *it == '0') {
       // castling, we presume
       return parseCastling(board, side, img);
    } else if (format == WB_IN) {
       if (img.length() < 4) return NullMove;
       Square start = SquareValue(img.substr(0,2));
       if (!OnBoard(start)) return NullMove;
       Square dest = SquareValue(img.substr(2,2));
       if (!OnBoard(dest)) return NullMove;
       PieceType promotion = Empty;
       if (img.length() > 4) {
          promotion = PieceCharValue(toupper(img[4]));
       }
       return CreateMove(board,start,dest,promotion);
    }
    int have_start = 0;
    if (isupper(*it)) {
       piece = PieceCharValue(*it);
       it++;
    }
    else {
       piece = Pawn;
       if ((it+1) != img.end()) {
          char next = *it;
          file = next-'a'+1;
          if (file < 1 || file > 8) return NullMove;
          char next2 = *(it+1);
          if (next2 == 'x' || is_file(next2)) {
             // allow "dc4" as in Informant, instead of dxc4
             it++;
             capture = 1;
          }
          else if (isdigit(next2) && img.length()>2) {
             char next3 = *(it+2);
             if ((next3 == 'x' || next3 == '-') && img.length()>=5) {
                // long algebraic notation
                have_start++;
                start = SquareValue(next,next2);
                if (start == InvalidSquare) return NullMove;
                it+=3; // point to dest
                piece = TypeOfPiece(board[start]);
             }
          }
       }
    }
    if (piece == Empty) {
       return NullMove;
    }
    if (piece != Pawn && !have_start && it != img.end()) {
       char next = *it;
       char next2 = '\0';
       if (it + 1 != img.end()) next2 = *(it+1);
       if (is_file(next) && isdigit(next2) && img.length()>=5) {
          // long algebraic notation, or a SAN move like Qd1d3
          start = SquareValue(next,next2);
          if (IsInvalid(start)) return NullMove;
          it+=2;
          have_start++;
       }
       // also look for disambiguating rank, e.g. '2' in "N2e4".
       else if (isdigit(next)) {
          rank = next - '0';
          if (rank < 1 || rank > 8) return NullMove;
          it++;
       }
       else if (is_file(next) && isalpha(next2)) {
          // disamiguating rank, e.g. "Rfd1"
          file = next - 'a' + 1;
          if (file < 1 || file > 8) return NullMove;
          it++;
       }
    }

    if (it != img.end() && *it == 'x') {
       capture = 1;
       it++;
    }
    if (it != img.end() && (it+1) != img.end()) {
       // remainder of move should be a square identifier, e.g. "g7"
       dest = SquareValue(*it,*(it+1));
       it += 2;
    }
    if (IsInvalid(dest)) {
       return NullMove;
    }
    if (it != img.end() && *it == '=') {
       it++;
       if (it == img.end()) {
          return NullMove;
       } else {
          promotion = PieceCharValue(*it);
          if (piece != Pawn || promotion == Empty)
             return NullMove;
          it++;
       }
    }
    else if (piece == Pawn && it != img.end() && isupper(*it)) {
       // Quite a few "PGN" files have a8Q instead of a8=Q.
       promotion = PieceCharValue(*it);
       if (promotion == Empty || Rank(dest,side) != 8)
          return NullMove;
    } else if (piece == Pawn && Rank(dest,side) == 8) {
       // promotion but no piece specified, treat as error
       return NullMove;
    }

    // Informant does not use "x" for captures.  Assume that if the destination
    // is occupied, this is a capture move.
    if (board[dest] != EmptyPiece) {
       capture = 1;
    }
    // Do a sanity check on capture moves:
    if (capture && !IsEmptyPiece(board[dest]) && PieceColor(board[dest]) == board.sideToMove()) {
       return NullMove;
    }

    // Ok, now we need to figure out where the start square is. For pawn
    // moves this is implicit.

    int dups = 0;

    if (!have_start) {
       if (capture && piece == Pawn && IsEmptyPiece(board[dest]) &&
           Rank(dest,board.sideToMove()) != 8) {
          // en passant capture, special case
          int start_rank = (board.sideToMove() == White) ?
             Rank(dest,White) - 1 :
             Rank(dest,White) + 1;

          start = MakeSquare(file, start_rank, White);
          dups = 1;
       }
       else if (piece == Pawn && board[dest] == EmptyPiece) {
          start = MakeSquare(file,Rank(dest,board.sideToMove())-1,board.sideToMove());
          if (board[start] == EmptyPiece && Rank(dest,board.sideToMove())==4) {
             start = MakeSquare(file,Rank(dest,board.sideToMove())-2,board.sideToMove());
          }
          if (board[start] == EmptyPiece) return NullMove;
          dups = 1;
       }
       else {
          Bitboard attacks = board.calcAttacks(dest,side);
          Square maybe;
          while (attacks.iterate(maybe)) {
             if (TypeOfPiece(board[maybe]) == piece &&
                 PieceColor(board[maybe]) == board.sideToMove()) {
                if (file && File(maybe) != file)
                   continue;
                if (rank && Rank(maybe,White) != rank)
                   continue;
                if (PieceColor(board[maybe]) == board.sideToMove()) {
                   // Possible move to this square.  Make sure it is legal.
                   Board board_copy(board);
                   Move emove = CreateMove(board,maybe,dest,
                                           promotion);
                   board_copy.doMove(emove);
                   if (!board_copy.anyAttacks(
                          board_copy.kingSquare(board_copy.oppositeSide()),
                          board_copy.sideToMove())) {
                      ++dups;
                      start = maybe;
                   }
                }
             }
          }
       }
    }
    if (dups == 1 || have_start) {
       if (start == InvalidSquare || board[start] == EmptyPiece)
          return NullMove;
       else
          return CreateMove(board, start, dest, promotion);
    }
    else                                           // ambiguous move
       return NullMove;
}
Esempio n. 9
0
		void AddRef() { if (!IsInvalid()) { ++m_Ref; } }
Esempio n. 10
0
		void Release() { if (m_Ref > 0) { --m_Ref; } if (IsInvalid()) { Dispose(); } }
Esempio n. 11
0
bool COBB::IsEmpty() const
{
  return IsInvalid(m_vCenter.x());
}
Esempio n. 12
0
bool XMLMsgGatherer::IsRight() const
{
	return !IsInvalid();
}
Esempio n. 13
0
bool CAABB::IsEmpty() const
{
  return IsInvalid(m_vMin.x());
}
Esempio n. 14
0
bool CSphere::IsEmpty() const
{
  return IsInvalid(m_nRadius);
}
Esempio n. 15
0
bool CPoint3D::IsEmpty() const
{
  return IsInvalid(m_vPoint.x());
}
Esempio n. 16
0
bool CPlane::IsEmpty() const
{
  return IsInvalid(m_vPlane.x());
}
Esempio n. 17
0
bool CLine3D::IsEmpty() const
{
  return IsInvalid(m_vPoints[0].x());
}