• 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
PrestoChung

Custom storage class - Look at my code?

10 posts in this topic

Hi
I have created a storage class to store arbitrary objects in linear memory. I think this is essentially a memory allocator but it stores a little information about the object allocated (size in bytes, number of objects)

This was originally meant to be the method of storing Components in an Entity-System.

Usually I hear that the STL is a better idea.
The obvious STL analogue is the std::vector. But the problem is how to store references to std::vector elements?
If you store a pointer to an element, that pointer may become invalid by re-sizing of the vector.
If you store an index, that index may also change.

The other problem is storing generic collections of std::vectors. Because it is a template you cannot have a homogenous collection of std::vectors: each one is a different type.
That is why this storage class is not a template: if it was a template I could not create a structure such as [source]Storage myStors[10][/source] if Storage is a template<>

There are two supplemental classes that are to help manage the allocation and ownership of the elements: Range and Rangeset.

Range is just what it sounds like, it is a minimum and maximum value. A Rangeset is a sorted linked-list of Ranges so that ownership of elements need not always be 100% contiguous.

The Storage keeps track of which elements are available with it's own Rangeset, which should be disjoint with the Rangesets of the Entities that have ownership of the objects.

Again I have found that a situation such as this will be necessary to hold object Entities themselves if I want them to be contiguous in memory: they will require references to parents and children which can't be stored as pointers to std::vector elements because of the aforesaid considerations.

Please correct me if I am causing myself too much trouble!

Here is a link to the code (about 850 lines): http://dl.dropbox.com/u/78425/stor.h
0

Share this post


Link to post
Share on other sites
Your code is, unfortunately, pretty hard to read; the formatting aside (whitespace is your friend!) I find it full of magic numbers, cryptic conditionals and variable names, and no documentation at all. I don't even know for sure what invariants your classes are meant to uphold, let alone whether or not they manage to do so.

I'd be willing to look through it and clean it up a bit, but unfortunately I already have a job ;-) But if you have some time to make it a bit more readable and document it a bit, I'd be happy to take another glance.
0

Share this post


Link to post
Share on other sites
Thanks for looking. I suppose the lack of whitespace (I'm assuming you mean between functions?) is probably due to my reliance on Visual Studio outlining. Sorry for that.

Here's a summary of the functionality [url="http://dl.dropbox.com/u/78425/stor.txt"]http://dl.dropbox.com/u/78425/stor.txt[/url]
0

Share this post


Link to post
Share on other sites
[quote name='PrestoChung' timestamp='1309199668' post='4828357']
But the problem is how to store references to std::vector elements?[/quote]

It depends on whether you really need to, and if so, why.

[quote]The other problem is storing generic collections of std::vectors. [/quote]

Again, what are you trying to solve by doing so? What's wrong with a separate vector for each element type?
0

Share this post


Link to post
Share on other sites
[quote name='Zahlman' timestamp='1309219911' post='4828466']
[quote name='PrestoChung' timestamp='1309199668' post='4828357']
But the problem is how to store references to std::vector elements?[/quote]

It depends on whether you really need to, and if so, why.[/quote]

I wish to be able to traverse the data linearly in memory but I also want to be able to have parent/child references to specific elements of that array or other arrays. I think that essentially is what I am trying to do though the two might be opposed.



[quote name='Zahlman' timestamp='1309219911' post='4828466']

[quote]The other problem is storing generic collections of std::vectors. [/quote]

Again, what are you trying to solve by doing so? What's wrong with a separate vector for each element type?
[/quote]

I want it this way to make it easy to write managers (I think they are usually called) for types of objects (game Entities)
This way they can derive from a common manager base class and I only need to write a single function for things like 'Clear all entities' even though each derived class might manage different entities, I won't have to re-write the same functionality for each one.

0

Share this post


Link to post
Share on other sites
I am confused, what is it that this code offers? You say you want to be able to traverse the container linearly, but why then not use a std::vector, like the above poster suggests?

Are you creating a flat tree? i.e. creating a tree, and using an array for the tree? If so, the elements will not be contiguous . .

i dunno. . .
0

Share this post


Link to post
Share on other sites
[quote name='PrestoChung' timestamp='1309303951' post='4828867']
[quote name='Zahlman' timestamp='1309219911' post='4828466']
[quote name='PrestoChung' timestamp='1309199668' post='4828357']
But the problem is how to store references to std::vector elements?[/quote]

It depends on whether you really need to, and if so, why.[/quote]

I wish to be able to traverse the data linearly in memory but I also want to be able to have parent/child references to specific elements of that array or other arrays. I think that essentially is what I am trying to do though the two might be opposed.
[/quote]

Ok, so why do you want to be able to have parent/child references? What do you mean by parent/child in this context? I thought we were looking at a sequence, not a tree.
0

Share this post


Link to post
Share on other sites
[quote name='Zahlman' timestamp='1309386805' post='4829279']
[quote name='PrestoChung' timestamp='1309303951' post='4828867']
[quote name='Zahlman' timestamp='1309219911' post='4828466']
[quote name='PrestoChung' timestamp='1309199668' post='4828357']
But the problem is how to store references to std::vector elements?[/quote]

It depends on whether you really need to, and if so, why.[/quote]

I wish to be able to traverse the data linearly in memory but I also want to be able to have parent/child references to specific elements of that array or other arrays. I think that essentially is what I am trying to do though the two might be opposed.
[/quote]

Ok, so why do you want to be able to have parent/child references? What do you mean by parent/child in this context? I thought we were looking at a sequence, not a tree.
[/quote]

Sorry, I did mention it in my first post but it was towards the bottom.

The first case where I have this is:

I have a manager (Subsystem) called Overlay. (Basically it is to display 2d graphics directly to screen space)

I have an Image object (Entity) that has a texture component.

Now, I create a couple of Graphic objects (Entities) that have vertex components and the use of these Graphic objects is to display the original Image object in a couple different places on the screen.

When I decide at some point that I need to get rid of the Image object, I don't want to worry about what Graphic objects are currently displaying it. I would like to simply remove the Image and have the Graphics to be removed implicitly because they are children of the Image.

I haven't had a case where relation in the other direction is needed but an example off the top of my head would be an interaction with one of the children affecting a change in the Parent.

That sort of thing.
0

Share this post


Link to post
Share on other sites
Isnt this why you create a class and have these items within the class? So, when you delete the class, those objects go too?
0

Share this post


Link to post
Share on other sites
[quote name='smasherprog' timestamp='1309415239' post='4829430']
Isnt this why you create a class and have these items within the class? So, when you delete the class, those objects go too?
[/quote]

Don't want to restrict to hard-coded relations such as this where it can be avoided. I can't foresee all the possible combinations of elements esp. if I want to update them dynamically.


Also if the sub-objects are to be processed independently you don't want the cache taken up by the containing class data.
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