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:
Josh Holtrop 2009-02-11 04:27:44 +00:00
parent 236cbc7db0
commit 8b9b6332cc
2 changed files with 64 additions and 38 deletions

View File

@ -31,12 +31,20 @@ class Node
{
public:
Node();
~Node();
int type;
double * the_double;
Material * the_Material;
Shape * the_Shape;
Vector * the_Vector;
refptr<double> the_double;
refptr<Material> the_Material;
refptr<Node> the_Node;
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;
@ -96,8 +104,8 @@ static Scene * g_scene;
%%
scene: /* empty */
| scene_spec { printf("Saw a scene\n"); }
scene: SCENE LCURLY scene_items RCURLY {
}
;
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_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 */
@ -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 = new Plane((*($3->the_Vector))[0],
(*($3->the_Vector))[1],
@ -193,18 +233,20 @@ plane: PLANE LPAREN vector COMMA number RPAREN LCURLY plane_items RCURLY {
}
;
plane_items: shape_items
;
scene_spec: SCENE LCURLY scene_items RCURLY
plane_items: shape_items { $$ = $1; }
;
scene_items: /* empty */
| scene_item scene_items
| scene_item scene_items {
$$ = new Node();
$$->the_Node = $1;
$$->the_tail = $2;
}
;
scene_item: camera { $$ = $1; }
| shape { $$ = $1; }
scene_item: camera { $$ = $1; $$->type = Node_Camera; }
| shape { $$ = $1; $$->type = Node_Shape; }
| options { $$ = $1; $$->type = Node_Options; }
;
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
@ -237,9 +279,9 @@ union: UNION LCURLY boolean_items RCURLY
vector: LESS number COMMA number COMMA number GREATER {
Vector * ptr = new Vector();
(*ptr)[0] = * (double *) $2->the_double;
(*ptr)[1] = * (double *) $4->the_double;
(*ptr)[2] = * (double *) $6->the_double;
(*ptr)[0] = * $2->the_double;
(*ptr)[1] = * $4->the_double;
(*ptr)[2] = * $6->the_double;
$$ = new Node();
$$->the_Vector = ptr;
}
@ -262,20 +304,4 @@ int parse(Scene * scene, const char * fileName)
Node::Node()
{
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;
}

View File

@ -16,7 +16,7 @@ class refptr
~refptr<T>();
T & operator*() const;
T * operator->() const;
T * getPtr() const { return m_ptr; }
bool isNull() const { return m_ptr == NULL; }
private:
void cloneFrom(const refptr<T> & orig);