added Scene::processForNode() to process for nodes
git-svn-id: svn://anubis/fart/branches/scene-file-scripting@332 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
71e40b0277
commit
01a713af98
@ -255,7 +255,7 @@ vector<ShapeRef> Scene::processTransformBlock(refptr<Node> node)
|
|||||||
|
|
||||||
vector<ShapeRef> Scene::processGeneralItems(refptr<Node> node)
|
vector<ShapeRef> Scene::processGeneralItems(refptr<Node> node)
|
||||||
{
|
{
|
||||||
vector<ShapeRef> shapes;
|
vector<ShapeRef> shapes, incoming;
|
||||||
|
|
||||||
for (Node_Iterator it = node->getChildren().begin();
|
for (Node_Iterator it = node->getChildren().begin();
|
||||||
it != node->getChildren().end();
|
it != node->getChildren().end();
|
||||||
@ -263,15 +263,11 @@ vector<ShapeRef> Scene::processGeneralItems(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
if ((*it)->isTransformBlock())
|
if ((*it)->isTransformBlock())
|
||||||
{
|
{
|
||||||
vector<ShapeRef> in = processTransformBlock(*it);
|
incoming = processTransformBlock(*it);
|
||||||
for (int i = 0, sz = in.size(); i < sz; i++)
|
|
||||||
{
|
|
||||||
shapes.push_back(in[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if ( typeid(*node) == typeid(MaterialDefinitionNode) )
|
else if ( typeid(**it) == typeid(MaterialDefinitionNode) )
|
||||||
{
|
{
|
||||||
processMaterialDefinition(node);
|
processMaterialDefinition(*it);
|
||||||
}
|
}
|
||||||
else if ( typeid(**it) == typeid(ShapeDefinitionNode) )
|
else if ( typeid(**it) == typeid(ShapeDefinitionNode) )
|
||||||
{
|
{
|
||||||
@ -281,6 +277,41 @@ vector<ShapeRef> Scene::processGeneralItems(refptr<Node> node)
|
|||||||
{
|
{
|
||||||
shapes.push_back(processShape(*it));
|
shapes.push_back(processShape(*it));
|
||||||
}
|
}
|
||||||
|
else if ( typeid(**it) == typeid(ForNode) )
|
||||||
|
{
|
||||||
|
incoming = processForNode(*it);
|
||||||
|
}
|
||||||
|
while (incoming.size() > 0)
|
||||||
|
{
|
||||||
|
shapes.push_back(incoming[0]);
|
||||||
|
incoming.erase(incoming.begin());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return shapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ShapeRef> Scene::processForNode(refptr<Node> node)
|
||||||
|
{
|
||||||
|
if (!node->getNode(0).isNull())
|
||||||
|
{
|
||||||
|
node->getNode(0)->getNumber();
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<ShapeRef> shapes, incoming;
|
||||||
|
|
||||||
|
while (node->getNode(1)->getInteger() != 0)
|
||||||
|
{
|
||||||
|
incoming = processGeneralItems(node);
|
||||||
|
while (incoming.size() > 0)
|
||||||
|
{
|
||||||
|
shapes.push_back(incoming[0]);
|
||||||
|
incoming.erase(incoming.begin());
|
||||||
|
}
|
||||||
|
if (!node->getNode(2).isNull())
|
||||||
|
{
|
||||||
|
node->getNode(2)->getNumber();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return shapes;
|
return shapes;
|
||||||
|
@ -78,6 +78,7 @@ class Scene
|
|||||||
void processOptions(refptr<Node> node);
|
void processOptions(refptr<Node> node);
|
||||||
std::vector<ShapeRef> processTransformBlock(refptr<Node> node);
|
std::vector<ShapeRef> processTransformBlock(refptr<Node> node);
|
||||||
std::vector<ShapeRef> processGeneralItems(refptr<Node> node);
|
std::vector<ShapeRef> processGeneralItems(refptr<Node> node);
|
||||||
|
std::vector<ShapeRef> processForNode(refptr<Node> node);
|
||||||
void processMaterialDefinition(refptr<Node> node);
|
void processMaterialDefinition(refptr<Node> node);
|
||||||
void processShapeDefinition(refptr<Node> node);
|
void processShapeDefinition(refptr<Node> node);
|
||||||
|
|
||||||
|
@ -42,6 +42,11 @@ class Node
|
|||||||
std::cerr << "Warning: Node::getString() called!" << std::endl;
|
std::cerr << "Warning: Node::getString() called!" << std::endl;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
virtual refptr<Node> getNode(int idx)
|
||||||
|
{
|
||||||
|
std::cerr << "Warning: Node::getNode() called!" << std::endl;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool isShape() { return false; }
|
virtual bool isShape() { return false; }
|
||||||
virtual bool isMaterial() { return false; }
|
virtual bool isMaterial() { return false; }
|
||||||
@ -550,11 +555,21 @@ class ForNode : public Node
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ForNode(refptr<Node> e1, refptr<Node> e2, refptr<Node> e3)
|
ForNode(refptr<Node> e1, refptr<Node> e2, refptr<Node> e3)
|
||||||
: m_e1(e1), m_e2(e2), m_e3(e3)
|
|
||||||
{
|
{
|
||||||
|
m_nodes[0] = e1;
|
||||||
|
m_nodes[1] = e2;
|
||||||
|
m_nodes[2] = e3;
|
||||||
|
}
|
||||||
|
refptr<Node> getNode(int idx)
|
||||||
|
{
|
||||||
|
if (0 <= idx && idx <= 2)
|
||||||
|
{
|
||||||
|
return m_nodes[idx];
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
refptr<Node> m_e1, m_e2, m_e3;
|
refptr<Node> m_nodes[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -593,6 +593,10 @@ expression: term { $$ = $1; }
|
|||||||
| stmt_expression { $$ = $1; }
|
| stmt_expression { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
maybe_expression: /* empty */
|
||||||
|
| expression { $$ = $1; }
|
||||||
|
;
|
||||||
|
|
||||||
stmt_expression: assignment { $$ = $1; }
|
stmt_expression: assignment { $$ = $1; }
|
||||||
| local_assignment { $$ = $1; }
|
| local_assignment { $$ = $1; }
|
||||||
| local_decl { $$ = $1; }
|
| local_decl { $$ = $1; }
|
||||||
@ -640,7 +644,7 @@ local_decl: LOCAL VARREF {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
for: FOR LPAREN expression SEMICOLON bool_expression SEMICOLON expression RPAREN LCURLY general_items RCURLY {
|
for: FOR LPAREN maybe_expression SEMICOLON bool_expression SEMICOLON maybe_expression RPAREN LCURLY general_items RCURLY {
|
||||||
$$ = new ForNode($3, $5, $7);
|
$$ = new ForNode($3, $5, $7);
|
||||||
$$->addChildren($10);
|
$$->addChildren($10);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user