QString QGraphicsSceneBspTree::debug(int index) const
{
    const Node *node = &nodes.at(index);

    QString tmp;
    if (node->type == Node::Leaf) {
        QRectF rect = rectForIndex(index);
        if (!leaves[node->leafIndex].isEmpty()) {
            tmp += QString::fromLatin1("[%1, %2, %3, %4] contains %5 items\n")
                   .arg(rect.left()).arg(rect.top())
                   .arg(rect.width()).arg(rect.height())
                   .arg(leaves[node->leafIndex].size());
        }
    } else {
        if (node->type == Node::Horizontal) {
            tmp += debug(firstChildIndex(index));
            tmp += debug(firstChildIndex(index) + 1);
        } else {
            tmp += debug(firstChildIndex(index));
            tmp += debug(firstChildIndex(index) + 1);
        }
    }

    return tmp;
}
Exemple #2
0
void QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor *visitor, const QRectF &rect, int index)
{
    if (nodes.isEmpty())
        return;

    const Node &node = nodes.at(index);
    int childIndex = firstChildIndex(index);

    switch (node.type) {
    case Node::Leaf: {
        visitor->visit(&leaves[node.leafIndex]);
        break;
    }
    case Node::Vertical:
        if (rect.left() < node.offset) {
            climbTree(visitor, rect, childIndex);
            if (rect.right() >= node.offset)
                climbTree(visitor, rect, childIndex + 1);
        } else {
            climbTree(visitor, rect, childIndex + 1);
        }
        break;
    case Node::Horizontal:
        int childIndex = firstChildIndex(index);
        if (rect.top() < node.offset) {
            climbTree(visitor, rect, childIndex);
            if (rect.bottom() >= node.offset)
                climbTree(visitor, rect, childIndex + 1);
        } else {
            climbTree(visitor, rect, childIndex + 1);
        }
    }
}
Exemple #3
0
    void BTSequence::childReturned(BTNode const *const node, BTNodeState state)
    {
        // child
        switch(state)
        {
            case BTNodeState::SUCCESS:
                switchToNextChild(node);

                // back to first child -> overall success
                if(firstChildIndex() == mCurrentChildNodeIndex)
                {
                    mState = BTNodeState::SUCCESS;
                }
                else
                {
                    mState = BTNodeState::SKIPT_TO;
                }

                break;

            case BTNodeState::FAILURE:
                mCurrentChildNodeIndex = firstChildIndex();
                mState = BTNodeState::FAILURE;
                break;

            default:
                Debug::error(STEEL_METH_INTRO, "child returned state ", state).endl();
                break;
        }
    }
Exemple #4
0
void QBspTree::init(const QRect &area, int depth, NodeType type, int index)
{
    Node::Type t = Node::None; // t should never have this value
    if (type == Node::Both) // if both planes are specified, use 2d bsp
        t = (depth & 1) ? Node::HorizontalPlane : Node::VerticalPlane;
    else
        t = type;
    QPoint center = area.center();
    nodes[index].pos = (t == Node::VerticalPlane ? center.x() : center.y());
    nodes[index].type = t;

    QRect front = area;
    QRect back = area;

    if (t == Node::VerticalPlane) {
        front.setLeft(center.x());
        back.setRight(center.x() - 1); // front includes the center
    } else { // t == Node::HorizontalPlane
        front.setTop(center.y());
        back.setBottom(center.y() - 1);
    }

    int idx = firstChildIndex(index);
    if (--depth) {
        init(back, depth, type, idx);
        init(front, depth, type, idx + 1);
    }
}
Exemple #5
0
void QGraphicsSceneBspTree::climbTree(QGraphicsSceneBspTreeVisitor *visitor, const QPointF &pos, int index)
{
    if (nodes.isEmpty())
        return;

    const Node &node = nodes.at(index);
    int childIndex = firstChildIndex(index);

    switch (node.type) {
    case Node::Leaf: {
        visitor->visit(&leaves[node.leafIndex]);
        break;
    }
    case Node::Vertical:
        if (pos.x() < node.offset) {
            climbTree(visitor, pos, childIndex);
        } else {
            climbTree(visitor, pos, childIndex + 1);
        }
        break;
    case Node::Horizontal:
        if (pos.y() < node.offset) {
            climbTree(visitor, pos, childIndex);
        } else {
            climbTree(visitor, pos, childIndex + 1);
        }
        break;
    }
}
void iterationCode(int reg, parseTree ast,FILE *fp)
{
	if (ast->name == 87){
		Label = Label + 2;
		fprintf(fp, "Label %d:\n", Label - 1);

		int k;
		k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;

		int n = firstChildIndex(ast->children[l]);
		int o = n;
		n++;
		while (ast->children[l]->children[n] == NULL & n < 50)
			n++;
		
		expressionCode(reg, ast->children[l]->children[o], fp);
		expressionCode(reg + 1, ast->children[l]->children[n], fp);
		fprintf(fp, "CMP R%d, R%d\n", reg, reg + 1);

		if (ast->children[l]->name==93)			
			fprintf(fp, "SETNE R%d\n", reg);
		else if (ast->children[l]->name == 94)
			fprintf(fp, "SETE R%d\n", reg);
		else if (ast->children[l]->name == 95)
			fprintf(fp, "SETGE R%d\n", reg);
		else if (ast->children[l]->name == 96)
			fprintf(fp, "SETLE R%d\n", reg);
		else if (ast->children[l]->name == 67)
			fprintf(fp, "SETG R%d\n", reg);
		else if (ast->children[l]->name == 68)
			fprintf(fp, "SETL R%d\n", reg);


		fprintf(fp, "CMP R%d, 0\n", reg);
		fprintf(fp, "JNE Label %d\n", Label);

		//code for compound statement of ast->children[k]
		compoundCode(reg, ast->children[k], fp);
		fprintf(fp, "JMP Label %d", Label - 1);
		fprintf(fp, "Label %d:\n", Label);
	}
}
Exemple #7
0
    BTStateIndex BTSequence::switchToNextChild(BTNode const *const child)
    {
        mCurrentChildNodeIndex = child->token().end;

        if(mCurrentChildNodeIndex == mToken.end)
            mCurrentChildNodeIndex = firstChildIndex();

        return mCurrentChildNodeIndex;
    }
Exemple #8
0
    bool BTSequence::parseNodeContent(Json::Value &root)
    {
        if(root.isMember(MAX_LOOPS_ATTRIBUTE))
        {
            mMaxLoops = JsonUtils::asUnsignedLong(root[MAX_LOOPS_ATTRIBUTE], 0);
            mNLoops = 0;
            mCurrentChildNodeIndex = firstChildIndex();
            mState = BTNodeState::SKIPT_TO;
        }

        return true;
    }
Exemple #9
0
bool WContainerWidget::wasEmpty() const
{
  /*
   * First case: on IE6, a popup widget has a shim child.
   * Second case: WGroupBox always has a legend
   */
  if (isPopup() || firstChildIndex() > 0)
    return false;
  else
    return ((transientImpl_ ? transientImpl_->addedChildren_.size() : 0)
	    == children_->size());
}
void assignmentCode(int reg, parseTree ast,FILE * fp)
{
	if (ast->name == 82)
	{
		int k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;
		expressionCode(reg, ast->children[k], fp);
		fprintf(fp, "MOV %s,R%d\n", ast->children[l]->info.lexeme, reg);
	}

}
Exemple #11
0
void WContainerWidget::updateDomChildren(DomElement& parent, WApplication *app)
{
  if (!app->session()->renderer().preLearning() && !layout_) {
    if (parent.mode() == DomElement::ModeUpdate)
      parent.setWasEmpty(wasEmpty());

    if (transientImpl_) {
      std::vector<int> orderedInserts;
      std::vector<WWidget *>& ac = transientImpl_->addedChildren_;

      for (unsigned i = 0; i < ac.size(); ++i)
	orderedInserts.push_back(Utils::indexOf(*children_, ac[i]));

      Utils::sort(orderedInserts);

      int addedCount = transientImpl_->addedChildren_.size();
      int totalCount = children_->size();
      int insertCount = 0;
      for (unsigned i = 0; i < orderedInserts.size(); ++i) {
	int pos = orderedInserts[i];
	
	DomElement *c = (*children_)[pos]->createSDomElement(app);

	if (pos + (addedCount - insertCount) == totalCount)
	  parent.addChild(c);
	else
	  parent.insertChildAt(c, pos + firstChildIndex());

	++insertCount;
      }

      transientImpl_->addedChildren_.clear();
    }
  }

#ifndef WT_NO_LAYOUT
  if (flags_.test(BIT_LAYOUT_NEEDS_UPDATE)) {
    if (layout_)
      layoutImpl()->updateDom(parent);

    flags_.reset(BIT_LAYOUT_NEEDS_UPDATE);
  }
#endif // WT_NO_LAYOUT
}
void QGraphicsSceneBspTree::initialize(const QRectF &rect, int depth, int index)
{
    Node *node = &nodes[index];
    if (index == 0) {
        node->type = Node::Horizontal;
        node->offset = rect.center().x();
    }

    if (depth) {
        Node::Type type;
        QRectF rect1, rect2;
        qreal offset1, offset2;

        if (node->type == Node::Horizontal) {
            type = Node::Vertical;
            rect1.setRect(rect.left(), rect.top(), rect.width(), rect.height() / 2);
            rect2.setRect(rect1.left(), rect1.bottom(), rect1.width(), rect.height() - rect1.height());
            offset1 = rect1.center().x();
            offset2 = rect2.center().x();
        } else {
            type = Node::Horizontal;
            rect1.setRect(rect.left(), rect.top(), rect.width() / 2, rect.height());
            rect2.setRect(rect1.right(), rect1.top(), rect.width() - rect1.width(), rect1.height());
            offset1 = rect1.center().y();
            offset2 = rect2.center().y();
        }

        int childIndex = firstChildIndex(index);

        Node *child = &nodes[childIndex];
        child->offset = offset1;
        child->type = type;

        child = &nodes[childIndex + 1];
        child->offset = offset2;
        child->type = type;

        initialize(rect1, depth - 1, childIndex);
        initialize(rect2, depth - 1, childIndex + 1);
    } else {
        node->type = Node::Leaf;
        node->leafIndex = leafCnt++;
    }
}
Exemple #13
0
void WContainerWidget::getDomChanges(std::vector<DomElement *>& result,
				     WApplication *app)
{
  DomElement *e = DomElement::getForUpdate(this, domElementType());

#ifndef WT_NO_LAYOUT
  if (!app->session()->renderer().preLearning()) {
    if (flags_.test(BIT_LAYOUT_NEEDS_RERENDER)) {
      e->removeAllChildren(firstChildIndex());
      createDomChildren(*e, app);

      flags_.reset(BIT_LAYOUT_NEEDS_RERENDER);
      flags_.reset(BIT_LAYOUT_NEEDS_UPDATE);
    }
  }
#endif // WT_NO_LAYOUT

  updateDomChildren(*e, app);

  updateDom(*e, false);

  result.push_back(e);
}
Exemple #14
0
void QBspTree::climbTree(const QRect &area, callback *function, QBspTreeData data, int index)
{
    if (index >= nodes.count()) { // the index points to a leaf
        Q_ASSERT(!nodes.isEmpty());
        function(leaf(index - nodes.count()), area, visited, data);
        return;
    }

    Node::Type t = (Node::Type) nodes.at(index).type;

    int pos = nodes.at(index).pos;
    int idx = firstChildIndex(index);
    if (t == Node::VerticalPlane) {
        if (area.left() < pos)
            climbTree(area, function, data, idx); // back
        if (area.right() >= pos)
            climbTree(area, function, data, idx + 1); // front
    } else {
        if (area.top() < pos)
            climbTree(area, function, data, idx); // back
        if (area.bottom() >= pos)
            climbTree(area, function, data, idx + 1); // front
    }
}
void selectionCode(int reg, parseTree ast,FILE * fp)
{
	if (ast->name == 85)
	{
		int num = ast->childrenNumber;
		int k;
		k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;
		int m = k;

		int n = firstChildIndex(ast->children[l]);
		int o = n;
		n++;
		while (ast->children[l]->children[n] == NULL & n < 50)
			n++;
		Label++;

		expressionCode(reg, ast->children[l]->children[o], fp);
		expressionCode(reg + 1, ast->children[l]->children[n], fp);
		fprintf(fp, "CMP R%d, R%d\n",reg,reg+1);

		if (ast->children[l]->name == 93)
			fprintf(fp, "SETNE R%d\n", reg);
		else if (ast->children[l]->name == 94)
			fprintf(fp, "SETE R%d\n", reg);
		else if (ast->children[l]->name == 95)
			fprintf(fp, "SETGE R%d\n", reg);
		else if (ast->children[l]->name == 96)
			fprintf(fp, "SETLE R%d\n", reg);
		else if (ast->children[l]->name == 67)
			fprintf(fp, "SETG R%d\n", reg);
		else if (ast->children[l]->name == 68)
			fprintf(fp, "SETL R%d\n", reg);


		fprintf(fp, "CMP R%d, 0\n",reg);
		fprintf(fp, "JNE Label %d\n",Label);
		
		if (num == 2)
		{
		//generate code for compound statement ast->children[m]
			compoundCode(reg, ast->children[m], fp);
			fprintf(fp, "Label %d:\n", Label);		
		}
		else
		{
			Label++;
			k++;
			while (ast->children[k] == NULL && k < 50)
				k++;

			//generate code for compound statement ast->children[m]
			compoundCode(reg, ast->children[m], fp);
			fprintf(fp, "JMP Label %d\n", Label);
			fprintf(fp, "Label %d:\n", Label-1);
			//generate code for compound statement ast->children[k]
			compoundCode(reg, ast->children[k], fp);
			fprintf(fp, "Label %d:\n", Label);
		}
	}
}
Exemple #16
0
 BTSequence::BTSequence(const Steel::BTShapeToken &token): BTNode(token),
     mCurrentChildNodeIndex(0), mNLoops(0), mMaxLoops(0)
 {
     mCurrentChildNodeIndex = firstChildIndex();
     mState = BTNodeState::SKIPT_TO;
 }
void expressionCode(int reg, parseTree ast,FILE * fp)
{
	//arithmetic
	if ((ast->name >= 97 && ast->name <= 102) || (ast->name >= 90 && ast->name <= 92))
	{
		int k;
		k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;

		expressionCode(reg, ast->children[l],fp);
		expressionCode(reg + 1, ast->children[k],fp);
		
		generateArithmetic(ast->children[l]->type,ast->name, reg, reg + 1,fp);
	}
	//relational
	else if (ast->name >= 93 && ast->name <= 96 || (ast->name >= 67 && ast->name <= 68))
	{
		int k;
		k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;

		expressionCode(reg, ast->children[l],fp);
		expressionCode(reg + 1, ast->children[k],fp);

		generateRelational(ast->name, reg, reg + 1,fp);
	}
	//logical
	else if (ast->name == 88 || ast->name == 89)
	{
		int k;
		k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;

		expressionCode(reg, ast->children[l],fp);
		expressionCode(reg + 1, ast->children[k],fp);

		generateLogical(ast->name, reg, reg + 1,fp);
	}
	else if (ast->name == 64)
	{
		fprintf(fp, "MOV R%d, %s\n", reg , ast->info.lexeme);
	}
	else if (ast->name == 83)
	{
		int k = firstChildIndex(ast);
		int l = k;
		k++;
		while (ast->children[k] == NULL && k < 50)
			k++;

		fprintf(fp, "LEA R%d, %s\n", reg + 1, ast->children[l]->info.lexeme);
		if (strcmp(ast->children[k]->info.lexeme, "first") == 0)
			{
				fprintf(fp, "MOV R%d, [R%d]\n", reg, reg+1);
			}
			
		else
			{
				fprintf(fp, "MOV R%d, [R%d+32]\n", reg, reg + 1);
			}
			
	}
	else if (ast->name >= 103 && ast->name <= 107)
	{
		fprintf(fp, "MOV R%d, %s\n", reg, ast->info.lexeme);
	}
	else{
		int k = 0;
		for (k = 0; k < 50; k++)
			if (ast->children[k] != NULL)
				expressionCode(reg,ast->children[k],fp);
	}
}