// ------------------------------------------------------------------------------------ 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(); name += layoutFile.Read(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 elements; // Read the number of input elements UInt numElements = layoutFile.Read(); 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(); elements[i].Name += layoutFile.Read(length); // Simply write the rest of the element to disk elements[i].Index = layoutFile.Read(); elements[i].Format = layoutFile.Read(); elements[i].Slot = layoutFile.Read(); elements[i].Offset = layoutFile.Read(); } // Read the shader blob length = layoutFile.Read(); 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; } } } } } }