Re: Reflection in game engine (c++)

Don Williamson <[email protected]> Fri, 15 Mar 2013 07:37:42 +0000
Newsgroups gmane.games.devel.sweng
Message-ID <CALtdbSXjBJfhNEtLVDFjxkSf_sC7KcVoPuj4QOm_vtAVcB9KCg@mail.gmail.com>
--===============1635441320==
Content-Type: multipart/alternative; boundary=047d7b86de88e7df3d04d7f1b62a

--047d7b86de88e7df3d04d7f1b62a
Content-Type: text/plain; charset=ISO-8859-1

You will never get an ideal C++ reflection system; you just have to pick
one technique that:

* Is as simple and transparent as possible.
* Suits the programming background of the majority of your team.
* Gives most benefits for the target game (not tech for tech's sake).

All methods can achieve that, but all methods can similarly bring your
entire code base to an over-engineered death of spectacular proportions. Be
careful and don't try to solve too many problems that C++ wasn't designed
to solve in the first place.

With that in mind, here's some experiences I've shared in the past...

This post covers a broad overview of various reflection techniques:

http://www.altdevblogaday.com/2011/09/25/reflection-in-c-part-1-introduction/

This post covers the SC5 approach, which includes live C++ code reloading
for the engine (we were doing this back in 2005):

http://www.altdevblogaday.com/2012/01/03/reflection-in-c-part-2-the-simple-implementation-of-splinter-cell/

I was working on part 3 that covers the use of IDL or DDL files. I can't
seem to find the latest draft (I've gotten really lazy over this) but I
still have a draft upload from a while ago:
   http://donw.org/b/?d=adr

My own company's code base is engineered with a clang parser that does all
this automatically. I've open-sourced most of it as clReflect:
   https://bitbucket.org/dwilliamson/clreflect

I use it for transparent interop between native C++ and javascript browser
code, live C++ code reloading, serialisation, replay logic, network code
and many other things. It also compiles across Windows, Mac OSX and Linux.
However, it's not seeing many updates these days because it's very stable
for the target application I made it for, meaning it may not work out of
the box for you (patches make me happy!). One nice point, is that you
probably won't see a simpler runtime reflection engine as there is no
registration required at runtime, beyond loading a binary blob and patching
up pointers.

Some alternative research implementations include:
   https://bitbucket.org/dwilliamson/reflectabit - Manual registration with
C++ templates
   https://bitbucket.org/dwilliamson/rfl - Auto-reflection through PDB
files (very powerful but may break any day MS decides to change or hide
their API).

So, yeah... pick one. But try to make it as invisible to your engineers as
possible :)

Cheers,
- Don

--047d7b86de88e7df3d04d7f1b62a
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

You will never get an ideal C++ reflection system; you just have to pick on=
e technique that:<div><br></div><div>* Is as simple and transparent as poss=
ible.</div><div>* Suits the programming background of the majority of your =
team.</div>
<div>* Gives most benefits for the target game (not tech for tech&#39;s sak=
e).</div><div><br></div><div>All methods can achieve that, but all methods =
can similarly bring your entire code base to an over-engineered death of sp=
ectacular proportions. Be careful and don&#39;t try to solve too many probl=
ems that C++ wasn&#39;t designed to solve in the first place.<div>
<br></div><div>With that in mind, here&#39;s some experiences I&#39;ve shar=
ed in the past...</div><div><br></div><div>This post covers a broad overvie=
w of various reflection techniques:</div><div>=A0 =A0<a href=3D"http://www.=
altdevblogaday.com/2011/09/25/reflection-in-c-part-1-introduction/">http://=
www.altdevblogaday.com/2011/09/25/reflection-in-c-part-1-introduction/</a><=
/div>
<div><br></div><div>This post covers the SC5 approach, which includes live =
C++ code reloading for the engine (we were doing this back in 2005):</div><=
div>=A0 =A0<a href=3D"http://www.altdevblogaday.com/2012/01/03/reflection-i=
n-c-part-2-the-simple-implementation-of-splinter-cell/">http://www.altdevbl=
ogaday.com/2012/01/03/reflection-in-c-part-2-the-simple-implementation-of-s=
plinter-cell/</a></div>
<div><br></div><div>I was working on part 3 that covers the use of IDL or D=
DL files. I can&#39;t seem to find the latest draft (I&#39;ve gotten really=
 lazy over this) but I still have a draft upload from a while ago:</div>
<div>=A0 =A0<a href=3D"http://donw.org/b/?d=3Dadr">http://donw.org/b/?d=3Da=
dr</a></div><div><br>My own company&#39;s code base is engineered with a cl=
ang parser that does all this automatically. I&#39;ve open-sourced most of =
it as clReflect:</div>
</div><div>=A0 =A0<a href=3D"https://bitbucket.org/dwilliamson/clreflect">h=
ttps://bitbucket.org/dwilliamson/clreflect</a></div><div><br></div><div>I u=
se it for transparent interop between native C++ and javascript browser cod=
e, live C++ code reloading, serialisation, replay logic, network code and m=
any other things. It also compiles across Windows, Mac OSX and Linux. Howev=
er, it&#39;s not seeing many updates these days because it&#39;s very stabl=
e for the target application I made it for, meaning it may not work out of =
the box for you (patches make me happy!). One nice point, is that you proba=
bly won&#39;t see a simpler runtime reflection engine as there is no regist=
ration required at runtime, beyond loading a binary blob and patching up po=
inters.</div>
<div><br></div><div>Some alternative research implementations include:</div=
><div>=A0 =A0<a href=3D"https://bitbucket.org/dwilliamson/reflectabit">http=
s://bitbucket.org/dwilliamson/reflectabit</a> - Manual registration with C+=
+ templates</div>
<div>=A0 =A0<a href=3D"https://bitbucket.org/dwilliamson/rfl">https://bitbu=
cket.org/dwilliamson/rfl</a> - Auto-reflection through PDB files (very powe=
rful but may break any day MS decides to change or hide their API).</div><d=
iv>
<br></div><div>So, yeah... pick one. But try to make it as invisible to you=
r=A0engineers as possible :)</div><div><br></div><div>Cheers,</div><div>- D=
on</div><br>

--047d7b86de88e7df3d04d7f1b62a--

--===============1635441320==
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

--===============1635441320==--