CppCast - C++ and Lua Game Development
Episode Date: July 6, 2016Rob and Jason are joined by Elias Daler, CS student and Indie game developer to discuss game development with C++ and Lua. Elias Daler is a CS student, indie game developer and C++ enthusiast.... Passion for game development was the starting point for learning C++ and he's been programming in it for 6 years. Elias is working on a game called Re:creation and various open source C++ libraries. He also writes various articles about game development, C++ and Lua/C++ integration at eliasdaler.wordpress.com. These articles are well received and frequently shared on various game development subreddits and forums. News Status Update on Qt for WinRT/UWP Trip report: Summer ISO C++ standards meeting Visual Studio Update 3 has been released Registration for CppCon 2016 is open Elias Daler @EliasDaler Elias' New Blog Elias' Old Blog Links Sol2 ImGui SFML Sponsor Incredibuild
Transcript
Discussion (0)
This episode of CppCast is sponsored by Incredibuild.
You won't believe how fast your build can run until you download your free developer version
at incredibuild.com slash cppoffer or just click the link on our website.
CppCast is also sponsored by CppCon, the annual week-long face-to-face gathering
for the entire C++ community.
Episode 62 of CppCast with guest Elias Daler recorded July 6th, 2016.
In this episode, we talk about updates from Qt and Visual Studio.
Then we talk to Elias Daler, a CS student currently developing the game Recreation.
Elias talks to us about developing his only podcast for C++ developers by C++ developers.
I'm your host, Rob Irving, joined by my co-host, Jason Turner.
Jason, how are you doing today?
All right, Rob. I saw that 62. I heard you say 62.
I'm like, 62, really?
Yeah, I know.
And it's been about a year and a half now, so we're keeping up a pretty good pace.
I wonder what we'll hit by the end of the year.
I guess maybe about 90 or so
uh sounds about right maybe i can't do that math at the moment i don't feel like doing that math
five times four is 20 yeah well 80s anyhow yeah something like that
uh so congratulations again for uh winning another microsoft mvp award jason and congratulations to
you as well.
Thank you.
Thank you.
Although mine's still not in C plus plus,
which is a little disappointing.
It's still,
Oh,
I didn't realize that.
Oh,
yeah.
But,
uh,
you know,
maybe,
uh,
maybe that'll change after this year.
I don't know.
I'm definitely doing more C plus plus stuff.
Maybe you'll have multiple awards starting next year.
Maybe,
maybe you never know.
I believe that's possible.
I think it is now.
Yeah.
Not that it actually gets you anything extra.
No,
and I'm already on the C++ mailing list.
So anyway,
uh,
at the top of every episode,
I like to read a piece of feedback.
Uh,
this week,
uh,
Rodrigo Montero wrote in on Twitter saying he's trying to forget about
Brexit for a bit by walk, having a walk while listening to CPP cast talking to Herb Sutter.
It was a great episode a week and a half ago talking to Herb Sutter.
I'm glad it's able to distract you from all the chaos happening in England right now.
It's great that that tweet also has the location.
He was in London when he sent it.
Yes, it's legit.
It is a legit Brexit tweet.
We'd love to hear your thoughts about the show as well.
You can always reach out to us on Facebook, Twitter, or email us at feedback at cppcast.com.
And don't forget to leave us reviews on iTunes.
Joining us today is Elias Daler.
Elias is a CS student, indie game developer, and C++ enthusiast.
He's got a passion for game development, and it was a starting point for learning C++,
and he's been programming in it for six years.
Elias is working on a game called Recreation and various open-source C++ libraries.
He also writes various articles about game development, C++, and Lua C++ integration
at EliasDaler.wordpress.com.
These articles are usually well-received and frequently shared on various game development
subreddits and forums.
Elias, welcome to the show.
Hey, thanks for having me.
Great to have you on.
So we had a couple of news items to go into, and then we'll start asking you questions
about all your work in game development and scripting and everything.
So the first article I have here is a status update on Qt,
or Qt, depending on how you want to pronounce it,
for WinRT and UWP.
So I thought this was pretty interesting.
If you're not familiar with the terms WinRT or UWP, it's the new Windows 10 app development model.
So if you wanted to develop an app for Windows, HoloLens, Windows Phone,
this is the newest way to do it, and Qt is working on adding support.
So if you want to be able to do it with C++ code that you can then share to other platforms as well,
that could be a really great option for you. I thought it was interesting that they said they did test it on the HoloLens
emulators, although they didn't have an actual device to test their QT integration on.
I didn't realize there was a HoloLens emulator.
Yeah, I actually haven't tried it myself, but I hear it actually works pretty well and it can be
easier to test on
compared to the actual device that's gonna say what's the point since you have access to an
actual hololens yeah i guess it depends on what type of hololens app you're making okay probably
somewhere the emulator makes sense and there's somewhere you just can't really do it without
having the device on yeah uh anything else you want to add here jason uh no i just uh yeah i just thought
it was interesting you know xbox one and hololens and everything else and and kind of in context of
how we've been discussing lately that uis in c++ are easier to do you know with javascript bridges
lately um so i just i was like yeah, Qt is still being updated,
which is, you know, I mean, I know it is,
but I just hadn't been thinking about it recently.
I don't want to get any hate mail for that.
The next one, going back to our last episode,
is a trip report from Herb Sutter
on the summer ISO C++ standards meeting
and a very in-depth blog post about all the work
that happened at this last meeting.
Was there anything you wanted to call out
that we didn't already talk to Herb about
when we had him on last week, Jason?
For me particularly, I don't believe we mentioned
the guaranteed copy elision.
Okay, do you want to just go over that a little bit?
So if you have something that you want to
return that you let's see no is not going to be copyable it's going to be move only
and you know that the compiler is going to move it and the compiler knows that the compiler is
going to move it but in some cases the compiler is still going to require you to have a copy constructor.
This is going to make it so that it can say,
no, the standard guarantees in these cases, things will be moved.
You don't have to have a copy constructor.
Okay. How about you, Elias?
Is there anything you wanted to talk about?
Were you happy with all the progress made at C++17 meeting?
Yeah, I'm very happy, and I'm especially happy about things like constexpr if
and, for example,
outer returns where you can return multiple variables
with the tuple and you can actually get them
and initialize them now
in the statement.
Yeah.
It's very cool.
Yeah, constexpr if is definitely going to be a great feature
to have in C++17.
Glad I made it in.
Well, let's hope that
it gets
into most compilers
and we can use it safely. Well,ers and we can use it safely.
Well, I know we can use it in Clang today,
but I don't believe any of the other compilers support it yet.
Yeah, they're mostly the first one to implement stuff.
Yeah.
Okay, next article is that Visual Studio
just released their Update 3,
and we had several guests on recently to talk about some of the new features that are in there,
most notably Andrew Pardot was on two episodes talking about a couple things that are in Update 3.
There's numerous updates for C++.
They're getting more standards compliant with every version, it seems,
so that's great news.
Was there anything you wanted to call out in this article, Jason?
Nothing for me that we haven't already talked about.
Okay.
And then the last article is that the early bird pricing for CppCon,
that period is now over, registration uh is still available uh and um
they should have a schedule out soon although i don't believe they do yet right no the schedule's
not out yet and i don't even think he's actually published an official list of speakers like yens
did straight away from meeting c++ right um but Speakers have been notified.
Yes.
Speakers have been notified. We are giving talks. Did we mention
that officially last week? I don't think we did.
I don't think we did.
Did we get our notice after talking to Herb?
I can't recall.
So yeah, Jason and I
will be doing a short
half-hour session. We'll be talking about some of the stuff
we've learned while doing this show
and doing work with the C++ community.
And then you're going to do a second talk by yourself, right, Jason?
Yeah, I'll be doing a recap of my practical performance practices talk
from C++ Now from Aspen.
Awesome.
Okay, so let's start talking to Elias.
You've been working on a game engine in
C++ for several years. Can you tell us what's the status of it? Yeah, well, it's used for my game.
You mentioned it's called Recreation, and I don't make it for general use. It's mostly for this game.
There are enough features in it already to make an entire game with it.
So I can say that the engine is completely done, of course.
And it's been developed along with the game.
It has lots of features, and it's pretty useful for me.
So I admit I didn't notice one way or the other.
Is the game itself open source or not?
No, it's closed source, but I think I open sourced it after the release.
After some time, I think. Well, most of the game
is in Lua, so people will be able to just
watch the scripts, and it will be half open sourced
by this time.
So do you expect after you release it that people will make their own mods and that kind of thing if it's all in Lua anyhow?
Yeah, I really hope they do,
because there's a pretty good modding community built around some games,
and even some awesome games started as mods originally.
I'll probably do some modding support, provide some docs and all the stuff to support modding.
Maybe we should take just a quick step back and what kind of game are you developing?
Well, my game is a retro-styled top-down action-adventure, something like The Legend of Zelda
and that.
It's about
an undead knight who
tries to show
people that undeaths are not
evil, that they
misinterpret their actions
and just look at their ugly faces
and think that they're
therefore evil, but they are not.
And the main mechanic of the game is that you can control dead people by your spirit and gain their
ability and skills, and with that you solve various puzzles and progress through the game. The game is very story-driven, and I try to create interesting stories
with unique situations and diverse characters.
That sounds like fun.
Yeah, and where is this game going to be available
when you do finish it?
Well, I think I'll release it on Steam
and different other platforms.
Okay. Okay.
Okay.
I wanted to interrupt this discussion for just a moment
to bring you a word from our sponsors.
IncrediBuild dramatically reduces compilation and development times
for both small and big companies like EA, Microsoft Game Studios, and NVIDIA.
IncrediBuild's unique process virtualization technology
will transform your computer network
into a virtual supercomputer
and let each workstation use hundreds of idle cores
across the network.
Use IncrediBuild to accelerate more
than just C++ compilations,
speed up your unit tests,
run more development cycles,
and scale your development to the cloud
to unleash Unreal speeds.
Join more than 100,000 users
to save hundreds of monthly
developer hours using existing hardware download your free developer version at incredibuild.com
slash cpp offer or just click on the link in our link section i saw there's some recent articles
on your blog about image gui and sfml And I was wondering if you could tell us about these tools and how
you utilize them in your game engine. Yeah. SFML is a library which I use for window creation,
rendering, input, and sound. It's not an engine, a game engine or framework. So it doesn't have
things like collision detection, AI, or something like that. So I implement all the game stuff by myself. So it's used for lower level systems and all the
stuff I have to develop for myself. ImGui is an immediate mode GUI library which
is very useful for creating different development tools fast and easy.
I used it to create in-game level editor and object property editor,
which can run in my game.
And I use them for creating my game and also for debugging different stuff.
Such an interesting.
So you actually use it while running the game.
So you can kind of make changes on the fly to your GUI and game objects, that sort of thing?
Yes.
Very cool.
Well, so then I guess while we're on the topic of runtime behavior, you've already mentioned most of the game is written in Lua.
I'm curious, you did not consider any other scripting languages,
or did you just go with Lua right from the beginning?
Well, yeah, I mostly went with Lua, and it just worked,
and I didn't notice any performance slowdowns or anything like that.
I watched at other languages, but I didn't find anything particular about them
which made them better than Lua for me.
So I wanted to stay with Lua.
So do you use any tools to help you with your Lua and C++ binding?
Yeah, I use C++ Lua binding library, which is called Sol2.
And it's pretty great.
In fact, Jason recommended it to me,
and I found it much better than the library I previously used.
It is used for easier registration of C++ functions and user types,
and also for calling Lua scripts and functions from c++ so i might answer
the next question i had which is do you go both ways do you call c++ from your lua yes uh well
mostly i call c++ from lua uh for example for setting some parameters in C++ objects
or getting their state and stuff like that.
And I call Lua from C++ to launch some game logic.
Though I prefer to call C++ from Lua and not the other way
because calling Lua from C++ is actually much slower
than calling C++ from Lua.
Interesting.
Are you able to debug at all when you're going from Lua to C++, back and forth?
Well, there are some tools for that, but I haven't figured how to use them at the moment.
So mostly I just use some printf
debugging and that works at the moment.
So we talked briefly
a moment ago about actually being able to change the behavior of the game
at runtime, is that right? Yes.
So how do you have that set up? Do you have like a console
and you can real-time interact with the game or something?
Yeah, well, I have in-game console, which can be used, for example, to reload different scripts or functions.
And so I may make some changes inside scripts, and then I can reload them, and I don't have to reload the game
itself. So the behavior of different objects or their properties can be changed. And I also use
MGUI for changing C++ objects without reloading any scripts, so I can reload them there so I can change them directly. Interesting. I was curious
then like how do you deal with like game objects that already exist and then you reload the script
that defined the game object or how does that work? Well I use entity component system pattern
which creates game objects out of different components, for example
graphics component and physics component and stuff like that. When I change
something about particular component I don't have to reload the entire
entity. I can just reload, for example, graphics component or something. But if changes are so big that I have to reload entire entity,
I just reload each entity in the game.
So there can be some bugs related to that,
but mostly it works good.
Okay.
I was wondering what guidelines you might have
for separating the scripting and C++
in order to keep your code well architected and organized.
Well, most of the time, the separation is pretty natural.
You want to do some performance-heavy stuff in C++ and some logic in Lua. For example, C++ checks for collision handling,
which can be pretty resource-intensive.
And when two entities collide, C++ sends an event to Lua,
and then Lua decides what to do about the collision.
So collision detection is in C++,
and collision response is actually in Lua,
which handles game logic.
And I have another example, for example, AI.
Lua code handles all the decision-making, which is not a very resource-intensive thing. And C++ uses different pathfinding algorithms to find the shortest path to some object,
which can be much more resource intensive.
So you get separation of different kinds,
and C++ can communicate with Lua without even calling Lua directly,
just by sending different events about what happened between entities.
So how big is the C++ API that you are exposing to your Lua engine?
Well, I expose something like 100 functions,
and mostly I don't write lots of wrapping code it mostly calls to existing
functions so it's not pretty big and i managed to do lots of stuff with just a couple of functions
so with uh soul 2 you have to manually specify each function you want exposed, right?
There's no binding generator like with Swig or something.
Yeah, I have to specify them by myself.
Okay.
You just got me thinking.
One of the large projects that I've worked on uses Swig,
and we've got tens of thousands of functions that are exported to our scripting engines.
And it's easy to do that when you have a binding generator.
But I was thinking without a binding generator,
it probably makes you be more deliberate
about what you're giving your scripting engine access to.
Yeah, I try to not expose...
Well, it actually is pretty good
because I don't expose lots of things about the engine.
So GameLogic tries to do its own thing and call as less as possible about the engine.
So they're not totally coupled.
And I can make some changes to engine while the GameLogic will still work the same.
Okay.
I want to know what your thoughts were on using some of the more modern C++ features
in game development.
Do you make use of a lot of C++ 11 and 14 concepts?
Yeah, I'm a big fan of modern C++ and I use it a lot.
Well, I first learned C++ 98 when I started programming.
So C++ 11 was a huge improvement when I started using it.
It's easier to appreciate how good it is
when you've done some development in old C++ before.
So do you interact with any other C++ game developers
who don't agree they don't use modern C++?
Well, yeah, there are some discussions that we have about modern C++,
and there are some myths about modern C++ that it's slow,
but it actually isn't,
because there isn't much performance overhead
for things like auto or unique pointer. And it is actually very useful to
have that kind of conversation where you explain how different modern C++ things can make you
code easier to use and write without getting some performance overhead.
Is this one of the things that you've addressed on your website
with the articles you've been writing?
Well, not yet, but I plan to.
I plan to write about all the things that I'm using
and show that most of the things don't impact any performance.
I could see there could be a lot of value to that.
Because it seems like any talk that you hear
from a game developer about these topics,
they just say, well, we don't use those things
because there's overhead,
but they never quantify that.
It would be awesome to see some articles
that quantify exactly what you're getting.
Yeah, and I think that
modern C++ is not as used in
AAA game dev industry as it should be
because lots of older platforms weren't using up-to-date compilers.
But now we have PS4 and Xbox One, which have Clang, and it's very modern.
And so they can use all the modern C++ stuff as PC programmers.
It's an interesting point that I never stopped to think about. I love to play the Lego games
with my wife, actually. And the most recent game to come out was released on PS3, PS4, Xbox One, Xbox 360, PC, all at once.
And who knows what limitations they have
because of what compilers they have to be able to use on all of those.
Yeah, the 360 and PS3 might be holding back
and they might still be using C++98 just for that reason.
Yeah, that's a very interesting point.
Since we're talking about your blog,
were there any favorite articles you have that you'd like to mention?
Well, I don't have any strong favorites,
but I think that my latest articles were the best ones I've ever written.
And I think that by the time this podcast airs,
I'll write some new articles about Lua,
and I think these ones will be the best ones I've ever written.
But you've been... Oh, go ahead.
Well, that's because I learned so much
when I first started the Lua C++ series
that now I just feel that I have to rewrite lots of stuff
because there were some misconceptions or stuff that I overlooked.
So they will definitely be a lot better.
Interesting.
So you've been keeping a dev log along the development of this game, right?
Yeah. I tried to
tell people
about all the
design decisions
about the engine that I'm
making because actually
it's not very easy to
find some information about
this. There are several books
but
that's pretty much that you have so i want to share with people
which things worked and which things don't and they can learn on my mistakes and there is also
lots of feedback coming about my game and my engine and so I improve from that feedback also.
Very cool.
You said you're going to try to release on Steam when you finish the games.
You'll be targeting Windows, Linux, and Mac platforms?
I think all those support Steam now, right?
Yeah.
Well, SFML supports all these platforms, so it will be pretty easy. Right now, I compile on all the platforms, and it works pretty good.
Are you using Clang or MinGW or Visual Studio on Windows?
I'm using Visual Studio on Windows.
Okay, and that's not been a problem for you?
Well, there were some problems, and actually it's pretty interesting.
I was implementing a reflection library,
and I got some bugs about an ordered map,
which suddenly stopped working, even on some trivial code.
I asked Microsoft about that
and they responded that they just fixed it in update 3.
So update 3 helped me solve this problem.
Do you have any other cross-platform issues
when working on the game? Well, not really.
I try to not use any platform-specific
code and most of it is abstracted away in SFML, so I don't have to deal with
that. So I don't have much problems. Mostly the problems come from different compilers thinking that some things are errors and some are not.
And Visual Studio doesn't really conform to...
Well, Visual Studio doesn't see errors that much as Clang or GCC.
So when I compile it on Linux,
I see how much errors I've got.
That is, in my opinion, quite handy
to use all the compilers to help you find
as many warnings and errors as possible in your code.
Yeah, especially when compiling
with some strict warnings in GCC, for example.
You'll find it dull.
So when you're building on Windows,
do you use pre-built binaries for SFML and MGUI and Sol2,
or do you build those things yourself as part of your build process?
Well, for SFML, I use pre-built binaries,
and in GUI, and, well, SOL2 is header-only library,
so I don't have to build it.
And in GUI, it's just integrated with my build process.
So I actually use all three approaches to build and stuff.
But there's no problem then finding binaries for SFML for Visual Studio 2015?
Well, there have been no problems on Windows, but there were some on Linux.
Oh, really?
Yeah.
That's surprising.
Because with Visual Studio, you can tell a compiler exactly where to find those bindings.
And I use CMake on Linux and Mac, and so they have to find it for themselves somewhere.
And I had some problems with that, but they fixed that.
So that's interesting.
Is that to say you don't use CMake on Windows, even though you're using it on Linux and Mac? Yeah, well, I eventually plan to use CMake later, but I have this giant project,
which is building good. So I know you're currently a CS student. How many more years do you have?
And do you plan on trying to go into full-time game development when you're done?
Well, I actually finished my bachelor's degree this year,
and I plan to go on with master's degree.
I don't have a goal of doing some game development full-time,
though I would like to work on some games if given some chance.
Because I just enjoy all sorts of programming,
so game dev is not the only option I have.
Okay.
Well, Jason, do you have any other questions today?
I don't have a question,
but I do want to make sure our listeners realize
that there is really a lot of information on Elias's website, and you should definitely check it out.
The dev blog and the examples for using SFML and MGUI, they look very good.
Thanks.
Oh, go ahead. And I actually plan to write even more articles, which I had plans to write but didn't have time.
But now I'm free, so I hope I'll write even more.
Summer break.
Yeah.
Makes you wish you were younger again, Rob.
Yeah, really. And I just want to say,
you'll have to let us know
as soon as you do publish
recreations that we can send
that link out
to all our listeners.
Yeah, all right.
Okay, well, thank you so much
for coming on the show today, Elias.
Thank you for having me
and thank you for making
such awesome podcast.
Thanks for joining us.
Thank you very much.
Thanks so much for listening as we chat about C++.
I'd love to hear what you think of the podcast.
Please let me know if we're discussing the stuff you're interested in,
or if you have a suggestion for a topic, I'd love to hear that also.
You can email all your thoughts to feedback at cppcast.com.
I'd also appreciate if you can follow CppCast on Twitter and like CppCast on Facebook.
And of course, you can find all that info and the show notes on the podcast website at cppcast.com.
Theme music for this episode is provided by podcastthemes.com.