diff --git a/src/easymesh/easymeshrender.cpp b/src/easymesh/easymeshrender.cpp index 6e5f5c21..8fe0427e 100644 --- a/src/easymesh/easymeshrender.cpp +++ b/src/easymesh/easymeshrender.cpp @@ -159,7 +159,7 @@ void DefaultShaderData::SetupShaderDatas(mat4 const &model) /* FIXME: the 4th component of the position can be used for other things */ /* FIXME: GetUniform("blabla") is costly */ for (int i = 0; i < lights.Count(); ++i) - light_data << lights[i]->GetPosition() << lights[i]->GetColor(); + light_data << vec4(lights[i]->GetPosition(), lights[i]->GetType()) << lights[i]->GetColor(); while (light_data.Count() < 8) light_data << vec4::zero << vec4::zero; diff --git a/src/easymesh/easymeshrender.h b/src/easymesh/easymeshrender.h index 7f6002ac..dd7e7d87 100644 --- a/src/easymesh/easymeshrender.h +++ b/src/easymesh/easymeshrender.h @@ -26,7 +26,7 @@ struct MeshRender { enum Value { - NeedData, + NeedData = 0, NeedConvert, CanRender, IgnoreRender, diff --git a/src/easymesh/shiny.lolfx b/src/easymesh/shiny.lolfx index bd9d3c77..6180ef0b 100644 --- a/src/easymesh/shiny.lolfx +++ b/src/easymesh/shiny.lolfx @@ -79,18 +79,19 @@ void main(void) { vec4 pos = u_Lights[i * 2]; vec4 color = u_Lights[i * 2 + 1]; - vec3 s, r; + vec3 s, r, p; + p = (in_View * pos).xyz; if (pos.w > 0.0) { /* Point light -- no attenuation yet */ - s = normalize((in_View * pos).xyz - pass_Vertex.xyz); + s = normalize(p - pass_Vertex.xyz); r = reflect(-s, TNormal); } else { /* Directional light */ - s = normalize(-pos.xyz); + s = normalize(-p); r = reflect(s, TNormal); } diff --git a/src/easymesh/shinyflat.lolfx b/src/easymesh/shinyflat.lolfx index 857b68bb..ff9a6185 100644 --- a/src/easymesh/shinyflat.lolfx +++ b/src/easymesh/shinyflat.lolfx @@ -63,7 +63,7 @@ void main(void) vec3 TNormal = pass_TNormal; vec3 X = dFdx(pass_Vertex.xyz); vec3 Y = dFdy(pass_Vertex.xyz); - TNormal = normalize(cross(X, Y) ) * length(normalize(pass_TNormal)); + TNormal = normalize(cross(Y, X)) * length(normalize(pass_TNormal)); /* Material properties */ vec3 specular_reflect = vec3(0.8, 0.75, 0.4); @@ -82,18 +82,19 @@ void main(void) { vec4 pos = u_Lights[i * 2]; vec4 color = u_Lights[i * 2 + 1]; - vec3 s, r; + vec3 s, r, p; + p = (in_View * pos).xyz; if (pos.w > 0.0) { /* Point light -- no attenuation yet */ - s = normalize((in_View * pos).xyz - pass_Vertex.xyz); + s = normalize(p - pass_Vertex.xyz); r = reflect(-s, TNormal); } else { /* Directional light */ - s = normalize(-pos.xyz); + s = normalize(-p); r = reflect(s, TNormal); } diff --git a/src/light.cpp b/src/light.cpp index 732f46ca..3bcb94c0 100644 --- a/src/light.cpp +++ b/src/light.cpp @@ -22,27 +22,36 @@ namespace lol Light::Light() : m_color(1.f), - m_directional(true) + m_type(LightType::Directional) { m_gamegroup = GAMEGROUP_BEFORE; m_drawgroup = DRAWGROUP_CAMERA; - SetPosition(vec4::zero); + SetPosition(vec3::zero); } Light::~Light() { } -void Light::SetPosition(vec4 const &pos) +void Light::SetType(LightType const &type) { - m_directional = (pos.w > 0.f); - m_position = pos.xyz; + m_type = type; } -vec4 Light::GetPosition() +LightType Light::GetType() { - return vec4(m_position, m_directional ? 1.f : 0.f); + return m_type; +} + +void Light::SetPosition(vec3 const &pos) +{ + m_position = pos; +} + +vec3 Light::GetPosition() +{ + return m_position; } void Light::SetColor(vec4 const &color) diff --git a/src/light.h b/src/light.h index d9bcd2be..54e6ef6f 100644 --- a/src/light.h +++ b/src/light.h @@ -21,6 +21,54 @@ namespace lol { +struct LightType +{ + enum Value + { + Directional = 0, + Point, + + Max, + } + m_value; + + static char const *GetName(Value v) + { + switch (v) + { + case Directional: + return ""; + case Point: + return ""; + default: + return ""; + } + } + + inline LightType(float v) + { + float top = FLT_MAX; + int iv = Directional; + for (int i = 0; i < Max; ++i) + { + LightType lv = LightType(i); + float nv = lv.f(); + float ntop = lol::abs(nv - v); + if (ntop < top) + { + top = ntop; + iv = i; + } + } + m_value = LightType(iv); + } + inline LightType(int v) : m_value((Value)v) {} + inline LightType(Value v) : m_value(v) {} + inline LightType() : m_value(Directional) {} + inline operator Value() { return m_value; } + inline float f() { return ((float)m_value / (float)Max); } +}; + class Light : public WorldEntity { public: @@ -29,19 +77,22 @@ public: char const *GetName() { return ""; } - void SetColor(vec4 const &col); + void SetType(LightType const &type); + LightType GetType(); + + void SetColor(vec4 const &color); vec4 GetColor(); - void SetPosition(vec4 const &pos); - vec4 GetPosition(); + void SetPosition(vec3 const &pos); + vec3 GetPosition(); protected: virtual void TickGame(float seconds); virtual void TickDraw(float seconds); private: - vec4 m_color; - bool m_directional; + vec4 m_color; + LightType m_type; }; } /* namespace lol */ diff --git a/test/generated/scenesetup-parser.cpp b/test/generated/scenesetup-parser.cpp index 8789e84e..5ff395d6 100644 --- a/test/generated/scenesetup-parser.cpp +++ b/test/generated/scenesetup-parser.cpp @@ -447,15 +447,15 @@ namespace lol { /* Line 677 of lalr1.cc */ #line 117 "scenesetup-parser.y" { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; - uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, (yysemantic_stack_[(2) - (2)].fval))); } + uc.m_sstp.m_lights.Last()->SetType(LightType((yysemantic_stack_[(2) - (2)].fval))); } break; case 14: /* Line 677 of lalr1.cc */ -#line 122 "scenesetup-parser.y" - { if (uc.m_last_cmd == "ADDLIGHT") - uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); } +#line 119 "scenesetup-parser.y" + { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; + uc.m_sstp.m_lights.Last()->SetType(FindValue((yysemantic_stack_[(2) - (2)].svval))); } break; case 15: @@ -463,7 +463,7 @@ namespace lol { /* Line 677 of lalr1.cc */ #line 124 "scenesetup-parser.y" { if (uc.m_last_cmd == "ADDLIGHT") - { /* */ } } + uc.m_sstp.m_lights.Last()->SetPosition(vec3((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2])); } break; case 16: @@ -471,13 +471,21 @@ namespace lol { /* Line 677 of lalr1.cc */ #line 126 "scenesetup-parser.y" { if (uc.m_last_cmd == "ADDLIGHT") - uc.m_sstp.m_lights.Last()->SetColor(vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3])); } + { /* */ } } break; case 17: /* Line 677 of lalr1.cc */ #line 128 "scenesetup-parser.y" + { if (uc.m_last_cmd == "ADDLIGHT") + uc.m_sstp.m_lights.Last()->SetColor(vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3])); } + break; + + case 18: + +/* Line 677 of lalr1.cc */ +#line 130 "scenesetup-parser.y" { uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); vec4 vv = vec4(v) * (1.f / 255.f); @@ -485,175 +493,175 @@ namespace lol { uc.m_sstp.m_lights.Last()->SetColor(vv); } break; - case 18: + case 19: /* Line 677 of lalr1.cc */ -#line 136 "scenesetup-parser.y" +#line 138 "scenesetup-parser.y" { uc.m_sstp.m_clear_color = vec4((yysemantic_stack_[(2) - (2)].vval)[0], (yysemantic_stack_[(2) - (2)].vval)[1], (yysemantic_stack_[(2) - (2)].vval)[2], (yysemantic_stack_[(2) - (2)].vval)[3]); } break; - case 19: + case 20: /* Line 677 of lalr1.cc */ -#line 137 "scenesetup-parser.y" +#line 139 "scenesetup-parser.y" { uc.m_sstp.m_clear_color = vec4((yysemantic_stack_[(5) - (2)].vval)[0], (yysemantic_stack_[(5) - (2)].vval)[1], (yysemantic_stack_[(5) - (2)].vval)[2], 1.f); } break; - case 20: + case 21: /* Line 677 of lalr1.cc */ -#line 138 "scenesetup-parser.y" +#line 140 "scenesetup-parser.y" { uint32_t x = (yysemantic_stack_[(2) - (2)].u32val); ivec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); uc.m_sstp.m_clear_color = vec4(v) * (1.f / 255.f); } break; - case 21: + case 22: /* Line 677 of lalr1.cc */ -#line 140 "scenesetup-parser.y" +#line 142 "scenesetup-parser.y" { uc.m_sstp.m_show_gizmo = (yysemantic_stack_[(2) - (2)].bval); } break; - case 22: + case 23: /* Line 677 of lalr1.cc */ -#line 141 "scenesetup-parser.y" +#line 143 "scenesetup-parser.y" { uc.m_sstp.m_show_lights = (yysemantic_stack_[(2) - (2)].bval); } break; - case 23: + case 24: /* Line 677 of lalr1.cc */ -#line 145 "scenesetup-parser.y" +#line 147 "scenesetup-parser.y" { uc.m_sstp.m_custom_cmd.Push((yysemantic_stack_[(3) - (2)].svval), (yysemantic_stack_[(3) - (3)].sval)); } break; - case 24: + case 25: /* Line 677 of lalr1.cc */ -#line 151 "scenesetup-parser.y" +#line 153 "scenesetup-parser.y" { (yyval.fval) = (yysemantic_stack_[(1) - (1)].fval); } break; - case 25: + case 26: /* Line 677 of lalr1.cc */ -#line 152 "scenesetup-parser.y" +#line 154 "scenesetup-parser.y" { (yyval.fval) = -(yysemantic_stack_[(2) - (2)].fval); } break; - case 26: + case 27: /* Line 677 of lalr1.cc */ -#line 153 "scenesetup-parser.y" +#line 155 "scenesetup-parser.y" { (yyval.fval) = (float)(yysemantic_stack_[(1) - (1)].ival); } break; - case 27: + case 28: /* Line 677 of lalr1.cc */ -#line 154 "scenesetup-parser.y" +#line 156 "scenesetup-parser.y" { (yyval.fval) = -(float)(yysemantic_stack_[(2) - (2)].ival); } break; - case 28: + case 29: /* Line 677 of lalr1.cc */ -#line 158 "scenesetup-parser.y" +#line 160 "scenesetup-parser.y" { (yyval.ival) = (yysemantic_stack_[(1) - (1)].ival); } break; - case 29: + case 30: /* Line 677 of lalr1.cc */ -#line 159 "scenesetup-parser.y" +#line 161 "scenesetup-parser.y" { (yyval.ival) = -(yysemantic_stack_[(2) - (2)].ival); } break; - case 30: + case 31: /* Line 677 of lalr1.cc */ -#line 160 "scenesetup-parser.y" +#line 162 "scenesetup-parser.y" { (yyval.ival) = (int)(yysemantic_stack_[(1) - (1)].fval); } break; - case 31: + case 32: /* Line 677 of lalr1.cc */ -#line 161 "scenesetup-parser.y" +#line 163 "scenesetup-parser.y" { (yyval.ival) = -(int)(yysemantic_stack_[(2) - (2)].fval); } break; - case 32: + case 33: /* Line 677 of lalr1.cc */ -#line 166 "scenesetup-parser.y" +#line 168 "scenesetup-parser.y" { (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); } break; - case 33: + case 34: /* Line 677 of lalr1.cc */ -#line 167 "scenesetup-parser.y" +#line 169 "scenesetup-parser.y" { (yyval.vval)[0] = (yysemantic_stack_[(5) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(5) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(5) - (4)].fval); } break; - case 34: + case 35: /* Line 677 of lalr1.cc */ -#line 176 "scenesetup-parser.y" +#line 178 "scenesetup-parser.y" { (yyval.vval)[0] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[2] = (yysemantic_stack_[(3) - (2)].fval); (yyval.vval)[3] = (yysemantic_stack_[(3) - (2)].fval); } break; - case 35: + case 36: /* Line 677 of lalr1.cc */ -#line 177 "scenesetup-parser.y" +#line 179 "scenesetup-parser.y" { (yyval.vval)[0] = (yysemantic_stack_[(6) - (2)].fval); (yyval.vval)[1] = (yysemantic_stack_[(6) - (3)].fval); (yyval.vval)[2] = (yysemantic_stack_[(6) - (4)].fval); (yyval.vval)[3] = (yysemantic_stack_[(6) - (5)].fval); } break; - case 36: + case 37: /* Line 677 of lalr1.cc */ -#line 182 "scenesetup-parser.y" +#line 184 "scenesetup-parser.y" { (yyval.bval) = (yysemantic_stack_[(1) - (1)].bval); } break; - case 37: + case 38: /* Line 677 of lalr1.cc */ -#line 183 "scenesetup-parser.y" +#line 185 "scenesetup-parser.y" { (yyval.bval) = !!(yysemantic_stack_[(1) - (1)].ival); } break; - case 38: + case 39: /* Line 677 of lalr1.cc */ -#line 184 "scenesetup-parser.y" +#line 186 "scenesetup-parser.y" { (yyval.bval) = !!(yysemantic_stack_[(1) - (1)].fval); } break; - case 39: + case 40: /* Line 677 of lalr1.cc */ -#line 188 "scenesetup-parser.y" +#line 190 "scenesetup-parser.y" { (yyval.svval) = (yysemantic_stack_[(1) - (1)].svval); } break; - case 40: + case 41: /* Line 677 of lalr1.cc */ -#line 192 "scenesetup-parser.y" +#line 194 "scenesetup-parser.y" { String t = (yysemantic_stack_[(1) - (1)].sval); t.Replace('"', ' ', true); free((yysemantic_stack_[(1) - (1)].sval)); (yyval.sval) = strdup((const char *)t.C()); } break; - case 41: + case 42: /* Line 677 of lalr1.cc */ -#line 196 "scenesetup-parser.y" +#line 198 "scenesetup-parser.y" { String t = (yysemantic_stack_[(2) - (1)].sval); t += (yysemantic_stack_[(2) - (2)].sval); t.Replace('"', ' ', true); @@ -665,7 +673,7 @@ namespace lol { /* Line 677 of lalr1.cc */ -#line 669 "generated/scenesetup-parser.cpp" +#line 677 "generated/scenesetup-parser.cpp" default: break; } @@ -870,17 +878,17 @@ namespace lol { /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ - const signed char SceneSetupParser::yypact_ninf_ = -20; + const signed char SceneSetupParser::yypact_ninf_ = -21; const signed char SceneSetupParser::yypact_[] = { - 38, 4, -18, -18, -7, 14, 16, 16, -10, 15, - 21, 38, 38, -20, -20, -20, -20, -20, -20, -20, - 6, -20, 4, -20, -20, -20, 4, -20, -20, -20, - -20, -20, -20, -20, -20, -20, 7, -20, -20, -20, - -20, -20, -20, 6, -20, -20, -9, -5, 18, 7, - -20, -20, -20, -20, 4, -20, 4, -18, -20, 10, - 4, -20, -20, 17, -20 + 38, 6, -18, -18, -6, -2, 37, 37, -13, 7, + 21, 38, 38, -21, -21, -21, -21, -21, -21, -21, + -21, 17, -21, -21, 19, -21, -21, -21, 19, -21, + -21, -21, -21, -21, -21, -21, -21, 8, -21, -21, + -21, -21, -21, -21, 17, -21, -21, -8, -4, 18, + 8, -21, -21, -21, -21, 19, -21, 19, -18, -21, + 13, 19, -21, -21, 31, -21 }; /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE @@ -890,28 +898,28 @@ namespace lol { SceneSetupParser::yydefact_[] = { 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 3, 5, 6, 8, 9, 10, 11, 24, 26, - 0, 13, 0, 14, 15, 17, 0, 16, 20, 18, - 38, 37, 36, 21, 22, 39, 0, 1, 2, 4, - 7, 24, 26, 0, 25, 27, 0, 0, 0, 40, - 23, 25, 27, 32, 0, 34, 0, 0, 41, 0, - 0, 19, 33, 0, 35 + 0, 3, 5, 6, 8, 9, 10, 11, 25, 27, + 40, 0, 13, 14, 0, 15, 16, 18, 0, 17, + 21, 19, 39, 38, 37, 22, 23, 0, 1, 2, + 4, 7, 25, 27, 0, 26, 28, 0, 0, 0, + 41, 24, 26, 28, 33, 0, 35, 0, 0, 42, + 0, 0, 20, 34, 0, 36 }; /* YYPGOTO[NTERM-NUM]. */ const signed char SceneSetupParser::yypgoto_[] = { - -20, -20, 25, -20, -20, 27, -20, -20, -20, -20, - -20, -19, 8, -3, 35, 43, -20, 3 + -21, -21, 28, -21, -21, 41, -21, -21, -21, -21, + -21, -20, -15, -3, 35, 49, 50, 9 }; /* YYDEFGOTO[NTERM-NUM]. */ const signed char SceneSetupParser::yydefgoto_[] = { - -1, 9, 10, 11, 12, 13, 14, 15, 16, 48, - 17, 21, 45, 23, 27, 33, 36, 50 + -1, 9, 10, 11, 12, 13, 14, 15, 16, 49, + 17, 22, 46, 25, 29, 35, 23, 51 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If @@ -921,24 +929,24 @@ namespace lol { const unsigned char SceneSetupParser::yytable_[] = { - 24, 44, 22, 46, 18, 19, 35, 47, 18, 19, - 20, 25, 53, 26, 20, 37, 55, 18, 19, 41, - 42, 38, 49, 20, 51, 43, 57, 54, 56, 30, - 31, 62, 28, 32, 26, 59, 39, 60, 64, 40, - 29, 63, 1, 2, 3, 4, 5, 6, 7, 8, - 34, 52, 58, 0, 61 + 26, 45, 24, 20, 47, 18, 19, 38, 48, 18, + 19, 21, 27, 54, 28, 21, 30, 56, 28, 18, + 19, 39, 20, 50, 52, 21, 58, 55, 57, 53, + 42, 43, 18, 19, 63, 60, 44, 61, 21, 40, + 31, 64, 1, 2, 3, 4, 5, 6, 7, 8, + 32, 33, 65, 41, 34, 62, 36, 0, 37, 59 }; /* YYCHECK. */ const signed char SceneSetupParser::yycheck_[] = { - 3, 20, 20, 22, 13, 14, 16, 26, 13, 14, - 19, 18, 21, 20, 19, 0, 21, 13, 14, 13, - 14, 0, 15, 19, 43, 19, 8, 46, 47, 13, - 14, 21, 18, 17, 20, 54, 11, 56, 21, 12, - 5, 60, 4, 5, 6, 7, 8, 9, 10, 11, - 7, 43, 49, -1, 57 + 3, 21, 20, 16, 24, 13, 14, 0, 28, 13, + 14, 19, 18, 21, 20, 19, 18, 21, 20, 13, + 14, 0, 16, 15, 44, 19, 8, 47, 48, 44, + 13, 14, 13, 14, 21, 55, 19, 57, 19, 11, + 5, 61, 4, 5, 6, 7, 8, 9, 10, 11, + 13, 14, 21, 12, 17, 58, 7, -1, 8, 50 }; /* STOS_[STATE-NUM] -- The (internal number of the) accessing @@ -948,11 +956,11 @@ namespace lol { { 0, 4, 5, 6, 7, 8, 9, 10, 11, 23, 24, 25, 26, 27, 28, 29, 30, 32, 13, 14, - 19, 33, 20, 35, 35, 18, 20, 36, 18, 36, - 13, 14, 17, 37, 37, 16, 38, 0, 0, 24, - 27, 13, 14, 19, 33, 34, 33, 33, 31, 15, - 39, 33, 34, 21, 33, 21, 33, 8, 39, 33, - 33, 35, 21, 33, 21 + 16, 19, 33, 38, 20, 35, 35, 18, 20, 36, + 18, 36, 13, 14, 17, 37, 37, 38, 0, 0, + 24, 27, 13, 14, 19, 33, 34, 33, 33, 31, + 15, 39, 33, 34, 21, 33, 21, 33, 8, 39, + 33, 33, 35, 21, 33, 21 }; #if YYDEBUG @@ -972,10 +980,10 @@ namespace lol { SceneSetupParser::yyr1_[] = { 0, 22, 23, 24, 24, 25, 26, 26, 27, 27, - 27, 27, 28, 28, 29, 29, 29, 29, 31, 30, - 30, 30, 30, 32, 33, 33, 33, 33, 34, 34, - 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, - 39, 39 + 27, 27, 28, 28, 28, 29, 29, 29, 29, 31, + 30, 30, 30, 30, 32, 33, 33, 33, 33, 34, + 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, + 38, 39, 39 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ @@ -983,10 +991,10 @@ namespace lol { SceneSetupParser::yyr2_[] = { 0, 2, 2, 1, 2, 1, 1, 2, 1, 1, - 1, 1, 1, 2, 2, 2, 2, 2, 0, 5, - 2, 2, 2, 3, 1, 2, 1, 2, 1, 2, - 1, 2, 3, 5, 3, 6, 1, 1, 1, 1, - 1, 2 + 1, 1, 1, 2, 2, 2, 2, 2, 2, 0, + 5, 2, 2, 2, 3, 1, 2, 1, 2, 1, + 2, 1, 2, 3, 5, 3, 6, 1, 1, 1, + 1, 1, 2 }; #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE @@ -1014,15 +1022,15 @@ namespace lol { 23, 0, -1, 24, 0, -1, 25, -1, 25, 24, -1, 26, -1, 27, -1, 26, 27, -1, 28, -1, 29, -1, 30, -1, 32, -1, 4, -1, 4, 33, - -1, 5, 35, -1, 6, 35, -1, 7, 36, -1, - 7, 18, -1, -1, 8, 36, 31, 8, 35, -1, - 8, 18, -1, 9, 37, -1, 10, 37, -1, 11, - 38, 39, -1, 13, -1, 19, 33, -1, 14, -1, - 19, 34, -1, 14, -1, 19, 34, -1, 13, -1, - 19, 33, -1, 20, 33, 21, -1, 20, 33, 33, - 33, 21, -1, 20, 33, 21, -1, 20, 33, 33, - 33, 33, 21, -1, 17, -1, 14, -1, 13, -1, - 16, -1, 15, -1, 15, 39, -1 + -1, 4, 38, -1, 5, 35, -1, 6, 35, -1, + 7, 36, -1, 7, 18, -1, -1, 8, 36, 31, + 8, 35, -1, 8, 18, -1, 9, 37, -1, 10, + 37, -1, 11, 38, 39, -1, 13, -1, 19, 33, + -1, 14, -1, 19, 34, -1, 14, -1, 19, 34, + -1, 13, -1, 19, 33, -1, 20, 33, 21, -1, + 20, 33, 33, 33, 21, -1, 20, 33, 21, -1, + 20, 33, 33, 33, 33, 21, -1, 17, -1, 14, + -1, 13, -1, 16, -1, 15, -1, 15, 39, -1 }; /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in @@ -1031,10 +1039,10 @@ namespace lol { SceneSetupParser::yyprhs_[] = { 0, 0, 3, 6, 8, 11, 13, 15, 18, 20, - 22, 24, 26, 28, 31, 34, 37, 40, 43, 44, - 50, 53, 56, 59, 63, 65, 68, 70, 73, 75, - 78, 80, 83, 87, 93, 97, 104, 106, 108, 110, - 112, 114 + 22, 24, 26, 28, 31, 34, 37, 40, 43, 46, + 47, 53, 56, 59, 62, 66, 68, 71, 73, 76, + 78, 81, 83, 86, 90, 96, 100, 107, 109, 111, + 113, 115, 117 }; /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ @@ -1042,10 +1050,10 @@ namespace lol { SceneSetupParser::yyrline_[] = { 0, 91, 91, 95, 96, 100, 104, 105, 109, 110, - 111, 112, 116, 117, 122, 124, 126, 128, 136, 136, - 138, 140, 141, 145, 151, 152, 153, 154, 158, 159, - 160, 161, 166, 167, 176, 177, 182, 183, 184, 188, - 192, 196 + 111, 112, 116, 117, 119, 124, 126, 128, 130, 138, + 138, 140, 142, 143, 147, 153, 154, 155, 156, 160, + 161, 162, 163, 168, 169, 178, 179, 184, 185, 186, + 190, 194, 198 }; // Print the state stack on the debug stream. @@ -1121,10 +1129,10 @@ namespace lol { } const int SceneSetupParser::yyeof_ = 0; - const int SceneSetupParser::yylast_ = 54; + const int SceneSetupParser::yylast_ = 59; const int SceneSetupParser::yynnts_ = 18; const int SceneSetupParser::yyempty_ = -2; - const int SceneSetupParser::yyfinal_ = 37; + const int SceneSetupParser::yyfinal_ = 38; const int SceneSetupParser::yyterror_ = 1; const int SceneSetupParser::yyerrcode_ = 256; const int SceneSetupParser::yyntokens_ = 22; @@ -1136,11 +1144,11 @@ namespace lol { } // lol /* Line 1053 of lalr1.cc */ -#line 1140 "generated/scenesetup-parser.cpp" +#line 1148 "generated/scenesetup-parser.cpp" /* Line 1055 of lalr1.cc */ -#line 204 "scenesetup-parser.y" +#line 206 "scenesetup-parser.y" void lol::SceneSetupParser::error(const SceneSetupParser::location_type& l, diff --git a/test/generated/scenesetup-parser.output b/test/generated/scenesetup-parser.output index 07992d18..b20f0bcf 100644 --- a/test/generated/scenesetup-parser.output +++ b/test/generated/scenesetup-parser.output @@ -11,23 +11,23 @@ Terminals unused in grammar Rules useless in grammar - 41 iv3: '(' iv ')' - 42 | '(' iv iv iv ')' + 42 iv3: '(' iv ')' + 43 | '(' iv iv iv ')' Rules useless in parser due to conflicts - 27 iv: I_NUMBER - 28 | '-' iv - 29 | F_NUMBER - 30 | '-' fv + 28 iv: I_NUMBER + 29 | '-' iv + 30 | F_NUMBER + 31 | '-' fv State 12 conflicts: 8 shift/reduce -State 41 conflicts: 13 reduce/reduce State 42 conflicts: 13 reduce/reduce -State 51 conflicts: 13 reduce/reduce +State 43 conflicts: 13 reduce/reduce State 52 conflicts: 13 reduce/reduce +State 53 conflicts: 13 reduce/reduce Grammar @@ -51,70 +51,71 @@ Grammar 11 light_command: T_ADDLIGHT 12 | T_ADDLIGHT fv + 13 | T_ADDLIGHT svv - 13 setup_command: T_OBJPOSITION v3 - 14 | T_OBJLOOKAT v3 - 15 | T_OBJCOLOR v4 - 16 | T_OBJCOLOR COLOR + 14 setup_command: T_OBJPOSITION v3 + 15 | T_OBJLOOKAT v3 + 16 | T_OBJCOLOR v4 + 17 | T_OBJCOLOR COLOR - 17 $@1: /* empty */ + 18 $@1: /* empty */ - 18 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3 - 19 | T_CLEARCOLOR COLOR - 20 | T_SHOWGIZMO bv - 21 | T_SHOWLIGHT bv + 19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3 + 20 | T_CLEARCOLOR COLOR + 21 | T_SHOWGIZMO bv + 22 | T_SHOWLIGHT bv - 22 custom_command: T_CUSTOMCMD svv sv + 23 custom_command: T_CUSTOMCMD svv sv - 23 fv: F_NUMBER - 24 | '-' fv - 25 | I_NUMBER - 26 | '-' iv + 24 fv: F_NUMBER + 25 | '-' fv + 26 | I_NUMBER + 27 | '-' iv - 27 iv: I_NUMBER - 28 | '-' iv - 29 | F_NUMBER - 30 | '-' fv + 28 iv: I_NUMBER + 29 | '-' iv + 30 | F_NUMBER + 31 | '-' fv - 31 v3: '(' fv ')' - 32 | '(' fv fv fv ')' + 32 v3: '(' fv ')' + 33 | '(' fv fv fv ')' - 33 v4: '(' fv ')' - 34 | '(' fv fv fv fv ')' + 34 v4: '(' fv ')' + 35 | '(' fv fv fv fv ')' - 35 bv: BOOLEAN - 36 | I_NUMBER - 37 | F_NUMBER + 36 bv: BOOLEAN + 37 | I_NUMBER + 38 | F_NUMBER - 38 svv: STRING_VAR + 39 svv: STRING_VAR - 39 sv: STRING - 40 | STRING sv + 40 sv: STRING + 41 | STRING sv Terminals, with rules where they appear T_END (0) 0 1 -'(' (40) 31 32 33 34 -')' (41) 31 32 33 34 -'-' (45) 24 26 28 30 +'(' (40) 32 33 34 35 +')' (41) 32 33 34 35 +'-' (45) 25 27 29 31 error (256) T_COLOR (258) -T_ADDLIGHT (259) 11 12 -T_OBJPOSITION (260) 13 -T_OBJLOOKAT (261) 14 -T_OBJCOLOR (262) 15 16 -T_CLEARCOLOR (263) 18 19 -T_SHOWGIZMO (264) 20 -T_SHOWLIGHT (265) 21 -T_CUSTOMCMD (266) 22 +T_ADDLIGHT (259) 11 12 13 +T_OBJPOSITION (260) 14 +T_OBJLOOKAT (261) 15 +T_OBJCOLOR (262) 16 17 +T_CLEARCOLOR (263) 19 20 +T_SHOWGIZMO (264) 21 +T_SHOWLIGHT (265) 22 +T_CUSTOMCMD (266) 23 T_ERROR (267) -F_NUMBER (268) 23 29 37 -I_NUMBER (269) 25 27 36 -STRING (270) 39 40 -STRING_VAR (271) 38 -BOOLEAN (272) 35 -COLOR (273) 16 19 +F_NUMBER (268) 24 30 38 +I_NUMBER (269) 26 28 37 +STRING (270) 40 41 +STRING_VAR (271) 39 +BOOLEAN (272) 36 +COLOR (273) 17 20 Nonterminals, with rules where they appear @@ -132,29 +133,29 @@ sstp_command_list (26) sstp_command (27) on left: 7 8 9 10, on right: 5 6 light_command (28) - on left: 11 12, on right: 7 + on left: 11 12 13, on right: 7 setup_command (29) - on left: 13 14 15 16, on right: 8 + on left: 14 15 16 17, on right: 8 scene_command (30) - on left: 18 19 20 21, on right: 9 + on left: 19 20 21 22, on right: 9 $@1 (31) - on left: 17, on right: 18 + on left: 18, on right: 19 custom_command (32) - on left: 22, on right: 10 + on left: 23, on right: 10 fv (33) - on left: 23 24 25 26, on right: 12 24 30 31 32 33 34 + on left: 24 25 26 27, on right: 12 25 31 32 33 34 35 iv (34) - on left: 27 28 29 30, on right: 26 28 + on left: 28 29 30 31, on right: 27 29 v3 (35) - on left: 31 32, on right: 13 14 18 + on left: 32 33, on right: 14 15 19 v4 (36) - on left: 33 34, on right: 15 18 + on left: 34 35, on right: 16 19 bv (37) - on left: 35 36 37, on right: 20 21 + on left: 36 37 38, on right: 21 22 svv (38) - on left: 38, on right: 22 + on left: 39, on right: 13 23 sv (39) - on left: 39 40, on right: 22 40 + on left: 40 41, on right: 23 41 state 0 @@ -185,99 +186,102 @@ state 1 11 light_command: T_ADDLIGHT . 12 | T_ADDLIGHT . fv + 13 | T_ADDLIGHT . svv - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + STRING_VAR shift, and go to state 20 + '-' shift, and go to state 21 $default reduce using rule 11 (light_command) - fv go to state 21 + fv go to state 22 + svv go to state 23 state 2 - 13 setup_command: T_OBJPOSITION . v3 + 14 setup_command: T_OBJPOSITION . v3 - '(' shift, and go to state 22 + '(' shift, and go to state 24 - v3 go to state 23 + v3 go to state 25 state 3 - 14 setup_command: T_OBJLOOKAT . v3 + 15 setup_command: T_OBJLOOKAT . v3 - '(' shift, and go to state 22 + '(' shift, and go to state 24 - v3 go to state 24 + v3 go to state 26 state 4 - 15 setup_command: T_OBJCOLOR . v4 - 16 | T_OBJCOLOR . COLOR + 16 setup_command: T_OBJCOLOR . v4 + 17 | T_OBJCOLOR . COLOR - COLOR shift, and go to state 25 - '(' shift, and go to state 26 + COLOR shift, and go to state 27 + '(' shift, and go to state 28 - v4 go to state 27 + v4 go to state 29 state 5 - 18 scene_command: T_CLEARCOLOR . v4 $@1 T_CLEARCOLOR v3 - 19 | T_CLEARCOLOR . COLOR + 19 scene_command: T_CLEARCOLOR . v4 $@1 T_CLEARCOLOR v3 + 20 | T_CLEARCOLOR . COLOR - COLOR shift, and go to state 28 - '(' shift, and go to state 26 + COLOR shift, and go to state 30 + '(' shift, and go to state 28 - v4 go to state 29 + v4 go to state 31 state 6 - 20 scene_command: T_SHOWGIZMO . bv + 21 scene_command: T_SHOWGIZMO . bv - F_NUMBER shift, and go to state 30 - I_NUMBER shift, and go to state 31 - BOOLEAN shift, and go to state 32 + F_NUMBER shift, and go to state 32 + I_NUMBER shift, and go to state 33 + BOOLEAN shift, and go to state 34 - bv go to state 33 + bv go to state 35 state 7 - 21 scene_command: T_SHOWLIGHT . bv + 22 scene_command: T_SHOWLIGHT . bv - F_NUMBER shift, and go to state 30 - I_NUMBER shift, and go to state 31 - BOOLEAN shift, and go to state 32 + F_NUMBER shift, and go to state 32 + I_NUMBER shift, and go to state 33 + BOOLEAN shift, and go to state 34 - bv go to state 34 + bv go to state 36 state 8 - 22 custom_command: T_CUSTOMCMD . svv sv + 23 custom_command: T_CUSTOMCMD . svv sv - STRING_VAR shift, and go to state 35 + STRING_VAR shift, and go to state 20 - svv go to state 36 + svv go to state 37 state 9 0 $accept: sstp_description . T_END - T_END shift, and go to state 37 + T_END shift, and go to state 38 state 10 1 sstp_description: sstp_expression_list . T_END - T_END shift, and go to state 38 + T_END shift, and go to state 39 state 11 @@ -296,7 +300,7 @@ state 11 $default reduce using rule 2 (sstp_expression_list) - sstp_expression_list go to state 39 + sstp_expression_list go to state 40 sstp_expression go to state 11 sstp_command_list go to state 12 sstp_command go to state 13 @@ -330,7 +334,7 @@ state 12 T_CUSTOMCMD [reduce using rule 4 (sstp_expression)] $default reduce using rule 4 (sstp_expression) - sstp_command go to state 40 + sstp_command go to state 41 light_command go to state 14 setup_command go to state 15 scene_command go to state 16 @@ -374,338 +378,196 @@ state 17 state 18 - 23 fv: F_NUMBER . + 24 fv: F_NUMBER . - $default reduce using rule 23 (fv) + $default reduce using rule 24 (fv) state 19 - 25 fv: I_NUMBER . + 26 fv: I_NUMBER . - $default reduce using rule 25 (fv) + $default reduce using rule 26 (fv) state 20 - 24 fv: '-' . fv - 26 | '-' . iv - - F_NUMBER shift, and go to state 41 - I_NUMBER shift, and go to state 42 - '-' shift, and go to state 43 + 39 svv: STRING_VAR . - fv go to state 44 - iv go to state 45 + $default reduce using rule 39 (svv) state 21 - 12 light_command: T_ADDLIGHT fv . + 25 fv: '-' . fv + 27 | '-' . iv - $default reduce using rule 12 (light_command) + F_NUMBER shift, and go to state 42 + I_NUMBER shift, and go to state 43 + '-' shift, and go to state 44 + fv go to state 45 + iv go to state 46 -state 22 - 31 v3: '(' . fv ')' - 32 | '(' . fv fv fv ')' +state 22 - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + 12 light_command: T_ADDLIGHT fv . - fv go to state 46 + $default reduce using rule 12 (light_command) state 23 - 13 setup_command: T_OBJPOSITION v3 . + 13 light_command: T_ADDLIGHT svv . - $default reduce using rule 13 (setup_command) + $default reduce using rule 13 (light_command) state 24 - 14 setup_command: T_OBJLOOKAT v3 . + 32 v3: '(' . fv ')' + 33 | '(' . fv fv fv ')' - $default reduce using rule 14 (setup_command) + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + '-' shift, and go to state 21 + + fv go to state 47 state 25 - 16 setup_command: T_OBJCOLOR COLOR . + 14 setup_command: T_OBJPOSITION v3 . - $default reduce using rule 16 (setup_command) + $default reduce using rule 14 (setup_command) state 26 - 33 v4: '(' . fv ')' - 34 | '(' . fv fv fv fv ')' - - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + 15 setup_command: T_OBJLOOKAT v3 . - fv go to state 47 + $default reduce using rule 15 (setup_command) state 27 - 15 setup_command: T_OBJCOLOR v4 . + 17 setup_command: T_OBJCOLOR COLOR . - $default reduce using rule 15 (setup_command) + $default reduce using rule 17 (setup_command) state 28 - 19 scene_command: T_CLEARCOLOR COLOR . + 34 v4: '(' . fv ')' + 35 | '(' . fv fv fv fv ')' - $default reduce using rule 19 (scene_command) + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + '-' shift, and go to state 21 + fv go to state 48 -state 29 - 18 scene_command: T_CLEARCOLOR v4 . $@1 T_CLEARCOLOR v3 +state 29 - $default reduce using rule 17 ($@1) + 16 setup_command: T_OBJCOLOR v4 . - $@1 go to state 48 + $default reduce using rule 16 (setup_command) state 30 - 37 bv: F_NUMBER . + 20 scene_command: T_CLEARCOLOR COLOR . - $default reduce using rule 37 (bv) + $default reduce using rule 20 (scene_command) state 31 - 36 bv: I_NUMBER . + 19 scene_command: T_CLEARCOLOR v4 . $@1 T_CLEARCOLOR v3 - $default reduce using rule 36 (bv) + $default reduce using rule 18 ($@1) + + $@1 go to state 49 state 32 - 35 bv: BOOLEAN . + 38 bv: F_NUMBER . - $default reduce using rule 35 (bv) + $default reduce using rule 38 (bv) state 33 - 20 scene_command: T_SHOWGIZMO bv . + 37 bv: I_NUMBER . - $default reduce using rule 20 (scene_command) + $default reduce using rule 37 (bv) state 34 - 21 scene_command: T_SHOWLIGHT bv . + 36 bv: BOOLEAN . - $default reduce using rule 21 (scene_command) + $default reduce using rule 36 (bv) state 35 - 38 svv: STRING_VAR . + 21 scene_command: T_SHOWGIZMO bv . - $default reduce using rule 38 (svv) + $default reduce using rule 21 (scene_command) state 36 - 22 custom_command: T_CUSTOMCMD svv . sv + 22 scene_command: T_SHOWLIGHT bv . - STRING shift, and go to state 49 - - sv go to state 50 + $default reduce using rule 22 (scene_command) state 37 - 0 $accept: sstp_description T_END . + 23 custom_command: T_CUSTOMCMD svv . sv - $default accept + STRING shift, and go to state 50 + + sv go to state 51 state 38 - 1 sstp_description: sstp_expression_list T_END . + 0 $accept: sstp_description T_END . - $default reduce using rule 1 (sstp_description) + $default accept state 39 - 3 sstp_expression_list: sstp_expression sstp_expression_list . + 1 sstp_description: sstp_expression_list T_END . - $default reduce using rule 3 (sstp_expression_list) + $default reduce using rule 1 (sstp_description) state 40 - 6 sstp_command_list: sstp_command_list sstp_command . + 3 sstp_expression_list: sstp_expression sstp_expression_list . - $default reduce using rule 6 (sstp_command_list) + $default reduce using rule 3 (sstp_expression_list) state 41 - 23 fv: F_NUMBER . - 29 iv: F_NUMBER . + 6 sstp_command_list: sstp_command_list sstp_command . - T_END reduce using rule 23 (fv) - T_END [reduce using rule 29 (iv)] - T_ADDLIGHT reduce using rule 23 (fv) - T_ADDLIGHT [reduce using rule 29 (iv)] - T_OBJPOSITION reduce using rule 23 (fv) - T_OBJPOSITION [reduce using rule 29 (iv)] - T_OBJLOOKAT reduce using rule 23 (fv) - T_OBJLOOKAT [reduce using rule 29 (iv)] - T_OBJCOLOR reduce using rule 23 (fv) - T_OBJCOLOR [reduce using rule 29 (iv)] - T_CLEARCOLOR reduce using rule 23 (fv) - T_CLEARCOLOR [reduce using rule 29 (iv)] - T_SHOWGIZMO reduce using rule 23 (fv) - T_SHOWGIZMO [reduce using rule 29 (iv)] - T_SHOWLIGHT reduce using rule 23 (fv) - T_SHOWLIGHT [reduce using rule 29 (iv)] - T_CUSTOMCMD reduce using rule 23 (fv) - T_CUSTOMCMD [reduce using rule 29 (iv)] - F_NUMBER reduce using rule 23 (fv) - F_NUMBER [reduce using rule 29 (iv)] - I_NUMBER reduce using rule 23 (fv) - I_NUMBER [reduce using rule 29 (iv)] - '-' reduce using rule 23 (fv) - '-' [reduce using rule 29 (iv)] - ')' reduce using rule 23 (fv) - ')' [reduce using rule 29 (iv)] - $default reduce using rule 23 (fv) + $default reduce using rule 6 (sstp_command_list) state 42 - 25 fv: I_NUMBER . - 27 iv: I_NUMBER . - - T_END reduce using rule 25 (fv) - T_END [reduce using rule 27 (iv)] - T_ADDLIGHT reduce using rule 25 (fv) - T_ADDLIGHT [reduce using rule 27 (iv)] - T_OBJPOSITION reduce using rule 25 (fv) - T_OBJPOSITION [reduce using rule 27 (iv)] - T_OBJLOOKAT reduce using rule 25 (fv) - T_OBJLOOKAT [reduce using rule 27 (iv)] - T_OBJCOLOR reduce using rule 25 (fv) - T_OBJCOLOR [reduce using rule 27 (iv)] - T_CLEARCOLOR reduce using rule 25 (fv) - T_CLEARCOLOR [reduce using rule 27 (iv)] - T_SHOWGIZMO reduce using rule 25 (fv) - T_SHOWGIZMO [reduce using rule 27 (iv)] - T_SHOWLIGHT reduce using rule 25 (fv) - T_SHOWLIGHT [reduce using rule 27 (iv)] - T_CUSTOMCMD reduce using rule 25 (fv) - T_CUSTOMCMD [reduce using rule 27 (iv)] - F_NUMBER reduce using rule 25 (fv) - F_NUMBER [reduce using rule 27 (iv)] - I_NUMBER reduce using rule 25 (fv) - I_NUMBER [reduce using rule 27 (iv)] - '-' reduce using rule 25 (fv) - '-' [reduce using rule 27 (iv)] - ')' reduce using rule 25 (fv) - ')' [reduce using rule 27 (iv)] - $default reduce using rule 25 (fv) - - -state 43 - - 24 fv: '-' . fv - 26 | '-' . iv - 28 iv: '-' . iv - 30 | '-' . fv - - F_NUMBER shift, and go to state 41 - I_NUMBER shift, and go to state 42 - '-' shift, and go to state 43 - - fv go to state 51 - iv go to state 52 - - -state 44 - - 24 fv: '-' fv . - - $default reduce using rule 24 (fv) - - -state 45 - - 26 fv: '-' iv . - - $default reduce using rule 26 (fv) - - -state 46 - - 31 v3: '(' fv . ')' - 32 | '(' fv . fv fv ')' - - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 - ')' shift, and go to state 53 - - fv go to state 54 - - -state 47 - - 33 v4: '(' fv . ')' - 34 | '(' fv . fv fv fv ')' - - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 - ')' shift, and go to state 55 - - fv go to state 56 - - -state 48 - - 18 scene_command: T_CLEARCOLOR v4 $@1 . T_CLEARCOLOR v3 - - T_CLEARCOLOR shift, and go to state 57 - - -state 49 - - 39 sv: STRING . - 40 | STRING . sv - - STRING shift, and go to state 49 - - $default reduce using rule 39 (sv) - - sv go to state 58 - - -state 50 - - 22 custom_command: T_CUSTOMCMD svv sv . - - $default reduce using rule 22 (custom_command) - - -state 51 - - 24 fv: '-' fv . - 30 iv: '-' fv . + 24 fv: F_NUMBER . + 30 iv: F_NUMBER . T_END reduce using rule 24 (fv) T_END [reduce using rule 30 (iv)] @@ -736,10 +598,10 @@ state 51 $default reduce using rule 24 (fv) -state 52 +state 43 - 26 fv: '-' iv . - 28 iv: '-' iv . + 26 fv: I_NUMBER . + 28 iv: I_NUMBER . T_END reduce using rule 26 (fv) T_END [reduce using rule 28 (iv)] @@ -770,99 +632,248 @@ state 52 $default reduce using rule 26 (fv) -state 53 +state 44 - 31 v3: '(' fv ')' . + 25 fv: '-' . fv + 27 | '-' . iv + 29 iv: '-' . iv + 31 | '-' . fv - $default reduce using rule 31 (v3) + F_NUMBER shift, and go to state 42 + I_NUMBER shift, and go to state 43 + '-' shift, and go to state 44 + fv go to state 52 + iv go to state 53 -state 54 - 32 v3: '(' fv fv . fv ')' +state 45 + + 25 fv: '-' fv . + + $default reduce using rule 25 (fv) + + +state 46 + + 27 fv: '-' iv . + + $default reduce using rule 27 (fv) + + +state 47 + + 32 v3: '(' fv . ')' + 33 | '(' fv . fv fv ')' F_NUMBER shift, and go to state 18 I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + '-' shift, and go to state 21 + ')' shift, and go to state 54 - fv go to state 59 + fv go to state 55 -state 55 +state 48 + + 34 v4: '(' fv . ')' + 35 | '(' fv . fv fv fv ')' - 33 v4: '(' fv ')' . + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + '-' shift, and go to state 21 + ')' shift, and go to state 56 - $default reduce using rule 33 (v4) + fv go to state 57 -state 56 +state 49 + + 19 scene_command: T_CLEARCOLOR v4 $@1 . T_CLEARCOLOR v3 + + T_CLEARCOLOR shift, and go to state 58 + + +state 50 + + 40 sv: STRING . + 41 | STRING . sv + + STRING shift, and go to state 50 + + $default reduce using rule 40 (sv) + + sv go to state 59 + + +state 51 + + 23 custom_command: T_CUSTOMCMD svv sv . + + $default reduce using rule 23 (custom_command) + + +state 52 + + 25 fv: '-' fv . + 31 iv: '-' fv . + + T_END reduce using rule 25 (fv) + T_END [reduce using rule 31 (iv)] + T_ADDLIGHT reduce using rule 25 (fv) + T_ADDLIGHT [reduce using rule 31 (iv)] + T_OBJPOSITION reduce using rule 25 (fv) + T_OBJPOSITION [reduce using rule 31 (iv)] + T_OBJLOOKAT reduce using rule 25 (fv) + T_OBJLOOKAT [reduce using rule 31 (iv)] + T_OBJCOLOR reduce using rule 25 (fv) + T_OBJCOLOR [reduce using rule 31 (iv)] + T_CLEARCOLOR reduce using rule 25 (fv) + T_CLEARCOLOR [reduce using rule 31 (iv)] + T_SHOWGIZMO reduce using rule 25 (fv) + T_SHOWGIZMO [reduce using rule 31 (iv)] + T_SHOWLIGHT reduce using rule 25 (fv) + T_SHOWLIGHT [reduce using rule 31 (iv)] + T_CUSTOMCMD reduce using rule 25 (fv) + T_CUSTOMCMD [reduce using rule 31 (iv)] + F_NUMBER reduce using rule 25 (fv) + F_NUMBER [reduce using rule 31 (iv)] + I_NUMBER reduce using rule 25 (fv) + I_NUMBER [reduce using rule 31 (iv)] + '-' reduce using rule 25 (fv) + '-' [reduce using rule 31 (iv)] + ')' reduce using rule 25 (fv) + ')' [reduce using rule 31 (iv)] + $default reduce using rule 25 (fv) + + +state 53 + + 27 fv: '-' iv . + 29 iv: '-' iv . + + T_END reduce using rule 27 (fv) + T_END [reduce using rule 29 (iv)] + T_ADDLIGHT reduce using rule 27 (fv) + T_ADDLIGHT [reduce using rule 29 (iv)] + T_OBJPOSITION reduce using rule 27 (fv) + T_OBJPOSITION [reduce using rule 29 (iv)] + T_OBJLOOKAT reduce using rule 27 (fv) + T_OBJLOOKAT [reduce using rule 29 (iv)] + T_OBJCOLOR reduce using rule 27 (fv) + T_OBJCOLOR [reduce using rule 29 (iv)] + T_CLEARCOLOR reduce using rule 27 (fv) + T_CLEARCOLOR [reduce using rule 29 (iv)] + T_SHOWGIZMO reduce using rule 27 (fv) + T_SHOWGIZMO [reduce using rule 29 (iv)] + T_SHOWLIGHT reduce using rule 27 (fv) + T_SHOWLIGHT [reduce using rule 29 (iv)] + T_CUSTOMCMD reduce using rule 27 (fv) + T_CUSTOMCMD [reduce using rule 29 (iv)] + F_NUMBER reduce using rule 27 (fv) + F_NUMBER [reduce using rule 29 (iv)] + I_NUMBER reduce using rule 27 (fv) + I_NUMBER [reduce using rule 29 (iv)] + '-' reduce using rule 27 (fv) + '-' [reduce using rule 29 (iv)] + ')' reduce using rule 27 (fv) + ')' [reduce using rule 29 (iv)] + $default reduce using rule 27 (fv) - 34 v4: '(' fv fv . fv fv ')' + +state 54 + + 32 v3: '(' fv ')' . + + $default reduce using rule 32 (v3) + + +state 55 + + 33 v3: '(' fv fv . fv ')' F_NUMBER shift, and go to state 18 I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + '-' shift, and go to state 21 fv go to state 60 +state 56 + + 34 v4: '(' fv ')' . + + $default reduce using rule 34 (v4) + + state 57 - 18 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR . v3 + 35 v4: '(' fv fv . fv fv ')' - '(' shift, and go to state 22 + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + '-' shift, and go to state 21 - v3 go to state 61 + fv go to state 61 state 58 - 40 sv: STRING sv . + 19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR . v3 - $default reduce using rule 40 (sv) + '(' shift, and go to state 24 + + v3 go to state 62 state 59 - 32 v3: '(' fv fv fv . ')' + 41 sv: STRING sv . - ')' shift, and go to state 62 + $default reduce using rule 41 (sv) state 60 - 34 v4: '(' fv fv fv . fv ')' - - F_NUMBER shift, and go to state 18 - I_NUMBER shift, and go to state 19 - '-' shift, and go to state 20 + 33 v3: '(' fv fv fv . ')' - fv go to state 63 + ')' shift, and go to state 63 state 61 - 18 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3 . + 35 v4: '(' fv fv fv . fv ')' + + F_NUMBER shift, and go to state 18 + I_NUMBER shift, and go to state 19 + '-' shift, and go to state 21 - $default reduce using rule 18 (scene_command) + fv go to state 64 state 62 - 32 v3: '(' fv fv fv ')' . + 19 scene_command: T_CLEARCOLOR v4 $@1 T_CLEARCOLOR v3 . - $default reduce using rule 32 (v3) + $default reduce using rule 19 (scene_command) state 63 - 34 v4: '(' fv fv fv fv . ')' + 33 v3: '(' fv fv fv ')' . - ')' shift, and go to state 64 + $default reduce using rule 33 (v3) state 64 - 34 v4: '(' fv fv fv fv ')' . + 35 v4: '(' fv fv fv fv . ')' - $default reduce using rule 34 (v4) + ')' shift, and go to state 65 + + +state 65 + + 35 v4: '(' fv fv fv fv ')' . + + $default reduce using rule 35 (v4) diff --git a/test/meshviewer.cpp b/test/meshviewer.cpp index 1b4d5314..d6ed4517 100644 --- a/test/meshviewer.cpp +++ b/test/meshviewer.cpp @@ -39,9 +39,9 @@ static int const TEXTURE_WIDTH = 256; #define WIDTH ((float)Video::GetSize().x) #define HEIGHT ((float)Video::GetSize().y) #define SCREEN_W (10.f / WIDTH) -#define SCREEN_LIMIT 1.4f #define RATIO_HW (HEIGHT / WIDTH) #define RATIO_WH (WIDTH / HEIGHT) +#define SCREEN_LIMIT 1.4f #define RESET_TIMER .2f #define ROT_SPEED vec2(50.f) @@ -140,6 +140,34 @@ struct LightData vec4 m_col; }; +class TargetCamera +{ +public: + void EmptyTargets() { m_targets.Empty(); } + void AddTarget(vec3 new_target) { m_targets << new_target; } + //This considers the box usage A to B as top-left to bottom-right + void AddTarget(box3 new_target) + { + vec3 base_off = .5f * (new_target.B - new_target.A); + vec3 base_pos = new_target.A + base_off; + int pass = 0; + while (pass < 3) + { + int mask = 3 - max(0, pass - 1); + while (mask-- > 0) + { + ivec3 A((pass == 1 || (pass == 2 && mask == 1))?(1):(0)); + ivec3 B((pass == 2)?(1):(0)); B[mask] = 1; + vec3 offset = vec3(ivec3((int)(!A.x != !B.x), (int)(!A.y != !B.y), (int)(!A.z != !B.z))); + AddTarget(base_pos + offset * base_off * 2.f - base_off); + } + pass++; + } + } + + Array m_targets; +}; + class MeshViewer : public WorldEntity { public: @@ -193,7 +221,7 @@ public: m_hist_scale_speed = vec2(.0f); m_mat_prev = mat4(quat::fromeuler_xyz(vec3::zero)); - m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); + m_mat = mat4::translate(vec3(0.f));//mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); m_build_timer = 0.1f; m_build_time = -1.f; @@ -312,7 +340,7 @@ public: for (int i = 0; i < m_ssetup->m_lights.Count(); ++i) { m_light_datas << LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor()); - m_ssetup->m_lights[i]->SetPosition(vec4(vec3::zero, m_ssetup->m_lights[i]->GetPosition().w)); + m_ssetup->m_lights[i]->SetPosition(vec3::zero); m_ssetup->m_lights[i]->SetColor(vec4::zero); } } @@ -358,13 +386,13 @@ public: //Update light position & damping for (int i = 0; i < m_ssetup->m_lights.Count(); ++i) { - vec3 pos = (m_mat * inverse(m_mat_prev) * vec4(m_ssetup->m_lights[i]->GetPosition().xyz, 1.f)).xyz; + vec3 pos = (m_mat * inverse(m_mat_prev) * vec4(m_ssetup->m_lights[i]->GetPosition(), 1.f)).xyz; vec3 tgt = (m_mat * vec4(m_light_datas[i].m_pos, 1.f)).xyz; vec3 new_pos = damp(pos, tgt, .3f, seconds); vec4 new_col = damp(m_ssetup->m_lights[i]->GetColor(), m_light_datas[i].m_col, .3f, seconds); - m_ssetup->m_lights[i]->SetPosition(vec4(new_pos, m_ssetup->m_lights[i]->GetPosition().w)); + m_ssetup->m_lights[i]->SetPosition(new_pos); m_ssetup->m_lights[i]->SetColor(new_col); } @@ -382,7 +410,7 @@ public: { tmpv += vec2(AxisValue(MSEX_CAM_Y), AxisValue(MSEX_CAM_X)); if (KeyDown(MSE_CAM_ROT)) - tmpv *= 6.f; + tmpv *= vec2(1.f, 1.f) * 6.f; if (KeyDown(MSE_CAM_POS)) tmpv *= vec2(1.f, -1.f) * 3.f; if (KeyDown(MSE_CAM_FOV)) @@ -394,7 +422,7 @@ public: #endif //NO_NACL_EM_INPUT //Base data - vec2 rot = (!is_pos && !is_fov)?(tmpv):(vec2(.0f)); rot = vec2(rot.x, rot.y); + vec2 rot = (!is_pos && !is_fov)?(tmpv):(vec2(.0f)); rot = vec2(rot.x, -rot.y); vec2 pos = ( is_pos && !is_fov)?(tmpv):(vec2(.0f)); pos = -vec2(pos.y, pos.x); vec2 fov = (!is_pos && is_fov )?(tmpv):(vec2(.0f)); fov = vec2(-fov.x, fov.y); vec2 hsc = (is_hsc)?(vec2(0.f)):(vec2(0.f)); @@ -460,13 +488,22 @@ public: //Mesh mat calculation m_mat_prev = m_mat; - m_mat = mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); + m_mat = mat4::translate(vec3(0.f));//mat4(quat::fromeuler_xyz(vec3(m_rot_mesh, .0f))); //Target List Setup - Array target_list; + TargetCamera tc; if (m_meshes.Count() && m_mesh_id >= 0) for (int i = 0; i < m_meshes[m_mesh_id].m1->GetVertexCount(); i++) - target_list << (m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz; + tc.AddTarget((m_mat * mat4::translate(m_meshes[m_mesh_id].m1->GetVertexLocation(i))).v3.xyz); + tc.AddTarget(box3(vec3::zero, vec3::one)); + for (int k = 0; k < m_ssetup->m_lights.Count() && m_ssetup->m_show_lights; ++k) + { + vec3 light_pos = m_ssetup->m_lights[k]->GetPosition(); + mat4 world_cam = m_camera->GetView(); + light_pos = (inverse(world_cam) * vec4((world_cam * vec4(light_pos, 1.0f)).xyz * vec3::axis_z, 1.0f)).xyz; + tc.AddTarget(box3(vec3::mone, vec3::one) + light_pos * + ((m_ssetup->m_lights[k]->GetType() == LightType::Directional)?(-1.f):(1.f))); + } //-- //Update mesh screen location - Get the Min/Max needed @@ -479,9 +516,9 @@ public: mat4 cam_screen = m_camera->GetProjection(); //target on-screen computation - for (int i = 0; i < target_list.Count(); i++) + for (int i = 0; i < tc.m_targets.Count(); i++) { - vec3 obj_loc = target_list[i]; + vec3 obj_loc = tc.m_targets[i]; { //Debug::DrawBox(obj_loc - vec3(4.f), obj_loc + vec3(4.f), vec4(1.f, 0.f, 0.f, 1.f)); mat4 target_mx = mat4::translate(obj_loc); @@ -504,21 +541,25 @@ public: cam_factor += 1.f; } } - float screen_ratio = max(max(lol::abs(local_min_max[0].x), lol::abs(local_min_max[0].y)), - max(lol::abs(local_min_max[1].x), lol::abs(local_min_max[1].y))); - float scale_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)), + float screen_ratio = max(max(lol::abs(screen_min_max[0].x), lol::abs(screen_min_max[0].y)), max(lol::abs(screen_min_max[1].x), lol::abs(screen_min_max[1].y))); + float z_dist = length(m_camera->m_position) + max(local_min_max[0].z, local_min_max[1].z); + vec2 screen_offset = vec2(0.f, -(screen_min_max[1].y + screen_min_max[0].y) * .5f); m_screen_offset = damp(m_screen_offset, screen_offset, .9f, seconds); - float z_pos = (inverse(world_cam) * mat4::translate(vec3(0.f, 0.f, max(local_min_max[0].z, local_min_max[1].z)))).v3.z; if (cam_factor > 0.f) { vec2 new_screen_scale = m_camera->GetScreenScale(); - m_camera->SetScreenScale(max(vec2(0.001f), new_screen_scale * ((1.0f + lol::max(0.f, m_zoom_mesh)) / (scale_ratio * (1.f + lol::max(0.f, -m_zoom_mesh)) * SCREEN_LIMIT)))); - m_camera->SetPosition(vec3(vec2::zero, damp(m_camera->m_position.z, z_pos + screen_ratio * 2.f, .1f, seconds)), true); + float zoom_in = 1.f + lol::max(0.f, m_zoom_mesh); + float zoom_out = 1.f + lol::max(0.f, -m_zoom_mesh); + m_camera->SetScreenScale(max(vec2(0.001f), ((new_screen_scale * zoom_in) / (screen_ratio * zoom_out * SCREEN_LIMIT)))); m_camera->SetFov(m_fov_mesh); - m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio * (1.f + lol::max(0.f, -m_zoom_mesh))), 1.2f, seconds)); + m_camera->SetScreenInfos(damp(m_camera->GetScreenSize(), max(1.f, screen_ratio * zoom_out), 1.2f, seconds)); + + vec3 posz = ((mat4::rotate(m_rot_mesh.y, vec3::axis_y) * mat4::rotate(-m_rot_mesh.x, vec3::axis_x) * vec4::axis_z)).xyz; + vec3 newpos = posz * damp(length(m_camera->m_position), z_dist * 1.2f, .1f, seconds); + m_camera->SetView(newpos, vec3(0.f), vec3::axis_y); } //-- @@ -537,7 +578,7 @@ public: //Store current light datas, in World Array light_datas; for (int i = 0; i < m_ssetup->m_lights.Count(); ++i) - light_datas << LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor()); + light_datas << LightData(m_ssetup->m_lights[i]->GetPosition(), m_ssetup->m_lights[i]->GetColor()); if (m_ssetup) delete(m_ssetup); @@ -549,7 +590,7 @@ public: for (int i = 0; i < m_ssetup->m_lights.Count(); ++i) { //Store local dst in current m_ld - LightData ltmp = LightData(m_ssetup->m_lights[i]->GetPosition().xyz, m_ssetup->m_lights[i]->GetColor()); + LightData ltmp = LightData(m_ssetup->m_lights[i]->GetPosition(), m_ssetup->m_lights[i]->GetColor()); if (i < m_light_datas.Count()) m_light_datas[i] = ltmp; else @@ -564,7 +605,7 @@ public: } //Restore old light datas in new lights - m_ssetup->m_lights[i]->SetPosition(vec4(loc, m_ssetup->m_lights[i]->GetPosition().w)); + m_ssetup->m_lights[i]->SetPosition(loc); m_ssetup->m_lights[i]->SetColor(col); } } @@ -798,13 +839,13 @@ public: for (int k = 0; k < m_ssetup->m_lights.Count(); ++k) { Light* ltmp = m_ssetup->m_lights[k]; - mat4 world = mat4::translate(ltmp->GetPosition().xyz); + mat4 world = mat4::translate(ltmp->GetPosition()); mat4 local = mat4::translate((inverse(m_mat) * world).v3.xyz); //dir light - if (ltmp->GetPosition().w == 0.f) + if (ltmp->GetType() == LightType::Directional) { m_gizmos[GZ_LightPos]->Render(m_mat * inverse(local)); - m_gizmos[GZ_LightDir]->Render(inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition().xyz, vec3::axis_y))); + m_gizmos[GZ_LightDir]->Render(inverse(world) * inverse(mat4::lookat(vec3::zero, -ltmp->GetPosition(), vec3::axis_y))); } else //point light { diff --git a/test/scenesetup-parser.y b/test/scenesetup-parser.y index 5b7d38bf..3387bf35 100644 --- a/test/scenesetup-parser.y +++ b/test/scenesetup-parser.y @@ -115,12 +115,14 @@ sstp_command: light_command: T_ADDLIGHT { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; } | T_ADDLIGHT fv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; - uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3::zero, $2)); } + uc.m_sstp.m_lights.Last()->SetType(LightType($2)); } + | T_ADDLIGHT svv { uc.m_sstp.m_lights << new Light(); uc.m_last_cmd = "ADDLIGHT"; + uc.m_sstp.m_lights.Last()->SetType(FindValue($2)); } ; setup_command: T_OBJPOSITION v3 { if (uc.m_last_cmd == "ADDLIGHT") - uc.m_sstp.m_lights.Last()->SetPosition(vec4(vec3($2[0], $2[1], $2[2]), uc.m_sstp.m_lights.Last()->GetPosition().w)); } + uc.m_sstp.m_lights.Last()->SetPosition(vec3($2[0], $2[1], $2[2])); } | T_OBJLOOKAT v3 { if (uc.m_last_cmd == "ADDLIGHT") { /* */ } } | T_OBJCOLOR v4 { if (uc.m_last_cmd == "ADDLIGHT")