this post was submitted on 16 Dec 2024
19 points (100.0% liked)

Game Development

3534 readers
2 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.

Community Wiki

founded 2 years ago
MODERATORS
 

I'm making an RPG in C++ and the items (loot/gear) will have immutable base versions, but then the player can get instantiations of them which can change with use and modification. These mutable instantiations will be saved in the DB. But I'm wondering if the base versions should be defined in JSON, or a separate DB (with the same schema), or maybe the same DB (seems dangerous), or if I should just hardcode them in C++ in the ItemFactory.

How have you approached this problem in your games? How do game engines do it? I'm using SDL2 so I'm doing most of these systems from scratch.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 6 days ago (1 children)

If you already have a factory for items couldn't it just access the base definitions stored in either a separate class or key them?

[โ€“] sentient_loom 2 points 4 days ago

I'm actually leaning toward this. I might have a class that holds a large unordered_map with a string key, where the value is actually a function which calls a constructor loaded with the defining data (a function so that I can create the map in an object or function without creating ALL the objects every time).

Still, creating a huge unordered_map every time I just need one (or ten) items seems bulky. But there will be five maps, each with their own native items, so maybe I can break it up that way.

I'm also concerned about using magic strings to access values. I wonder if I should make another unordered_map just to hold string values (something like ["BASTARD_SWORD"] = "bastard_sword") so that I never write the string, I just write... the string to access the string... maybe silly and bulky.