Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Any suggestions on what data structure to use?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 hburd   Members   -  Reputation: 108

Like
0Likes
Like

Posted 26 June 2014 - 10:07 PM

Hi there,

 

I'm trying to write a rendering function for a game. I have an array of object transforms (position, rotation, scale), which should be sorted by material as to not waste time binding the same material multiple times.

 

The problem is that I would rather not store a reference to a material in each transform. It's such a basic type that I don't want it to get cluttered with references to every part of the game that depends on it. The transform should only store the position, rotation and scale, and the relationship to the material should be stored elsewhere.

 

I could instead store references to the transforms inside each material, but then sorting the array of transforms would be a lot less straightforward.

 

Does anyone have any suggestions on how to store this data relationship? Is there a particular data structure which is good at representing this kind of relationship?



Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 14662

Like
0Likes
Like

Posted 26 June 2014 - 10:20 PM

What's wrong with a separate array of object transforms for each material? That seems to hit all the boxes.

#3 hburd   Members   -  Reputation: 108

Like
0Likes
Like

Posted 26 June 2014 - 11:00 PM

You mean allocating a new array of transforms for each material, not just references to another array with all the transforms?

 

Seems like a good idea. The only reason I wanted to keep all of the transforms in one array was for optimal cache usage when looping through and rendering all of them. Now that I think of it though, a single cache miss when switching materials is not bad at all.



#4 hburd   Members   -  Reputation: 108

Like
0Likes
Like

Posted 27 June 2014 - 12:05 AM

Actually, wouldn't it be better to keep the transforms separate from the materials? Because what about all of the other parts of the game that want to know about the transforms, wouldn't they then have to point to the mesh to access the transforms?

 

The problem seems to be that I'm not representing any sort of unified sort of game entity, it's all just separate arrays of data so it's hard to represent connections between the data.



#5 swiftcoder   Senior Moderators   -  Reputation: 11810

Like
0Likes
Like

Posted 27 June 2014 - 05:21 AM


The problem seems to be that I'm not representing any sort of unified sort of game entity, it's all just separate arrays of data so it's hard to represent connections between the data.

Your entities are a little abstract at the moment, that's all.

 

With your current structure, a single entity would be an index into the transforms array, plus an index into the materials array. If you set it up that way, and then sort the array of entities by the material index, you'll be golden.


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS