Exemplo n.º 1
0
//------------------------------------------------------------------------------
// Name: getObject
//------------------------------------------------------------------------------
QJsonObject *QJsonParser::getObject() {

	QScopedPointer<QJsonObject> obj(new QJsonObject);

	char tok = peek();
	if(tok != ObjectBegin) {
		throwError(QJsonParseError::IllegalValue);
	}

	++p_;

	// handle empty object
	tok = peek();
	if(peek() == ObjectEnd) {
		++p_;
	} else {

		do {
			QPair<QString, QJsonValue> p = getPair();
			obj->values_.insert(p.first, p.second);

			tok = peek();
			++p_;

		} while(tok == ValueSeparator);
	}

	if(tok != ObjectEnd) {
		throwError(QJsonParseError::UnterminatedObject);
	}

	return obj.take();
}
Exemplo n.º 2
0
std::vector<float> getPoints(std::string& line){
  std::vector<float> points;

  size_t first=line.find("points=\"");
  size_t fillLenght=8;
  size_t second=line.find("\"",first);
  std::string spoints=line.substr(first+fillLenght,second-first-fillLenght-1);
  size_t p1=0;
  size_t p2=spoints.find(" ",0)+1;
  size_t p3=spoints.find(" ",p2)+1;
  size_t p4=spoints.find(" ",p3)+1;
  
  getPair(spoints.substr(p1,p2-p1-1),points);
  getPair(spoints.substr(p2,p3-p2-1),points);
  getPair(spoints.substr(p3,p4-p3-1),points);  
  getPair(spoints.substr(p4),points);

  return points;
}
Exemplo n.º 3
0
// Проверяем логин
int checkLogin(struct Connection *connection) {
    char *login = NULL;
    if (readNonBlock(connection->connectionfd, &login, 0) == -1) {
        fprintf(stderr, "Error: receiving login from connection %d\n", connection->connectionfd);
        return -1;
    }
    connection->pair = getPair(login);
    if (connection->pair == NULL) {
        if (sendMsg(connection->connectionfd, "Wrong login, try again\n") == -1) {
            fprintf(stderr, "Error: sending wrong login msg\n");
            return -1;
        }
        requestLogin(connection);
    } else {
        connection->auth.status = PASSWORD_REQUEST;
        requestPassword(connection);
    }
    free(login);
    return 0;
}
Exemplo n.º 4
0
 void CursesRenderer::style(int x, int y, int len, Colour fg, Colour bg, int styleMask)
 {
   int pair = getPair(fg, bg);
   styleMask |= A_COLOR;
   mvwchgat(win(), y, x, len, styleMask, pair, NULL);
 }
Exemplo n.º 5
0
 void CursesRenderer::style(Colour fg, Colour bg, int styleMask)
 {
   int pair = getPair(fg, bg);
   styleMask |= A_COLOR;
   wattr_set(win(), styleMask, pair, NULL);
 }
Exemplo n.º 6
0
bool Point::operator>=(const Point& t) const{
  return getPair() >= t.getPair();
}
Exemplo n.º 7
0
bool Point::operator<(const Point& t) const{
  return getPair() < t.getPair() ;
}
Exemplo n.º 8
0
void CollisionDetector::addCollisionsBetween(Entity* e1, Entity* e2, std::vector<CollisionEvent*>* events, float timeLeft)
{
	if (Entity::areWrapperPartners(e1, e2))
	{
		Debug::warn(std::string(__PRETTY_FUNCTION__) + ": between collision partners");
	}

	const GameRect wrapper1 = e1->getWrapper(0.f); // TODO make getWrapper more beautiful
	const GameRect wrapper2 = e2->getWrapper(0.f);

	const float posX1 = e1->getPosition().x;
	const float posY1 = e1->getPosition().y;
	const float sizeX1 = wrapper1.getSize().x;
	const float sizeY1 = wrapper1.getSize().y;

	const float posX2 = e2->getPosition().x;
	const float posY2 = e2->getPosition().y;
	const float sizeX2 = wrapper2.getSize().x;
	const float sizeY2 = wrapper2.getSize().y;

	// speed subtraction
	const float speedX = e1->getSpeed().x - e2->getSpeed().x;
	const float speedY = e1->getSpeed().y - e2->getSpeed().y;

	// getestet
	CollisionStatus xCol, yCol;
	const float right1 = wrapper1.getRight();
	const float right2 = wrapper2.getRight();

	const float left1 = wrapper1.getLeft();
	const float left2 = wrapper2.getLeft();

	const float bot1 = wrapper1.getBot();
	const float bot2 = wrapper2.getBot();

	const float top1 = wrapper1.getTop();
	const float top2 = wrapper2.getTop();

	if ((right1 > left2) && (right2 > left1)) // Wenn die Entities sich auf der xAchse schneiden
	{
		xCol = CollisionStatus::IN;
	}
	else if ((right1 == left2) || (right2 == left1)) // Wenn die Entities sich auf der xAchse berühren
	{
		xCol = CollisionStatus::BORDER;
	}
	else // sonst OUT
	{
		xCol = CollisionStatus::OUT;
	}

	if ((bot1 > top2) && (bot2 > top1))
	{
		yCol = CollisionStatus::IN;
	}
	else if ((bot1 == top2) || (bot2 == top1))
	{
		yCol = CollisionStatus::BORDER;
	}
	else
	{
		yCol = CollisionStatus::OUT;
	}

	CollisionStatus oldStatus = std::max(xCol, yCol);

	if (oldStatus < CollisionStatus::OUT)
	{
		CollisionEvent* ev = new CollisionEvent(e1, e2, timeLeft);
		addEvent(events, ev);
	}

	std::pair<std::vector<float>, std::vector<bool>> pair = getPair(posX1, posY1, sizeX1, sizeY1, speedX, speedY, posX2, posY2, sizeX2, sizeY2, timeLeft);
	std::vector<float> floats = pair.first;
	std::vector<bool> bools = pair.second;

	while (floats.size() > 0)
	{
		int index = getNextIndex(floats);
		float time = floats[index];

		if (bools[index])
		{
			if (xCol == CollisionStatus::IN)
			{
				xCol = CollisionStatus::OUT;
			}
			else if (xCol == CollisionStatus::OUT)
			{
				xCol = CollisionStatus::IN;
			}
			else
			{
				// linke entity schneller:
				if (speedX == 0) Debug::error("CollisionDetector::addCollisionsBetweenEvenRects(): logical issue here (x)");
				if ((speedX > 0) == (posX1 < posX2))
				{
					xCol = CollisionStatus::IN;
				}
				else
				{
					xCol = CollisionStatus::OUT;
				}
			}
		}
		else
		{
			if (yCol == CollisionStatus::IN)
			{
				yCol = CollisionStatus::OUT;
			}
			else if (yCol == CollisionStatus::OUT)
			{
				yCol = CollisionStatus::IN;
			}
			else
			{
				// obere entity schneller:
				if (speedY == 0) Debug::error("CollisionDetector::addCollisionsBetweenEvenRects(): logical issue here (y)");
				if ((speedY > 0) == (posY1 < posY2))
				{
					yCol = CollisionStatus::IN;
				}
				else
				{
					yCol = CollisionStatus::OUT;
				}
			}
		}

		floats.erase(floats.begin() + index);
		bools.erase(bools.begin() + index);

		if (oldStatus != std::max(xCol, yCol))
		{
			oldStatus = std::max(xCol, yCol);
			CollisionEvent* ev = new CollisionEvent(e1, e2, timeLeft-time);
			addEvent(events, ev);
		}
	}
}
Exemplo n.º 9
0
	std::pair<std::string, std::string> autoDetect()
	{
		auto cameraList = autoDetectAll();
		
		return cameraList.getPair(0);
	}