this post was submitted on 16 Dec 2024
20 points (100.0% liked)
Game Development
3537 readers
3 users here now
Welcome to the game development community! This is a place to talk about and post anything related to the field of game development.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Unless I really know I need something more complicated, I would just make a struct for Item. Create an array of Items that serve as the templates for instantiation. Handwrite the first pass of a few Items in C++ (or maybe C99 for syntactical convenience). Switch to CSV later and work with bulk definition in a spreadsheet.
I wouldn't use either a DB or JSON for this unless I had a really good reason. Like, I know I need to do a lot of complicated joins or I actually have hierarchical data -- not just an array of objects, respectively. The additional complexity of dealing with them isn't worth it otherwise.
I never considered CSV but that would be the simplest way to store basic definitions.
There will be complicated behavior. And a bit of hierarchical data (each item will belong to a specific map). Plus I want inheritance so they can perform different functions on different screens. But the basic data is fairly simple.
Is there a good CSV library you use to read the data into C++?
Honestly I'd just hand write a CSV parser, they aren't that complicated ESPECIALLY if you don't care about having commas in your data because then you don't need to quote wrap the entries but that's just me.
Same. I already have one I wrote myself that's good enough for my needs -- which means it doesn't handle quoting or alternate line endings or other quirks. (I can just change the separator to
\t
if I really need commas in values, and since I control the data format, I can just say "it will always have Unix line endings" to keep it simple.)There's probably thousands of open source CSV parsers out there though if you don't want to roll your own, but I don't have a specific recommendation.
Yeah, I had the same thought LOL. If you need commas in your data just use a TSV and call it good. I have yet to need the commas though
When your items have complicated behavior, I'd strongly suggest defining them in code.