Advertisement
Zgragselus

Directory Tree

May 14th, 2023
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.97 KB | None | 0 0
  1. void DirectoryTree::ProcessFile(Record* r, const std::string& file, const std::vector<std::string>& files)
  2. {
  3.     Engine::LoaderDevIL textureLoader(mLog);
  4.     Engine::LoaderAssimp modelLoader(mLog, mRenderer);
  5.     modelLoader.SetManagers(mMeshManager, mModelManager, mTextureManager);
  6.     modelLoader.SetTextureHeap(mRenderer->Heap(), nullptr);
  7.  
  8.     if ((file.find(".tga") != std::string::npos) || (file.find(".png") != std::string::npos))
  9.     {
  10.         Engine::Manager<Engine::Texture>::Node* node = mTextureManager->GetNode(file);
  11.  
  12.         Engine::LoaderDevIL::Image* image = textureLoader.Load(file);
  13.         if (image != nullptr)
  14.         {
  15.             image->mUseAlphaMipmap = false;
  16.             textureLoader.GenerateMipmaps(image);
  17.         }
  18.         Engine::Texture* t = new Engine::Texture(file);
  19.         t->InitMipmaps(mRenderer, image->mWidth, image->mHeight, 1, image->mMipLevels, Engine::Graphics::RGBA8, (const void**)image->mMipmaps);
  20.         t->SetName(file);
  21.         if (node == nullptr)
  22.         {
  23.             mTextureManager->Insert<Engine::Texture>(file, t);
  24.             node = mTextureManager->GetNode(file);
  25.         }
  26.         else
  27.         {
  28.             delete node->mItem;
  29.             node->mItem = t;
  30.         }
  31.         delete image;
  32.  
  33.         r->mResourceType = ResourceType::TEXTURE;
  34.         r->mResource = node;
  35.     }
  36.     else if (file.find(".obj") != std::string::npos)
  37.     {
  38.         Engine::Manager<Engine::Model>::Node* node = mModelManager->GetNode(file);
  39.  
  40.         Engine::Model* mdl = modelLoader.Load(file);
  41.         if (node == nullptr)
  42.         {
  43.             mModelManager->Insert<Engine::Model>(file, mdl);
  44.             node = mModelManager->GetNode(file);
  45.         }
  46.         else
  47.         {
  48.             delete node->mItem;
  49.             node->mItem = mdl;
  50.         }
  51.        
  52.         r->mResourceType = ResourceType::MODEL;
  53.         r->mResource = node;
  54.     }
  55.     else if (file.find(".cpp") != std::string::npos)
  56.     {
  57.         // Check if there isn't dll that corresponds to the cpp file
  58.         bool compile = true;
  59.         for (size_t i = 0; i < files.size(); i++)
  60.         {
  61.             if ((files[i].substr(0, files[i].length() - 4) == file.substr(0, file.length() - 4)) &&
  62.                 (files[i].find(".dll") != std::string::npos))
  63.             {
  64.                 // If such dll exists, check if its write time is greater than cpp write time
  65.                 if (Engine::Files::GetWriteTime(files[i]) > Engine::Files::GetWriteTime(file))
  66.                 {
  67.                     // In such case our dll is most-recent version of the script, we don't need to compile
  68.                     compile = false;
  69.                 }
  70.             }
  71.         }
  72.  
  73.         // If we need to compile, build the dll
  74.         if (compile)
  75.         {
  76.             // TODO: Compiler call
  77.             // Temporary hard-coded compiler
  78.             std::string command = std::string("\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvarsall.bat/\" amd64 && \
  79.                 \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe/\" /O2 /EHsc /GL /MD /I \
  80.                 \"../../../Source/\" \
  81.                 /LD \
  82.                 DemoController.cpp \
  83.                 \"../../../Bin64/Core.lib\" \
  84.                 DemoController.dll > Build.log");
  85.  
  86.             // Compile
  87.             //system(command.c_str());
  88.         }
  89.     }
  90.     else if (file.find(".dll") != std::string::npos)
  91.     {
  92.         Engine::Manager<Engine::Plugin>::Node* node = mPluginManager->GetNode(file);
  93.  
  94.         mLog->Print("Plugin", std::string("Loading plugin: ") + file);
  95.         Engine::Plugin* plugin = new Engine::Plugin(file);
  96.         void* create = plugin->GetProc<void*>("CreateBehavior");
  97.         void* name = plugin->GetProc<void*>("GetName");
  98.         const char* (*fn)() = (const char*(*)())name;
  99.         const char* pluginName = (*fn)();
  100.  
  101.         if (create == nullptr || name == nullptr)
  102.         {
  103.             mLog->Print("Plugin", std::string("CreateBehavior or GetName function not found!"));
  104.             delete plugin;
  105.         }
  106.         else
  107.         {
  108.             mLog->Print("Plugin", std::string("CreateBehavior and GetName function found!"));
  109.             mLog->Print("Plugin", std::string("Initializing plugin with name: ") + pluginName);
  110.  
  111.             if (node == nullptr)
  112.             {
  113.                 mPluginManager->Insert<Engine::Plugin>(file, plugin);
  114.                 node = mPluginManager->GetNode(file);
  115.  
  116.                 //Engine::ComponentTypeId::Get(pluginName);
  117.             }
  118.             else
  119.             {
  120.                 delete node->mItem;
  121.                 node->mItem = plugin;
  122.             }
  123.  
  124.             r->mResourceType = ResourceType::SCRIPT;
  125.             r->mResource = node;
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement