it's about unique IDs in game engines again...
I've been using enums for some IDs (GUI controls, events) and std::string IDs for game objects/entities and resources (textures etc.). Now I would like to get rid of enums (because it's hard to add new events etc with them) and for performance reasons also get rid of strings; and everyone seems to be recommending hashed strings for identifiers.
And here comes my problem - I'm at the end of my abilities, I've spent days (well, weeks in fact) searching for solutions, reading books, threads here etc., but I still don't understand how does it work. Everyone always just says "hashed strings" or "hash table", but nobody mentions how is it implemented in fact, not even in the (otherwse great) book Game Engine Architecture by Jason Gregory.
It will be maybe stupid questions for most of you, but I'm probably missing some basic point of the whole hashing stuff
Please note that I don't need a whole code, I just need you to point me to the right direction, in few specific implementation details.
1. Storing the elements.
Now I have a simple
std::map<std::string, BlaBlaClass*>.
What would I use with hashed string ids instead of this?
2. Accessing the elements.
Besides iterating (of course), I can access any element by directly using its string id, something like (pseudocode)
resourceManager.GetTexture("bricks.tga")->DoSomething();The key "bricks.tga" is found simply by map::Find() or map::Operator[]How would that be done with hashed ids?
3. Identifying elements.
For example with event types as an enum, I can decide what to do in an event handling callback method by simply making a switch statement:
switch (e.eventType) {
case EVENT_SOMETHING:
break;
case EVENT_SOMETHINGELSE:
break;
}
(Would be similar with strings, just with if-else instead of switch.)How could that be done with hashed strings?
That you very much very any input.
(Btw, as far as theory goes, I know what a hash function is and I know how to calculate a hash value of lets say a string.)






