Problem
In making a game, I am writing a framework which handles a large number of items that can be in a player’s inventory. Currently, the only things in the player’s inventory are things that the player can equip (tools). However, I have been looking on expanding that in case I want to write a MMORPG style game.
Background
Weapons are established as a big table which is currently about 40 entries. All weapons are defined in this table which the key is the weapon Id. Each record of this table contains the location of the tool instance itself, location of the model (for map pickups), weapon class, pickup message, respawn time, etc… The module script that holds this has it’s own functions for accessing this data which is treated as being immutable.
For other equippable items, I don’t really have anything specific.
Ideas
So, here’s a few ideas that I have had bouncing around in my head:
-
A master index list where all items have an Item Id which is an index into this table. From there, it references the locations of where the specific data can be found, if it’s not contained within itself.
- Pros
- The data for all items exist in server memory for fast lookup.
- Best used for a small number of items (< 5,000).
- Cons
- Memory consumption for a large number of items can be excessive.
- Items which are rarely used still has their data stored in memory.
- Pros
-
Instead of using a fixed master list, use Data Stores to store the information with a local caching system. If the item is not in the cache, then it’s queried from the data store.
- Pros
- Memory usage on the server is reduced.
- Cache lookups are fast.
- Fixed size cache can expire items not used frequently.
- Cons
- Time required to launch the query and come back with the results.
- Data store functions can fail resulting in retries.
- Data store limits can cause lookups to fail.
- Pros
Final
#1 I think would be good for a low number of items (< 5,000), but above that I think #2 would be good. What do you think? Which should I implement?