Home Artists Posts Import Register

Content

A necessary week.

After writing the last weekly recap on Tuesday, where I wrote about how I was having a hard time with C++ and missed Lua, a few people came to me saying that integrating Lua was really not that hard and (more or less) that I should totally do it!

So I decided to research the matter, my main concerns being how fast would Lua execute in the compiled program and how easy/quick it would be to integrate it.

The first thing I learned, and it was quite a surprise, is that Lua can actually quite fast, in fact near as fact as C! (at least according to this source which also explains why) Not so much with the official Lua library but more so with Luajit, another standalone library which compiles Lua in more CPU-optimized ways.

So how hard would it be to integrate this Luajit? Well, not apparently not so hard. The most time-costly part would be to write the 'bridge' version of the Sugar API to be able to use it in the Lua scripts. The actual Lua setup is just a bunch of functions to call when you want to start using Lua and then when you're done with Lua. It doesn't look like a big deal.

And yet. Despite all that info, I was still very hesitant to actually go ahead and integrate Lua. The main reason being that it's not in the plan I set myself. When I started making Sugar, I had a pretty narrow vision of what it would be, and so far all I did fits in that vision from back then. I did consider Lua scripting back then and decided that maybe I would add it after the engine is functional, it would not be in the first version of Sugar.

What I realized when I wrote the last weekly recap is that I'm on a learning curve with C++. The last time I had used it before Sugar was 2 years back and even then I used it for only a couple of months after it was teached to me. I needed to understand that I am re-learning how to use the language effectively and that I should figure out my own coding practices to answer my needs.

And that's what I did for the rest of the week! While some progress was done on the 'Melee' game, I actually did a lot of refactoring on the little code I had already written for it. My focus has been on developing patterns that look light in code-form and are performant.

One of the things I did is to decompose long functions into smaller functions. When I was in school, a programming teacher had us do a one-week project where no file could be more than 200 lines long, and no one function could have more than two layers of for/while loops into it. Looking back on it, this was an extremely good exercise and there's definitely some good practices to get from it.

Doing this for a big part of the week meant that I didn't have anything new to show. That said, I did get some little progress done on the game at the start of the week, adding some very simple (invincible and inoffensive) enemies. (also, collisions)

There should be a lot more new stuff in this game next week, since I'm almost done with the refactoring as I write this.


To conclude, I will not be integrating Lua, or at least not before Sugar 1.0. Instead, I will be learning to harness the power of C++, even if that means going through a learning curve which may slow me down for some time.

And that's it for this week! Even though there's not much to show for it, progress sure was made!

Next week I'm finishing up on my refactoring and then I'm actually developing the game again. Hopefully I should start being more comfortable with my new workflow and go a little faster!

Thank you to all my Patreon supporters, because I couldn't be writing posts like this one without you! Here are the names of all the 3$+ supporters:

Ryan Malm, Joseph White, Austin East, Marcin Majewski, Zachary Cook, Jefff, Riccardo Straccia, HERVAN, Andreas Bretteville, Bitzawolf, Alan Oliver, Paul Nguyen, Dan Lewis, Christian Östman, Dan Rees-Jones, Reza Esmaili, Thomas Wright, Chris McCluskey, Joel Jorgensen, Marty Kovach, Cole Smith, Giles Graham, Tim and Alexandra Swast, Sasha Bilton, berkfrei, Jearl, Dave Hoffman, Finn Ellis, Egor Dorichev, Jakub Wasilewski, amaris, Brent Werness, Anne Le Clech, Jeremy Bouin, Jesse Bergerstock, Jacel the Thing, Pierre B., Sean S. LeBlanc, C Oakreef, Andrew Reist, vaporstack, hushcoil

Have a great week everyone!

Take care!

TRASEVOL_DOG

Files

Comments

Tim S

Makes sense to me to work on getting the C++ engine the way you like it before adding a Lua layer. I've never embedded a scripting language in a project, though, so I don't know if I would end up designing an engine differently if the main interface is through scripting.

punkcake

Well I don't know either, but I do know this: you'd have two different ways to make things with the engine, all C++ or all(-ish) Lua, and those could be two very different experiences, which I think is not ideal. It also depends on how the Lua system is presented in the framework, encouraging only scripting individual behaviors, or scripting the whole game à-la Pico-8. This is definitely worth some pondering!

Anonymous

I went through a period recently where I grinded through the C++ literature (I tend to read about programming more than I do so recently : ( ). But I recall Bjarne making the point that he considered his language valuable as a means of learning because it 'grows with you'. Bjarne is very proud of the learning curve C++ offers, and I can see where he's coming from. C++ is a leaky abstraction of the underlying machine, but it's meant to be, it's meant to give you the full range of motion over that machine while still providing a useful abstraction language. Of course the problem with any leaky abstraction is that it's not always obvious where things are going to leak, and even when they do leak it's not always obvious what exactly is leaking from the developer's perspective. But I think just by forcing yourself through the C++ grind you learn a thing or two about how programming languages churn out machine code in a way that most other language just won't make apparent (Especially if you get into the nitty gritty of compile vs runtime). If you don't already I highly suggest playing around in some C++ to Assembly software such as: <a href="https://godbolt.org/" rel="nofollow noopener" target="_blank">https://godbolt.org/</a> . That might have grown my intuitions greater than any book I've read. Getting comfortable with the allocation and dellocation of memory via the stack and free store is direly important to not losing your mind. Good luck and have fun, it's not so bad with practice and study.

punkcake

Cheers Jesse, and thanks for the link! This is some very interesting information! I have very little knowledge of assembly but I feel like I really should have more, so thanks for the reminder! :)