E
Eric Lilja
Hello, I am currently designing a small program that's supposed to become a
helper program
for a computer game. The program is to store a number of recipes and this
collection of recipes
is expected to grow to quite big over time. Each recipe can be categorized
into one of several
categories, for example: wood-working, tailoring, brewing, blacksmithing
etc.
I am planning on having a base class Recipe and inherit a new class for each
category of recipe.
I also plan on having an Item class for each item that is used in a
recipe...and now to my problem,
several recipes use the same items...my program would consume a lot of
memory indeed if each
recipe that uses, for example, the item Water had its own copy of the Item
class instance describing water.
How should I solve that? Maybe assign a unique ID to each item (and maybe
each recipe) and have a global
item_map which maps item_IDs to items. So instead of storing objects of type
Item in the recipes
I store keys to this item map. Other alternatives? Hmm...ohh, and I need to
be able to serialize everything.
So what I am looking for is, ideally, a solution that can be implemented
using standard c++ that doesn't
consume too much memory and that allows for easy serialization.
Thanks for any input
helper program
for a computer game. The program is to store a number of recipes and this
collection of recipes
is expected to grow to quite big over time. Each recipe can be categorized
into one of several
categories, for example: wood-working, tailoring, brewing, blacksmithing
etc.
I am planning on having a base class Recipe and inherit a new class for each
category of recipe.
I also plan on having an Item class for each item that is used in a
recipe...and now to my problem,
several recipes use the same items...my program would consume a lot of
memory indeed if each
recipe that uses, for example, the item Water had its own copy of the Item
class instance describing water.
How should I solve that? Maybe assign a unique ID to each item (and maybe
each recipe) and have a global
item_map which maps item_IDs to items. So instead of storing objects of type
Item in the recipes
I store keys to this item map. Other alternatives? Hmm...ohh, and I need to
be able to serialize everything.
So what I am looking for is, ideally, a solution that can be implemented
using standard c++ that doesn't
consume too much memory and that allows for easy serialization.
Thanks for any input