I'm revisiting my Resource Class in my engine and I think it could use some improvements, so I'd like to ask for suggestions.
First, I'll explain what I have so far:
I got a class called ResourceCache which accepts a template class (of Textures, Meshes, AnimatedMeshes, etc) and keeps them in a vector for multiple instances of the same and resource management.
The class also have methods to add/remove, and to read/save from/to a file.
When saving, I pass a filename and pointer offset, and it'll call it's templates' own Save function. So Textures know how to Save/Load themselves, same as Meshes, AnimatedMeshes, Sounds, etc
The templates' Save function writes in binary mode in a format I decided, paired with it's Load, so I only keep the minimum relevant/necessary data for it.
The ResourceCache's Save function creates a header section so I don't have to read the whole file on every Load.
The header section is like this:
[long] headerStart [long] headerEnd //headerStart pointer - repeats this section till "headerEnd" [int] resourceID [int] resourceNameLength [char] resourceName (* resourceNameLength) [long] resourceDataPointer //headerEnd pointer //resourceDataPointer - repeats this till eof //Varies according to resourceType //File end
I can save multiple resource types (meshes, textures) in the same file with the Save function as well.
So, my concerns for now are:
1 - Currently I'm reading the header section for all resource files I type as I start the game, and saving them in a vector of "headers". This way when a resource is requested, I don't parse the read again, I just loop the vector, find the file pointer, move to it, and load the resource. I'm not sure how this method will work once my resource files get bigger and bigger. Any input on this?
2 - The format model I choose has an issue when developing, I have to manually (for now) insert new resources and save them in the binary files so I can use them (in the binary format), when I get my map editor this shouldn't be an issue but for now it's... really annoying and time consuming.
3 - The binary format I decided on doesn't seem a good idea if I ever need to add new resources, such as downloadable content and expansions. Since adding bytes in the middle of a file requires rewriting everything from that point forward (and I don't think I want to), I was thinking in separating between "header" file and "data" file, so if I ever need to add resources, it's just writing more bytes to the files' end.
Anyway, do you have any extra tips or suggestions, anything at all of what should I do that could improve this?