浏览代码

easymesh: motherfucking planetary gears demo.

legacy
Sam Hocevar sam 12 年前
父节点
当前提交
7fa661a2fd
共有 10 个文件被更改,包括 580 次插入481 次删除
  1. +7
    -5
      src/easymesh/easymesh-parser.y
  2. +0
    -4
      src/easymesh/easymesh.cpp
  3. +306
    -184
      src/generated/easymesh-parser.cpp
  4. +20
    -47
      src/generated/easymesh-parser.h
  5. +2
    -2
      src/generated/location.hh
  6. +176
    -77
      src/generated/lolfx-parser.cpp
  7. +19
    -46
      src/generated/lolfx-parser.h
  8. +2
    -2
      src/generated/position.hh
  9. +4
    -4
      src/generated/stack.hh
  10. +44
    -110
      tutorial/05_easymesh.cpp

+ 7
- 5
src/easymesh/easymesh-parser.y 查看文件

@@ -37,7 +37,7 @@
float fval;
/* Can't use uin32_t here for some reason */
unsigned u32val;
struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args;
struct { float f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; } args;
}

%start mesh_description
@@ -60,7 +60,7 @@
%token <u32val> COLOR

%type <fval> number
%type <args> args1 args2 args3 args4 args5 args6 args7 args8
%type <args> args1 args2 args3 args4 args5 args6 args7 args8 args9 args10

%{
#include "easymesh/easymesh-compiler.h"
@@ -157,9 +157,9 @@ primitive_command:
| T_DISC args3 { mc.m_mesh.AppendDisc((int)$2.f0, $2.f1, (int)$2.f2); }
| T_TRIANGLE args2 { mc.m_mesh.AppendSimpleTriangle($2.f0, (int)$2.f1); }
| T_QUAD args2 { mc.m_mesh.AppendSimpleQuad($2.f0, (int)$2.f1); }
| T_COG args8 { mc.m_mesh.AppendCog((int)$2.f0, $2.f1,
$2.f2 / 2, $2.f3 / 2, $2.f2, $2.f3, $2.f4,
$2.f5, $2.f6, (int)$2.f7); }
| T_COG args10 { mc.m_mesh.AppendCog((int)$2.f0, $2.f1,
$2.f2, $2.f3, $2.f4, $2.f5, $2.f6,
$2.f7, $2.f8, (int)$2.f9); }
;

args1: number { $$.f0 = $1; } ;
@@ -170,6 +170,8 @@ args5: args4 number { $$ = $1; $$.f4 = $2; } ;
args6: args5 number { $$ = $1; $$.f5 = $2; } ;
args7: args6 number { $$ = $1; $$.f6 = $2; } ;
args8: args7 number { $$ = $1; $$.f7 = $2; } ;
args9: args8 number { $$ = $1; $$.f8 = $2; } ;
args10: args9 number { $$ = $1; $$.f9 = $2; } ;

number:
NUMBER { $$ = $1; }


+ 0
- 4
src/easymesh/easymesh.cpp 查看文件

@@ -791,11 +791,7 @@ void EasyMesh::AppendCog(int nbsides, float h, float r10, float r20,

/* FIXME: enforce this some other way */
if (r12 < 0)
{
r10 *= 2.5;
r20 *= 2.5;
h = -h;
}

mat3 rotmat = mat3::rotate(180.0f / nbsides, 0.f, 1.f, 0.f);
mat3 smat1 = mat3::rotate(sidemul * 180.0f / nbsides, 0.f, 1.f, 0.f);


+ 306
- 184
src/generated/easymesh-parser.cpp
文件差异内容过多而无法显示
查看文件


+ 20
- 47
src/generated/easymesh-parser.h 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Skeleton interface for Bison LALR(1) parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,20 +40,6 @@
#include <string>
#include <iostream>
#include "stack.hh"


namespace lol {

/* Line 34 of lalr1.cc */
#line 49 "generated/easymesh-parser.h"
class position;
class location;

} // lol

/* Line 34 of lalr1.cc */
#line 56 "generated/easymesh-parser.h"

#include "location.hh"

/* Enabling traces. */
@@ -74,30 +60,11 @@ namespace lol {
# define YYTOKEN_TABLE 0
#endif

/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).begin = (Rhs)[1].begin; \
(Current).end = (Rhs)[N].end; \
} \
else \
{ \
(Current).begin = (Current).end = (Rhs)[0].end; \
} \
} while (false)
#endif


namespace lol {

/* Line 34 of lalr1.cc */
#line 101 "generated/easymesh-parser.h"
/* Line 35 of lalr1.cc */
#line 68 "generated/easymesh-parser.h"

/// A Bison parser.
class EasyMeshParser
@@ -108,18 +75,18 @@ namespace lol {
union semantic_type
{

/* Line 34 of lalr1.cc */
/* Line 35 of lalr1.cc */
#line 36 "easymesh/easymesh-parser.y"

float fval;
/* Can't use uin32_t here for some reason */
unsigned u32val;
struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args;
struct { float f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; } args;



/* Line 34 of lalr1.cc */
#line 123 "generated/easymesh-parser.h"
/* Line 35 of lalr1.cc */
#line 90 "generated/easymesh-parser.h"
};
#else
typedef YYSTYPE semantic_type;
@@ -242,6 +209,14 @@ namespace lol {
/// The location stack.
location_stack_type yylocation_stack_;

/// Whether the given \c yypact_ value indicates a defaulted state.
/// \param yyvalue the value to check
static bool yy_pact_value_is_default_ (int yyvalue);

/// Whether the given \c yytable_ value indicates a syntax error.
/// \param yyvalue the value to check
static bool yy_table_value_is_error_ (int yyvalue);

/// Internal symbol numbers.
typedef unsigned char token_number_type;
/* Tables. */
@@ -249,7 +224,7 @@ namespace lol {
static const signed char yypact_[];
static const signed char yypact_ninf_;

/// For a state, default rule to reduce.
/// For a state, default reduction number.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const unsigned char yydefact_[];
@@ -280,10 +255,8 @@ namespace lol {
static const char* const yytname_[];
#endif

#if YYERROR_VERBOSE
/// Convert the symbol name \a n to a form suitable for a diagnostic.
virtual std::string yytnamerr_ (const char *n);
#endif
static std::string yytnamerr_ (const char *n);

#if YYDEBUG
/// A type to store symbol numbers and -1.
@@ -341,8 +314,8 @@ namespace lol {

} // lol

/* Line 34 of lalr1.cc */
#line 346 "generated/easymesh-parser.h"
/* Line 35 of lalr1.cc */
#line 319 "generated/easymesh-parser.h"





+ 2
- 2
src/generated/location.hh 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Locations for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by


+ 176
- 77
src/generated/lolfx-parser.cpp 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Skeleton implementation for Bison LALR(1) parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@

/* First part of user declarations. */

/* Line 310 of lalr1.cc */
/* Line 293 of lalr1.cc */
#line 1 "gpu/lolfx-parser.y"

//
@@ -58,7 +58,7 @@



/* Line 310 of lalr1.cc */
/* Line 293 of lalr1.cc */
#line 63 "generated/lolfx-parser.cpp"


@@ -66,7 +66,7 @@

/* User implementation prologue. */

/* Line 316 of lalr1.cc */
/* Line 299 of lalr1.cc */
#line 241 "gpu/lolfx-parser.y"

#include "gpu/lolfx-compiler.h"
@@ -75,7 +75,7 @@
#define yylex mc.m_lexer->lex


/* Line 316 of lalr1.cc */
/* Line 299 of lalr1.cc */
#line 80 "generated/lolfx-parser.cpp"

#ifndef YY_
@@ -90,6 +90,26 @@
# endif
#endif

/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */

#define YYRHSLOC(Rhs, K) ((Rhs)[K])
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do \
if (N) \
{ \
(Current).begin = YYRHSLOC (Rhs, 1).begin; \
(Current).end = YYRHSLOC (Rhs, N).end; \
} \
else \
{ \
(Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
} \
while (false)
#endif

/* Suppress unused-variable warnings by "using" E. */
#define YYUSE(e) ((void) (e))

@@ -141,9 +161,8 @@ do { \

namespace lol {

/* Line 379 of lalr1.cc */
#line 146 "generated/lolfx-parser.cpp"
#if YYERROR_VERBOSE
/* Line 382 of lalr1.cc */
#line 166 "generated/lolfx-parser.cpp"

/* Return YYSTR after stripping away unnecessary quotes and
backslashes, so that it's suitable for yyerror. The heuristic is
@@ -182,7 +201,6 @@ namespace lol {
return yystr;
}

#endif

/// Build a parser object.
LolFxParser::LolFxParser (class LolFxCompiler& mc_yyarg)
@@ -283,6 +301,18 @@ namespace lol {
}
#endif

inline bool
LolFxParser::yy_pact_value_is_default_ (int yyvalue)
{
return yyvalue == yypact_ninf_;
}

inline bool
LolFxParser::yy_table_value_is_error_ (int yyvalue)
{
return yyvalue == yytable_ninf_;
}

int
LolFxParser::parse ()
{
@@ -304,7 +334,7 @@ namespace lol {
/// Location of the lookahead.
location_type yylloc;
/// The locations where the error started and ended.
location_type yyerror_range[2];
location_type yyerror_range[3];

/// $$.
semantic_type yyval;
@@ -342,7 +372,7 @@ namespace lol {

/* Try to take a decision without lookahead. */
yyn = yypact_[yystate];
if (yyn == yypact_ninf_)
if (yy_pact_value_is_default_ (yyn))
goto yydefault;

/* Read a lookahead token. */
@@ -375,8 +405,8 @@ namespace lol {
yyn = yytable_[yyn];
if (yyn <= 0)
{
if (yyn == 0 || yyn == yytable_ninf_)
goto yyerrlab;
if (yy_table_value_is_error_ (yyn))
goto yyerrlab;
yyn = -yyn;
goto yyreduce;
}
@@ -432,46 +462,57 @@ namespace lol {
{
case 202:

/* Line 677 of lalr1.cc */
/* Line 690 of lalr1.cc */
#line 728 "gpu/lolfx-parser.y"
{ std::cout << "New tech " << std::endl; }
break;

case 203:

/* Line 677 of lalr1.cc */
/* Line 690 of lalr1.cc */
#line 736 "gpu/lolfx-parser.y"
{ std::cout << "New name " << (yysemantic_stack_[(1) - (1)].sval) << std::endl; }
break;

case 204:

/* Line 677 of lalr1.cc */
/* Line 690 of lalr1.cc */
#line 737 "gpu/lolfx-parser.y"
{ std::cout << "New name " << (yysemantic_stack_[(1) - (1)].sval) << std::endl; }
break;

case 207:

/* Line 677 of lalr1.cc */
/* Line 690 of lalr1.cc */
#line 750 "gpu/lolfx-parser.y"
{ std::cout << "New pass " << std::endl; }
break;

case 226:

/* Line 677 of lalr1.cc */
/* Line 690 of lalr1.cc */
#line 786 "gpu/lolfx-parser.y"
{ std::cout << "new shader" << std::endl; }
break;



/* Line 677 of lalr1.cc */
#line 472 "generated/lolfx-parser.cpp"
/* Line 690 of lalr1.cc */
#line 502 "generated/lolfx-parser.cpp"
default:
break;
}
/* User semantic actions sometimes alter yychar, and that requires
that yytoken be updated with the new translation. We take the
approach of translating immediately before every use of yytoken.
One alternative is translating here after every semantic action,
but that translation would be missed if the semantic action
invokes YYABORT, YYACCEPT, or YYERROR immediately after altering
yychar. In the case of YYABORT or YYACCEPT, an incorrect
destructor might then be invoked immediately. In the case of
YYERROR, subsequent parser actions might lead to an incorrect
destructor call or verbose syntax error message before the
lookahead is translated. */
YY_SYMBOL_PRINT ("-> $$ =", yyr1_[yyn], &yyval, &yyloc);

yypop_ (yylen);
@@ -495,14 +536,20 @@ namespace lol {
| yyerrlab -- here on detecting error |
`------------------------------------*/
yyerrlab:
/* Make sure we have latest lookahead translation. See comments at
user semantic actions for why this is necessary. */
yytoken = yytranslate_ (yychar);

/* If not already recovering from an error, report this error. */
if (!yyerrstatus_)
{
++yynerrs_;
if (yychar == yyempty_)
yytoken = yyempty_;
error (yylloc, yysyntax_error_ (yystate, yytoken));
}

yyerror_range[0] = yylloc;
yyerror_range[1] = yylloc;
if (yyerrstatus_ == 3)
{
/* If just tried and failed to reuse lookahead token after an
@@ -537,7 +584,7 @@ namespace lol {
if (false)
goto yyerrorlab;

yyerror_range[0] = yylocation_stack_[yylen - 1];
yyerror_range[1] = yylocation_stack_[yylen - 1];
/* Do not reclaim the symbols of the rule which action triggered
this YYERROR. */
yypop_ (yylen);
@@ -554,7 +601,7 @@ namespace lol {
for (;;)
{
yyn = yypact_[yystate];
if (yyn != yypact_ninf_)
if (!yy_pact_value_is_default_ (yyn))
{
yyn += yyterror_;
if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_)
@@ -569,7 +616,7 @@ namespace lol {
if (yystate_stack_.height () == 1)
YYABORT;

yyerror_range[0] = yylocation_stack_[0];
yyerror_range[1] = yylocation_stack_[0];
yydestruct_ ("Error: popping",
yystos_[yystate],
&yysemantic_stack_[0], &yylocation_stack_[0]);
@@ -578,10 +625,10 @@ namespace lol {
YY_STACK_PRINT ();
}

yyerror_range[1] = yylloc;
yyerror_range[2] = yylloc;
// Using YYLLOC is tempting, but would change the location of
// the lookahead. YYLOC is available though.
YYLLOC_DEFAULT (yyloc, (yyerror_range - 1), 2);
YYLLOC_DEFAULT (yyloc, yyerror_range, 2);
yysemantic_stack_.push (yylval);
yylocation_stack_.push (yyloc);

@@ -604,7 +651,13 @@ namespace lol {

yyreturn:
if (yychar != yyempty_)
yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
{
/* Make sure we have latest lookahead translation. See comments
at user semantic actions for why this is necessary. */
yytoken = yytranslate_ (yychar);
yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval,
&yylloc);
}

/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
@@ -623,51 +676,97 @@ namespace lol {

// Generate an error message.
std::string
LolFxParser::yysyntax_error_ (int yystate, int tok)
LolFxParser::yysyntax_error_ (int yystate, int yytoken)
{
std::string res;
YYUSE (yystate);
#if YYERROR_VERBOSE
int yyn = yypact_[yystate];
if (yypact_ninf_ < yyn && yyn <= yylast_)
std::string yyres;
// Number of reported tokens (one for the "unexpected", one per
// "expected").
size_t yycount = 0;
// Its maximum.
enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
// Arguments of yyformat.
char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];

/* There are many possibilities here to consider:
- If this state is a consistent state with a default action, then
the only way this function was invoked is if the default action
is an error action. In that case, don't check for expected
tokens because there are none.
- The only way there can be no lookahead present (in yytoken) is
if this state is a consistent state with a default action.
Thus, detecting the absence of a lookahead is sufficient to
determine that there is no unexpected or expected token to
report. In that case, just report a simple "syntax error".
- Don't assume there isn't a lookahead just because this state is
a consistent state with a default action. There might have
been a previous inconsistent state, consistent state with a
non-default action, or user semantic action that manipulated
yychar.
- Of course, the expected token list depends on states to have
correct lookahead information, and it depends on the parser not
to perform extra reductions after fetching a lookahead from the
scanner and before detecting a syntax error. Thus, state
merging (from LALR or IELR) and default reductions corrupt the
expected token list. However, the list is correct for
canonical LR with one exception: it will still contain any
token that will not be accepted due to an error action in a
later state.
*/
if (yytoken != yyempty_)
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. */
int yyxbegin = yyn < 0 ? -yyn : 0;

/* Stay within bounds of both yycheck and yytname. */
int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
int count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_)
++count;

// FIXME: This method of building the message is not compatible
// with internationalization. It should work like yacc.c does it.
// That is, first build a string that looks like this:
// "syntax error, unexpected %s or %s or %s"
// Then, invoke YY_ on this string.
// Finally, use the string as a format to output
// yytname_[tok], etc.
// Until this gets fixed, this message appears in English only.
res = "syntax error, unexpected ";
res += yytnamerr_ (yytname_[tok]);
if (count < 5)
{
count = 0;
for (int x = yyxbegin; x < yyxend; ++x)
if (yycheck_[x + yyn] == x && x != yyterror_)
{
res += (!count++) ? ", expecting " : " or ";
res += yytnamerr_ (yytname_[x]);
}
}
yyarg[yycount++] = yytname_[yytoken];
int yyn = yypact_[yystate];
if (!yy_pact_value_is_default_ (yyn))
{
/* Start YYX at -YYN if negative to avoid negative indexes in
YYCHECK. In other words, skip the first -YYN actions for
this state because they are default actions. */
int yyxbegin = yyn < 0 ? -yyn : 0;
/* Stay within bounds of both yycheck and yytname. */
int yychecklim = yylast_ - yyn + 1;
int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_;
for (int yyx = yyxbegin; yyx < yyxend; ++yyx)
if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_
&& !yy_table_value_is_error_ (yytable_[yyx + yyn]))
{
if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
{
yycount = 1;
break;
}
else
yyarg[yycount++] = yytname_[yyx];
}
}
}
else
#endif
res = YY_("syntax error");
return res;

char const* yyformat = 0;
switch (yycount)
{
#define YYCASE_(N, S) \
case N: \
yyformat = S; \
break
YYCASE_(0, YY_("syntax error"));
YYCASE_(1, YY_("syntax error, unexpected %s"));
YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
#undef YYCASE_
}

// Argument number.
size_t yyi = 0;
for (char const* yyp = yyformat; *yyp; ++yyp)
if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount)
{
yyres += yytnamerr_ (yyarg[yyi++]);
++yyp;
}
else
yyres += *yyp;
return yyres;
}


@@ -746,9 +845,9 @@ namespace lol {
-68, -559, -559, -559, -559
};

/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
doesn't specify something else to do. Zero means the default is an
error. */
/* YYDEFACT[S] -- default reduction number in state S. Performed when
YYTABLE doesn't specify something else to do. Zero means the
default is an error. */
const unsigned short int
LolFxParser::yydefact_[] =
{
@@ -855,7 +954,7 @@ namespace lol {

/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
number is the opposite. If YYTABLE_NINF_, syntax error. */
const short int LolFxParser::yytable_ninf_ = -323;
const short int
LolFxParser::yytable_[] =
@@ -3791,11 +3890,11 @@ namespace lol {

} // lol

/* Line 1053 of lalr1.cc */
#line 3796 "generated/lolfx-parser.cpp"
/* Line 1136 of lalr1.cc */
#line 3895 "generated/lolfx-parser.cpp"


/* Line 1055 of lalr1.cc */
/* Line 1138 of lalr1.cc */
#line 1298 "gpu/lolfx-parser.y"




+ 19
- 46
src/generated/lolfx-parser.h 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Skeleton interface for Bison LALR(1) parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -40,20 +40,6 @@
#include <string>
#include <iostream>
#include "stack.hh"


namespace lol {

/* Line 34 of lalr1.cc */
#line 49 "generated/lolfx-parser.h"
class position;
class location;

} // lol

/* Line 34 of lalr1.cc */
#line 56 "generated/lolfx-parser.h"

#include "location.hh"

/* Enabling traces. */
@@ -74,30 +60,11 @@ namespace lol {
# define YYTOKEN_TABLE 0
#endif

/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
If N is 0, then set CURRENT to the empty location which ends
the previous symbol: RHS[0] (always defined). */

#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(Current, Rhs, N) \
do { \
if (N) \
{ \
(Current).begin = (Rhs)[1].begin; \
(Current).end = (Rhs)[N].end; \
} \
else \
{ \
(Current).begin = (Current).end = (Rhs)[0].end; \
} \
} while (false)
#endif


namespace lol {

/* Line 34 of lalr1.cc */
#line 101 "generated/lolfx-parser.h"
/* Line 35 of lalr1.cc */
#line 68 "generated/lolfx-parser.h"

/// A Bison parser.
class LolFxParser
@@ -108,7 +75,7 @@ namespace lol {
union semantic_type
{

/* Line 34 of lalr1.cc */
/* Line 35 of lalr1.cc */
#line 34 "gpu/lolfx-parser.y"

int ival;
@@ -118,8 +85,8 @@ namespace lol {



/* Line 34 of lalr1.cc */
#line 123 "generated/lolfx-parser.h"
/* Line 35 of lalr1.cc */
#line 90 "generated/lolfx-parser.h"
};
#else
typedef YYSTYPE semantic_type;
@@ -640,6 +607,14 @@ namespace lol {
/// The location stack.
location_stack_type yylocation_stack_;

/// Whether the given \c yypact_ value indicates a defaulted state.
/// \param yyvalue the value to check
static bool yy_pact_value_is_default_ (int yyvalue);

/// Whether the given \c yytable_ value indicates a syntax error.
/// \param yyvalue the value to check
static bool yy_table_value_is_error_ (int yyvalue);

/// Internal symbol numbers.
typedef unsigned short int token_number_type;
/* Tables. */
@@ -647,7 +622,7 @@ namespace lol {
static const short int yypact_[];
static const short int yypact_ninf_;

/// For a state, default rule to reduce.
/// For a state, default reduction number.
/// Unless\a yytable_ specifies something else to do.
/// Zero means the default is an error.
static const unsigned short int yydefact_[];
@@ -678,10 +653,8 @@ namespace lol {
static const char* const yytname_[];
#endif

#if YYERROR_VERBOSE
/// Convert the symbol name \a n to a form suitable for a diagnostic.
virtual std::string yytnamerr_ (const char *n);
#endif
static std::string yytnamerr_ (const char *n);

#if YYDEBUG
/// A type to store symbol numbers and -1.
@@ -739,8 +712,8 @@ namespace lol {

} // lol

/* Line 34 of lalr1.cc */
#line 744 "generated/lolfx-parser.h"
/* Line 35 of lalr1.cc */
#line 717 "generated/lolfx-parser.h"





+ 2
- 2
src/generated/position.hh 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Positions for Bison parsers in C++
Copyright (C) 2002-2007, 2009-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by


+ 4
- 4
src/generated/stack.hh 查看文件

@@ -1,8 +1,8 @@
/* A Bison parser, made by GNU Bison 2.4.2. */
/* A Bison parser, made by GNU Bison 2.5. */

/* Stack handling for Bison parsers in C++
Copyright (C) 2002-2010 Free Software Foundation, Inc.
Copyright (C) 2002-2011 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -38,7 +38,7 @@

namespace lol {

/* Line 1066 of lalr1.cc */
/* Line 1149 of lalr1.cc */
#line 43 "generated/stack.hh"
template <class T, class S = std::deque<T> >
class stack
@@ -128,7 +128,7 @@ namespace lol {

} // lol

/* Line 1152 of lalr1.cc */
/* Line 1235 of lalr1.cc */
#line 133 "generated/stack.hh"

#endif // not BISON_STACK_HH[]dnl


+ 44
- 110
tutorial/05_easymesh.cpp 查看文件

@@ -20,127 +20,62 @@ using namespace lol;
class EasyMeshTutorial : public WorldEntity
{
public:
void AddPiece(int x, int y, int h, int dx, int dy, int dh)
{
m_mesh.OpenBrace();
for (int j = 0; j < y; ++j)
for (int i = 0; i < x; ++i)
{
m_mesh.OpenBrace();
m_mesh.Compile("ad12,2.2,0 ty.1 ac12,.2,2.4,2.2,0,1 ty.8 ac12,1.7,2.4,2.4,0,1 ty2.5");
m_mesh.Translate(vec3(i * 8.f, (h - 1) * 3.2f, j * 8.f));
m_mesh.CloseBrace();
}
m_mesh.OpenBrace();
m_mesh.AppendFlatChamfBox(vec3(x * 8.f, h * 3.2f, y * 8.f), -.1f);
m_mesh.Translate(vec3((x - 1) * 4.f, (h - 1) * 1.6f, (y - 1) * 4.f));
m_mesh.CloseBrace();
m_mesh.Translate(vec3(dx * 8.f, dh * 3.2f, dy * 8.f));

m_mesh.CloseBrace();
}

EasyMeshTutorial()
{
m_angle = 0;

//m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 5 5 0.1 0");
m_mesh.Compile("sc#ffb scb#ffb acg 12 10 30 30 -5 -5 0.1 0");

#if 0
m_mesh.Compile("sc#8d3 [ato40 10 40 rx20 ry130 tx30]");

m_mesh.OpenBrace();
m_mesh.Compile("sc#800 [asph10 25 25 25]");
m_mesh.Compile("ty50");
m_mesh.RadialJitter(0.2f);
m_mesh.Compile("ty-50 tx-40");
m_mesh.CloseBrace();
#endif
m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f);
m_gears.Push(EasyMesh(), mat4(1.0f), 0.0f);
m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);
m_gears.Push(EasyMesh(), mat4(1.0f), 180.0f / 18);

m_gears[0].m1.Compile("sc#f9f scb#f9f acg 12 10 5 5 20 20 5 5 0.1 0");
m_gears[1].m1.Compile("sc#ff9 scb#ff9 acg 54 10 95 95 90 90 -5 -5 0.1 0");
m_gears[2].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0");
m_gears[3].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0");
m_gears[4].m1.Compile("sc#9ff scb#9ff acg 18 10 5 5 30 30 5 5 0.1 0");

#if 0
//m_mesh.Compile("sc#94e scb#649 [asph3 7 7 7 tx-6 tz-9]");
//m_mesh.Compile("sc#49e scb#469 [asph31 7 7 7 tx-6 tz9]");
m_mesh.Compile("sc#1c1 scb#1c1");
AddPiece(16, 16, 1, -8, -8, -4);

/* Flat white LOL */
m_mesh.Compile("sc#ccc scb#ccc");

AddPiece(1, 4, 1, -7, -7, -3);
AddPiece(2, 1, 1, -6, -4, -3);

AddPiece(1, 4, 1, -3, -7, -3);
AddPiece(2, 1, 1, -2, -7, -3);
AddPiece(2, 1, 1, -2, -4, -3);
AddPiece(1, 2, 1, -1, -6, -3);

AddPiece(1, 4, 1, 1, -7, -3);
AddPiece(2, 1, 1, 2, -4, -3);

/* High red LOL */
m_mesh.Compile("sc#e33 scb#e33");

AddPiece(3, 1, 3, 3, 4, -3);
AddPiece(1, 1, 3, 5, 4, 0);
AddPiece(1, 1, 3, 5, 4, 3);
AddPiece(1, 1, 3, 5, 4, 6);

AddPiece(3, 1, 3, -1, 4, -3);
AddPiece(1, 1, 3, 1, 4, 0);
AddPiece(1, 1, 3, 1, 4, 3);
AddPiece(1, 1, 3, -1, 4, 0);
AddPiece(1, 1, 3, -1, 4, 3);
AddPiece(3, 1, 3, -1, 4, 6);

AddPiece(3, 1, 3, -5, 4, -3);
AddPiece(1, 1, 3, -3, 4, 0);
AddPiece(1, 1, 3, -3, 4, 3);
AddPiece(1, 1, 3, -3, 4, 6);

/* Some random crap */
m_mesh.Compile("sc#e0e scb#e0e");
AddPiece(1, 1, 1, -1, 0, 2);
m_mesh.Compile("sc#0ee scb#0ee");
AddPiece(2, 1, 1, -1, 0, 1);
m_mesh.Compile("sc#e94 scb#e94");
AddPiece(1, 1, 1, 0, 0, 0);
m_mesh.Compile("sc#94e scb#94e");
AddPiece(2, 1, 1, 0, 0, -1);
m_mesh.Compile("sc#9e4 scb#9e4");
AddPiece(1, 2, 3, -1, -1, -2);
m_mesh.Compile("sc#49e scb#49e");
AddPiece(2, 3, 1, 0, -1, -2);
m_mesh.Compile("sc#4e9 scb#4e9");
AddPiece(6, 2, 1, -2, 0, -3);
m_mesh.Compile("sc#e49 scb#e49");
AddPiece(6, 2, 1, -2, -2, -3);
#endif

/* Center everything -- is it needed? */
// m_mesh.Compile("tx4 tz4");
m_angle = 0;

m_camera = new Camera(vec3(0.f, 600.f, 0.f),
vec3(0.f, 0.f, 0.f),
vec3(0, 1, 0));
m_camera->SetPerspective(70.f, 960.f, 600.f, .1f, 1000.f);
m_camera->SetTarget(vec3(0.f, -10.f, 0.f));
m_camera->SetPosition(vec3(-100.f, 60.f, 0.f));
m_camera->SetPosition(vec3(-150.f, 100.f, 0.f));
Ticker::Ref(m_camera);

m_ready = false;
}

~EasyMeshTutorial()
{
Ticker::Unref(m_camera);
}

virtual void TickGame(float seconds)
{
WorldEntity::TickGame(seconds);

m_angle += seconds * 80.0f;

mat4 anim = mat4::rotate(m_angle, vec3(0, 1, 0));
mat4 model = mat4::translate(vec3(0, 0, 0));

m_matrix = model * anim;
m_angle += seconds * 70.0f;
m_mat = mat4::rotate(10.0f, vec3(0, 0, 1))
* mat4::rotate(m_angle, vec3(0, 1, 0));

m_gears[0].m3 += seconds * 150.0f;
m_gears[1].m3 += seconds * 150.0f * -2 / 9;
m_gears[2].m3 += seconds * 150.0f * -2 / 3;
m_gears[3].m3 += seconds * 150.0f * -2 / 3;
m_gears[4].m3 += seconds * 150.0f * -2 / 3;

m_gears[0].m2 = mat4::translate(vec3(0, 0, 0))
* mat4::rotate(m_gears[0].m3, vec3(0, 1, 0));
m_gears[1].m2 = mat4::translate(vec3(0, 0, 0))
* mat4::rotate(m_gears[1].m3, vec3(0, 1, 0));
m_gears[2].m2 = mat4::translate(vec3(0, 0, 55))
* mat4::rotate(m_gears[2].m3, vec3(0, 1, 0));
m_gears[3].m2 = mat4::translate(vec3(55 * lol::sqrt(3.f) * 0.5f, 0, -55 * 0.5f))
* mat4::rotate(m_gears[3].m3, vec3(0, 1, 0));
m_gears[4].m2 = mat4::translate(vec3(-55 * lol::sqrt(3.f) * 0.5f, 0, -55 * 0.5f))
* mat4::rotate(m_gears[4].m3, vec3(0, 1, 0));
}

virtual void TickDraw(float seconds)
@@ -149,22 +84,21 @@ public:

if (!m_ready)
{
m_mesh.MeshConvert();
for (int i = 0; i < m_gears.Count(); i++)
m_gears[i].m1.MeshConvert();
m_ready = true;
}

Video::SetClearColor(vec4(0.0f, 0.0f, 0.0f, 1.0f));

m_mesh.Render(m_matrix);
m_mesh.Render(mat4::translate(vec3(-65, 0, -65) * lol::sqrt(0.5)) * mat4::rotate(-m_angle, vec3(0, 1, 0)));
m_mesh.Render(mat4::translate(vec3(0, 0, 65)) * mat4::rotate(-m_angle, vec3(0, 1, 0)));
m_mesh.Render(mat4::translate(vec3(-65, 0, 65)) * mat4::rotate(m_angle, vec3(0, 1, 0)));
for (int i = 0; i < m_gears.Count(); i++)
m_gears[i].m1.Render(m_mat * m_gears[i].m2);
}

private:
Array<EasyMesh, mat4, float> m_gears;
float m_angle;
mat4 m_matrix;
EasyMesh m_mesh;
mat4 m_mat;
Camera *m_camera;

bool m_ready;


正在加载...
取消
保存