• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Orymus3

[resolved] Inventory System 'Architecture'

5 posts in this topic

Hi,

 

I'm currently toying with an Inventory system for one of my project and I'm not sure on what the best approach is to avoid future hurdles. 

The way it works is that it contains a series of 'components' each with their own ID, which are different types (there are 6 types of components, and any given component is one, and only one type at any given time).

 

Initially, I had created 6 Hashmaps (ordered by an integer, thus the component ID). This allowed me to quickly find all necessary information for a component's specifications when looking up the appropriate INT in the appropriate MAP.

 

As the project progressed, I ended up having a few generic methods in the code that could do with a more fluid approach (for example, creating a button that refers to 'any component' as it would effectively have the same behavior, such as when buying or selling that component).

I've been thinking up two solutions:

 

1 - Merge all of the inventories together and differentiate each component's type by adding a field named along the lines of 'component type'.

 

2 - Create a 'macro' hashmap that contains all of the submaps.

For example

macroMap[0] = componentType1Inventory
macroMap[1] = componentType2Inventory
macroMap[2] = componentType3Inventory
...

#1 seems like the cleanest methods, but #2 feels a lot more organic for what I'm trying to achieve (and prevents using unnecessary getters). I feel I'd get more mileage out of the 2nd approach because it prevents me from having to 'peek inside' any object to figure out if it should be considered or not (if it's in that sub-map, it is de facto meant to be in that list).

 

Any pointers on how I should approach this?

Edited by Orymus3
0

Share this post


Link to post
Share on other sites

I'm using the approach suggested by Ashaman, having an array of items as inventory and keeping a pointer in a secondary data structure for equipped (in use) items: I can have n weapons but only one is the "in use" one. When player change weapon (choosing from a displayed list) I simply overwrite the weaponInUse pointer with the new item address.

Edited by arka80
2

Share this post


Link to post
Share on other sites


I don't know if I understood your system correctly, but your component types are, for example, weapons,armor,quest items ? And your components are like a sword, club, helm etc ?

 

Something similar indeed, except for a space game. A "ship" is nothing but a container of components, each of which have their own behavior in my game. So a ship can move because it has engines, can attack because it has weapons, can sustain damage because it has a shield, etc.

The item itself is just the "model" for that component. For all intents and purposes, it behaves as you have suggested.

 





An inventory system is often a very low frequently accessed system (compared to physics,AI,rendering), therefor not really performance critical. In this case I would always sugguest to keep the data-structures and manipulation methods simple,small and clear. Eg a simple array as inventory holding all your components (each component includes its own type) plus some common manipulation methods like add,remove,swap,merge, get next by type, get next by id etc.



On top of this you can build other utility methods, like filtered,sorted views (show me only weapons, sorted by damage), links (button A is linked to item X at inventory index Y).

 

I had not considered this, but you're right. It gets accessed only a few times, and nearly always out of the actual game loop.

 



I'm not 100% sure why you think you need separate inventory lists, though it certainly is useful for _some_ types of games. It's possible for any item that can function as an inventory item to contain an InventoryItemComponent that indicates which types of inventories it can be contained in (and some other details like display name key, description key, icon, etc.).

 

Mainly because of my poor coding practices. I was refactoring something big and ugly (prototype) as I implemented the inventory system (yeah, I did both at the same time for no apparent reason) and wanted to make sure there was no way I would end up assigning an incorrect component type to a "gear" (Equipment) slot by mistake and not understand why everything crashed. That's a very weak reason, but given status quo, I did not revisit this in the last month and as such, it sort of became the standard.

Time to refactor this mess :)

 


I'm using the approach suggested by Ashaman, having an array of items as inventory and keeping a pointer in a secondary data structure for equipped (in use) items: I can have n weapons but only one is the "in use" one. When player change weapon (choosing from a displayed list) I simply overwrite the weaponInUse pointer with the new item address.

 

I have a bit more flexibility. My "hull" component class determines how many of each component types my ship can have (generally more than a single weapon). I build a gear hashmap from this by adding each equipped component. Thus, I can generate a ship on the fly from just a few integers instead of keeping multiple references of ship components all around. This is very light and I like it, but to go to the "next step" I need to revise my approach to inventory management itself (I'm quite satisfied with the equipped part however).

 


I similarly am not sure that I understood the description of your implementation. However, I think I would expect to see something which implemented either a base interface or abstract class of "Component" behaviour. Different component types then differentiate their behaviours through the implementation of their abstract or virtual methods. When this is done, you don't need to store them in separate lists. You have one list of "Component" objects, and the components all respond to a common interface in different ways.

This is what I do. I call them metaComponents. Since this is already done, there are indeed no longer any reason to keep them in separate lists.

 

Thanks all!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0