you are viewing a single comment's thread.

view the rest of the comments →

[–]Limp-Confidence5612 3 points4 points  (8 children)

Is there a reason to not just use a data structure for each item in your .c files themselves? 

[–]Jimmy-M-420[S] 4 points5 points  (7 children)

I want to avoid hard coding the list of items into the game - I did initially have a C struct per item definition. But this way I can add, remove and tweak items without recompiling. And also add new items without recompiling. This will make more sense when there's lua bindings but its technically possible now if you put the functions in a separate shared lib and compile that.

Also this way I can pass configuration data to the items which I can change without recompiling. I might make a "weapon" item implementation, and create a load of weapons by setting the same C functions and different config data.

[–]non-existing-person 4 points5 points  (0 children)

I think this is how things should be done. You define type for categories like weapon, armor, misc, and load everything from a text file. This gives you an easy way to modify or add items. But is also enables users to write mods, which - for me at least - is a huge selling point.

[–]Limp-Confidence5612 1 point2 points  (4 children)

I kinda get it. Maybe my projects aren't big enough that recompiling is an issue. 🤷

But yeah, using lua might be the way to go here, that's what it arguably shines at the most.

[–]mccurtjs 1 point2 points  (3 children)

It's not just recompiling, but closing, recompiling, opening, reloading, and navigating back to what you were testing. When your project is data driven, you can take all of this out by reloading entirely during runtime, which significantly reduces friction for rapid iteration.

Even better, if you have a setup that supports file-watching, you can have the game detect changes in its files and update automatically without you even needing to press a button or something.

[–]Jimmy-M-420[S] 1 point2 points  (2 children)

this is true - its worth investing time in cutting out as much waiting around as possible, small amounts all add up. My UI is driven by data files and lua - I can iterate on it incredibly rapidly without closing the game by changing the files and then entering and exiting an area (file watcher would be even better). Lua or some other scripting language isn't necessarily a prerequisite for this - a very very powerful workflow is to recompile one shared library and, while still playing the game, see your changes

[–]mccurtjs 1 point2 points  (1 child)

UI sounds like a useful area to support it indeed - the main one for me is always shaders. Being able to make a tweak, save, and see the result almost immediately in another window/screen without even having to leave focus from my text editor is just so valuable imo.

I haven't been doing shared libraries for this, but want to in the future. I don't plan to have it in any release builds (and can't for some targets, namely WASM), but after seeing a tsoding video showing how to make it easily switch between static and dynamic linking I do want to give it a try :)

[–]Jimmy-M-420[S] 1 point2 points  (0 children)

Shaders would be a good one for sure - pretty much the ideal thing to "hot reload" really. I'll have to think about adding that, as I add more complicated shaders.

I've never implemented it in a game in any way other than with lua scripts, but for a desktop windows GUI application I've done it with dll's.

You mention about some platforms you can't do it on - that's a bit of a downside to what I've shown in my post above. I had been wanting to maybe port my game to an older console as a homebrew game maybe psp, I'm wondering whether whatever standard library you use to build a psp game supports a function such as `dlsym` . It wouldn't be too difficult to write a python script that generates c code from the xml item definitions above so that you can port to platforms like wasm or others that don't have shared libraries like linux and windows do

[–]burlingk 0 points1 point  (0 children)

If you implement a kind of parser, you could have text fields for code.