summaryrefslogtreecommitdiffstats
path: root/dimension
diff options
context:
space:
mode:
Diffstat (limited to 'dimension')
-rw-r--r--dimension/common.terminals6
-rw-r--r--dimension/grammar.epilogue58
-rw-r--r--dimension/grammar.nonterminals5
-rw-r--r--dimension/grammar.rules31
-rw-r--r--dimension/lexer.l91
-rw-r--r--dimension/parse.h14
-rw-r--r--dimension/realize.c55
7 files changed, 177 insertions, 83 deletions
diff --git a/dimension/common.terminals b/dimension/common.terminals
index fbe1eb2..20b6459 100644
--- a/dimension/common.terminals
+++ b/dimension/common.terminals
@@ -90,7 +90,7 @@
%token DMNSN_T_ASCII
%token DMNSN_T_ASIN
%token DMNSN_T_ASINH
-%token DMNSN_T_ASSUMED_GAMMA
+%token DMNSN_T_ASSUMED_GAMMA "assumed_gamma"
%token DMNSN_T_ATAN
%token DMNSN_T_ATAN2
%token DMNSN_T_ATANH
@@ -211,7 +211,7 @@
%token DMNSN_T_GATHER
%token DMNSN_T_GIF
%token DMNSN_T_GLOBAL_LIGHTS
-%token DMNSN_T_GLOBAL_SETTINGS
+%token DMNSN_T_GLOBAL_SETTINGS "global_settings"
%token DMNSN_T_GRADIENT
%token DMNSN_T_GRANITE
%token DMNSN_T_GRAY "gray"
@@ -277,7 +277,7 @@
%token DMNSN_T_MAX_ITERATION
%token DMNSN_T_MAX_SAMPLE
%token DMNSN_T_MAX_TRACE
-%token DMNSN_T_MAX_TRACE_LEVEL
+%token DMNSN_T_MAX_TRACE_LEVEL "max_trace_level"
%token DMNSN_T_MEDIA
%token DMNSN_T_MEDIA_ATTENUATION
%token DMNSN_T_MEDIA_INTERACTION
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue
index 6ea459d..d666b0a 100644
--- a/dimension/grammar.epilogue
+++ b/dimension/grammar.epilogue
@@ -116,24 +116,24 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_NONE, "none");
- dmnsn_astnode_map(DMNSN_AST_ROTATION, "rotate");
- dmnsn_astnode_map(DMNSN_AST_SCALE, "scale");
- dmnsn_astnode_map(DMNSN_AST_TRANSLATION, "translate");
-
- dmnsn_astnode_map(DMNSN_AST_CAMERA, "camera");
- dmnsn_astnode_map(DMNSN_AST_PERSPECTIVE, "perspective");
- dmnsn_astnode_map(DMNSN_AST_LOCATION, "location");
- dmnsn_astnode_map(DMNSN_AST_RIGHT, "right");
- dmnsn_astnode_map(DMNSN_AST_UP, "up");
- dmnsn_astnode_map(DMNSN_AST_SKY, "sky");
- dmnsn_astnode_map(DMNSN_AST_ANGLE, "angle");
- dmnsn_astnode_map(DMNSN_AST_LOOK_AT, "look_at");
- dmnsn_astnode_map(DMNSN_AST_DIRECTION, "direction");
+ dmnsn_astnode_map(DMNSN_AST_GLOBAL_SETTINGS, "global_settings");
+ dmnsn_astnode_map(DMNSN_AST_ASSUMED_GAMMA, "assumed_gamma");
+ dmnsn_astnode_map(DMNSN_AST_MAX_TRACE_LEVEL, "max_trace_level");
dmnsn_astnode_map(DMNSN_AST_BACKGROUND, "background");
- dmnsn_astnode_map(DMNSN_AST_BOX, "box");
- dmnsn_astnode_map(DMNSN_AST_SPHERE, "sphere");
+ dmnsn_astnode_map(DMNSN_AST_CAMERA, "camera");
+ dmnsn_astnode_map(DMNSN_AST_PERSPECTIVE, "perspective");
+ dmnsn_astnode_map(DMNSN_AST_LOCATION, "location");
+ dmnsn_astnode_map(DMNSN_AST_RIGHT, "right");
+ dmnsn_astnode_map(DMNSN_AST_UP, "up");
+ dmnsn_astnode_map(DMNSN_AST_SKY, "sky");
+ dmnsn_astnode_map(DMNSN_AST_ANGLE, "angle");
+ dmnsn_astnode_map(DMNSN_AST_LOOK_AT, "look_at");
+ dmnsn_astnode_map(DMNSN_AST_DIRECTION, "direction");
+
+ dmnsn_astnode_map(DMNSN_AST_BOX, "box");
+ dmnsn_astnode_map(DMNSN_AST_SPHERE, "sphere");
dmnsn_astnode_map(DMNSN_AST_LIGHT_SOURCE, "light_source");
dmnsn_astnode_map(DMNSN_AST_OBJECT_MODIFIERS, "object-modifiers");
@@ -142,18 +142,22 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_PIGMENT, "pigment");
- dmnsn_astnode_map(DMNSN_AST_FINISH, "finish");
- dmnsn_astnode_map(DMNSN_AST_AMBIENT, "ambient");
- dmnsn_astnode_map(DMNSN_AST_DIFFUSE, "diffuse");
- dmnsn_astnode_map(DMNSN_AST_PHONG, "phong");
+ dmnsn_astnode_map(DMNSN_AST_FINISH, "finish");
+ dmnsn_astnode_map(DMNSN_AST_AMBIENT, "ambient");
+ dmnsn_astnode_map(DMNSN_AST_DIFFUSE, "diffuse");
+ dmnsn_astnode_map(DMNSN_AST_PHONG, "phong");
dmnsn_astnode_map(DMNSN_AST_PHONG_SIZE, "phong_size");
- dmnsn_astnode_map(DMNSN_AST_REFLECTION, "reflection");
+ dmnsn_astnode_map(DMNSN_AST_REFLECTION, "reflection");
dmnsn_astnode_map(DMNSN_AST_REFLECTION_ITEMS, "reflection-items");
- dmnsn_astnode_map(DMNSN_AST_FALLOFF, "falloff");
+ dmnsn_astnode_map(DMNSN_AST_FALLOFF, "falloff");
dmnsn_astnode_map(DMNSN_AST_INTERIOR, "interior");
- dmnsn_astnode_map(DMNSN_AST_IOR, "ior");
+ dmnsn_astnode_map(DMNSN_AST_IOR, "ior");
+
+ dmnsn_astnode_map(DMNSN_AST_ROTATION, "rotate");
+ dmnsn_astnode_map(DMNSN_AST_SCALE, "scale");
+ dmnsn_astnode_map(DMNSN_AST_TRANSLATION, "translate");
dmnsn_astnode_map(DMNSN_AST_FLOAT, "float");
dmnsn_astnode_map(DMNSN_AST_INTEGER, "integer");
@@ -174,11 +178,11 @@ dmnsn_astnode_string(dmnsn_astnode_type astnode_type)
dmnsn_astnode_map(DMNSN_AST_AND, "&" );
dmnsn_astnode_map(DMNSN_AST_OR, "|" );
- dmnsn_astnode_map(DMNSN_AST_NEGATE, "-");
- dmnsn_astnode_map(DMNSN_AST_DOT_X, ".x");
- dmnsn_astnode_map(DMNSN_AST_DOT_Y, ".y");
- dmnsn_astnode_map(DMNSN_AST_DOT_Z, ".z");
- dmnsn_astnode_map(DMNSN_AST_DOT_T, ".t");
+ dmnsn_astnode_map(DMNSN_AST_NEGATE, "-");
+ dmnsn_astnode_map(DMNSN_AST_DOT_X, ".x");
+ dmnsn_astnode_map(DMNSN_AST_DOT_Y, ".y");
+ dmnsn_astnode_map(DMNSN_AST_DOT_Z, ".z");
+ dmnsn_astnode_map(DMNSN_AST_DOT_T, ".t");
dmnsn_astnode_map(DMNSN_AST_DOT_TRANSMIT, ".transmit");
dmnsn_astnode_map(DMNSN_AST_IDENTIFIER, "identifier");
diff --git a/dimension/grammar.nonterminals b/dimension/grammar.nonterminals
index 5b29089..896bff9 100644
--- a/dimension/grammar.nonterminals
+++ b/dimension/grammar.nonterminals
@@ -22,6 +22,11 @@
/* Top-level items */
%type <astnode> SCENE_ITEM
+/* Global settings */
+%type <astnode> GLOBAL_SETTINGS
+%type <astnode> GLOBAL_SETTINGS_ITEMS
+%type <astnode> GLOBAL_SETTINGS_ITEM
+
/* Atmospheric effects */
%type <astnode> ATMOSPHERIC_EFFECT
%type <astnode> BACKGROUND
diff --git a/dimension/grammar.rules b/dimension/grammar.rules
index af8a5de..25f8a3c 100644
--- a/dimension/grammar.rules
+++ b/dimension/grammar.rules
@@ -30,11 +30,40 @@ SCENE: /* empty */
;
/* Top-level scene item */
-SCENE_ITEM: ATMOSPHERIC_EFFECT
+SCENE_ITEM: GLOBAL_SETTINGS
+ | ATMOSPHERIC_EFFECT
| CAMERA
| OBJECT
;
+/* Global settings */
+
+GLOBAL_SETTINGS: "global_settings" "{"
+ GLOBAL_SETTINGS_ITEMS
+ "}"
+ {
+ $$ = $3;
+ }
+;
+
+GLOBAL_SETTINGS_ITEMS: /* empty */ {
+ $$ = dmnsn_new_astnode(DMNSN_AST_GLOBAL_SETTINGS, @$);
+ }
+ | GLOBAL_SETTINGS_ITEMS GLOBAL_SETTINGS_ITEM {
+ $$ = $1;
+ dmnsn_array_push($$.children, &$2);
+ }
+;
+
+GLOBAL_SETTINGS_ITEM: "assumed_gamma" FLOAT {
+ $$ = dmnsn_new_astnode1(DMNSN_AST_ASSUMED_GAMMA, @$, $2);
+ }
+ | "max_trace_level" FLOAT {
+ $$ = dmnsn_new_astnode1(DMNSN_AST_MAX_TRACE_LEVEL,
+ @$, $2);
+ }
+;
+
/* Atmospheric effects */
ATMOSPHERIC_EFFECT: BACKGROUND
diff --git a/dimension/lexer.l b/dimension/lexer.l
index 6531e0c..05c6711 100644
--- a/dimension/lexer.l
+++ b/dimension/lexer.l
@@ -163,50 +163,53 @@ unsigned long wchar;
}
(?# Keywords)
-"ambient" RETURN_TOKEN(DMNSN_T_AMBIENT);
-"angle" RETURN_TOKEN(DMNSN_T_ANGLE);
-"background" RETURN_TOKEN(DMNSN_T_BACKGROUND);
-"box" RETURN_TOKEN(DMNSN_T_BOX);
-"blue" RETURN_TOKEN(DMNSN_T_BLUE);
-"camera" RETURN_TOKEN(DMNSN_T_CAMERA);
-"color" RETURN_TOKEN(DMNSN_T_COLOR);
-"colour" RETURN_TOKEN(DMNSN_T_COLOR);
-"direction" RETURN_TOKEN(DMNSN_T_DIRECTION);
-"diffuse" RETURN_TOKEN(DMNSN_T_DIFFUSE);
-"falloff" RETURN_TOKEN(DMNSN_T_FALLOFF);
-"filter" RETURN_TOKEN(DMNSN_T_FILTER);
-"finish" RETURN_TOKEN(DMNSN_T_FINISH);
-"gray" RETURN_TOKEN(DMNSN_T_GRAY);
-"grey" RETURN_TOKEN(DMNSN_T_GRAY);
-"green" RETURN_TOKEN(DMNSN_T_GREEN);
-"interior" RETURN_TOKEN(DMNSN_T_INTERIOR);
-"ior" RETURN_TOKEN(DMNSN_T_IOR);
-"location" RETURN_TOKEN(DMNSN_T_LOCATION);
-"look_at" RETURN_TOKEN(DMNSN_T_LOOK_AT);
-"light_source" RETURN_TOKEN(DMNSN_T_LIGHT_SOURCE);
-"perspective" RETURN_TOKEN(DMNSN_T_PERSPECTIVE);
-"phong" RETURN_TOKEN(DMNSN_T_PHONG);
-"phong_size" RETURN_TOKEN(DMNSN_T_PHONG_SIZE);
-"pigment" RETURN_TOKEN(DMNSN_T_PIGMENT);
-"red" RETURN_TOKEN(DMNSN_T_RED);
-"reflection" RETURN_TOKEN(DMNSN_T_REFLECTION);
-"rgb" RETURN_TOKEN(DMNSN_T_RGB);
-"rgbf" RETURN_TOKEN(DMNSN_T_RGBF);
-"rgbft" RETURN_TOKEN(DMNSN_T_RGBFT);
-"rgbt" RETURN_TOKEN(DMNSN_T_RGBT);
-"right" RETURN_TOKEN(DMNSN_T_RIGHT);
-"rotate" RETURN_TOKEN(DMNSN_T_ROTATE);
-"sphere" RETURN_TOKEN(DMNSN_T_SPHERE);
-"sky" RETURN_TOKEN(DMNSN_T_SKY);
-"t" RETURN_TOKEN(DMNSN_T_T);
-"texture" RETURN_TOKEN(DMNSN_T_TEXTURE);
-"transmit" RETURN_TOKEN(DMNSN_T_TRANSMIT);
-"u" RETURN_TOKEN(DMNSN_T_U);
-"up" RETURN_TOKEN(DMNSN_T_UP);
-"v" RETURN_TOKEN(DMNSN_T_V);
-"x" RETURN_TOKEN(DMNSN_T_X);
-"y" RETURN_TOKEN(DMNSN_T_Y);
-"z" RETURN_TOKEN(DMNSN_T_Z);
+"ambient" RETURN_TOKEN(DMNSN_T_AMBIENT);
+"angle" RETURN_TOKEN(DMNSN_T_ANGLE);
+"assumed_gamma" RETURN_TOKEN(DMNSN_T_ASSUMED_GAMMA);
+"background" RETURN_TOKEN(DMNSN_T_BACKGROUND);
+"box" RETURN_TOKEN(DMNSN_T_BOX);
+"blue" RETURN_TOKEN(DMNSN_T_BLUE);
+"camera" RETURN_TOKEN(DMNSN_T_CAMERA);
+"color" RETURN_TOKEN(DMNSN_T_COLOR);
+"colour" RETURN_TOKEN(DMNSN_T_COLOR);
+"direction" RETURN_TOKEN(DMNSN_T_DIRECTION);
+"diffuse" RETURN_TOKEN(DMNSN_T_DIFFUSE);
+"falloff" RETURN_TOKEN(DMNSN_T_FALLOFF);
+"filter" RETURN_TOKEN(DMNSN_T_FILTER);
+"finish" RETURN_TOKEN(DMNSN_T_FINISH);
+"global_settings" RETURN_TOKEN(DMNSN_T_GLOBAL_SETTINGS);
+"gray" RETURN_TOKEN(DMNSN_T_GRAY);
+"grey" RETURN_TOKEN(DMNSN_T_GRAY);
+"green" RETURN_TOKEN(DMNSN_T_GREEN);
+"interior" RETURN_TOKEN(DMNSN_T_INTERIOR);
+"ior" RETURN_TOKEN(DMNSN_T_IOR);
+"location" RETURN_TOKEN(DMNSN_T_LOCATION);
+"look_at" RETURN_TOKEN(DMNSN_T_LOOK_AT);
+"light_source" RETURN_TOKEN(DMNSN_T_LIGHT_SOURCE);
+"max_trace_level" RETURN_TOKEN(DMNSN_T_MAX_TRACE_LEVEL);
+"perspective" RETURN_TOKEN(DMNSN_T_PERSPECTIVE);
+"phong" RETURN_TOKEN(DMNSN_T_PHONG);
+"phong_size" RETURN_TOKEN(DMNSN_T_PHONG_SIZE);
+"pigment" RETURN_TOKEN(DMNSN_T_PIGMENT);
+"red" RETURN_TOKEN(DMNSN_T_RED);
+"reflection" RETURN_TOKEN(DMNSN_T_REFLECTION);
+"rgb" RETURN_TOKEN(DMNSN_T_RGB);
+"rgbf" RETURN_TOKEN(DMNSN_T_RGBF);
+"rgbft" RETURN_TOKEN(DMNSN_T_RGBFT);
+"rgbt" RETURN_TOKEN(DMNSN_T_RGBT);
+"right" RETURN_TOKEN(DMNSN_T_RIGHT);
+"rotate" RETURN_TOKEN(DMNSN_T_ROTATE);
+"sphere" RETURN_TOKEN(DMNSN_T_SPHERE);
+"sky" RETURN_TOKEN(DMNSN_T_SKY);
+"t" RETURN_TOKEN(DMNSN_T_T);
+"texture" RETURN_TOKEN(DMNSN_T_TEXTURE);
+"transmit" RETURN_TOKEN(DMNSN_T_TRANSMIT);
+"u" RETURN_TOKEN(DMNSN_T_U);
+"up" RETURN_TOKEN(DMNSN_T_UP);
+"v" RETURN_TOKEN(DMNSN_T_V);
+"x" RETURN_TOKEN(DMNSN_T_X);
+"y" RETURN_TOKEN(DMNSN_T_Y);
+"z" RETURN_TOKEN(DMNSN_T_Z);
(?# Directives)
#[\b\r\t\v ]*break RETURN_TOKEN(DMNSN_T_BREAK);
diff --git a/dimension/parse.h b/dimension/parse.h
index 2d946b6..6da36d7 100644
--- a/dimension/parse.h
+++ b/dimension/parse.h
@@ -30,9 +30,11 @@
typedef enum {
DMNSN_AST_NONE,
- DMNSN_AST_ROTATION,
- DMNSN_AST_SCALE,
- DMNSN_AST_TRANSLATION,
+ DMNSN_AST_GLOBAL_SETTINGS,
+ DMNSN_AST_ASSUMED_GAMMA,
+ DMNSN_AST_MAX_TRACE_LEVEL,
+
+ DMNSN_AST_BACKGROUND,
DMNSN_AST_CAMERA,
DMNSN_AST_PERSPECTIVE,
@@ -44,8 +46,6 @@ typedef enum {
DMNSN_AST_LOOK_AT,
DMNSN_AST_DIRECTION,
- DMNSN_AST_BACKGROUND,
-
DMNSN_AST_BOX,
DMNSN_AST_LIGHT_SOURCE,
DMNSN_AST_SPHERE,
@@ -69,6 +69,10 @@ typedef enum {
DMNSN_AST_INTERIOR,
DMNSN_AST_IOR,
+ DMNSN_AST_ROTATION,
+ DMNSN_AST_SCALE,
+ DMNSN_AST_TRANSLATION,
+
DMNSN_AST_FLOAT,
DMNSN_AST_INTEGER,
diff --git a/dimension/realize.c b/dimension/realize.c
index c41ac93..9fa333b 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -24,6 +24,23 @@
#include <stdio.h>
#include <stdbool.h>
+static long
+dmnsn_realize_integer(dmnsn_astnode astnode)
+{
+ switch (astnode.type) {
+ case DMNSN_AST_INTEGER:
+ return *(long *)astnode.ptr;
+ case DMNSN_AST_FLOAT:
+ dmnsn_diagnostic(astnode.filename, astnode.line, astnode.col,
+ "WARNING: float cast to integer");
+ return *(double *)astnode.ptr;
+
+ default:
+ dmnsn_assert(false, "Invalid integer.");
+ return 0; /* Silence compiler warning */
+ }
+}
+
static double
dmnsn_realize_float(dmnsn_astnode astnode)
{
@@ -137,6 +154,34 @@ dmnsn_realize_translation(dmnsn_astnode astnode)
return dmnsn_translation_matrix(trans);
}
+static void
+dmnsn_realize_global_settings(dmnsn_astnode astnode, dmnsn_scene *scene)
+{
+ dmnsn_assert(astnode.type == DMNSN_AST_GLOBAL_SETTINGS,
+ "Expected global settings.");
+
+ unsigned int i;
+ for (i = 0; i < dmnsn_array_size(astnode.children); ++i) {
+ dmnsn_astnode item, child;
+ dmnsn_array_get(astnode.children, i, &item);
+
+ switch (item.type) {
+ case DMNSN_AST_ASSUMED_GAMMA:
+ dmnsn_diagnostic(item.filename, item.line, item.col,
+ "WARNING: assumed_gamma not supported");
+ break;
+
+ case DMNSN_AST_MAX_TRACE_LEVEL:
+ dmnsn_array_get(item.children, 0, &child);
+ scene->reclimit = dmnsn_realize_integer(child);
+ break;
+
+ default:
+ dmnsn_assert(false, "Invalid global settings item.");
+ }
+ }
+}
+
static dmnsn_camera *
dmnsn_realize_camera(dmnsn_astnode astnode)
{
@@ -741,9 +786,8 @@ dmnsn_realize_astree(const dmnsn_astree *astree)
dmnsn_light *light;
dmnsn_object *object;
switch (astnode.type) {
- case DMNSN_AST_CAMERA:
- dmnsn_delete_camera(scene->camera);
- scene->camera = dmnsn_realize_camera(astnode);
+ case DMNSN_AST_GLOBAL_SETTINGS:
+ dmnsn_realize_global_settings(astnode, scene);
break;
case DMNSN_AST_BACKGROUND:
@@ -751,6 +795,11 @@ dmnsn_realize_astree(const dmnsn_astree *astree)
scene->background = dmnsn_realize_color(astnode);
break;
+ case DMNSN_AST_CAMERA:
+ dmnsn_delete_camera(scene->camera);
+ scene->camera = dmnsn_realize_camera(astnode);
+ break;
+
case DMNSN_AST_BOX:
object = dmnsn_realize_box(astnode);
dmnsn_array_push(scene->objects, &object);