Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Arcibald Wearlot

A good way to handle resources?

This topic is 5311 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

im caching textures and models in my engine. i created some classes such as CTextureManager or CModelManager, and they use std::vector<> to hold pointers to the actual resources. here''s my problem: i need to assign to every entity a texture, a model, a shader etc and im looking for a clever way to do this. i''m using indices for now, but it''s not a very good way since doing so its hard to load/delete other resources without messing up everything. for example i declare an entity like this: CEntity MyEntity(4,2,3,4); the numbers are indices to the texture, shader etc. then when i render the scene i loop trough every entity and i call stuff like this: CTextureManager->SetTexture( Entity->GetTextureIndex() ); so i was thinking of using something like std::map<> with a string as a key, but maybe it will be slow to compare all those strings.. here''s another idea: i could use a string for the entity initialization, then pass the string to the resource manager, get a pointer to the resource and hold this one, instead of the string.. any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
I think doing map lookups with string keys in your rendering routines is probably a bad idea.

But during an initialisation phase, when you are loading the models up at the beginning of a level,mission etc, that''s probably fine, it may make the data more human-readable, and thus easier to maintain.

Anyway, if each entity has pointers to its model, texture etc, that''s fine, you just need to figure out some sensible way to initialise them from your level data.

Mark

Share this post


Link to post
Share on other sites
quote:

but it''s not a very good way since doing so its hard to load/delete other resources without messing up everything.


If i get you right, the problem is that if you have 3 textures in your lookup vector, and you want to delete the second one, the [1] index would be unused? That really dosn''t matter.

You know, you don''t have to remove the pointer in you lookup vector, just free the memory that it points to. Its not like you are going to do any random access to it, if you need to loop trough it just use iterators or check if a pointer is a null pointer before operation. Vector is the perfect structure for it.

quote:

get a pointer to the resource and hold this one, instead of the string..


Storing an id is probelby a better idea than storing a pointer, pointers are hard to deal with if you want to serialize data, say for saving the game, or sending it over network.

Share this post


Link to post
Share on other sites

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