True. I don't like functions relying on a special value, but I wasn't sure how to go about it. It is a DWORD return type so -1 is 0xFFFFFFFF but returning -1 in a DWORD return type function didn't look quite right.
Any ideas on how I can change this?
Code:
bool GetID(DWORD dwSeqID,DWORD dwFrameID,DWORD &dwOutID)
{
if (dwSeqID<AnimSeqs.size())
{
dwOutID=AnimSeqs[dwSeqID]->GetID(dwFrameID);
return false;
} else return true;
}
Ya like?
GetID might seem redundant but there are reasons for it. The ID's assigned by the editor are stored on disk in the main file and the actual ID or index of the object in memory is also stored.
The reason for this is that ID's must be assigned in the editor to represent the index in the vector/array, but these IDs cannot be placed into the map. This is because the engine would then have to load the bitmaps in the exact same order as the editor. This would require either a naming convention that used values in the filename or it would require a game def file that showed the order. I opted for something else.
At load time, the engine knows how many bitmaps are in the data file. It creates an array and then proceeds to load. As it loads it uses the ResourceID as the index into the engine array. In this way, the final engine array should exactly match the editor array. However, the editor need not do this when it loads resource files. It can simply load and as long as it places the ResourceID into the map instead of the ID of the bitmap in the current editor vector, it will work. The IDs will match.
Using these methods requires no look ups and I don't have to use any of the STL find() functions on my container in the editor.
It took some time to come up with this system, but it seems to work ok.