Advertisement
Ember

bluh

Aug 17th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.79 KB | None | 0 0
  1. // ------------------------------------------------------------------------------------
  2. Void Resource::Manager::InitializeResourceLocation(const String& location)
  3. {
  4.     Bool result;
  5.  
  6.     Directory folder;
  7.     // Get all the files and folders in the location
  8.     result = folder.Read(location);
  9.  
  10.     // If recursive, be recursive
  11.     for(Int i = 0; i < folder.Folders.Count; ++i)
  12.     {
  13.         InitializeResourceLocation(location + folder.Folders[i] + "\\");
  14.     }
  15.  
  16.     // Iterate through every located file
  17.     for(Int i = 0; i < folder.Files.Count; ++i)
  18.     {
  19.         // Get the position of the extension separator
  20.         UInt pos = folder.Files[i].rfind('.');
  21.  
  22.         //
  23.         if(pos != std::string::npos)
  24.         {
  25.             // Get the extension
  26.             String extension = folder.Files[i].substr(pos + 1);
  27.  
  28.             if(extension.length() == 3)
  29.             {
  30.                 // Hash the extension for faster comparisons
  31.                 UInt hash = (extension[0] << 16) + (extension[1] << 8) + (extension[2]); //Hash::FNV32(extension.data(), extension.length());
  32.  
  33.                 // Match the extension to a supported resource type
  34.                 switch(hash)
  35.                 {
  36.                     // Input layout file
  37.                     case 'lay':
  38.                     {
  39.                         File layoutFile;
  40.                         // Open the file containing the layout
  41.                         layoutFile.Open(location + folder.Files[i], File::Mode::Read);
  42.  
  43.                         String name;
  44.                         // Get the resource name of the input layout
  45.                         UInt length = layoutFile.Read<UByte>();
  46.                         name += layoutFile.Read<Letter>(length);
  47.  
  48.                         // Hash the resource name and add it to the lookup list
  49.                         LayoutIDs[Layouts.Count] = Move(Hash::FNV32(name.c_str(), name.length()));
  50.  
  51.                         // Prepare an array of elements to construct the layout with
  52.                         Array<Layout::Element> elements;
  53.  
  54.                         // Read the number of input elements
  55.                         UInt numElements = layoutFile.Read<UByte>();
  56.                         elements.Reserve(numElements);
  57.                         elements.Count = numElements;
  58.  
  59.                         // Read each input layout
  60.                         for(UInt i = 0; i < numElements; ++i)
  61.                         {
  62.                             // Write the size of the string then the string to the file
  63.                             length = layoutFile.Read<UByte>();
  64.                             elements[i].Name += layoutFile.Read<Letter>(length);
  65.                             // Simply write the rest of the element to disk
  66.                             elements[i].Index = layoutFile.Read<UInt>();
  67.                             elements[i].Format = layoutFile.Read<Texture::Format>();
  68.                             elements[i].Slot = layoutFile.Read<UInt>();
  69.                             elements[i].Offset = layoutFile.Read<UInt>();
  70.                         }
  71.  
  72.                         // Read the shader blob
  73.                         length = layoutFile.Read<UInt>();
  74.                         layoutFile.Allocate(length + 1);
  75.                         layoutFile.Load(length);
  76.  
  77.                         // Allocate a slot for the input layout
  78.                         Layouts.Expand(1);
  79.  
  80.                         UInt slot = Layouts.Append();
  81.                         // Retrieve the slot and create the layout from the data
  82.                         Layouts[slot].Create(elements, layoutFile.Data, layoutFile.Size);
  83.                         Assert(slot < elements.Count);
  84.                         // Buh
  85.                         break;
  86.                     }
  87.                 }
  88.             }
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement