Re: Reflection in game engine (c++)

"Nathan Martz" <[email protected]> Thu, 14 Mar 2013 16:40:27 -0700
Newsgroups gmane.games.devel.sweng
Message-ID <A1693E7EC0F6AB40BF00BF17BAE9AC890B955D7C@clem>
This is a multi-part message in MIME format.

--===============0304474254==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
	boundary="----_=_NextPart_001_01CE210D.4EF6693B"

This is a multi-part message in MIME format.

------_=_NextPart_001_01CE210D.4EF6693B
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

We use something very similar to what Adrian describes on his blog here
at DF. The syntax is a bit different, but I'd definitely vouch taking an
approach like the one Adrian describes. One really great upside of this
type of solution is that done right, there's not much boilerplate at all
and you get the benefit of the entire system being implemented in code
that you own and know. Building solutions off of heavy weight tools like
CLANG or a big lexer or whatever may open up big long term opportunities
and eventually minimize the amount of "boilerplate" someone needs to
write, but it requires you (and anyone who will extend or maintain the
system) to develop deep knowledge of some seriously complex software, so
much so that it may make the investment prohibitive.

=20

-Nathan

=20

From: [email protected]
[mailto:[email protected]] On Behalf Of
Adrian Stone
Sent: Thursday, March 14, 2013 4:29 PM
To: [email protected]
Subject: Re: [Sweng-Gamedev] Reflection in game engine (c++)

=20

=20

I'm not sure which number describes our approach, but we've been using
it for about 8 years on many different projects and I believe everyone
on the team has been very happy with it.  I've written about it pretty
extensively here: http://gameangst.com/?p=3D107

=20

There are some implementation details I'd change if I were starting over
from scratch, but I still think that using advanced C++ features to
create an embedded DSL is the best option for reflection in C++.

=20

Adrian

=20

=20

________________________________

From: [email protected]
[mailto:[email protected]] On Behalf Of Alen
Ladavac
Sent: Thursday, March 14, 2013 6:45 PM
To: Gabriel Sassone
Cc: [email protected];
[email protected]
Subject: Re: [Sweng-Gamedev] Reflection in game engine (c++)

=20

We've been using #4 in our projects for a decade already and it works a
treat. And... why couldn't you invoke methods? :)

That method is the only really fully portable (AFAIK), as it doesn't
really care what compiler/toolset you have. It is also very light in
terms of runtime requirements, and very easy to use (not much extra
typing for each class, member or function).=20

Though it is rather involved to implement.

JM2C,
Alen

Thursday, March 14, 2013, 7:09:30 PM, you wrote:

=20

Hello gents,
   I wanted to experiment with reflection and I found different way to
obtain it:

  1) Invasive macro based registration
  2) Reflection visitor pattern
  3) Parsing pdb/clang stuff and create a manual table of what you
want/need
  4) c++ custom parser that uses tags to create reflection informations
(like a comment near a member, ...) (exuberant ctags???)
  5) create serializable/reflected classes in a data format, then run a
tool that generates headers and cpps

I am trying to figure out flaws and merits of each kind, and even if
there are other solutions.
I love the idea to have the possibility to serialize in and out
structures, access fields and change values, stream in/out stuff from
network ,and maybe link with scripting.

My goal is to have fast iteration times, both artists and programmers,
and I achieved it for rendering programmers already with having json
binarized configurable rendering, but still there are code stuff that
are not easy to achieve.

Here are my thoughts, but I would like to hear your ideas and
experiences!

1) Very precise on what you can register/serialize, but painful to
maintain or plug into an existing codebase
2) Less precise but you just need one method per class, that you can use
to serialize/reflect. Still bad in maintaining, but better in plugging
in.
3) You make the compiler do the work, then translate the informations
you need in your format. Easy to maintain, to plug...maybe slow in
parsing? Slow your build pipeline?
4) maybe easier than using pdbs, but less powerful (you cannot invoke
methods on objects). should be faster than 3.
5) crazy idea. requires generation of code from outside...powerful like
4, so data reflection, but you cannot invoke methods if you want.

What are your experiences/thoughts?

Thanks to everyone that read this mail!
=20
    Gabriel





--=20
Best regards,
 Alen                            mailto:[email protected]


------_=_NextPart_001_01CE210D.4EF6693B
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><META =
HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii"><meta name=3DGenerator content=3D"Microsoft Word 12 =
(filtered medium)"><!--[if !mso]><style>v\:* =
{behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><title>Re: [Sweng-Gamedev] Reflection in game engine =
(c++)</title><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
	{mso-style-priority:99;
	mso-style-link:"Balloon Text Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:8.0pt;
	font-family:"Tahoma","sans-serif";}
span.EmailStyle17
	{mso-style-type:personal;
	font-family:"Arial","sans-serif";
	color:navy;}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
span.BalloonTextChar
	{mso-style-name:"Balloon Text Char";
	mso-style-priority:99;
	mso-style-link:"Balloon Text";
	font-family:"Tahoma","sans-serif";}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dblue><div class=3DWordSection1><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>We use something very similar to what Adrian describes on his blog =
here at DF. The syntax is a bit different, but I&#8217;d definitely =
vouch taking an approach like the one Adrian describes. One really great =
upside of this type of solution is that done right, there&#8217;s not =
much boilerplate at all and you get the benefit of the entire system =
being implemented in code that you own and know. Building solutions off =
of heavy weight tools like CLANG or a big lexer or whatever may open up =
big long term opportunities and eventually minimize the amount of =
&#8220;boilerplate&#8221; someone needs to write, but it requires you =
(and anyone who will extend or maintain the system) to develop deep =
knowledge of some seriously complex software, so much so that it may =
make the investment prohibitive.<o:p></o:p></span></p><p =
class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>-Nathan<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><div><div =
style=3D'border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in =
0in 0in'><p class=3DMsoNormal><b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> =
[email protected] =
[mailto:[email protected]] <b>On Behalf Of =
</b>Adrian Stone<br><b>Sent:</b> Thursday, March 14, 2013 4:29 =
PM<br><b>To:</b> [email protected]<br><b>Subject:</b> Re: =
[Sweng-Gamedev] Reflection in game engine =
(c++)<o:p></o:p></span></p></div></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'><o=
:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'>I&=
#8217;m not sure which number describes our approach, but we&#8217;ve =
been using it for about 8 years on many different projects and I believe =
everyone on the team has been very happy with it.&nbsp; I&#8217;ve =
written about it pretty extensively here: <a =
href=3D"http://gameangst.com/?p=3D107">http://gameangst.com/?p=3D107</a><=
o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'><o=
:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'>Th=
ere are some implementation details I&#8217;d change if I were starting =
over from scratch, but I still think that using advanced C++ features to =
create an embedded DSL is the best option for reflection in =
C++.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'><o=
:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'>Ad=
rian<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'><o=
:p>&nbsp;</o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:10.0pt;font-family:"Arial","sans-serif";color:navy'><o=
:p>&nbsp;</o:p></span></p><div style=3D'border:none;border-left:solid =
blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div class=3DMsoNormal =
align=3Dcenter style=3D'text-align:center'><hr size=3D2 width=3D"100%" =
align=3Dcenter></div><p class=3DMsoNormal><b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> =
<a =
href=3D"mailto:[email protected]">sweng-gamed=
[email protected]</a> [<a =
href=3D"mailto:[email protected]">mailto:swen=
[email protected]</a>] <b>On Behalf Of </b>Alen =
Ladavac<br><b>Sent:</b> Thursday, March 14, 2013 6:45 PM<br><b>To:</b> =
Gabriel Sassone<br><b>Cc:</b> <a =
href=3D"mailto:[email protected]">sweng-gamedev@lists=
.midnightryder.com</a>; <a =
href=3D"mailto:[email protected]">sweng-gamedev@midnightryd=
er.com</a><br><b>Subject:</b> Re: [Sweng-Gamedev] Reflection in game =
engine (c++)</span><o:p></o:p></p></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><p class=3DMsoNormal =
style=3D'margin-bottom:12.0pt'><span =
style=3D'font-size:9.0pt;font-family:"Courier New"'>We've been using #4 =
in our projects for a decade already and it works a treat. And... why =
couldn't you invoke methods? :)<br><br>That method is the only really =
fully portable (AFAIK), as it doesn't really care what compiler/toolset =
you have. It is also very light in terms of runtime requirements, and =
very easy to use (not much extra typing for each class, member or =
function).&nbsp;<br><br>Though it is rather involved to =
implement.<br><br>JM2C,<br>Alen<br><br>Thursday, March 14, 2013, 7:09:30 =
PM, you wrote:</span><o:p></o:p></p><table class=3DMsoNormalTable =
border=3D0 cellpadding=3D0><tr><td width=3D15 =
style=3D'width:11.25pt;background:blue;padding:.75pt .75pt .75pt =
.75pt'><p class=3DMsoNormal><o:p>&nbsp;</o:p></p></td><td width=3D1142 =
style=3D'width:856.5pt;padding:.75pt .75pt .75pt .75pt'><p =
class=3DMsoNormal><span style=3D'font-size:9.0pt;font-family:"Courier =
New"'>Hello gents,<br>&nbsp; &nbsp;I wanted to experiment with =
reflection and I found different way to obtain it:<br><br>&nbsp; 1) =
Invasive macro based registration<br>&nbsp; 2) Reflection visitor =
pattern<br>&nbsp; 3) Parsing pdb/clang stuff and create a manual table =
of what you want/need<br>&nbsp; 4) c++ custom parser that uses tags to =
create reflection informations (like a comment near a member, ...) =
(exuberant ctags???)<br>&nbsp; 5) create serializable/reflected classes =
in a data format, then run a tool that generates headers and =
cpps<br><br>I am trying to figure out flaws and merits of each kind, and =
even if there are other solutions.<br>I love the idea to have the =
possibility to serialize in and out structures, access fields and change =
values, stream in/out stuff from network ,and maybe link with =
scripting.<br><br>My goal is to have fast iteration times, both artists =
and programmers, and I achieved it for rendering programmers already =
with having json binarized configurable rendering, but still there are =
code stuff that are not easy to achieve.<br><br>Here are my thoughts, =
but I would like to hear your ideas and experiences!<br><br>1) Very =
precise on what you can register/serialize, but painful to maintain or =
plug into an existing codebase<br>2) Less precise but you just need one =
method per class, that you can use to serialize/reflect. Still bad in =
maintaining, but better in plugging in.<br>3) You make the compiler do =
the work, then translate the informations you need in your format. Easy =
to maintain, to plug...maybe slow in parsing? Slow your build =
pipeline?<br>4) maybe easier than using pdbs, but less powerful (you =
cannot invoke methods on objects). should be faster than 3.<br>5) crazy =
idea. requires generation of code from outside...powerful like 4, so =
data reflection, but you cannot invoke methods if you want.<br><br>What =
are your experiences/thoughts?<br><br>Thanks to everyone that read this =
mail!<br>&nbsp;<br>&nbsp; &nbsp; =
Gabriel</span><o:p></o:p></p></td></tr></table><p =
class=3DMsoNormal><br><br><br><br><i><span =
style=3D'font-family:"Arial","sans-serif";color:silver'>--&nbsp;<br>Best =
regards,<br>&nbsp;Alen &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</span></i><a =
href=3D"mailto:[email protected]">mailto:[email protected]</a><o:p>=
</o:p></p></div></div></body></html>
------_=_NextPart_001_01CE210D.4EF6693B--

--===============0304474254==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Sweng-Gamedev mailing list
[email protected]
http://lists.midnightryder.com/listinfo.cgi/sweng-gamedev-midnightryder.com

--===============0304474254==--