changed getPtr() to isNull() in util/refptr, filled in parser logic a lot more
git-svn-id: svn://anubis/fart/trunk@99 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
236cbc7db0
commit
8b9b6332cc
100
parser/parser.yy
100
parser/parser.yy
@ -31,12 +31,20 @@ class Node
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Node();
|
Node();
|
||||||
~Node();
|
|
||||||
int type;
|
int type;
|
||||||
double * the_double;
|
refptr<double> the_double;
|
||||||
Material * the_Material;
|
refptr<Material> the_Material;
|
||||||
Shape * the_Shape;
|
refptr<Node> the_Node;
|
||||||
Vector * the_Vector;
|
refptr<Node> the_tail;
|
||||||
|
refptr<Shape> the_Shape;
|
||||||
|
refptr<Vector> the_Vector;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum Node_Type
|
||||||
|
{
|
||||||
|
Node_Shape = 0x42001, /* don't clash with bison token namespace */
|
||||||
|
Node_Camera,
|
||||||
|
Node_Options
|
||||||
};
|
};
|
||||||
|
|
||||||
static Scene * g_scene;
|
static Scene * g_scene;
|
||||||
@ -96,9 +104,9 @@ static Scene * g_scene;
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
scene: /* empty */
|
scene: SCENE LCURLY scene_items RCURLY {
|
||||||
| scene_spec { printf("Saw a scene\n"); }
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
boolean_items: shape shape boolean_items_more
|
boolean_items: shape shape boolean_items_more
|
||||||
;
|
;
|
||||||
@ -110,10 +118,14 @@ boolean_items_more: /* empty */
|
|||||||
box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY
|
box: BOX LPAREN vector RPAREN LCURLY box_items RCURLY
|
||||||
;
|
;
|
||||||
|
|
||||||
box_items: shape_items
|
box_items: shape_items { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
camera: CAMERA LCURLY camera_items RCURLY
|
camera: CAMERA LCURLY camera_items RCURLY {
|
||||||
|
Vector default_position(0, -1, 0);
|
||||||
|
Vector default_look_at(0, 0, 0);
|
||||||
|
Vector default_up(0, 0, 1);
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
camera_items: /* empty */
|
camera_items: /* empty */
|
||||||
@ -183,6 +195,34 @@ number: DEC_NUMBER {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
options: OPTIONS LCURLY options_items RCURLY { $$ = $3; }
|
||||||
|
;
|
||||||
|
|
||||||
|
options_items: /* empty */
|
||||||
|
| options_item options_items {
|
||||||
|
$$ = new Node();
|
||||||
|
$$->the_Node = $1;
|
||||||
|
$$->the_tail = $2;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
|
options_item: WIDTH number {
|
||||||
|
$$ = new Node();
|
||||||
|
$$->type = WIDTH;
|
||||||
|
$$->the_double = $2->the_double;
|
||||||
|
}
|
||||||
|
| HEIGHT number {
|
||||||
|
$$ = new Node();
|
||||||
|
$$->type = HEIGHT;
|
||||||
|
$$->the_double = $2->the_double;
|
||||||
|
}
|
||||||
|
| MULTISAMPLE number {
|
||||||
|
$$ = new Node();
|
||||||
|
$$->type = MULTISAMPLE;
|
||||||
|
$$->the_double = $2->the_double;
|
||||||
|
}
|
||||||
|
;
|
||||||
|
|
||||||
plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY {
|
plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY {
|
||||||
Plane * plane = new Plane((*($3->the_Vector))[0],
|
Plane * plane = new Plane((*($3->the_Vector))[0],
|
||||||
(*($3->the_Vector))[1],
|
(*($3->the_Vector))[1],
|
||||||
@ -193,18 +233,20 @@ plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
plane_items: shape_items
|
plane_items: shape_items { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
scene_spec: SCENE LCURLY scene_items RCURLY
|
|
||||||
;
|
|
||||||
|
|
||||||
scene_items: /* empty */
|
scene_items: /* empty */
|
||||||
| scene_item scene_items
|
| scene_item scene_items {
|
||||||
|
$$ = new Node();
|
||||||
|
$$->the_Node = $1;
|
||||||
|
$$->the_tail = $2;
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
scene_item: camera { $$ = $1; }
|
scene_item: camera { $$ = $1; $$->type = Node_Camera; }
|
||||||
| shape { $$ = $1; }
|
| shape { $$ = $1; $$->type = Node_Shape; }
|
||||||
|
| options { $$ = $1; $$->type = Node_Options; }
|
||||||
;
|
;
|
||||||
|
|
||||||
shape: plane { $$ = $1; }
|
shape: plane { $$ = $1; }
|
||||||
@ -226,7 +268,7 @@ sphere: SPHERE LPAREN number RPAREN LCURLY sphere_items RCURLY {
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
sphere_items: shape_items
|
sphere_items: shape_items { $$ = $1; }
|
||||||
;
|
;
|
||||||
|
|
||||||
subtract: SUBTRACT LCURLY boolean_items RCURLY
|
subtract: SUBTRACT LCURLY boolean_items RCURLY
|
||||||
@ -237,9 +279,9 @@ union: UNION LCURLY boolean_items RCURLY
|
|||||||
|
|
||||||
vector: LESS number COMMA number COMMA number GREATER {
|
vector: LESS number COMMA number COMMA number GREATER {
|
||||||
Vector * ptr = new Vector();
|
Vector * ptr = new Vector();
|
||||||
(*ptr)[0] = * (double *) $2->the_double;
|
(*ptr)[0] = * $2->the_double;
|
||||||
(*ptr)[1] = * (double *) $4->the_double;
|
(*ptr)[1] = * $4->the_double;
|
||||||
(*ptr)[2] = * (double *) $6->the_double;
|
(*ptr)[2] = * $6->the_double;
|
||||||
$$ = new Node();
|
$$ = new Node();
|
||||||
$$->the_Vector = ptr;
|
$$->the_Vector = ptr;
|
||||||
}
|
}
|
||||||
@ -262,20 +304,4 @@ int parse(Scene * scene, const char * fileName)
|
|||||||
Node::Node()
|
Node::Node()
|
||||||
{
|
{
|
||||||
type = -1;
|
type = -1;
|
||||||
the_double = NULL;
|
|
||||||
the_Material = NULL;
|
|
||||||
the_Shape = NULL;
|
|
||||||
the_Vector = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node::~Node()
|
|
||||||
{
|
|
||||||
if (the_double != NULL)
|
|
||||||
delete the_double;
|
|
||||||
if (the_Material != NULL)
|
|
||||||
delete the_Material;
|
|
||||||
if (the_Shape != NULL)
|
|
||||||
delete the_Shape;
|
|
||||||
if (the_Vector != NULL)
|
|
||||||
delete the_Vector;
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@ class refptr
|
|||||||
~refptr<T>();
|
~refptr<T>();
|
||||||
T & operator*() const;
|
T & operator*() const;
|
||||||
T * operator->() const;
|
T * operator->() const;
|
||||||
T * getPtr() const { return m_ptr; }
|
bool isNull() const { return m_ptr == NULL; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void cloneFrom(const refptr<T> & orig);
|
void cloneFrom(const refptr<T> & orig);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user