@@ -43,7 +43,7 @@ lolremez-$(LOLREMEZ_VERSION).tar.gz: | |||
$(top_srcdir)/test/math/remez.vcxproj.filters \ | |||
lolremez-$(LOLREMEZ_VERSION)/ | |||
cp $(top_srcdir)/src/lol/math/real.h \ | |||
$(top_srcdir)/src/lol/math/matrix.h \ | |||
$(top_srcdir)/src/lol/math/vector.h \ | |||
$(top_srcdir)/src/lol/math/remez.h \ | |||
lolremez-$(LOLREMEZ_VERSION)/lol/math/ | |||
printf 'remez: real.cpp remez.cpp\n' > lolremez-$(LOLREMEZ_VERSION)/Makefile | |||
@@ -15,9 +15,17 @@ liblol_a_SOURCES = \ | |||
lol/unit.h lol/debug.h \ | |||
lol/math/vector.h lol/math/half.h lol/math/real.h lol/math/remez.h \ | |||
\ | |||
generated/location.hh generated/position.hh generated/stack.hh \ | |||
\ | |||
application/application.cpp application/application.h \ | |||
eglapp.cpp eglapp.h \ | |||
\ | |||
easymesh/easymesh.cpp easymesh/easymesh.h \ | |||
easymesh/shiny.lolfx \ | |||
easymesh/easymesh-compiler.cpp easymesh/easymesh-compiler.h \ | |||
generated/easymesh-parser.cpp generated/easymesh-parser.h \ | |||
generated/easymesh-scanner.cpp \ | |||
\ | |||
$(ps3_sources) \ | |||
$(xbox_sources) \ | |||
$(nacl_sources) \ | |||
@@ -59,6 +67,18 @@ SUFFIXES = .lolfx | |||
$(SED) 's/\([^\r]*\).*/"\1\\n"/'; \ | |||
echo ";") | $(CXXCOMPILE) -xc++ -c - -o $@ | |||
if TRUE | |||
generated: .FORCE | |||
$(MKDIR_P) generated | |||
rm -f generated/[a-zA-Z]* | |||
flex -o generated/easymesh-scanner.cpp easymesh/easymesh-scanner.l | |||
bison -o generated/easymesh-parser.cpp --defines=generated/easymesh-parser.h \ | |||
-d -b generated/easymesh easymesh/easymesh-parser.y | |||
.FORCE: | |||
endif | |||
EXTRA_DIST = easymesh/easymesh-scanner.l easymesh/easymesh-parser.y | |||
sdl_sources = \ | |||
image/codec/sdl-image.cpp \ | |||
platform/sdl/sdlapp.cpp platform/sdl/sdlapp.h \ | |||
@@ -112,6 +112,7 @@ static inline int isnan(float f) | |||
#include "gpu/framebuffer.h" | |||
#include "image/image.h" | |||
#include "application/application.h" | |||
#include "easymesh/easymesh.h" | |||
// Managers | |||
#include "ticker.h" | |||
@@ -0,0 +1,52 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include <string> | |||
#include "core.h" | |||
#include "easymesh/easymesh-compiler.h" | |||
namespace lol | |||
{ | |||
EasyMeshCompiler::EasyMeshCompiler(EasyMesh &mesh) | |||
: m_mesh(mesh) | |||
{ | |||
} | |||
bool EasyMeshCompiler::ParseString(char const *command) | |||
{ | |||
EasyMeshScanner scanner(command); | |||
m_lexer = &scanner; | |||
EasyMeshParser parser(*this); | |||
if (parser.parse() != 0) | |||
return false; | |||
return true; | |||
} | |||
void EasyMeshCompiler::Error(const class location& l, const std::string& m) | |||
{ | |||
Log::Error("Syntax error line %d column %d: %s", | |||
l.begin.line, l.begin.column, m.c_str()); | |||
} | |||
void EasyMeshCompiler::Error(const std::string& m) | |||
{ | |||
Log::Error("Syntax error: %s", m.c_str()); | |||
} | |||
} /* namespace lol */ | |||
@@ -0,0 +1,61 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
#ifndef __EASYMESH_COMPILER_H__ | |||
#define __EASYMESH_COMPILER_H__ | |||
#include <string> | |||
#ifndef __FLEX_LEXER_H | |||
# define yyFlexLexer EasyMeshFlexLexer | |||
# include "FlexLexer.h" | |||
# undef yyFlexLexer | |||
#endif | |||
#include "generated/easymesh-parser.h" | |||
class EasyMesh; | |||
namespace lol | |||
{ | |||
class EasyMeshScanner : public EasyMeshFlexLexer | |||
{ | |||
public: | |||
EasyMeshScanner(char const *command); | |||
virtual ~EasyMeshScanner(); | |||
virtual int LexerInput(char* buf, int max_size); | |||
virtual EasyMeshParser::token_type lex(EasyMeshParser::semantic_type* yylval, | |||
EasyMeshParser::location_type* yylloc); | |||
private: | |||
char const *m_input; | |||
}; | |||
class EasyMeshCompiler | |||
{ | |||
public: | |||
EasyMeshCompiler(class EasyMesh &mesh); | |||
bool ParseString(char const *command); | |||
void Error(const class location& l, const std::string& m); | |||
void Error(const std::string& m); | |||
class EasyMeshScanner* m_lexer; | |||
class EasyMesh &m_mesh; | |||
}; | |||
} /* namespace lol */ | |||
#endif /* __EASYMESH_COMPILER_H__ */ | |||
@@ -0,0 +1,182 @@ | |||
%{ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include "core.h" | |||
#include "easymesh/easymesh.h" | |||
#include <string> | |||
%} | |||
%require "2.3" | |||
%debug | |||
%defines | |||
%skeleton "lalr1.cc" | |||
%name-prefix="lol" | |||
%define parser_class_name "EasyMeshParser" | |||
%locations | |||
%parse-param { class EasyMeshCompiler& mc } | |||
%error-verbose | |||
%union | |||
{ | |||
float fval; | |||
/* Can't use uin32_t here for some reason */ | |||
unsigned u32val; | |||
struct { float f0, f1, f2, f3, f4, f5, f6, f7; } args; | |||
} | |||
%start mesh_description | |||
%token T_COLOR T_BGCOLOR | |||
%token T_TRANSLATEX T_ROTATEX T_TAPERX T_SCALEX T_MIRRORX | |||
%token T_TRANSLATEY T_ROTATEY T_TAPERY T_SCALEY T_MIRRORY | |||
%token T_TRANSLATEZ T_ROTATEZ T_TAPERZ T_SCALEZ T_MIRRORZ | |||
%token T_TRANSLATE T_SCALE | |||
%token T_CHAMFER | |||
%token T_CYLINDER T_BOX T_SMOOTHCHAMFBOX T_FLATCHAMFBOX T_SPHERE T_STAR | |||
%token T_EXPANDEDSTAR T_DISC T_TRIANGLE T_QUAD T_COG | |||
%token T_END 0 | |||
%token T_ERROR | |||
%token <fval> NUMBER | |||
%token <u32val> COLOR | |||
%type <fval> number | |||
%type <args> args1 args2 args3 args4 args5 args6 args7 args8 | |||
%{ | |||
#include "easymesh/easymesh-compiler.h" | |||
#undef yylex | |||
#define yylex mc.m_lexer->lex | |||
%} | |||
%% | |||
mesh_description: | |||
mesh_expression_list T_END | |||
; | |||
mesh_expression_list: | |||
mesh_expression | |||
| mesh_expression mesh_expression_list | |||
; | |||
mesh_expression: | |||
mesh_command_list | |||
| mesh_open mesh_expression_list mesh_close | |||
; | |||
mesh_open: | |||
'[' { mc.m_mesh.OpenBrace(); } | |||
; | |||
mesh_close: | |||
']' { mc.m_mesh.CloseBrace(); } | |||
; | |||
mesh_command_list: | |||
mesh_command | |||
| mesh_command_list mesh_command | |||
; | |||
mesh_command: | |||
color_command | |||
| transform_command | |||
| primitive_command | |||
; | |||
color_command: | |||
T_COLOR args4 { mc.m_mesh.SetCurColor(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } | |||
| T_COLOR COLOR { uint32_t x = $2; | |||
vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); | |||
mc.m_mesh.SetCurColor(vec4(v) * (1. / 255)); } | |||
| T_BGCOLOR args4 { mc.m_mesh.SetCurColor2(vec4($2.f0, $2.f1, $2.f2, $2.f3)); } | |||
| T_BGCOLOR COLOR { uint32_t x = $2; | |||
vec4 v(x >> 24, (x >> 16) & 0xff, (x >> 8) & 0xff, x & 0xff); | |||
mc.m_mesh.SetCurColor2(vec4(v) * (1. / 255)); } | |||
; | |||
transform_command: | |||
T_CHAMFER args1 { mc.m_mesh.Chamfer($2.f0); } | |||
| T_TRANSLATEX args1 { mc.m_mesh.Translate(vec3($2.f0, 0, 0)); } | |||
| T_TRANSLATEY args1 { mc.m_mesh.Translate(vec3(0, $2.f0, 0)); } | |||
| T_TRANSLATEZ args1 { mc.m_mesh.Translate(vec3(0, 0, $2.f0)); } | |||
| T_TRANSLATE args3 { mc.m_mesh.Translate(vec3($2.f0, $2.f1, $2.f2)); } | |||
| T_ROTATEX args1 { mc.m_mesh.RotateX($2.f0); } | |||
| T_ROTATEY args1 { mc.m_mesh.RotateY($2.f0); } | |||
| T_ROTATEZ args1 { mc.m_mesh.RotateZ($2.f0); } | |||
| T_TAPERX args3 { mc.m_mesh.TaperX($2.f0, $2.f1, $2.f2); } | |||
| T_TAPERY args3 { mc.m_mesh.TaperY($2.f0, $2.f1, $2.f2); } | |||
| T_TAPERZ args3 { mc.m_mesh.TaperZ($2.f0, $2.f1, $2.f2); } | |||
| T_SCALEX args1 { mc.m_mesh.Scale(vec3($2.f0, 0, 0)); } | |||
| T_SCALEY args1 { mc.m_mesh.Scale(vec3(0, $2.f0, 0)); } | |||
| T_SCALEZ args1 { mc.m_mesh.Scale(vec3(0, 0, $2.f0)); } | |||
| T_SCALE args3 { mc.m_mesh.Scale(vec3($2.f0, $2.f1, $2.f2)); } | |||
| T_MIRRORX { mc.m_mesh.MirrorX(); } | |||
| T_MIRRORY { mc.m_mesh.MirrorY(); } | |||
| T_MIRRORZ { mc.m_mesh.MirrorZ(); } | |||
; | |||
primitive_command: | |||
T_CYLINDER args6 { mc.m_mesh.AppendCylinder((int)$2.f0, $2.f1, | |||
$2.f2, $2.f3, | |||
(int)$2.f4, (int)$2.f5); } | |||
| T_BOX args3 { mc.m_mesh.AppendBox(vec3($2.f0, $2.f1, $2.f2)); } | |||
| T_SMOOTHCHAMFBOX args4 { mc.m_mesh.AppendSmoothChamfBox(vec3($2.f0, $2.f1, | |||
$2.f2), $2.f3); } | |||
| T_FLATCHAMFBOX args4 { mc.m_mesh.AppendFlatChamfBox(vec3($2.f0, $2.f1, | |||
$2.f2), $2.f3); } | |||
| T_SPHERE args4 { mc.m_mesh.AppendSphere($2.f0, | |||
vec3($2.f1, $2.f2, $2.f3)); } | |||
| T_STAR args5 { mc.m_mesh.AppendStar((int)$2.f0, $2.f1, $2.f2, | |||
(int)$2.f3, (int)$2.f4); } | |||
| T_EXPANDEDSTAR args4 { mc.m_mesh.AppendExpandedStar((int)$2.f0, $2.f1, | |||
$2.f2, $2.f3); } | |||
| 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.f3, | |||
$2.f4, $2.f5, $2.f6, (int)$2.f7); } | |||
; | |||
args1: number { $$.f0 = $1; } ; | |||
args2: args1 number { $$ = $1; $$.f1 = $2; } ; | |||
args3: args2 number { $$ = $1; $$.f2 = $2; } ; | |||
args4: args3 number { $$ = $1; $$.f3 = $2; } ; | |||
args5: args4 number { $$ = $1; $$.f4 = $2; } ; | |||
args6: args5 number { $$ = $1; $$.f5 = $2; } ; | |||
args7: args6 number { $$ = $1; $$.f6 = $2; } ; | |||
args8: args7 number { $$ = $1; $$.f7 = $2; } ; | |||
number: | |||
NUMBER { $$ = $1; } | |||
| '-' number { $$ = -$2; } | |||
; | |||
%% | |||
void lol::EasyMeshParser::error(const EasyMeshParser::location_type& l, | |||
const std::string& m) | |||
{ | |||
mc.Error(l, m); | |||
} | |||
@@ -0,0 +1,142 @@ | |||
%{ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include "core.h" | |||
#include "easymesh/easymesh-compiler.h" | |||
typedef lol::EasyMeshParser::token token; | |||
typedef lol::EasyMeshParser::token_type token_type; | |||
#ifndef YY_DECL | |||
# define YY_DECL lol::EasyMeshParser::token_type \ | |||
lol::EasyMeshScanner::lex(lol::EasyMeshParser::semantic_type* yylval, \ | |||
lol::EasyMeshParser::location_type* yylloc) | |||
#endif | |||
#define yyterminate() return token::T_END | |||
#define YY_NO_UNISTD_H | |||
#define YY_USER_ACTION yylloc->columns(yyleng); | |||
%} | |||
%option c++ prefix="EasyMesh" | |||
%option batch yywrap nounput stack | |||
%% | |||
%{ | |||
/* reset location at the beginning of yylex() */ | |||
yylloc->step(); | |||
%} | |||
sc { return token::T_COLOR; } | |||
scb { return token::T_BGCOLOR; } | |||
ch { return token::T_CHAMFER; } | |||
tx { return token::T_TRANSLATEX; } | |||
ty { return token::T_TRANSLATEY; } | |||
tz { return token::T_TRANSLATEZ; } | |||
t { return token::T_TRANSLATE; } | |||
rx { return token::T_ROTATEX; } | |||
ry { return token::T_ROTATEY; } | |||
rz { return token::T_ROTATEZ; } | |||
tax { return token::T_TAPERX; } | |||
tay { return token::T_TAPERY; } | |||
taz { return token::T_TAPERZ; } | |||
sx { return token::T_SCALEX; } | |||
sy { return token::T_SCALEY; } | |||
sz { return token::T_SCALEZ; } | |||
s { return token::T_SCALE; } | |||
mx { return token::T_MIRRORX; } | |||
my { return token::T_MIRRORY; } | |||
mz { return token::T_MIRRORZ; } | |||
ac { return token::T_CYLINDER; } | |||
ab { return token::T_BOX; } | |||
ascb { return token::T_SMOOTHCHAMFBOX; } | |||
afcb { return token::T_FLATCHAMFBOX; } | |||
asph { return token::T_SPHERE; } | |||
as { return token::T_STAR; } | |||
aes { return token::T_EXPANDEDSTAR; } | |||
ad { return token::T_DISC; } | |||
at { return token::T_TRIANGLE; } | |||
aq { return token::T_QUAD; } | |||
acg { return token::T_COG; } | |||
#[0-9a-f]{3} { | |||
uint32_t tmp = strtol(yytext + 1, NULL, 16); | |||
yylval->u32val = 0x11000000u * (tmp >> 8) | |||
| 0x00110000u * ((tmp >> 4) & 0xf) | |||
| 0x00001100u * (tmp & 0xf) | |||
| 0x000000ffu; | |||
return token::COLOR; } | |||
#[0-9a-f]{4} { | |||
uint32_t tmp = strtol(yytext + 1, NULL, 16); | |||
yylval->u32val = 0x11000000u * (tmp >> 12) | |||
| 0x00110000u * ((tmp >> 8) & 0xf) | |||
| 0x00001100u * ((tmp >> 4) & 0xf) | |||
| 0x00000011u * (tmp & 0xf); | |||
return token::COLOR; } | |||
#[0-9a-f]{6} { | |||
yylval->u32val = 0xffu | |||
| 0x100u * (uint32_t)strtol(yytext + 1, NULL, 16); | |||
return token::COLOR; } | |||
#[0-9a-f]{8} { | |||
yylval->u32val = (uint32_t)strtol(yytext + 1, NULL, 16); | |||
return token::COLOR; } | |||
[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)? { | |||
yylval->fval = atof(yytext); return token::NUMBER; } | |||
- { return token_type('-'); } | |||
"[" { return token_type('['); } | |||
"]" { return token_type(']'); } | |||
[ ,] { /* ignore this */ } | |||
[\n] { /* ignore this */ } | |||
. { return token::T_ERROR; } | |||
%% | |||
lol::EasyMeshScanner::EasyMeshScanner(char const *command) | |||
: EasyMeshFlexLexer(0, 0), | |||
m_input(command) | |||
{ | |||
} | |||
lol::EasyMeshScanner::~EasyMeshScanner() | |||
{ | |||
} | |||
int lol::EasyMeshScanner::LexerInput(char* buf, int max_size) | |||
{ | |||
buf[0] = m_input[0]; | |||
if (buf[0]) | |||
++m_input; | |||
return buf[0] ? 1 : 0; | |||
} | |||
#ifdef yylex | |||
#undef yylex | |||
#endif | |||
int EasyMeshFlexLexer::yylex() | |||
{ | |||
std::cerr << "in EasyMeshFlexLexer::yylex() !" << std::endl; | |||
return 0; | |||
} | |||
int EasyMeshFlexLexer::yywrap() | |||
{ | |||
return 1; | |||
} | |||
@@ -0,0 +1,721 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#if defined HAVE_CONFIG_H | |||
# include "config.h" | |||
#endif | |||
#include "core.h" | |||
#include "easymesh/easymesh-compiler.h" | |||
extern char const *lolfx_shiny; | |||
namespace lol | |||
{ | |||
EasyMesh::EasyMesh() | |||
: m_color(0), m_color2(0) | |||
{ | |||
m_cursors.Push(0, 0); | |||
} | |||
bool EasyMesh::Compile(char const *command) | |||
{ | |||
EasyMeshCompiler mc(*this); | |||
return mc.ParseString(command); | |||
} | |||
void EasyMesh::OpenBrace() | |||
{ | |||
m_cursors.Push(m_vert.Count(), m_indices.Count()); | |||
} | |||
void EasyMesh::CloseBrace() | |||
{ | |||
m_cursors.Pop(); | |||
} | |||
void EasyMesh::MeshConvert() | |||
{ | |||
m_gpu.shader = Shader::Create(lolfx_shiny); | |||
m_gpu.modelview = m_gpu.shader->GetUniformLocation("in_ModelView"); | |||
m_gpu.proj = m_gpu.shader->GetUniformLocation("in_Proj"); | |||
m_gpu.normalmat = m_gpu.shader->GetUniformLocation("in_NormalMat"); | |||
m_gpu.damage = m_gpu.shader->GetUniformLocation("in_Damage"); | |||
m_gpu.coord = m_gpu.shader->GetAttribLocation("in_Vertex", | |||
VertexUsage::Position, 0); | |||
m_gpu.norm = m_gpu.shader->GetAttribLocation("in_Normal", | |||
VertexUsage::Normal, 0); | |||
m_gpu.color = m_gpu.shader->GetAttribLocation("in_Color", | |||
VertexUsage::Color, 0); | |||
m_gpu.vdecl = new VertexDeclaration( | |||
VertexStream<vec3,vec3,u8vec4>(VertexUsage::Position, | |||
VertexUsage::Normal, | |||
VertexUsage::Color)); | |||
Array<vec3,vec3,u8vec4> vertexlist; | |||
for (int i = 0; i < m_vert.Count(); i++) | |||
vertexlist.Push(m_vert[i].m1, | |||
m_vert[i].m2, | |||
(u8vec4)(m_vert[i].m3 * 255.f)); | |||
Array<uint16_t> indexlist; | |||
for (int i = 0; i < m_indices.Count(); i += 3) | |||
{ | |||
indexlist << m_indices[i + 0]; | |||
indexlist << m_indices[i + 1]; | |||
indexlist << m_indices[i + 2]; | |||
} | |||
m_gpu.vbo = new VertexBuffer(vertexlist.Bytes()); | |||
void *mesh = m_gpu.vbo->Lock(0, 0); | |||
memcpy(mesh, &vertexlist[0], vertexlist.Bytes()); | |||
m_gpu.vbo->Unlock(); | |||
m_gpu.ibo = new IndexBuffer(indexlist.Bytes()); | |||
void *indices = m_gpu.ibo->Lock(0, 0); | |||
memcpy(indices, &indexlist[0], indexlist.Bytes()); | |||
m_gpu.ibo->Unlock(); | |||
m_gpu.vertexcount = vertexlist.Count(); | |||
m_gpu.indexcount = indexlist.Count(); | |||
} | |||
void EasyMesh::Render(mat4 const &model, float damage) | |||
{ | |||
mat4 modelview = Scene::GetDefault()->GetViewMatrix() * model; | |||
mat3 normalmat = transpose(inverse(mat3(modelview))); | |||
m_gpu.shader->Bind(); | |||
m_gpu.shader->SetUniform(m_gpu.modelview, modelview); | |||
m_gpu.shader->SetUniform(m_gpu.proj, Scene::GetDefault()->GetProjMatrix()); | |||
m_gpu.shader->SetUniform(m_gpu.normalmat, normalmat); | |||
m_gpu.shader->SetUniform(m_gpu.damage, damage); | |||
m_gpu.vdecl->SetStream(m_gpu.vbo, m_gpu.coord, m_gpu.norm, m_gpu.color); | |||
m_gpu.vdecl->Bind(); | |||
m_gpu.ibo->Bind(); | |||
m_gpu.vdecl->DrawIndexedElements(MeshPrimitive::Triangles, | |||
0, 0, m_gpu.vertexcount, | |||
0, m_gpu.indexcount / 3); | |||
m_gpu.ibo->Unbind(); | |||
m_gpu.vdecl->Unbind(); | |||
} | |||
void EasyMesh::SetCurColor(vec4 const &color) | |||
{ | |||
m_color = color; | |||
} | |||
void EasyMesh::SetCurColor2(vec4 const &color) | |||
{ | |||
m_color2 = color; | |||
} | |||
void EasyMesh::AddVertex(vec3 const &coord) | |||
{ | |||
m_vert.Push(coord, vec3(0.f, 1.f, 0.f), m_color); | |||
} | |||
void EasyMesh::AddDuplicateVertex(int i) | |||
{ | |||
m_vert.Push(m_vert[i].m1, vec3(0.f, 1.f, 0.f), m_vert[i].m3); | |||
} | |||
void EasyMesh::AppendQuad(int i1, int i2, int i3, int i4, int base) | |||
{ | |||
m_indices << base + i1; | |||
m_indices << base + i2; | |||
m_indices << base + i3; | |||
m_indices << base + i4; | |||
m_indices << base + i1; | |||
m_indices << base + i3; | |||
} | |||
void EasyMesh::AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base) | |||
{ | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i2); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i4); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); | |||
} | |||
void EasyMesh::AppendTriangle(int i1, int i2, int i3, int base) | |||
{ | |||
m_indices << base + i1; | |||
m_indices << base + i2; | |||
m_indices << base + i3; | |||
} | |||
void EasyMesh::AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base) | |||
{ | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i1); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i2); | |||
m_indices << m_vert.Count(); AddDuplicateVertex(base + i3); | |||
} | |||
void EasyMesh::ComputeNormals(int start, int vcount) | |||
{ | |||
for (int i = 0; i < vcount; i += 3) | |||
{ | |||
vec3 v0 = m_vert[m_indices[start + i + 2]].m1 | |||
- m_vert[m_indices[start + i + 0]].m1; | |||
vec3 v1 = m_vert[m_indices[start + i + 1]].m1 | |||
- m_vert[m_indices[start + i + 0]].m1; | |||
vec3 n = normalize(cross(v1, v0)); | |||
for (int j = 0; j < 3; j++) | |||
m_vert[m_indices[start + i + j]].m2 = n; | |||
} | |||
} | |||
void EasyMesh::SetVertColor(vec4 const &color) | |||
{ | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
m_vert[i].m3 = color; | |||
} | |||
void EasyMesh::SetCurVertNormal(vec3 const &normal) | |||
{ | |||
m_vert[m_vert.Count() - 1].m2 = normal; | |||
} | |||
void EasyMesh::SetCurVertColor(vec4 const &color) | |||
{ | |||
m_vert[m_vert.Count() - 1].m3 = color; | |||
} | |||
void EasyMesh::Translate(vec3 const &v) | |||
{ | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
m_vert[i].m1 += v; | |||
} | |||
void EasyMesh::RotateX(float t) { Rotate(t, vec3(1, 0, 0)); } | |||
void EasyMesh::RotateY(float t) { Rotate(t, vec3(0, 1, 0)); } | |||
void EasyMesh::RotateZ(float t) { Rotate(t, vec3(0, 0, 1)); } | |||
void EasyMesh::Rotate(float t, vec3 const &axis) | |||
{ | |||
mat3 m = mat3::rotate(t, axis); | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
{ | |||
m_vert[i].m1 = m * m_vert[i].m1; | |||
m_vert[i].m2 = m * m_vert[i].m2; | |||
} | |||
} | |||
void EasyMesh::TaperX(float y, float z, float xoff) | |||
{ | |||
/* FIXME: this code breaks normals! */ | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
{ | |||
m_vert[i].m1.y *= 1.f + (y * m_vert[i].m1.x + xoff); | |||
m_vert[i].m1.z *= 1.f + (z * m_vert[i].m1.x + xoff); | |||
} | |||
} | |||
void EasyMesh::TaperY(float x, float z, float yoff) | |||
{ | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
{ | |||
m_vert[i].m1.x *= 1.f + (x * m_vert[i].m1.y + yoff); | |||
m_vert[i].m1.z *= 1.f + (z * m_vert[i].m1.y + yoff); | |||
} | |||
} | |||
void EasyMesh::TaperZ(float x, float y, float zoff) | |||
{ | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
{ | |||
m_vert[i].m1.x *= 1.f + (x * m_vert[i].m1.z + zoff); | |||
m_vert[i].m1.y *= 1.f + (y * m_vert[i].m1.z + zoff); | |||
} | |||
} | |||
void EasyMesh::Scale(vec3 const &s) | |||
{ | |||
vec3 const invs = vec3(1) / s; | |||
for (int i = m_cursors.Last().m1; i < m_vert.Count(); i++) | |||
{ | |||
m_vert[i].m1 *= s; | |||
m_vert[i].m2 = normalize(m_vert[i].m2 * invs); | |||
} | |||
/* Flip winding if the scaling involves mirroring */ | |||
if (s.x * s.y * s.z < 0) | |||
{ | |||
for (int i = m_cursors.Last().m2; i < m_indices.Count(); i += 3) | |||
{ | |||
uint16_t tmp = m_indices[i + 0]; | |||
m_indices[i + 0] = m_indices[i + 1]; | |||
m_indices[i + 1] = tmp; | |||
} | |||
} | |||
} | |||
void EasyMesh::MirrorX() { DupAndScale(vec3(-1, 1, 1)); } | |||
void EasyMesh::MirrorY() { DupAndScale(vec3(1, -1, 1)); } | |||
void EasyMesh::MirrorZ() { DupAndScale(vec3(1, 1, -1)); } | |||
void EasyMesh::DupAndScale(vec3 const &s) | |||
{ | |||
int vlen = m_vert.Count() - m_cursors.Last().m1; | |||
int tlen = m_indices.Count() - m_cursors.Last().m2; | |||
for (int i = 0; i < vlen; i++) | |||
m_vert << m_vert[m_cursors.Last().m1++]; | |||
for (int i = 0; i < tlen; i++) | |||
m_indices << m_indices[m_cursors.Last().m2++] + vlen; | |||
Scale(s); | |||
m_cursors.Last().m1 -= vlen; | |||
m_cursors.Last().m2 -= tlen; | |||
} | |||
void EasyMesh::AppendCylinder(int nsides, float h, float r1, float r2, | |||
int dualside, int smooth) | |||
{ | |||
int vbase = m_vert.Count(); | |||
mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f); | |||
vec3 p1(r1, -h * .5f, 0.f), p2(r2, h * .5f, 0.f), n; | |||
/* Construct normal */ | |||
n = p2; | |||
n.y = r1 * (r1 - r2) / h; | |||
if (!smooth) | |||
n = mat3::rotate(180.0f / nsides, 0.f, 1.f, 0.f) * n; | |||
n = normalize(n); | |||
/* FIXME: normals should be flipped in two-sided mode, but that | |||
* means duplicating the vertices again... */ | |||
for (int i = 0; i < nsides; i++) | |||
{ | |||
AddVertex(p1); SetCurVertNormal(n); | |||
AddVertex(p2); SetCurVertNormal(n); | |||
SetCurVertColor(m_color2); | |||
if (smooth) | |||
{ | |||
int j = (i + 1) % nsides; | |||
AppendQuad(j * 2, j * 2 + 1, i * 2 + 1, i * 2, vbase); | |||
if (dualside) | |||
AppendQuad(i * 2, i * 2 + 1, j * 2 + 1, j * 2, vbase); | |||
} | |||
p1 = rotmat * p1; | |||
p2 = rotmat * p2; | |||
if (!smooth) | |||
{ | |||
AddVertex(p1); SetCurVertNormal(n); | |||
AddVertex(p2); SetCurVertNormal(n); | |||
SetCurVertColor(m_color2); | |||
AppendQuad(i * 4 + 2, i * 4 + 3, i * 4 + 1, i * 4, vbase); | |||
if (dualside) | |||
AppendQuad(i * 4, i * 4 + 1, i * 4 + 3, i * 4 + 2, vbase); | |||
} | |||
n = rotmat * n; | |||
} | |||
} | |||
void EasyMesh::AppendSphere(int ndivisions, vec3 const &size) | |||
{ | |||
ndivisions *= 2; | |||
int ibase = m_indices.Count(); | |||
int vbase = m_vert.Count(); | |||
vec3 d = size * 0.5f; | |||
float const pi = std::acos(-1.0f); | |||
Array<vec2> table; | |||
for (int i = 0; i <= ndivisions; i++) | |||
table.Push(vec2(std::sin(pi * 2 / ndivisions * i) + 1e-5f, | |||
std::cos(pi * 2 / ndivisions * i) + 1e-5f)); | |||
for (int j = 0; j <= ndivisions / 2; j++) | |||
for (int i = 0; i < ndivisions; i++) | |||
{ | |||
int j2 = j + 1; | |||
int i2 = (i + 1) % ndivisions; | |||
AddVertex(d * vec3(table[i], 1.0f) * table[j].xxy); | |||
AddVertex(d * vec3(table[i2], 1.0f) * table[j].xxy); | |||
AddVertex(d * vec3(table[i2], 1.0f) * table[j2].xxy); | |||
AddVertex(d * vec3(table[i], 1.0f) * table[j2].xxy); | |||
} | |||
for (int i = vbase; i < m_vert.Count(); i += 4) | |||
AppendQuad(0, 1, 2, 3, i); | |||
ComputeNormals(ibase, m_indices.Count() - ibase); | |||
} | |||
void EasyMesh::AppendBox(vec3 const &size, float chamf) | |||
{ | |||
AppendBox(size, chamf, false); | |||
} | |||
void EasyMesh::AppendSmoothChamfBox(vec3 const &size, float chamf) | |||
{ | |||
AppendBox(size, chamf, true); | |||
} | |||
void EasyMesh::AppendFlatChamfBox(vec3 const &size, float chamf) | |||
{ | |||
AppendBox(size, chamf, false); | |||
} | |||
void EasyMesh::AppendBox(vec3 const &size, float chamf, bool smooth) | |||
{ | |||
if (chamf < 0.0f) | |||
{ | |||
AppendBox(size + vec3(chamf * 2.0f), -chamf, smooth); | |||
return; | |||
} | |||
int vbase = m_vert.Count(); | |||
int ibase = m_indices.Count(); | |||
vec3 d = size * 0.5f; | |||
AddVertex(vec3(-d.x, -d.y, -d.z - chamf)); | |||
AddVertex(vec3(-d.x, +d.y, -d.z - chamf)); | |||
AddVertex(vec3(+d.x, +d.y, -d.z - chamf)); | |||
AddVertex(vec3(+d.x, -d.y, -d.z - chamf)); | |||
AddVertex(vec3(-d.x - chamf, -d.y, +d.z)); | |||
AddVertex(vec3(-d.x - chamf, +d.y, +d.z)); | |||
AddVertex(vec3(-d.x - chamf, +d.y, -d.z)); | |||
AddVertex(vec3(-d.x - chamf, -d.y, -d.z)); | |||
AddVertex(vec3(+d.x, -d.y, +d.z + chamf)); | |||
AddVertex(vec3(+d.x, +d.y, +d.z + chamf)); | |||
AddVertex(vec3(-d.x, +d.y, +d.z + chamf)); | |||
AddVertex(vec3(-d.x, -d.y, +d.z + chamf)); | |||
AddVertex(vec3(+d.x + chamf, -d.y, -d.z)); | |||
AddVertex(vec3(+d.x + chamf, +d.y, -d.z)); | |||
AddVertex(vec3(+d.x + chamf, +d.y, +d.z)); | |||
AddVertex(vec3(+d.x + chamf, -d.y, +d.z)); | |||
AddVertex(vec3(-d.x, -d.y - chamf, +d.z)); | |||
AddVertex(vec3(-d.x, -d.y - chamf, -d.z)); | |||
AddVertex(vec3(+d.x, -d.y - chamf, -d.z)); | |||
AddVertex(vec3(+d.x, -d.y - chamf, +d.z)); | |||
AddVertex(vec3(-d.x, +d.y + chamf, -d.z)); | |||
AddVertex(vec3(-d.x, +d.y + chamf, +d.z)); | |||
AddVertex(vec3(+d.x, +d.y + chamf, +d.z)); | |||
AddVertex(vec3(+d.x, +d.y + chamf, -d.z)); | |||
/* The 6 quads on each side of the box */ | |||
for (int i = 0; i < 24; i += 4) | |||
AppendQuad(i, i + 1, i + 2, i + 3, vbase); | |||
ComputeNormals(ibase, m_indices.Count() - ibase); | |||
ibase = m_indices.Count(); | |||
/* The 8 quads at each edge of the box */ | |||
if (chamf) | |||
{ | |||
static int const quadlist[48] = | |||
{ | |||
0, 3, 18, 17, 4, 7, 17, 16, 8, 11, 16, 19, 12, 15, 19, 18, | |||
2, 1, 20, 23, 6, 5, 21, 20, 10, 9, 22, 21, 14, 13, 23, 22, | |||
1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 3, 2, | |||
}; | |||
for (int i = 0; i < 48; i += 4) | |||
{ | |||
if (smooth) | |||
AppendQuad(quadlist[i], quadlist[i + 1], | |||
quadlist[i + 2], quadlist[i + 3], vbase); | |||
else | |||
AppendQuadDuplicateVerts(quadlist[i], quadlist[i + 1], | |||
quadlist[i + 2], quadlist[i + 3], vbase); | |||
} | |||
} | |||
/* The 8 triangles at each corner of the box */ | |||
if (chamf) | |||
{ | |||
static int const trilist[24] = | |||
{ | |||
3, 12, 18, 15, 8, 19, 11, 4, 16, 7, 0, 17, | |||
2, 23, 13, 14, 22, 9, 10, 21, 5, 6, 20, 1, | |||
}; | |||
for (int i = 0; i < 24; i += 3) | |||
{ | |||
if (smooth) | |||
AppendTriangle(trilist[i], trilist[i + 1], | |||
trilist[i + 2], vbase); | |||
else | |||
AppendTriangleDuplicateVerts(trilist[i], trilist[i + 1], | |||
trilist[i + 2], vbase); | |||
} | |||
} | |||
if (!smooth) | |||
ComputeNormals(ibase, m_indices.Count() - ibase); | |||
} | |||
void EasyMesh::AppendStar(int nbranches, float r1, float r2, | |||
int fade, int fade2) | |||
{ | |||
int vbase = m_vert.Count(); | |||
AddVertex(vec3(0.f, 0.f, 0.f)); | |||
mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); | |||
vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f); | |||
p2 = rotmat * p2; | |||
rotmat = rotmat * rotmat; | |||
for (int i = 0; i < nbranches; i++) | |||
{ | |||
AddVertex(p1); | |||
if (fade2) | |||
SetCurVertColor(m_color2); | |||
AddVertex(p2); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
AppendQuad(0, 2 * i + 1, 2 * i + 2, (2 * i + 3) % (2 * nbranches), | |||
vbase); | |||
p1 = rotmat * p1; | |||
p2 = rotmat * p2; | |||
} | |||
} | |||
void EasyMesh::AppendExpandedStar(int nbranches, float r1, | |||
float r2, float extrar) | |||
{ | |||
int vbase = m_vert.Count(); | |||
AddVertex(vec3(0.f, 0.f, 0.f)); | |||
mat3 rotmat = mat3::rotate(180.0f / nbranches, 0.f, 1.f, 0.f); | |||
vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f), | |||
p3(r1 + extrar, 0.f, 0.f), p4(r2 + extrar, 0.f, 0.f);; | |||
p2 = rotmat * p2; | |||
p4 = rotmat * p4; | |||
rotmat = rotmat * rotmat; | |||
for (int i = 0; i < nbranches; i++) | |||
{ | |||
AddVertex(p1); | |||
AddVertex(p2); | |||
AddVertex(p3); SetCurVertColor(m_color2); | |||
AddVertex(p4); SetCurVertColor(m_color2); | |||
int j = (i + 1) % nbranches; | |||
AppendQuad(0, 4 * i + 1, 4 * i + 2, 4 * j + 1, vbase); | |||
AppendQuad(4 * i + 1, 4 * i + 3, 4 * i + 4, 4 * i + 2, vbase); | |||
AppendQuad(4 * j + 1, 4 * i + 2, 4 * i + 4, 4 * j + 3, vbase); | |||
p1 = rotmat * p1; | |||
p2 = rotmat * p2; | |||
p3 = rotmat * p3; | |||
p4 = rotmat * p4; | |||
} | |||
} | |||
void EasyMesh::AppendDisc(int nsides, float r, int fade) | |||
{ | |||
int vbase = m_vert.Count(); | |||
AddVertex(vec3(0.f, 0.f, 0.f)); | |||
mat3 rotmat = mat3::rotate(360.0f / nsides, 0.f, 1.f, 0.f); | |||
vec3 p1(r, 0.f, 0.f); | |||
for (int i = 0; i < nsides; i++) | |||
{ | |||
AddVertex(p1); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
AppendTriangle(0, i + 1, ((i + 1) % nsides) + 1, vbase); | |||
p1 = rotmat * p1; | |||
} | |||
} | |||
void EasyMesh::AppendSimpleTriangle(float size, int fade) | |||
{ | |||
mat3 m = mat3::rotate(120.f, 0.f, 1.f, 0.f); | |||
vec3 p(0.f, 0.f, size); | |||
AddVertex(p); | |||
p = m * p; | |||
AddVertex(p); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
p = m * p; | |||
AddVertex(p); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
AppendTriangle(0, 1, 2, m_vert.Count() - 3); | |||
} | |||
void EasyMesh::AppendSimpleQuad(float size, int fade) | |||
{ | |||
AppendSimpleQuad(vec2(size * .5f), vec2(size * -.5f), 0.f, fade); | |||
} | |||
void EasyMesh::AppendSimpleQuad(vec2 p1, vec2 p2, float z, int fade) | |||
{ | |||
AddVertex(vec3(p2.x, z, -p1.y)); | |||
AddVertex(vec3(p2.x, z, -p2.y)); | |||
AddVertex(vec3(p1.x, z, -p2.y)); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
AddVertex(vec3(p1.x, z, -p1.y)); | |||
if (fade) | |||
SetCurVertColor(m_color2); | |||
AppendQuad(3, 2, 1, 0, m_vert.Count() - 4); | |||
ComputeNormals(m_indices.Count() - 6, 6); | |||
} | |||
void EasyMesh::AppendCog(int nbsides, float h, float r1, float r2, float r12, | |||
float r22, float sidemul, int offset) | |||
{ | |||
int ibase = m_indices.Count(); | |||
int vbase = m_vert.Count(); | |||
AddVertex(vec3(0.f, h * .5f, 0.f)); | |||
AddVertex(vec3(0.f, h * -.5f, 0.f)); | |||
SetCurVertColor(m_color2); | |||
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); | |||
mat3 smat2 = mat3::rotate(sidemul * -360.0f / nbsides, 0.f, 1.f, 0.f); | |||
vec3 p[8]; | |||
p[0] = vec3(r1, h * .5f, 0.f); | |||
p[1] = rotmat * p[0]; | |||
p[2] = smat1 * (rotmat * vec3(r1 + r12, h * .5f, 0.f)); | |||
p[3] = smat2 * (rotmat * p[2]); | |||
p[4] = vec3(r2, h * -.5f, 0.f); | |||
p[5] = rotmat * p[4]; | |||
p[6] = smat1 * (rotmat * vec3(r2 + r22, h * -.5f, 0.f)); | |||
p[7] = smat2 * (rotmat * p[6]); | |||
if (offset & 1) | |||
for (int n = 0; n < 8; n++) | |||
p[n] = rotmat * p[n]; | |||
rotmat = rotmat * rotmat; | |||
for (int i = 0; i < nbsides; i++) | |||
{ | |||
/* Each vertex will share three faces, so three different | |||
* normals, therefore we add each vertex three times. */ | |||
for (int n = 0; n < 24; n++) | |||
{ | |||
AddVertex(p[n / 3]); | |||
if (n / 3 >= 4) | |||
SetCurVertColor(m_color2); | |||
} | |||
int j = 24 * i, k = 24 * ((i + 1) % nbsides); | |||
/* The top and bottom faces */ | |||
AppendQuad(0, j + 2, j + 5, k + 2, vbase); | |||
AppendQuad(1, k + 14, j + 17, j + 14, vbase); | |||
AppendQuad(j + 5, j + 8, j + 11, k + 2, vbase); | |||
AppendQuad(k + 14, j + 23, j + 20, j + 17, vbase); | |||
/* The side quads */ | |||
AppendQuad(j + 6, j + 3, j + 15, j + 18, vbase); | |||
AppendQuad(j + 9, j + 7, j + 19, j + 21, vbase); | |||
AppendQuad(j + 12, j + 10, j + 22, j + 24, vbase); | |||
AppendQuad(k + 4, j + 13, j + 25, k + 16, vbase); | |||
for (int n = 0; n < 8; n++) | |||
p[n] = rotmat * p[n]; | |||
} | |||
ComputeNormals(ibase, m_indices.Count() - ibase); | |||
} | |||
void EasyMesh::Chamfer(float f) | |||
{ | |||
int vlen = m_vert.Count() - m_cursors.Last().m1; | |||
int ilen = m_indices.Count() - m_cursors.Last().m2; | |||
/* Step 1: enumerate all faces. This is done by merging triangles | |||
* that are coplanar and share an edge. */ | |||
int *triangle_classes = new int[ilen / 3]; | |||
for (int i = 0; i < ilen / 3; i++) | |||
triangle_classes[i] = -1; | |||
for (int i = 0; i < ilen / 3; i++) | |||
{ | |||
} | |||
/* Fun shit: reduce all triangles */ | |||
int *vertices = new int[vlen]; | |||
memset(vertices, 0, vlen * sizeof(int)); | |||
for (int i = 0; i < ilen; i++) | |||
vertices[m_indices[i]]++; | |||
for (int i = 0; i < ilen / 3; i++) | |||
{ | |||
#if 0 | |||
if (vertices[m_indices[i * 3]] > 1) | |||
continue; | |||
if (vertices[m_indices[i * 3 + 1]] > 1) | |||
continue; | |||
if (vertices[m_indices[i * 3 + 2]] > 1) | |||
continue; | |||
#endif | |||
vec3 bary = 1.f / 3.f * (m_vert[m_indices[i * 3]].m1 + | |||
m_vert[m_indices[i * 3 + 1]].m1 + | |||
m_vert[m_indices[i * 3 + 2]].m1); | |||
for (int k = 0; k < 3; k++) | |||
{ | |||
vec3 &p = m_vert[m_indices[i * 3 + k]].m1; | |||
p -= normalize(p - bary) * f; | |||
} | |||
} | |||
} | |||
} /* namespace lol */ | |||
@@ -0,0 +1,107 @@ | |||
// | |||
// Lol Engine | |||
// | |||
// Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> | |||
// (c) 2009-2012 Cédric Lecacheur <jordx@free.fr> | |||
// (c) 2009-2012 Benjamin Huet <huet.benjamin@gmail.com> | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the Do What The Fuck You Want To | |||
// Public License, Version 2, as published by Sam Hocevar. See | |||
// http://sam.zoy.org/projects/COPYING.WTFPL for more details. | |||
// | |||
// | |||
// The EasyMesh class | |||
// ------------------ | |||
// | |||
#if !defined __EASYMESH_EASYMESH_H__ | |||
#define __EASYMESH_EASYMESH_H__ | |||
namespace lol | |||
{ | |||
class EasyMesh | |||
{ | |||
friend class EasyMeshParser; | |||
public: | |||
EasyMesh(); | |||
bool Compile(char const *command); | |||
void MeshConvert(); | |||
void Render(mat4 const &model, float damage = 0.f); | |||
private: | |||
void OpenBrace(); | |||
void CloseBrace(); | |||
void SetCurColor(vec4 const &color); | |||
void SetCurColor2(vec4 const &color); | |||
void AddVertex(vec3 const &coord); | |||
void AddDuplicateVertex(int i); | |||
void AppendQuad(int i1, int i2, int i3, int i4, int base); | |||
void AppendQuadDuplicateVerts(int i1, int i2, int i3, int i4, int base); | |||
void AppendTriangle(int i1, int i2, int i3, int base); | |||
void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base); | |||
void ComputeNormals(int start, int vcount); | |||
void SetVertColor(vec4 const &color); | |||
void SetCurVertNormal(vec3 const &normal); | |||
void SetCurVertColor(vec4 const &color); | |||
void Translate(vec3 const &v); | |||
void RotateX(float t); | |||
void RotateY(float t); | |||
void RotateZ(float t); | |||
void Rotate(float t, vec3 const &axis); | |||
void TaperX(float y, float z, float xoff); | |||
void TaperY(float x, float z, float yoff); | |||
void TaperZ(float x, float y, float zoff); | |||
void Scale(vec3 const &s); | |||
void MirrorX(); | |||
void MirrorY(); | |||
void MirrorZ(); | |||
void DupAndScale(vec3 const &s); | |||
void Chamfer(float f); | |||
void AppendCylinder(int nsides, float h, float r1, float r2, | |||
int dualside, int smooth); | |||
void AppendSphere(int ndivisions, vec3 const &size); | |||
void AppendBox(vec3 const &size, float chamf = 0.f); | |||
void AppendSmoothChamfBox(vec3 const &size, float chamf); | |||
void AppendFlatChamfBox(vec3 const &size, float chamf); | |||
void AppendBox(vec3 const &size, float chamf, bool smooth); | |||
void AppendStar(int nbranches, float r1, float r2, | |||
int fade = 0, int fade2 = 0); | |||
void AppendExpandedStar(int nbranches, float r1, float r2, float extrar); | |||
void AppendDisc(int nsides, float r, int fade = 0); | |||
void AppendSimpleTriangle(float size, int fade = 0); | |||
void AppendSimpleQuad(float size, int fade = 0); | |||
void AppendSimpleQuad(vec2 p1, vec2 p2, float z = 0.f, int fade = 0); | |||
void AppendCog(int nbsides, float h, float r1, float r2, | |||
float r12, float r22, float sidemul, int offset); | |||
private: | |||
vec4 m_color, m_color2; | |||
Array<uint16_t> m_indices; | |||
Array<vec3, vec3, vec4> m_vert; | |||
Array<int, int> m_cursors; | |||
/* FIXME: put this in a separate class so that we can copy meshes. */ | |||
struct | |||
{ | |||
Shader *shader; | |||
ShaderAttrib coord, norm, color; | |||
ShaderUniform modelview, proj, normalmat, damage; | |||
VertexDeclaration *vdecl; | |||
VertexBuffer *vbo; | |||
IndexBuffer *ibo; | |||
int vertexcount, indexcount; | |||
} | |||
m_gpu; | |||
}; | |||
} /* namespace lol */ | |||
#endif /* __EASYMESH_EASYMESH_H__ */ | |||
@@ -0,0 +1,109 @@ | |||
-- GLSL.Vert -- | |||
#version 120 | |||
attribute vec3 in_Vertex; | |||
attribute vec3 in_Normal; | |||
attribute vec4 in_Color; | |||
uniform mat4 in_ModelView; | |||
uniform mat4 in_Proj; | |||
uniform mat3 in_NormalMat; | |||
uniform float in_Damage; | |||
varying vec4 pass_Color; | |||
void main(void) | |||
{ | |||
/* Material properties */ | |||
vec3 specular_reflect = vec3(0.8, 0.75, 0.4); | |||
float specular_power = 60.0; | |||
/* World properties */ | |||
float ambient_mul = 0.5; | |||
vec3 light_dir = normalize(vec3(0.3, 0.3, 0.7)); | |||
vec3 ambient_color = vec3(0.25, 0.2, 0.35); | |||
vec3 diffuse_color = vec3(1.0, 1.0, 0.6); | |||
vec3 specular_color = vec3(1.0, 1.0, 0.6); | |||
vec3 tnorm = normalize(in_NormalMat * in_Normal); | |||
vec4 eye = in_ModelView * vec4(in_Vertex, 1.0); | |||
vec3 s = light_dir; /* normalize(eye - lightpos); */ | |||
vec3 v = normalize(-eye.xyz); | |||
vec3 r = reflect(-s, tnorm); | |||
vec3 ambient = ambient_color; | |||
float sdotn = max(dot(s, tnorm), 0.0); | |||
vec3 diffuse = diffuse_color * sdotn; | |||
vec3 specular = vec3(0.0, 0.0, 0.0); | |||
if (sdotn > 0.0) | |||
specular = specular_color * specular_reflect | |||
* pow(max(dot(r, v), 0.0), specular_power); | |||
vec3 light = ambient + diffuse + specular; | |||
vec4 real_color = in_Damage * vec4(1.2, 1.2, 1.2, 1.0) | |||
+ (1.0 - in_Damage) * in_Color; | |||
pass_Color = real_color * vec4(light, 1.0); | |||
gl_Position = in_Proj * eye; | |||
} | |||
-- GLSL.Frag -- | |||
#version 120 | |||
//precision highp float; | |||
varying vec4 pass_Color; | |||
void main(void) { | |||
gl_FragColor = pass_Color; | |||
} | |||
-- HLSL.Vert -- | |||
void main(float3 in_Vertex : POSITION, | |||
float3 in_Normal : NORMAL, | |||
float4 in_Color : COLOR, | |||
uniform float4x4 in_ModelView, | |||
uniform float4x4 in_Proj, | |||
uniform float3x3 in_NormalMat, | |||
uniform float in_Damage, | |||
out float4 out_Position : POSITION, | |||
out float4 pass_Color : COLOR) | |||
{ | |||
float3 specular_reflect = float3(0.8, 0.75, 0.4); | |||
float specular_power = 60.0; | |||
float ambient_mul = 0.5; | |||
float3 light_dir = normalize(float3(0.3, 0.3, 0.7)); | |||
float3 ambient_color = float3(0.25, 0.2, 0.35); | |||
float3 diffuse_color = float3(1.0, 1.0, 0.6); | |||
float3 specular_color = float3(1.0, 1.0, 0.6); | |||
float3 tnorm = normalize(mul(in_NormalMat, in_Normal)); | |||
float4 eye = mul(in_ModelView, float4(in_Vertex, 1.0)); | |||
float3 s = light_dir; | |||
float3 v = normalize(-eye.xyz); | |||
float3 r = reflect(-s, tnorm); | |||
float3 ambient = ambient_color; | |||
float sdotn = max(dot(s, tnorm), 0.0); | |||
float3 diffuse = diffuse_color * sdotn; | |||
float3 specular = float3(0.0, 0.0, 0.0); | |||
if (sdotn > 0.0) | |||
specular = specular_color * specular_reflect | |||
* pow(max(dot(r, v), 0.0), specular_power); | |||
float3 light = ambient + diffuse + specular; | |||
#ifdef _XBOX | |||
float4 real_color = in_Color.abgr; | |||
#else | |||
float4 real_color = in_Color; | |||
#endif | |||
real_color = in_Damage * float4(1.2, 1.2, 1.2, 1.0) | |||
+ (1.0 - in_Damage) * real_color; | |||
pass_Color = real_color * float4(light, 1.0); | |||
out_Position = mul(in_Proj, eye); | |||
} | |||
-- HLSL.Frag -- | |||
void main(float4 pass_Color : COLOR, | |||
out float4 out_FragColor : COLOR) | |||
{ | |||
out_FragColor = pass_Color; | |||
} | |||
@@ -0,0 +1,319 @@ | |||
/* A Bison parser, made by GNU Bison 2.5. */ | |||
/* Skeleton interface for Bison LALR(1) parsers in C++ | |||
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 | |||
the Free Software Foundation, either version 3 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |||
/* As a special exception, you may create a larger work that contains | |||
part or all of the Bison parser skeleton and distribute that work | |||
under terms of your choice, so long as that work isn't itself a | |||
parser generator using the skeleton or a modified version thereof | |||
as a parser skeleton. Alternatively, if you modify or redistribute | |||
the parser skeleton itself, you may (at your option) remove this | |||
special exception, which will cause the skeleton and the resulting | |||
Bison output files to be licensed under the GNU General Public | |||
License without this special exception. | |||
This special exception was added by the Free Software Foundation in | |||
version 2.2 of Bison. */ | |||
/* C++ LALR(1) parser skeleton written by Akim Demaille. */ | |||
#ifndef PARSER_HEADER_H | |||
# define PARSER_HEADER_H | |||
#include <string> | |||
#include <iostream> | |||
#include "stack.hh" | |||
#include "location.hh" | |||
/* Enabling traces. */ | |||
#ifndef YYDEBUG | |||
# define YYDEBUG 1 | |||
#endif | |||
/* Enabling verbose error messages. */ | |||
#ifdef YYERROR_VERBOSE | |||
# undef YYERROR_VERBOSE | |||
# define YYERROR_VERBOSE 1 | |||
#else | |||
# define YYERROR_VERBOSE 1 | |||
#endif | |||
/* Enabling the token table. */ | |||
#ifndef YYTOKEN_TABLE | |||
# define YYTOKEN_TABLE 0 | |||
#endif | |||
namespace lol { | |||
/* Line 35 of lalr1.cc */ | |||
#line 68 "generated/easymesh-parser.h" | |||
/// A Bison parser. | |||
class EasyMeshParser | |||
{ | |||
public: | |||
/// Symbol semantic values. | |||
#ifndef YYSTYPE | |||
union semantic_type | |||
{ | |||
/* 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; | |||
/* Line 35 of lalr1.cc */ | |||
#line 90 "generated/easymesh-parser.h" | |||
}; | |||
#else | |||
typedef YYSTYPE semantic_type; | |||
#endif | |||
/// Symbol locations. | |||
typedef location location_type; | |||
/// Tokens. | |||
struct token | |||
{ | |||
/* Tokens. */ | |||
enum yytokentype { | |||
T_END = 0, | |||
T_COLOR = 258, | |||
T_BGCOLOR = 259, | |||
T_TRANSLATEX = 260, | |||
T_ROTATEX = 261, | |||
T_TAPERX = 262, | |||
T_SCALEX = 263, | |||
T_MIRRORX = 264, | |||
T_TRANSLATEY = 265, | |||
T_ROTATEY = 266, | |||
T_TAPERY = 267, | |||
T_SCALEY = 268, | |||
T_MIRRORY = 269, | |||
T_TRANSLATEZ = 270, | |||
T_ROTATEZ = 271, | |||
T_TAPERZ = 272, | |||
T_SCALEZ = 273, | |||
T_MIRRORZ = 274, | |||
T_TRANSLATE = 275, | |||
T_SCALE = 276, | |||
T_CHAMFER = 277, | |||
T_CYLINDER = 278, | |||
T_BOX = 279, | |||
T_SMOOTHCHAMFBOX = 280, | |||
T_FLATCHAMFBOX = 281, | |||
T_SPHERE = 282, | |||
T_STAR = 283, | |||
T_EXPANDEDSTAR = 284, | |||
T_DISC = 285, | |||
T_TRIANGLE = 286, | |||
T_QUAD = 287, | |||
T_COG = 288, | |||
T_ERROR = 289, | |||
NUMBER = 290, | |||
COLOR = 291 | |||
}; | |||
}; | |||
/// Token type. | |||
typedef token::yytokentype token_type; | |||
/// Build a parser object. | |||
EasyMeshParser (class EasyMeshCompiler& mc_yyarg); | |||
virtual ~EasyMeshParser (); | |||
/// Parse. | |||
/// \returns 0 iff parsing succeeded. | |||
virtual int parse (); | |||
#if YYDEBUG | |||
/// The current debugging stream. | |||
std::ostream& debug_stream () const; | |||
/// Set the current debugging stream. | |||
void set_debug_stream (std::ostream &); | |||
/// Type for debugging levels. | |||
typedef int debug_level_type; | |||
/// The current debugging level. | |||
debug_level_type debug_level () const; | |||
/// Set the current debugging level. | |||
void set_debug_level (debug_level_type l); | |||
#endif | |||
private: | |||
/// Report a syntax error. | |||
/// \param loc where the syntax error is found. | |||
/// \param msg a description of the syntax error. | |||
virtual void error (const location_type& loc, const std::string& msg); | |||
/// Generate an error message. | |||
/// \param state the state where the error occurred. | |||
/// \param tok the lookahead token. | |||
virtual std::string yysyntax_error_ (int yystate, int tok); | |||
#if YYDEBUG | |||
/// \brief Report a symbol value on the debug stream. | |||
/// \param yytype The token type. | |||
/// \param yyvaluep Its semantic value. | |||
/// \param yylocationp Its location. | |||
virtual void yy_symbol_value_print_ (int yytype, | |||
const semantic_type* yyvaluep, | |||
const location_type* yylocationp); | |||
/// \brief Report a symbol on the debug stream. | |||
/// \param yytype The token type. | |||
/// \param yyvaluep Its semantic value. | |||
/// \param yylocationp Its location. | |||
virtual void yy_symbol_print_ (int yytype, | |||
const semantic_type* yyvaluep, | |||
const location_type* yylocationp); | |||
#endif | |||
/// State numbers. | |||
typedef int state_type; | |||
/// State stack type. | |||
typedef stack<state_type> state_stack_type; | |||
/// Semantic value stack type. | |||
typedef stack<semantic_type> semantic_stack_type; | |||
/// location stack type. | |||
typedef stack<location_type> location_stack_type; | |||
/// The state stack. | |||
state_stack_type yystate_stack_; | |||
/// The semantic value stack. | |||
semantic_stack_type yysemantic_stack_; | |||
/// 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. */ | |||
/// For a state, the index in \a yytable_ of its portion. | |||
static const signed char yypact_[]; | |||
static const signed char yypact_ninf_; | |||
/// 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_[]; | |||
static const signed char yypgoto_[]; | |||
static const signed char yydefgoto_[]; | |||
/// What to do in a state. | |||
/// \a yytable_[yypact_[s]]: what to do in state \a s. | |||
/// - if positive, shift that token. | |||
/// - if negative, reduce the rule which number is the opposite. | |||
/// - if zero, do what YYDEFACT says. | |||
static const unsigned char yytable_[]; | |||
static const signed char yytable_ninf_; | |||
static const signed char yycheck_[]; | |||
/// For a state, its accessing symbol. | |||
static const unsigned char yystos_[]; | |||
/// For a rule, its LHS. | |||
static const unsigned char yyr1_[]; | |||
/// For a rule, its RHS length. | |||
static const unsigned char yyr2_[]; | |||
#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE | |||
/// For a symbol, its name in clear. | |||
static const char* const yytname_[]; | |||
#endif | |||
/// Convert the symbol name \a n to a form suitable for a diagnostic. | |||
static std::string yytnamerr_ (const char *n); | |||
#if YYDEBUG | |||
/// A type to store symbol numbers and -1. | |||
typedef signed char rhs_number_type; | |||
/// A `-1'-separated list of the rules' RHS. | |||
static const rhs_number_type yyrhs_[]; | |||
/// For each rule, the index of the first RHS symbol in \a yyrhs_. | |||
static const unsigned char yyprhs_[]; | |||
/// For each rule, its source line number. | |||
static const unsigned char yyrline_[]; | |||
/// For each scanner token number, its symbol number. | |||
static const unsigned short int yytoken_number_[]; | |||
/// Report on the debug stream that the rule \a r is going to be reduced. | |||
virtual void yy_reduce_print_ (int r); | |||
/// Print the state stack on the debug stream. | |||
virtual void yystack_print_ (); | |||
/* Debugging. */ | |||
int yydebug_; | |||
std::ostream* yycdebug_; | |||
#endif | |||
/// Convert a scanner token number \a t to a symbol number. | |||
token_number_type yytranslate_ (int t); | |||
/// \brief Reclaim the memory associated to a symbol. | |||
/// \param yymsg Why this token is reclaimed. | |||
/// \param yytype The symbol type. | |||
/// \param yyvaluep Its semantic value. | |||
/// \param yylocationp Its location. | |||
inline void yydestruct_ (const char* yymsg, | |||
int yytype, | |||
semantic_type* yyvaluep, | |||
location_type* yylocationp); | |||
/// Pop \a n symbols the three stacks. | |||
inline void yypop_ (unsigned int n = 1); | |||
/* Constants. */ | |||
static const int yyeof_; | |||
/* LAST_ -- Last index in TABLE_. */ | |||
static const int yylast_; | |||
static const int yynnts_; | |||
static const int yyempty_; | |||
static const int yyfinal_; | |||
static const int yyterror_; | |||
static const int yyerrcode_; | |||
static const int yyntokens_; | |||
static const unsigned int yyuser_token_number_max_; | |||
static const token_number_type yyundef_token_; | |||
/* User arguments. */ | |||
class EasyMeshCompiler& mc; | |||
}; | |||
} // lol | |||
/* Line 35 of lalr1.cc */ | |||
#line 316 "generated/easymesh-parser.h" | |||
#endif /* ! defined PARSER_HEADER_H */ |
@@ -0,0 +1,164 @@ | |||
/* A Bison parser, made by GNU Bison 2.5. */ | |||
/* Locations for Bison parsers in C++ | |||
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 | |||
the Free Software Foundation, either version 3 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |||
/* As a special exception, you may create a larger work that contains | |||
part or all of the Bison parser skeleton and distribute that work | |||
under terms of your choice, so long as that work isn't itself a | |||
parser generator using the skeleton or a modified version thereof | |||
as a parser skeleton. Alternatively, if you modify or redistribute | |||
the parser skeleton itself, you may (at your option) remove this | |||
special exception, which will cause the skeleton and the resulting | |||
Bison output files to be licensed under the GNU General Public | |||
License without this special exception. | |||
This special exception was added by the Free Software Foundation in | |||
version 2.2 of Bison. */ | |||
/** | |||
** \file location.hh | |||
** Define the lol::location class. | |||
*/ | |||
#ifndef BISON_LOCATION_HH | |||
# define BISON_LOCATION_HH | |||
# include <iostream> | |||
# include <string> | |||
# include "position.hh" | |||
namespace lol { | |||
/* Line 162 of location.cc */ | |||
#line 50 "generated/location.hh" | |||
/// Abstract a location. | |||
class location | |||
{ | |||
public: | |||
/// Construct a location. | |||
location () | |||
: begin (), end () | |||
{ | |||
} | |||
/// Initialization. | |||
inline void initialize (std::string* fn) | |||
{ | |||
begin.initialize (fn); | |||
end = begin; | |||
} | |||
/** \name Line and Column related manipulators | |||
** \{ */ | |||
public: | |||
/// Reset initial location to final location. | |||
inline void step () | |||
{ | |||
begin = end; | |||
} | |||
/// Extend the current location to the COUNT next columns. | |||
inline void columns (unsigned int count = 1) | |||
{ | |||
end += count; | |||
} | |||
/// Extend the current location to the COUNT next lines. | |||
inline void lines (unsigned int count = 1) | |||
{ | |||
end.lines (count); | |||
} | |||
/** \} */ | |||
public: | |||
/// Beginning of the located region. | |||
position begin; | |||
/// End of the located region. | |||
position end; | |||
}; | |||
/// Join two location objects to create a location. | |||
inline const location operator+ (const location& begin, const location& end) | |||
{ | |||
location res = begin; | |||
res.end = end.end; | |||
return res; | |||
} | |||
/// Add two location objects. | |||
inline const location operator+ (const location& begin, unsigned int width) | |||
{ | |||
location res = begin; | |||
res.columns (width); | |||
return res; | |||
} | |||
/// Add and assign a location. | |||
inline location& operator+= (location& res, unsigned int width) | |||
{ | |||
res.columns (width); | |||
return res; | |||
} | |||
/// Compare two location objects. | |||
inline bool | |||
operator== (const location& loc1, const location& loc2) | |||
{ | |||
return loc1.begin == loc2.begin && loc1.end == loc2.end; | |||
} | |||
/// Compare two location objects. | |||
inline bool | |||
operator!= (const location& loc1, const location& loc2) | |||
{ | |||
return !(loc1 == loc2); | |||
} | |||
/** \brief Intercept output stream redirection. | |||
** \param ostr the destination output stream | |||
** \param loc a reference to the location to redirect | |||
** | |||
** Avoid duplicate information. | |||
*/ | |||
inline std::ostream& operator<< (std::ostream& ostr, const location& loc) | |||
{ | |||
position last = loc.end - 1; | |||
ostr << loc.begin; | |||
if (last.filename | |||
&& (!loc.begin.filename | |||
|| *loc.begin.filename != *last.filename)) | |||
ostr << '-' << last; | |||
else if (loc.begin.line != last.line) | |||
ostr << '-' << last.line << '.' << last.column; | |||
else if (loc.begin.column != last.column) | |||
ostr << '-' << last.column; | |||
return ostr; | |||
} | |||
} // lol | |||
/* Line 271 of location.cc */ | |||
#line 163 "generated/location.hh" | |||
#endif // not BISON_LOCATION_HH |
@@ -0,0 +1,161 @@ | |||
/* A Bison parser, made by GNU Bison 2.5. */ | |||
/* Positions for Bison parsers in C++ | |||
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 | |||
the Free Software Foundation, either version 3 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |||
/* As a special exception, you may create a larger work that contains | |||
part or all of the Bison parser skeleton and distribute that work | |||
under terms of your choice, so long as that work isn't itself a | |||
parser generator using the skeleton or a modified version thereof | |||
as a parser skeleton. Alternatively, if you modify or redistribute | |||
the parser skeleton itself, you may (at your option) remove this | |||
special exception, which will cause the skeleton and the resulting | |||
Bison output files to be licensed under the GNU General Public | |||
License without this special exception. | |||
This special exception was added by the Free Software Foundation in | |||
version 2.2 of Bison. */ | |||
/** | |||
** \file position.hh | |||
** Define the lol::position class. | |||
*/ | |||
#ifndef BISON_POSITION_HH | |||
# define BISON_POSITION_HH | |||
# include <iostream> | |||
# include <string> | |||
# include <algorithm> | |||
namespace lol { | |||
/* Line 37 of location.cc */ | |||
#line 50 "generated/position.hh" | |||
/// Abstract a position. | |||
class position | |||
{ | |||
public: | |||
/// Construct a position. | |||
position () | |||
: filename (0), line (1), column (1) | |||
{ | |||
} | |||
/// Initialization. | |||
inline void initialize (std::string* fn) | |||
{ | |||
filename = fn; | |||
line = 1; | |||
column = 1; | |||
} | |||
/** \name Line and Column related manipulators | |||
** \{ */ | |||
public: | |||
/// (line related) Advance to the COUNT next lines. | |||
inline void lines (int count = 1) | |||
{ | |||
column = 1; | |||
line += count; | |||
} | |||
/// (column related) Advance to the COUNT next columns. | |||
inline void columns (int count = 1) | |||
{ | |||
column = std::max (1u, column + count); | |||
} | |||
/** \} */ | |||
public: | |||
/// File name to which this position refers. | |||
std::string* filename; | |||
/// Current line number. | |||
unsigned int line; | |||
/// Current column number. | |||
unsigned int column; | |||
}; | |||
/// Add and assign a position. | |||
inline const position& | |||
operator+= (position& res, const int width) | |||
{ | |||
res.columns (width); | |||
return res; | |||
} | |||
/// Add two position objects. | |||
inline const position | |||
operator+ (const position& begin, const int width) | |||
{ | |||
position res = begin; | |||
return res += width; | |||
} | |||
/// Add and assign a position. | |||
inline const position& | |||
operator-= (position& res, const int width) | |||
{ | |||
return res += -width; | |||
} | |||
/// Add two position objects. | |||
inline const position | |||
operator- (const position& begin, const int width) | |||
{ | |||
return begin + -width; | |||
} | |||
/// Compare two position objects. | |||
inline bool | |||
operator== (const position& pos1, const position& pos2) | |||
{ | |||
return (pos1.line == pos2.line | |||
&& pos1.column == pos2.column | |||
&& (pos1.filename == pos2.filename | |||
|| (pos1.filename && pos2.filename | |||
&& *pos1.filename == *pos2.filename))); | |||
} | |||
/// Compare two position objects. | |||
inline bool | |||
operator!= (const position& pos1, const position& pos2) | |||
{ | |||
return !(pos1 == pos2); | |||
} | |||
/** \brief Intercept output stream redirection. | |||
** \param ostr the destination output stream | |||
** \param pos a reference to the position to redirect | |||
*/ | |||
inline std::ostream& | |||
operator<< (std::ostream& ostr, const position& pos) | |||
{ | |||
if (pos.filename) | |||
ostr << *pos.filename << ':'; | |||
return ostr << pos.line << '.' << pos.column; | |||
} | |||
} // lol | |||
/* Line 144 of location.cc */ | |||
#line 161 "generated/position.hh" | |||
#endif // not BISON_POSITION_HH |
@@ -0,0 +1,135 @@ | |||
/* A Bison parser, made by GNU Bison 2.5. */ | |||
/* Stack handling for Bison parsers in C++ | |||
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 | |||
the Free Software Foundation, either version 3 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |||
/* As a special exception, you may create a larger work that contains | |||
part or all of the Bison parser skeleton and distribute that work | |||
under terms of your choice, so long as that work isn't itself a | |||
parser generator using the skeleton or a modified version thereof | |||
as a parser skeleton. Alternatively, if you modify or redistribute | |||
the parser skeleton itself, you may (at your option) remove this | |||
special exception, which will cause the skeleton and the resulting | |||
Bison output files to be licensed under the GNU General Public | |||
License without this special exception. | |||
This special exception was added by the Free Software Foundation in | |||
version 2.2 of Bison. */ | |||
#ifndef BISON_STACK_HH | |||
# define BISON_STACK_HH | |||
#include <deque> | |||
namespace lol { | |||
/* Line 1149 of lalr1.cc */ | |||
#line 43 "generated/stack.hh" | |||
template <class T, class S = std::deque<T> > | |||
class stack | |||
{ | |||
public: | |||
// Hide our reversed order. | |||
typedef typename S::reverse_iterator iterator; | |||
typedef typename S::const_reverse_iterator const_iterator; | |||
stack () : seq_ () | |||
{ | |||
} | |||
stack (unsigned int n) : seq_ (n) | |||
{ | |||
} | |||
inline | |||
T& | |||
operator [] (unsigned int i) | |||
{ | |||
return seq_[i]; | |||
} | |||
inline | |||
const T& | |||
operator [] (unsigned int i) const | |||
{ | |||
return seq_[i]; | |||
} | |||
inline | |||
void | |||
push (const T& t) | |||
{ | |||
seq_.push_front (t); | |||
} | |||
inline | |||
void | |||
pop (unsigned int n = 1) | |||
{ | |||
for (; n; --n) | |||
seq_.pop_front (); | |||
} | |||
inline | |||
unsigned int | |||
height () const | |||
{ | |||
return seq_.size (); | |||
} | |||
inline const_iterator begin () const { return seq_.rbegin (); } | |||
inline const_iterator end () const { return seq_.rend (); } | |||
private: | |||
S seq_; | |||
}; | |||
/// Present a slice of the top of a stack. | |||
template <class T, class S = stack<T> > | |||
class slice | |||
{ | |||
public: | |||
slice (const S& stack, | |||
unsigned int range) : stack_ (stack), | |||
range_ (range) | |||
{ | |||
} | |||
inline | |||
const T& | |||
operator [] (unsigned int i) const | |||
{ | |||
return stack_[range_ - i]; | |||
} | |||
private: | |||
const S& stack_; | |||
unsigned int range_; | |||
}; | |||
} // lol | |||
/* Line 1235 of lalr1.cc */ | |||
#line 133 "generated/stack.hh" | |||
#endif // not BISON_STACK_HH[]dnl | |||
@@ -81,11 +81,15 @@ | |||
<ClCompile Include="..\src\debug\sphere.cpp" /> | |||
<ClCompile Include="..\src\debug\stats.cpp" /> | |||
<ClCompile Include="..\src\dict.cpp" /> | |||
<ClCompile Include="..\src\easymesh\easymesh-compiler.cpp" /> | |||
<ClCompile Include="..\src\easymesh\easymesh.cpp" /> | |||
<ClCompile Include="..\src\eglapp.cpp" /> | |||
<ClCompile Include="..\src\emitter.cpp" /> | |||
<ClCompile Include="..\src\entity.cpp" /> | |||
<ClCompile Include="..\src\font.cpp" /> | |||
<ClCompile Include="..\src\forge.cpp" /> | |||
<ClCompile Include="..\src\generated\easymesh-parser.cpp" /> | |||
<ClCompile Include="..\src\generated\easymesh-scanner.cpp" /> | |||
<ClCompile Include="..\src\gpu\framebuffer.cpp" /> | |||
<ClCompile Include="..\src\gpu\indexbuffer.cpp" /> | |||
<ClCompile Include="..\src\gpu\shader.cpp" /> | |||
@@ -141,11 +145,17 @@ | |||
<ClInclude Include="..\src\debug\sphere.h" /> | |||
<ClInclude Include="..\src\debug\stats.h" /> | |||
<ClInclude Include="..\src\dict.h" /> | |||
<ClInclude Include="..\src\easymesh\easymesh-compiler.h" /> | |||
<ClInclude Include="..\src\easymesh\easymesh.h" /> | |||
<ClInclude Include="..\src\eglapp.h" /> | |||
<ClInclude Include="..\src\emitter.h" /> | |||
<ClInclude Include="..\src\entity.h" /> | |||
<ClInclude Include="..\src\font.h" /> | |||
<ClInclude Include="..\src\forge.h" /> | |||
<ClInclude Include="..\src\generated\easymesh-parser.h" /> | |||
<ClInclude Include="..\src\generated\location.hh" /> | |||
<ClInclude Include="..\src\generated\position.hh" /> | |||
<ClInclude Include="..\src\generated\stack.hh" /> | |||
<ClInclude Include="..\src\gpu\framebuffer.h" /> | |||
<ClInclude Include="..\src\gpu\indexbuffer.h" /> | |||
<ClInclude Include="..\src\gpu\shader.h" /> | |||
@@ -193,10 +203,15 @@ | |||
<ClInclude Include="..\src\worldentity.h" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<LolFxCompile Include="..\src\easymesh\shiny.lolfx" /> | |||
<LolFxCompile Include="..\src\gpu\defaultmaterial.lolfx" /> | |||
<LolFxCompile Include="..\src\gpu\emptymaterial.lolfx" /> | |||
<LolFxCompile Include="..\src\gpu\testmaterial.lolfx" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="..\src\easymesh\easymesh-parser.y" /> | |||
<None Include="..\src\easymesh\easymesh-scanner.l" /> | |||
</ItemGroup> | |||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> | |||
<ImportGroup Label="ExtensionTargets"> | |||
<Import Project="$(SolutionDir)\Lol.Fx.targets" /> | |||
@@ -50,6 +50,12 @@ | |||
<Filter Include="src\..."> | |||
<UniqueIdentifier>{3592ed6a-59d7-4a6d-be5a-c05cb5dab730}</UniqueIdentifier> | |||
</Filter> | |||
<Filter Include="src\generated"> | |||
<UniqueIdentifier>{8d536fa6-9ef8-4bdb-b945-48fe4549e8ec}</UniqueIdentifier> | |||
</Filter> | |||
<Filter Include="src\easymesh"> | |||
<UniqueIdentifier>{07117029-d79d-4d59-beec-691b00a97c8f}</UniqueIdentifier> | |||
</Filter> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClCompile Include="..\src\image\image.cpp"> | |||
@@ -217,6 +223,18 @@ | |||
<ClCompile Include="..\src\gpu\framebuffer.cpp"> | |||
<Filter>src\gpu</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\src\easymesh\easymesh.cpp"> | |||
<Filter>src\easymesh</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\src\easymesh\easymesh-compiler.cpp"> | |||
<Filter>src\easymesh</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\src\generated\easymesh-parser.cpp"> | |||
<Filter>src\generated</Filter> | |||
</ClCompile> | |||
<ClCompile Include="..\src\generated\easymesh-scanner.cpp"> | |||
<Filter>src\generated</Filter> | |||
</ClCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ClInclude Include="..\src\image\image.h"> | |||
@@ -405,6 +423,24 @@ | |||
<ClInclude Include="..\src\gpu\framebuffer.h"> | |||
<Filter>src\gpu</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\generated\position.hh"> | |||
<Filter>src\generated</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\generated\location.hh"> | |||
<Filter>src\generated</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\generated\stack.hh"> | |||
<Filter>src\generated</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\easymesh\easymesh.h"> | |||
<Filter>src\easymesh</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\easymesh\easymesh-compiler.h"> | |||
<Filter>src\easymesh</Filter> | |||
</ClInclude> | |||
<ClInclude Include="..\src\generated\easymesh-parser.h"> | |||
<Filter>src\generated</Filter> | |||
</ClInclude> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<LolFxCompile Include="..\src\gpu\emptymaterial.lolfx"> | |||
@@ -416,5 +452,16 @@ | |||
<LolFxCompile Include="..\src\gpu\testmaterial.lolfx"> | |||
<Filter>src\gpu</Filter> | |||
</LolFxCompile> | |||
<LolFxCompile Include="..\src\easymesh\shiny.lolfx"> | |||
<Filter>src\easymesh</Filter> | |||
</LolFxCompile> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<None Include="..\src\easymesh\easymesh-parser.y"> | |||
<Filter>src\easymesh</Filter> | |||
</None> | |||
<None Include="..\src\easymesh\easymesh-scanner.l"> | |||
<Filter>src\easymesh</Filter> | |||
</None> | |||
</ItemGroup> | |||
</Project> |