CppCast - C++ and Lua Game Development

Episode Date: July 6, 2016

Rob 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)
Starting point is 00:00:00 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.
Starting point is 00:00:54 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.
Starting point is 00:01:43 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,
Starting point is 00:02:08 which is a little disappointing. It's still, Oh, I didn't realize that. Oh, yeah. But, uh,
Starting point is 00:02:13 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,
Starting point is 00:02:24 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,
Starting point is 00:02:34 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.
Starting point is 00:02:50 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.
Starting point is 00:03:16 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.
Starting point is 00:03:45 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,
Starting point is 00:04:11 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
Starting point is 00:04:49 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
Starting point is 00:05:27 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
Starting point is 00:06:00 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.
Starting point is 00:06:21 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.
Starting point is 00:06:55 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
Starting point is 00:07:27 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
Starting point is 00:07:42 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,
Starting point is 00:08:07 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.
Starting point is 00:08:36 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.
Starting point is 00:09:11 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.
Starting point is 00:09:28 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.
Starting point is 00:10:00 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
Starting point is 00:10:35 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.
Starting point is 00:11:14 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
Starting point is 00:11:37 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.
Starting point is 00:12:14 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.
Starting point is 00:12:32 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
Starting point is 00:12:54 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
Starting point is 00:13:12 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,
Starting point is 00:14:11 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.
Starting point is 00:14:39 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?
Starting point is 00:15:19 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
Starting point is 00:16:05 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.
Starting point is 00:16:46 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.
Starting point is 00:17:17 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
Starting point is 00:18:18 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.
Starting point is 00:18:50 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.
Starting point is 00:19:31 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,
Starting point is 00:20:22 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,
Starting point is 00:20:58 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.
Starting point is 00:21:27 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.
Starting point is 00:21:59 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,
Starting point is 00:22:36 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.
Starting point is 00:23:11 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.
Starting point is 00:23:33 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.
Starting point is 00:24:08 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,
Starting point is 00:24:46 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
Starting point is 00:25:17 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
Starting point is 00:25:47 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
Starting point is 00:26:03 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.
Starting point is 00:26:40 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.
Starting point is 00:27:24 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.
Starting point is 00:28:11 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
Starting point is 00:28:41 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.
Starting point is 00:29:15 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.
Starting point is 00:29:48 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.
Starting point is 00:30:38 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
Starting point is 00:31:04 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.
Starting point is 00:31:41 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
Starting point is 00:31:55 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.
Starting point is 00:32:13 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.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.