Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux fix paths #32

Merged
merged 3 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions TerraForge3D/include/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

#ifdef TERR3D_WIN32

#define PATH_SEPERATOR "\\"
#define PATH_SEPARATOR "\\"

#else

#define PATH_SEPERATOR "/"
#define PATH_SEPARATOR "/"

#endif
#endif
4 changes: 2 additions & 2 deletions TerraForge3D/src/Base/Logging/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Logger::Logger(std::string logsDir)
strftime(buffer, sizeof(buffer), "%A %d-%m-%Y %I-%M-%S %p", timeinfo);
std::string str(buffer);
str += ".txt";
mLogHandler = new LoggingOutputStreambuf(std::cout, logsDir + PATH_SEPERATOR + str);
mLogHandler = new LoggingOutputStreambuf(std::cout, logsDir + PATH_SEPARATOR + str);
}

Logger::~Logger()
{
delete mLogHandler;
}
}
14 changes: 7 additions & 7 deletions TerraForge3D/src/Data/ProjectData.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "Data/ProjectData.h"
#include "Data/ApplicationState.h"
#include "Utils/Utils.h"
#include "Platform.h"

#include <json/json.hpp>

#include "Platform.h"

ProjectManager *ProjectManager::s_ProjectManager;

Expand Down Expand Up @@ -81,12 +81,12 @@ void ProjectManager::SaveDatabase()
MkDir(GetResourcePath());
}

SaveToFile(GetResourcePath() + PATH_SEPERATOR "project_database.terr3d", projectDatase.dump());
SaveToFile(GetResourcePath() + PATH_SEPARATOR "project_database.terr3d", projectDatase.dump());
}

std::string ProjectManager::GetResourcePath()
{
return GetExecutableDir() + PATH_SEPERATOR "Data" PATH_SEPERATOR "cache" PATH_SEPERATOR "project_data" PATH_SEPERATOR "project_" + GetId();
return GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "project_data" PATH_SEPARATOR "project_" + GetId();
}

std::string ProjectManager::SaveTexture(Texture2D *texture)
Expand All @@ -102,10 +102,10 @@ std::string ProjectManager::SaveTexture(Texture2D *texture)

if (GetAsset(hash).size() <= 0)
{
MkDir(GetResourcePath() + PATH_SEPERATOR "textures");
CopyFileData(path, GetResourcePath() + PATH_SEPERATOR "textures" PATH_SEPERATOR + hash);
RegisterAsset(hash, "textures" PATH_SEPERATOR + hash);
MkDir(GetResourcePath() + PATH_SEPARATOR "textures");
CopyFileData(path, GetResourcePath() + PATH_SEPARATOR "textures" PATH_SEPARATOR + hash);
RegisterAsset(hash, "textures" PATH_SEPARATOR + hash);
}

return hash;
}
}
49 changes: 31 additions & 18 deletions TerraForge3D/src/Data/Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Data/ApplicationState.h"
#include "Misc/AppStyles.h"
#include "Shading/ShadingManager.h"
#include "Platform.h"

#ifdef TERR3D_WIN32
#include "dirent/dirent.h"
Expand Down Expand Up @@ -46,7 +47,7 @@ static void zip_walk(struct zip_t *zip, const char *path, bool isFristLayer = tr

if (S_ISDIR(s.st_mode))
{
zip_walk(zip, fullpath, false, prevPath + entry->d_name + "\\");
zip_walk(zip, fullpath, false, prevPath + entry->d_name + PATH_SEPARATOR);
}

else
Expand Down Expand Up @@ -116,9 +117,9 @@ nlohmann::json Serializer::Serialize()

if (projectAsset == "")
{
MkDir(appState->projectManager->GetResourcePath() + "\\models");
CopyFileData(appState->globals.currentBaseModelPath, appState->projectManager->GetResourcePath() + "\\models\\" + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
appState->projectManager->RegisterAsset(baseHash, "models\\" + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
MkDir(appState->projectManager->GetResourcePath() + PATH_SEPARATOR "models");
CopyFileData(appState->globals.currentBaseModelPath, appState->projectManager->GetResourcePath() + PATH_SEPARATOR "models" PATH_SEPARATOR + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
appState->projectManager->RegisterAsset(baseHash, "models" PATH_SEPARATOR + baseHash + appState->globals.currentBaseModelPath.substr(appState->globals.currentBaseModelPath.find_last_of(".")));
}

data["baseid"] = baseHash;
Expand All @@ -137,12 +138,12 @@ void Serializer::PackProject(std::string path)

Serialize();
std::ofstream outfile;
outfile.open(appState->projectManager->GetResourcePath() + "\\project.terr3d");
outfile.open(appState->projectManager->GetResourcePath() + PATH_SEPARATOR "project.terr3d");
outfile << data.dump(4, ' ', false);
outfile.close();
MkDir(GetExecutableDir() + "\\Data\\temp");
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "temp");
std::string uid = GenerateId(64);
SaveFile(GetExecutableDir() + "\\Data\\temp\\" + uid);
SaveFile(GetExecutableDir() + "Data" + PATH_SEPARATOR "temp" PATH_SEPARATOR + uid);
zip_t *packed = zip_open(path.c_str(), 9, 'w');
zip_walk(packed, appState->projectManager->GetResourcePath().c_str());
zip_close(packed);
Expand All @@ -156,16 +157,21 @@ void Serializer::LoadPackedProject(std::string path)
}

std::string uid = GenerateId(64);
MkDir(GetExecutableDir() + "\\Data\\temp\\pcache_" + uid);
zip_extract(path.c_str(), (GetExecutableDir() + "\\Data\\temp\\pcache_" + uid).c_str(), [](const char *filename, void *arg)
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "temp"
PATH_SEPARATOR "pcache_" + uid);
zip_extract(path.c_str(), (GetExecutableDir() + PATH_SEPARATOR "Data"
PATH_SEPARATOR "temp" PATH_SEPARATOR "pcache_" + uid).c_str(),
[](const char *filename, void *arg)
{
return 1;
}, (void *)0);

if (FileExists(GetExecutableDir() + "\\Data\\temp\\pcache_" + uid + "\\project.terr3d", true))
if (FileExists(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "temp" PATH_SEPARATOR "pcache_" + uid + PATH_SEPARATOR "project.terr3d", true))
{
bool tmp = false;
std::string sdata = ReadShaderSourceFile(GetExecutableDir() + "\\Data\\temp\\pcache_" + uid + "\\project.terr3d", &tmp);
std::string sdata = ReadShaderSourceFile(GetExecutableDir() +
PATH_SEPARATOR "Data" PATH_SEPARATOR "temp" PATH_SEPARATOR
"pcache_" + uid + PATH_SEPARATOR "project.terr3d", &tmp);

if (sdata.size() <= 0)
{
Expand All @@ -187,15 +193,22 @@ void Serializer::LoadPackedProject(std::string path)
}

std::string projId = data["projectID"];
zip_extract(path.c_str(), (GetExecutableDir() + "\\Data\\cache\\project_data\\project_" + projId).c_str(), [](const char *filename, void *arg)
zip_extract(path.c_str(), (GetExecutableDir() + PATH_SEPARATOR "Data"
PATH_SEPARATOR "cache" PATH_SEPARATOR "project_data"
PATH_SEPARATOR "project_" + projId).c_str(), [](const char
*filename, void *arg)
{
Log(std::string("Extracted ") + filename);
return 1;
}, (void *)0);
std::string oriDir = path.substr(0, path.rfind("\\"));
std::string oriName = path.substr(path.rfind("\\") + 1);
CopyFileData((GetExecutableDir() + "\\Data\\cache\\project_data\\project_" + projId + "\\project.terr3d").c_str(), oriDir + "\\" + oriName + ".terr3d");
LoadFile(oriDir + "\\" + oriName + ".terr3d");
std::string oriDir = path.substr(0, path.rfind(PATH_SEPARATOR));
std::string oriName = path.substr(path.rfind(PATH_SEPARATOR) + 1);
CopyFileData((GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR
"cache" PATH_SEPARATOR "project_data" PATH_SEPARATOR
"project_" + projId + PATH_SEPARATOR
"project.terr3d").c_str(), oriDir + PATH_SEPARATOR +
oriName + ".terr3d");
LoadFile(oriDir + PATH_SEPARATOR + oriName + ".terr3d");
}

else
Expand Down Expand Up @@ -223,7 +236,7 @@ void Serializer::SaveFile(std::string path)

Serialize();
std::ofstream outfile;
outfile.open(appState->projectManager->GetResourcePath() + "\\project.terr3d");
outfile.open(appState->projectManager->GetResourcePath() + PATH_SEPARATOR "project.terr3d");
outfile << data.dump(4, ' ', false);
outfile.close();
outfile.open(path);
Expand Down Expand Up @@ -356,7 +369,7 @@ ApplicationState *Serializer::Deserialize(nlohmann::json d)
delete appState->models.customBaseCopy;
}

appState->globals.currentBaseModelPath = appState->projectManager->GetResourcePath() + "\\" + projectAsset;
appState->globals.currentBaseModelPath = appState->projectManager->GetResourcePath() + PATH_SEPARATOR + projectAsset;
appState->models.customBase = LoadModel(appState->globals.currentBaseModelPath);
appState->models.customBaseCopy = LoadModel(appState->globals.currentBaseModelPath);
appState->states.usingBase = false;
Expand Down
8 changes: 6 additions & 2 deletions TerraForge3D/src/Filters/AdvancedErosionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Data/ApplicationState.h"

#include "Utils/Utils.h"
#include "Platform.h"

#include <imgui.h>
#include <iostream>
Expand Down Expand Up @@ -72,12 +73,15 @@ void AdvancedErosionFilter::Apply()
localWorkSize = 1;
}

std::string kernelSrc = ReadShaderSourceFile(GetExecutableDir() + "\\Data\\kernels\\advanced_erosion.cl", &tmp);
std::string kernelSrc = ReadShaderSourceFile(GetExecutableDir() +
PATH_SEPARATOR "Data" PATH_SEPARATOR "kernels"
PATH_SEPARATOR "advanced_erosion.cl", &tmp);
// Some constants
kernelSrc = std::regex_replace(kernelSrc, std::regex("LOCAL_WORK_SIZE"), std::to_string(localWorkSize));
kernels.Clear();
kernels.AddSoruce(kernelSrc);
kernels.BuildProgram("-I\"" + GetExecutableDir() + "\\Data\\kernels" + "\"");
kernels.BuildProgram("-I\"" + GetExecutableDir() + PATH_SEPARATOR
"Data" PATH_SEPARATOR "kernels" + "\"");
kernels.AddKernel("erode");
kernels.CreateBuffer("mesh", CL_MEM_READ_WRITE, sizeof(Vert) * model->mesh->vertexCount);
kernels.WriteBuffer("mesh", true, sizeof(Vert) * model->mesh->vertexCount, model->mesh->vert);
Expand Down
3 changes: 2 additions & 1 deletion TerraForge3D/src/Filters/GPUErosionFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>

#include "Data/ApplicationState.h"
#include "Platform.h"

#include <ComputeShader.h>
#include <ShaderStorageBuffer.h>
Expand Down Expand Up @@ -80,7 +81,7 @@ void GPUErosionFilter::Apply()
mapSize = model->mesh->res;
mapSize = MAX(0, mapSize - 2 * erosionBrushRadius);
bool tmp = false;
std::string shaderSrc = ReadShaderSourceFile(GetExecutableDir() + "\\Data\\compute\\erosion.glsl", &tmp);
std::string shaderSrc = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "compute" PATH_SEPARATOR "erosion.glsl", &tmp);
shaderSrc = std::regex_replace(shaderSrc, std::regex("LAYOUT_SIZE_X"), std::to_string(1024));
//shaderSrc = std::regex_replace(shaderSrc, std::regex("LAYOUT_SIZE_X"), std::to_string(1));
shaderSrc = std::regex_replace(shaderSrc, std::regex("LAYOUT_SIZE_Y"), std::to_string(1));
Expand Down
13 changes: 7 additions & 6 deletions TerraForge3D/src/Foliage/FoliagePlacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Base/Texture2D.h"
#include "Data/ProjectData.h"
#include "Data/ApplicationState.h"
#include "Platform.h"

#include <glm/gtc/type_ptr.hpp>
#include <imgui/imgui.h>
Expand Down Expand Up @@ -139,8 +140,8 @@ void FoliageManager::ShowSettings(bool *pOpen)

if(path.size() > 3)
{
foliageItems.push_back(new FoliageItem(appState->constants.texturesDir + "\\white.png"));
foliageItems.back()->name = path.substr(path.find("\\") + 1);
foliageItems.push_back(new FoliageItem(appState->constants.texturesDir + PATH_SEPARATOR "white.png"));
foliageItems.back()->name = path.substr(path.find(PATH_SEPARATOR) + 1);
foliageItems.back()->model = LoadModel(path);
foliageItems.back()->model->SetupMeshOnGPU();
foliageItems.back()->model->UploadToGPU();
Expand All @@ -156,9 +157,9 @@ void FoliageManager::ShowSettings(bool *pOpen)
{
delete appState->shaders.foliage;
bool res = false;
appState->shaders.foliage = new Shader(ReadShaderSourceFile(appState->constants.shadersDir + "\\foliage\\vert.glsl", &res),
ReadShaderSourceFile(appState->constants.shadersDir + "\\foliage\\frag.glsl", &res),
ReadShaderSourceFile(appState->constants.shadersDir + "\\foliage\\geom.glsl", &res));
appState->shaders.foliage = new Shader(ReadShaderSourceFile(appState->constants.shadersDir + PATH_SEPARATOR "foliage" PATH_SEPARATOR "vert.glsl", &res),
ReadShaderSourceFile(appState->constants.shadersDir + PATH_SEPARATOR "foliage" PATH_SEPARATOR "frag.glsl", &res),
ReadShaderSourceFile(appState->constants.shadersDir + PATH_SEPARATOR "foliage" PATH_SEPARATOR "geom.glsl", &res));
}

ImGui::End();
Expand Down Expand Up @@ -198,4 +199,4 @@ nlohmann::json FoliageManager::Save()
void FoliageManager::Load(nlohmann::json data)
{
Log("Foliage Manager does not support Save/Load yet!");
}
}
5 changes: 3 additions & 2 deletions TerraForge3D/src/Generators/CPUNodeEditor/CPUNodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Data/ApplicationState.h"
#include "Profiler.h"
#include "Utils/Utils.h"
#include "Platform.h"

#include "imgui.h"
#include "Base/ImGuiShapes.h"
Expand Down Expand Up @@ -134,7 +135,7 @@ CPUNodeEditor::CPUNodeEditor(ApplicationState *as)
name.reserve(1024);
name = "CPU Node Editor " + std::to_string(count++);
NodeEditorConfig config;
config.saveFile = GetExecutableDir() + "\\Data\\configs\\CPUNodeEditorconfigs.terr3d";
config.saveFile = GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "configs" PATH_SEPARATOR "CPUNodeEditorconfigs.terr3d";
config.makeNodeFunc = [&]()
{
ImGuiNodeEditor::Suspend();
Expand Down Expand Up @@ -413,4 +414,4 @@ void CPUNodeEditor::ShowSetting(int id)

ImGui::Text("UID : %s", uid.data());
ImGui::Text("Time : %lf ms", time);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <mutex>
#include <cmath>
#include "Base/ImGuiCurveEditor.h"
#include "Platform.h"

#define CLAMP01(x) x > 1 ? 1 : ( x < 0 ? 0 : x )

Expand Down Expand Up @@ -130,7 +131,7 @@ void TextureNode::Load(nlohmann::json data)
if (isDefault)
{
delete texture;
texture = new Texture2D(GetExecutableDir() + "\\Data\\textures\\white.png", false, false);
texture = new Texture2D(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "textures" PATH_SEPARATOR "white.png", false, false);
}

else
Expand All @@ -146,7 +147,7 @@ void TextureNode::Load(nlohmann::json data)
else
{
delete texture;
texture = new Texture2D(ProjectManager::Get()->GetResourcePath() + "\\" + ProjectManager::Get()->GetAsset(hash));
texture = new Texture2D(ProjectManager::Get()->GetResourcePath() + PATH_SEPARATOR + ProjectManager::Get()->GetAsset(hash));
Log("Loaded Cached Texture : " + hash);
}
}
Expand Down Expand Up @@ -285,7 +286,7 @@ TextureNode::TextureNode()
outputPins.push_back(new NodeEditorPin(NodeEditorPinType::Output));
outputPins.push_back(new NodeEditorPin(NodeEditorPinType::Output));
headerColor = ImColor(IMAGE_NODE_COLOR);
texture = new Texture2D(GetExecutableDir() + "\\Data\\textures\\white.png", false, false);
texture = new Texture2D(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "textures" PATH_SEPARATOR "white.png", false, false);
isDefault = true;
scale = 1.0f;
inv = false;
Expand Down
3 changes: 2 additions & 1 deletion TerraForge3D/src/Generators/MeshGeneratorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Base/UIFontManager.h"

#include "Profiler.h"
#include "Platform.h"

MeshGeneratorManager::MeshGeneratorManager(ApplicationState *as)
:appState(as)
Expand Down Expand Up @@ -436,7 +437,7 @@ void MeshGeneratorManager::ExecuteCPUGenerators()
void MeshGeneratorManager::LoadKernels()
{
bool tmp = false;
std::string source = ReadShaderSourceFile(GetExecutableDir() + "\\Data\\kernels\\generators\\generators.cl", &tmp);
std::string source = ReadShaderSourceFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "kernels" PATH_SEPARATOR "generators" PATH_SEPARATOR "generators.cl", &tmp);
kernels->AddSoruce(source);
kernels->BuildProgram("-I" + appState->globals.kernelsIncludeDir + " -cl-fast-relaxed-math -cl-mad-enable");
kernels->AddKernel("clear_mesh_terrain");
Expand Down
Loading