Jump to content
  • Advertisement
Sign in to follow this  
hburd

Any suggestions on what data structure to use?

This topic is 1483 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
What's wrong with a separate array of object transforms for each material? That seems to hit all the boxes.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!