Something with mesh loading does not work
This commit is contained in:
@@ -28,6 +28,17 @@ JsonParser::~JsonParser()
|
||||
|
||||
}
|
||||
|
||||
static std::mutex s_ModelsMutex;
|
||||
|
||||
static void loadModel(const std::string modelName, const std::string modelPath, std::vector<Model*>* model_vec) {
|
||||
Model *current_model = new Model(modelName, modelPath);
|
||||
if(current_model) {
|
||||
std::lock_guard<std::mutex> lock(s_ModelsMutex);
|
||||
model_vec->push_back(current_model);
|
||||
std::cout << "Loaded Model \"" << modelName << "\" from \"" << modelPath << "\"" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<Model*> JsonParser::getModels()
|
||||
{
|
||||
std::vector<Model*> temp_models;
|
||||
@@ -50,20 +61,19 @@ std::vector<Model*> JsonParser::getModels()
|
||||
|
||||
std::vector<std::future<void>> futures;
|
||||
|
||||
std::mutex s_ModelsMutex;
|
||||
auto* temp_models_ptr = &temp_models;
|
||||
for (auto model_skeleton : model_skeletons) {
|
||||
auto loadModel = [&]() {
|
||||
Model *current_model = new Model(model_skeleton.model_name, model_skeleton.model_path);
|
||||
for (const auto& model_skeleton : model_skeletons) {
|
||||
/*auto loadModel = [](const std::string& modelName, const std::string& modelPath, std::mutex& mutex, std::vector<Model*>* model_vec) {
|
||||
Model *current_model = new Model(modelName, modelPath);
|
||||
if(current_model) {
|
||||
std::lock_guard<std::mutex> lock(s_ModelsMutex);
|
||||
temp_models_ptr->push_back(current_model);
|
||||
std::cout << "Loaded Model \"" << model_skeleton.model_name << "\" from \"" << model_skeleton.model_path << "\"" << std::endl;
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
model_vec->push_back(current_model);
|
||||
std::cout << "Loaded Model \"" << modelName << "\" from \"" << modelPath << "\"" << std::endl;
|
||||
}
|
||||
};
|
||||
};*/
|
||||
|
||||
futures.push_back(std::async(std::launch::async, loadModel));
|
||||
}
|
||||
futures.push_back(std::async(std::launch::async, loadModel, model_skeleton.model_name, model_skeleton.model_path, temp_models_ptr));
|
||||
}
|
||||
|
||||
return temp_models;
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
uint32_t Model::id_counter = 0;
|
||||
|
||||
Model::Model(std::string &modelName, std::string &modelPath) :
|
||||
Model::Model(const std::string &modelName, const std::string &modelPath) :
|
||||
unique_name(modelName)
|
||||
{
|
||||
directory = modelPath.substr(0, modelPath.find_last_of('/'));
|
||||
@@ -38,7 +38,7 @@ void Model::drawWithoutTextures()
|
||||
}
|
||||
}
|
||||
|
||||
void Model::loadModel(std::string &pathToModel)
|
||||
void Model::loadModel(const std::string &pathToModel)
|
||||
{
|
||||
std::ifstream input(pathToModel, std::ios::in | std::ios::binary);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
class Model
|
||||
{
|
||||
public:
|
||||
Model(std::string &modelName, std::string &pathToModel);
|
||||
Model(const std::string& modelName, const std::string& pathToModel);
|
||||
~Model();
|
||||
|
||||
void draw(ShaderProgram *shaderProgram);
|
||||
@@ -18,7 +18,7 @@ public:
|
||||
std::string getUniqueName();
|
||||
|
||||
private:
|
||||
void loadModel(std::string &pathToModel);
|
||||
void loadModel(const std::string &pathToModel);
|
||||
|
||||
private:
|
||||
std::vector<Mesh *> meshes;
|
||||
|
||||
Reference in New Issue
Block a user