Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DirectoryTree::ProcessFile(Record* r, const std::string& file, const std::vector<std::string>& files)
- {
- Engine::LoaderDevIL textureLoader(mLog);
- Engine::LoaderAssimp modelLoader(mLog, mRenderer);
- modelLoader.SetManagers(mMeshManager, mModelManager, mTextureManager);
- modelLoader.SetTextureHeap(mRenderer->Heap(), nullptr);
- if ((file.find(".tga") != std::string::npos) || (file.find(".png") != std::string::npos))
- {
- Engine::Manager<Engine::Texture>::Node* node = mTextureManager->GetNode(file);
- Engine::LoaderDevIL::Image* image = textureLoader.Load(file);
- if (image != nullptr)
- {
- image->mUseAlphaMipmap = false;
- textureLoader.GenerateMipmaps(image);
- }
- Engine::Texture* t = new Engine::Texture(file);
- t->InitMipmaps(mRenderer, image->mWidth, image->mHeight, 1, image->mMipLevels, Engine::Graphics::RGBA8, (const void**)image->mMipmaps);
- t->SetName(file);
- if (node == nullptr)
- {
- mTextureManager->Insert<Engine::Texture>(file, t);
- node = mTextureManager->GetNode(file);
- }
- else
- {
- delete node->mItem;
- node->mItem = t;
- }
- delete image;
- r->mResourceType = ResourceType::TEXTURE;
- r->mResource = node;
- }
- else if (file.find(".obj") != std::string::npos)
- {
- Engine::Manager<Engine::Model>::Node* node = mModelManager->GetNode(file);
- Engine::Model* mdl = modelLoader.Load(file);
- if (node == nullptr)
- {
- mModelManager->Insert<Engine::Model>(file, mdl);
- node = mModelManager->GetNode(file);
- }
- else
- {
- delete node->mItem;
- node->mItem = mdl;
- }
- r->mResourceType = ResourceType::MODEL;
- r->mResource = node;
- }
- else if (file.find(".cpp") != std::string::npos)
- {
- // Check if there isn't dll that corresponds to the cpp file
- bool compile = true;
- for (size_t i = 0; i < files.size(); i++)
- {
- if ((files[i].substr(0, files[i].length() - 4) == file.substr(0, file.length() - 4)) &&
- (files[i].find(".dll") != std::string::npos))
- {
- // If such dll exists, check if its write time is greater than cpp write time
- if (Engine::Files::GetWriteTime(files[i]) > Engine::Files::GetWriteTime(file))
- {
- // In such case our dll is most-recent version of the script, we don't need to compile
- compile = false;
- }
- }
- }
- // If we need to compile, build the dll
- if (compile)
- {
- // TODO: Compiler call
- // Temporary hard-coded compiler
- std::string command = std::string("\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvarsall.bat/\" amd64 && \
- \"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 \
- \"../../../Source/\" \
- /LD \
- DemoController.cpp \
- \"../../../Bin64/Core.lib\" \
- DemoController.dll > Build.log");
- // Compile
- //system(command.c_str());
- }
- }
- else if (file.find(".dll") != std::string::npos)
- {
- Engine::Manager<Engine::Plugin>::Node* node = mPluginManager->GetNode(file);
- mLog->Print("Plugin", std::string("Loading plugin: ") + file);
- Engine::Plugin* plugin = new Engine::Plugin(file);
- void* create = plugin->GetProc<void*>("CreateBehavior");
- void* name = plugin->GetProc<void*>("GetName");
- const char* (*fn)() = (const char*(*)())name;
- const char* pluginName = (*fn)();
- if (create == nullptr || name == nullptr)
- {
- mLog->Print("Plugin", std::string("CreateBehavior or GetName function not found!"));
- delete plugin;
- }
- else
- {
- mLog->Print("Plugin", std::string("CreateBehavior and GetName function found!"));
- mLog->Print("Plugin", std::string("Initializing plugin with name: ") + pluginName);
- if (node == nullptr)
- {
- mPluginManager->Insert<Engine::Plugin>(file, plugin);
- node = mPluginManager->GetNode(file);
- //Engine::ComponentTypeId::Get(pluginName);
- }
- else
- {
- delete node->mItem;
- node->mItem = plugin;
- }
- r->mResourceType = ResourceType::SCRIPT;
- r->mResource = node;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement