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.
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
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?
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.