Skip to content

Some fix on macosx #60

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

Merged
merged 3 commits into from
Sep 11, 2024
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
4 changes: 3 additions & 1 deletion TerraForge3D/include/Utils/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ struct Hash
};


#ifndef MAX
#define MAX(x, y) (x > y ? x : y)
#endif // !MAX


#ifdef TERR3D_WIN32
Expand Down Expand Up @@ -263,4 +265,4 @@ std::string FormatMemoryToString(uint64_t size);
#define TERR3D_KEY_RIGHT_SUPER 347
#define TERR3D_KEY_MENU 348

#define TERR3D_KEY_LAST TERR3D_KEY_MENU
#define TERR3D_KEY_LAST TERR3D_KEY_MENU
6 changes: 3 additions & 3 deletions TerraForge3D/src/Exporters/STLExporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bool STLExporter::ExportBinary(const std::string& path, Mesh* mesh, float* progr
BinaryFileWriter writer(path);
buffer[0] = buffer[1] = 0;
if (!writer.IsOpen()) return false;
memset(buffer, 0, 80); sprintf(buffer, "Generated by TerraForge3D Gen 2");
memset(buffer, 0, 80); snprintf(buffer, 4096, "Generated by TerraForge3D Gen 2");
writer.Write(buffer, 80);
uint32_t facet_count = (uint32_t)(mesh->GetFaceCount());
writer.Write(facet_count);
Expand Down Expand Up @@ -55,7 +55,7 @@ bool STLExporter::ExportASCII(const std::string& path, Mesh* mesh, float* progre
const auto& pb = mesh->GetPosition(face.b);
const auto& pc = mesh->GetPosition(face.c);
const auto normal = glm::normalize(glm::cross(glm::vec3(pc - pb), glm::vec3(pa - pb)));
sprintf(buffer,
snprintf(buffer, 4096,
" facet normal % f % f % f" "\n"
" outer loop" "\n"
" vertex %f %f %f" "\n"
Expand All @@ -76,4 +76,4 @@ bool STLExporter::ExportASCII(const std::string& path, Mesh* mesh, float* progre
writer.Write(out_str.data(), out_str.size());
*progress = 1.0f;
return true;
}
}
2 changes: 1 addition & 1 deletion TerraForge3D/src/Generators/BiomeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ BiomeManager::BiomeManager(ApplicationState* appState)
bool success = false;
m_Data = std::make_shared<GeneratorData>();
static int s_BiomeID = 1;
sprintf(m_BiomeName, "Biome %d", s_BiomeID++);
snprintf(m_BiomeName, 64, "Biome %d", s_BiomeID++);
LoadUpResources();
// m_SelectedBaseShapeGeneratorMode = BiomeBaseShapeGeneratorMode_GlobalElevation;
for (auto i = 0; i < static_cast<int32_t>(m_BaseShapeGenerators.size()); i++)
Expand Down
4 changes: 2 additions & 2 deletions TerraForge3D/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class MyApp : public Application
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "logs");
SetLogsDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "logs");
SetWindowConfigPath(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "configs" PATH_SEPARATOR "windowconfigs.terr3d");
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "autosave\"");
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "temp\"");
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "autosave");
MkDir(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "temp");
}

virtual void OnUpdate(float deltatime) override
Expand Down
11 changes: 8 additions & 3 deletions TerraForge3D/src/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@
#include <windows.h>
#include <Commdlg.h>
#endif
#ifdef __APPLE__
#include <libproc.h>
#endif // DEBUG


static std::string getExecutablePath()
{
char rawPathName[MAX_PATH];
#ifdef TERR3D_WIN32
GetModuleFileNameA(NULL, rawPathName, MAX_PATH);
#elif defined(__APPLE__)
proc_pidpath(getpid(), rawPathName, MAX_PATH);
#else
readlink("/proc/self/exe", rawPathName, PATH_MAX);
#endif
Expand Down Expand Up @@ -355,13 +360,13 @@ bool PowerOfTwoDropDown(const char* label, int32_t* value, int start, int end)
if (!value) return false;
static char buffer[32];
int tmp = (int)(log((double)*value) / log(2.0));
sprintf(buffer, "%d", (int)pow(2, tmp));
snprintf(buffer, 32, "%d", (int)pow(2, tmp));
if (ImGui::BeginCombo(label, buffer))
{
for (int i = start; i <= end; i++)
{
bool is_selected = (tmp == i);
sprintf(buffer, "%d", (int)pow(2, i));
snprintf(buffer, 32, "%d", (int)pow(2, i));
if (ImGui::Selectable(buffer, is_selected)) tmp = i;
if (is_selected) ImGui::SetItemDefaultFocus();
}
Expand Down Expand Up @@ -729,7 +734,7 @@ bool ShowSeedSettings(const std::string& label, int* seed, std::vector<int>& his
ImGui::PushID(label.c_str());
for (auto i : historyStack)
{
sprintf(s_Buffer, "%d", i);
snprintf(s_Buffer, 256, "%d", i);
if (ImGui::Selectable(s_Buffer, *seed == i))
{
*seed = i;
Expand Down
Loading