Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------------------------------------------------------------
- Void Resource::Manager::InitializeResourceLocation(const String& location)
- {
- Bool result;
- Directory folder;
- // Get all the files and folders in the location
- result = folder.Read(location);
- // If recursive, be recursive
- for(Int i = 0; i < folder.Folders.Count; ++i)
- {
- InitializeResourceLocation(location + folder.Folders[i] + "\\");
- }
- // Iterate through every located file
- for(Int i = 0; i < folder.Files.Count; ++i)
- {
- // Get the position of the extension separator
- UInt pos = folder.Files[i].rfind('.');
- //
- if(pos != std::string::npos)
- {
- // Get the extension
- String extension = folder.Files[i].substr(pos + 1);
- if(extension.length() == 3)
- {
- // Hash the extension for faster comparisons
- UInt hash = (extension[0] << 16) + (extension[1] << 8) + (extension[2]); //Hash::FNV32(extension.data(), extension.length());
- // Match the extension to a supported resource type
- switch(hash)
- {
- // Input layout file
- case 'lay':
- {
- File layoutFile;
- // Open the file containing the layout
- layoutFile.Open(location + folder.Files[i], File::Mode::Read);
- String name;
- // Get the resource name of the input layout
- UInt length = layoutFile.Read<UByte>();
- name += layoutFile.Read<Letter>(length);
- // Hash the resource name and add it to the lookup list
- LayoutIDs[Layouts.Count] = Move(Hash::FNV32(name.c_str(), name.length()));
- // Prepare an array of elements to construct the layout with
- Array<Layout::Element> elements;
- // Read the number of input elements
- UInt numElements = layoutFile.Read<UByte>();
- elements.Reserve(numElements);
- elements.Count = numElements;
- // Read each input layout
- for(UInt i = 0; i < numElements; ++i)
- {
- // Write the size of the string then the string to the file
- length = layoutFile.Read<UByte>();
- elements[i].Name += layoutFile.Read<Letter>(length);
- // Simply write the rest of the element to disk
- elements[i].Index = layoutFile.Read<UInt>();
- elements[i].Format = layoutFile.Read<Texture::Format>();
- elements[i].Slot = layoutFile.Read<UInt>();
- elements[i].Offset = layoutFile.Read<UInt>();
- }
- // Read the shader blob
- length = layoutFile.Read<UInt>();
- layoutFile.Allocate(length + 1);
- layoutFile.Load(length);
- // Allocate a slot for the input layout
- Layouts.Expand(1);
- UInt slot = Layouts.Append();
- // Retrieve the slot and create the layout from the data
- Layouts[slot].Create(elements, layoutFile.Data, layoutFile.Size);
- Assert(slot < elements.Count);
- // Buh
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement