From 3703fa01d1c4b2225ac9f4c3efaff0b680e483c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torsten=20Pf=C3=BCtzenreuter?= Date: Tue, 28 Mar 2023 12:26:26 +0200 Subject: [PATCH] Changes for Microsoft Visual C++ compiler (2022) compatibility - moved functions to SystemUtil.cpp to not include windows.h in other c++ files (preprocessor names collide) - replaced pragmas pack(1)...pack(0) with pack(push, 1)...pack(pop) (pack(0) does not reset the alignment) - variabe-length arrays are not supported - _USE_MATH_DEFINES must be set before cmath inclusion to get macros like M_PI, M_PI_2, ... - Tests: SDL requires "int main(int argc, char * argv[])" instead of "int main(int argc, const char * argv[])" Right now all programs are running, but GUI elements (like checkboxes) do not show text --- CMakeLists.txt | 8 +- Library/include/StonefishCommon.h | 4 + Library/include/graphics/OpenGLAtmosphere.h | 4 +- Library/include/graphics/OpenGLContent.h | 4 +- Library/include/graphics/OpenGLLight.h | 4 +- Library/include/graphics/OpenGLOcean.h | 4 +- Library/include/graphics/OpenGLPointLight.h | 5 +- Library/include/graphics/OpenGLSpotLight.h | 4 +- Library/include/graphics/OpenGLView.h | 4 +- Library/include/sensors/Sample.h | 8 ++ Library/include/utils/SystemUtil.hpp | 50 +---------- Library/src/entities/solids/Cylinder.cpp | 3 + Library/src/entities/solids/Sphere.cpp | 3 + Library/src/entities/solids/Torus.cpp | 4 + Library/src/entities/statics/Terrain.cpp | 4 +- Library/src/graphics/OpenGLCamera.cpp | 6 +- Library/src/graphics/OpenGLContent.cpp | 2 +- Library/src/graphics/OpenGLFLS.cpp | 20 +++++ Library/src/graphics/OpenGLMSIS.cpp | 21 +++++ Library/src/graphics/OpenGLOceanParticles.cpp | 4 + Library/src/graphics/OpenGLPrinter.cpp | 29 +++++-- Library/src/sensors/Sample.cpp | 12 +++ Library/src/sensors/ScalarSensor.cpp | 5 +- Library/src/utils/ScientificFileUtil.cpp | 8 ++ Library/src/utils/SystemUtil.cpp | 82 +++++++++++++++++++ Tests/FallingTest/main.cpp | 2 +- Tests/FloatingTest/main.cpp | 2 +- Tests/FlyingTest/main.cpp | 2 +- Tests/JointsTest/main.cpp | 2 +- Tests/SlidingTest/main.cpp | 2 +- Tests/UnderwaterTest/main.cpp | 2 +- 31 files changed, 228 insertions(+), 86 deletions(-) create mode 100644 Library/src/utils/SystemUtil.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e7ba06df..beb603a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,12 @@ option(EMBED_RESOURCES "Embed internal resources in the library executable" OFF) # Compile flags set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -DDEBUG") -set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") +if(MSVC) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS YES CACHE BOOL "Export all symbols") +else() + set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -DDEBUG") + set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG") +endif() set(OpenGL_GL_PREFERENCE "GLVND") # Find required libraries diff --git a/Library/include/StonefishCommon.h b/Library/include/StonefishCommon.h index cd904379..347a5126 100644 --- a/Library/include/StonefishCommon.h +++ b/Library/include/StonefishCommon.h @@ -31,6 +31,10 @@ #include #include +// cmath +#define _USE_MATH_DEFINES // for Microsoft Visual C++ to get M_PI, M_PI_2 etc. +#include + //Bullet Physics #include "btBulletDynamicsCommon.h" #include "btBulletCollisionCommon.h" diff --git a/Library/include/graphics/OpenGLAtmosphere.h b/Library/include/graphics/OpenGLAtmosphere.h index 49d1398a..8eb84c27 100644 --- a/Library/include/graphics/OpenGLAtmosphere.h +++ b/Library/include/graphics/OpenGLAtmosphere.h @@ -32,7 +32,7 @@ namespace sf { //! A structure representing data of the SunSky UBO (std140 aligned). - #pragma pack(1) + #pragma pack(push, 1) struct SunSkyUBO { glm::mat4 sunClipSpace[4]; @@ -43,7 +43,7 @@ namespace sf glm::vec3 whitePoint; GLfloat atmLengthUnitInMeters; }; - #pragma pack(0) + #pragma pack(pop) //! An enum definind id's of atmosphere textures. enum AtmosphereTextures diff --git a/Library/include/graphics/OpenGLContent.h b/Library/include/graphics/OpenGLContent.h index 30dd4c08..0901c774 100644 --- a/Library/include/graphics/OpenGLContent.h +++ b/Library/include/graphics/OpenGLContent.h @@ -53,7 +53,7 @@ namespace sf : attach(attachment), target(target), tex(texture), lvl(level), z(zoffset) {} }; - #pragma pack(1) + #pragma pack(push, 1) //! A structure representing data of the Lights UBO (std140 aligned) struct LightsUBO { @@ -70,7 +70,7 @@ namespace sf glm::vec3 params; //Additional params GLuint type; //Type of velocity field }; - #pragma pack(0) + #pragma pack(pop) //! A structure representing a material shader collection. struct MaterialShader diff --git a/Library/include/graphics/OpenGLLight.h b/Library/include/graphics/OpenGLLight.h index daab2d65..af72ac11 100644 --- a/Library/include/graphics/OpenGLLight.h +++ b/Library/include/graphics/OpenGLLight.h @@ -34,9 +34,9 @@ namespace sf enum class LightType {POINT, SPOT}; //! A structure representing a generic light in the Lights UBO. - #pragma pack(1) + #pragma pack(push, 1) struct LightUBO {}; - #pragma pack(0) + #pragma pack(pop) class GLSLShader; class OpenGLPipeline; diff --git a/Library/include/graphics/OpenGLOcean.h b/Library/include/graphics/OpenGLOcean.h index 89ea2756..479cda56 100644 --- a/Library/include/graphics/OpenGLOcean.h +++ b/Library/include/graphics/OpenGLOcean.h @@ -50,7 +50,7 @@ namespace sf float t; }; - #pragma pack(1) + #pragma pack(push, 1) //! A structure representing the ocean currents UBO. struct OceanCurrentsUBO { @@ -58,7 +58,7 @@ namespace sf glm::vec3 gravity; GLuint numCurrents; }; - #pragma pack(0) + #pragma pack(pop) class GLSLShader; class OpenGLCamera; diff --git a/Library/include/graphics/OpenGLPointLight.h b/Library/include/graphics/OpenGLPointLight.h index d70e34d1..4e87f854 100644 --- a/Library/include/graphics/OpenGLPointLight.h +++ b/Library/include/graphics/OpenGLPointLight.h @@ -31,7 +31,7 @@ namespace sf { //! A structure representing point light in the Lights UBO. - #pragma pack(1) + #pragma pack(push, 1) struct PointLightUBO : public LightUBO { glm::vec3 position; @@ -39,7 +39,8 @@ namespace sf glm::vec3 color; uint8_t pad[4]; }; - #pragma pack(0) + #pragma pack(pop) + //! A class implementing an OpenGL point light (shadow not supported). class OpenGLPointLight : public OpenGLLight diff --git a/Library/include/graphics/OpenGLSpotLight.h b/Library/include/graphics/OpenGLSpotLight.h index 66bed791..783aa58f 100644 --- a/Library/include/graphics/OpenGLSpotLight.h +++ b/Library/include/graphics/OpenGLSpotLight.h @@ -31,7 +31,7 @@ namespace sf { //! A structure representing a spot light in the Ligths UBO (std140 aligned). - #pragma pack(1) + #pragma pack(push, 1) struct SpotLightUBO : public LightUBO { glm::mat4 clipSpace; @@ -44,7 +44,7 @@ namespace sf glm::vec3 radius; //UV + physical radius uint8_t pad[4]; }; - #pragma pack(0) + #pragma pack(pop) //! A class implementing an OpenGL spot light with shadow. class OpenGLSpotLight : public OpenGLLight diff --git a/Library/include/graphics/OpenGLView.h b/Library/include/graphics/OpenGLView.h index 93acabfb..1023869b 100644 --- a/Library/include/graphics/OpenGLView.h +++ b/Library/include/graphics/OpenGLView.h @@ -33,7 +33,7 @@ namespace sf //! An enum defining types of views. enum class ViewType {CAMERA, TRACKBALL, DEPTH_CAMERA, SONAR}; - #pragma pack(1) + #pragma pack(push, 1) struct ViewUBO { glm::mat4 VP; @@ -41,7 +41,7 @@ namespace sf glm::vec3 eye; GLfloat pad; }; - #pragma pack(0) + #pragma pack(pop) //! An abstract class representing an OpenGL view. class OpenGLView diff --git a/Library/include/sensors/Sample.h b/Library/include/sensors/Sample.h index ade0804c..b7a5a57a 100644 --- a/Library/include/sensors/Sample.h +++ b/Library/include/sensors/Sample.h @@ -42,6 +42,14 @@ namespace sf \param index a number specifying the id of the sample */ Sample(unsigned short nDimensions, Scalar* values, bool invalid = false, uint64_t index = 0); + + //! Constructor for initialized sample. + /*! + \param nDimensions the number of dimensions of the measurement + \param invalid a flag to mark if it is and invalid output + \param index a number specifying the id of the sample + */ + Sample(unsigned short nDimensions, bool invalid = false, uint64_t index = 0); //! A copy constructor. /*! diff --git a/Library/include/utils/SystemUtil.hpp b/Library/include/utils/SystemUtil.hpp index c43e7d0d..78334a4e 100644 --- a/Library/include/utils/SystemUtil.hpp +++ b/Library/include/utils/SystemUtil.hpp @@ -40,7 +40,6 @@ #include #include #else //WINDOWS - #include #endif #include "core/GraphicalSimulationApp.h" @@ -61,14 +60,7 @@ inline int64_t GetTimeInNanoseconds() return std::chrono::duration_cast(now.time_since_epoch()).count(); } -inline void GetCWD(char* buffer, int length) -{ -#ifdef _MSC_VER - GetCurrentDirectory(length, buffer); -#else - getcwd(buffer, length); -#endif -} +void GetCWD(char* buffer, int length); inline std::string GetShaderPath() { @@ -80,48 +72,11 @@ inline std::string GetDataPath() return SimulationApp::getApp()->getDataPath(); } -inline const char* GetDataPathPrefix(const char* directory) -{ - static char dataPathPrefix[PATH_MAX]; - -#ifdef __linux__ - -#elif __APPLE__ - CFStringRef dir = CFStringCreateWithCString(CFAllocatorGetDefault(), directory, kCFStringEncodingMacRoman); - - CFURLRef datafilesURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), dir, 0, 0); - - CFURLGetFileSystemRepresentation(datafilesURL, true, reinterpret_cast(dataPathPrefix), PATH_MAX); - - if(datafilesURL != NULL) - CFRelease(datafilesURL); - - CFRelease(dir); -#else //WINDOWS - char* envDataPath = 0; - - // get data path from environment var - envDataPath = getenv(DATAPATH_VAR_NAME); - - // set data path prefix / base directory. This will - // be either from an environment variable, or from - // a compiled in default based on original configure - // options - if (envDataPath != 0) - strcpy(dataPathPrefix, envDataPath); - else - strcpy(dataPathPrefix, CEGUI_SAMPLE_DATAPATH); -#endif - - return dataPathPrefix; -} +const char* GetDataPathPrefix(const char* directory); //Extensions inline bool CheckForExtension(const char* extensionName) { -#ifdef _MSC_VER - return glewIsSupported(extensionName); -#else char* extensions = (char*)glGetString(GL_EXTENSIONS); if(extensions == NULL) return false; @@ -137,7 +92,6 @@ inline bool CheckForExtension(const char* extensionName) extensions += (n+1); } return false; -#endif } //Random functions diff --git a/Library/src/entities/solids/Cylinder.cpp b/Library/src/entities/solids/Cylinder.cpp index 2cd60b79..7fe604db 100644 --- a/Library/src/entities/solids/Cylinder.cpp +++ b/Library/src/entities/solids/Cylinder.cpp @@ -23,6 +23,9 @@ // Copyright (c) 2013-2019 Patryk Cieslak. All rights reserved. // +#define _USE_MATH_DEFINES // for Microsoft Visual C++ +#include + #include "entities/solids/Cylinder.h" #include "graphics/OpenGLContent.h" diff --git a/Library/src/entities/solids/Sphere.cpp b/Library/src/entities/solids/Sphere.cpp index c4d95060..75c69bba 100644 --- a/Library/src/entities/solids/Sphere.cpp +++ b/Library/src/entities/solids/Sphere.cpp @@ -23,6 +23,9 @@ // Copyright (c) 2013-2019 Patryk Cieslak. All rights reserved. // +#define _USE_MATH_DEFINES // for Microsoft Visual C++ +#include + #include "entities/solids/Sphere.h" #include "graphics/OpenGLContent.h" diff --git a/Library/src/entities/solids/Torus.cpp b/Library/src/entities/solids/Torus.cpp index 4da4f0df..23930bb5 100644 --- a/Library/src/entities/solids/Torus.cpp +++ b/Library/src/entities/solids/Torus.cpp @@ -23,6 +23,10 @@ // Copyright (c) 2013-2021 Patryk Cieslak. All rights reserved. // +#define _USE_MATH_DEFINES // for Microsoft Visual C++ +#include + + #include "entities/solids/Torus.h" #include "core/TorusShape.h" diff --git a/Library/src/entities/statics/Terrain.cpp b/Library/src/entities/statics/Terrain.cpp index 4250d1b6..5c6d407e 100644 --- a/Library/src/entities/statics/Terrain.cpp +++ b/Library/src/entities/statics/Terrain.cpp @@ -47,7 +47,7 @@ Terrain::Terrain(std::string uniqueName, std::string pathToHeightmap, Scalar sca heightmap = new GLfloat[w*h]; for(int i=0; i> fanData((fanDiv + 1) * 2); + //auto fanData = std::unique_ptr([(fanDiv + 1) * 2][4]); + + //GLfloat** fanData = (GLfloat**)malloc((fanDiv + 1) * 2 * 4 * sizeof(GLfloat*)); + + GLfloat (*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData); +#else GLfloat fanData[(fanDiv+1)*2][4]; +#endif GLfloat Rmin = range.x/range.y; //Flipped vertically to account for OpenGL window coordinates @@ -189,6 +199,9 @@ OpenGLFLS::OpenGLFLS(glm::vec3 eyePosition, glm::vec3 direction, glm::vec3 sonar sonarPostprocessShader->SetUniform("sonarOutput", TEX_POSTPROCESS1); sonarPostprocessShader->SetUniform("sonarPost", TEX_POSTPROCESS2); OpenGLState::UseProgram(0); +#ifdef _MSC_VER + free(fanData); +#endif } OpenGLFLS::~OpenGLFLS() @@ -235,7 +248,11 @@ void OpenGLFLS::UpdateTransform() projection[2] = glm::vec4(0.f, 0.f, -(far + near)/(far-near), -1.f); projection[3] = glm::vec4(0.f, 0.f, -2.f*far*near/(far-near), 0.f); +#ifdef _MSC_VER + GLfloat(*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData); +#else GLfloat fanData[(fanDiv+1)*2][4]; +#endif GLfloat Rmin = range.x/range.y; GLfloat hFactor = sinf(fov.x/2.f); //Flipped vertically to account for OpenGL window coordinates @@ -257,6 +274,9 @@ void OpenGLFLS::UpdateTransform() glBindBuffer(GL_ARRAY_BUFFER, displayVBO); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(fanData), fanData); glBindBuffer(GL_ARRAY_BUFFER, 0); +#ifdef _MSC_VER + free(fanData); +#endif } //Inform sonar to run callback diff --git a/Library/src/graphics/OpenGLMSIS.cpp b/Library/src/graphics/OpenGLMSIS.cpp index ac3196a5..48db5dfc 100644 --- a/Library/src/graphics/OpenGLMSIS.cpp +++ b/Library/src/graphics/OpenGLMSIS.cpp @@ -104,7 +104,11 @@ OpenGLMSIS::OpenGLMSIS(glm::vec3 eyePosition, glm::vec3 direction, glm::vec3 son //Display fan fanDiv = btMin((GLuint)ceil(360), nSteps); +#ifdef _MSC_VER + GLfloat(*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData); +#else GLfloat fanData[(fanDiv+1)*2][4]; +#endif GLfloat Rmin = range.x/range.y; //Flipped vertically to account for OpenGL window coordinates @@ -163,6 +167,9 @@ OpenGLMSIS::OpenGLMSIS(glm::vec3 eyePosition, glm::vec3 direction, glm::vec3 son sonarUpdateShader->SetUniform("sonarHist", TEX_POSTPROCESS1); sonarUpdateShader->SetUniform("sonarOutput", TEX_POSTPROCESS2); OpenGLState::UseProgram(0); +#ifdef _MSC_VER + free(fanData); +#endif } OpenGLMSIS::~OpenGLMSIS() @@ -217,7 +224,11 @@ void OpenGLMSIS::UpdateTransform() projection[2] = glm::vec4(0.f, 0.f, -(far + near)/(far-near), -1.f); projection[3] = glm::vec4(0.f, 0.f, -2.f*far*near/(far-near), 0.f); +#ifdef _MSC_VER + GLfloat(*fanData)[4] = (GLfloat(*)[4]) calloc((fanDiv + 1) * 2, sizeof * fanData); +#else GLfloat fanData[(fanDiv+1)*2][4]; +#endif GLfloat Rmin = range.x/range.y; //Flipped vertically to account for OpenGL window coordinates for(GLuint i=0; i& objects) settingsUpdated = false; //Clear image OpenGLState::BindTexture(TEX_POSTPROCESS3, GL_TEXTURE_2D, outputTex[1]); +#ifdef _MSC_VER + uint8_t* zeros = new uint8_t[nSteps * nBins]; +#else uint8_t zeros[nSteps * nBins]; +#endif memset(zeros, 0, sizeof(zeros)); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, nSteps, nBins, GL_RED, GL_UNSIGNED_BYTE, (GLvoid*)zeros); OpenGLState::UnbindTexture(TEX_POSTPROCESS3); +#ifdef _MSC_VER + delete[] zeros; +#endif } glMemoryBarrier(GL_FRAMEBUFFER_BARRIER_BIT); glDispatchCompute((GLuint)ceilf(nBeamSamples.y/64.f), 1, 1); diff --git a/Library/src/graphics/OpenGLOceanParticles.cpp b/Library/src/graphics/OpenGLOceanParticles.cpp index 3f8fa2a2..3d346a4b 100644 --- a/Library/src/graphics/OpenGLOceanParticles.cpp +++ b/Library/src/graphics/OpenGLOceanParticles.cpp @@ -198,7 +198,11 @@ void OpenGLOceanParticles::Init() unsigned int seed = (unsigned int)GetTimeInMicroseconds(); std::mt19937 generator(seed); +#ifdef _MSC_VER + std::uniform_int_distribution dist(-127, 127); +#else std::uniform_int_distribution dist(-127,127); +#endif glm::uvec3 noiseSize3(noiseSize, noiseSize, noiseSize); int8_t* noiseData = new int8_t[noiseSize3.x * noiseSize3.y * noiseSize3.z * 4]; int8_t *ptr = noiseData; diff --git a/Library/src/graphics/OpenGLPrinter.cpp b/Library/src/graphics/OpenGLPrinter.cpp index 80c08b3d..469c388a 100644 --- a/Library/src/graphics/OpenGLPrinter.cpp +++ b/Library/src/graphics/OpenGLPrinter.cpp @@ -163,6 +163,16 @@ void OpenGLPrinter::Print(const std::string& text, glm::vec4 color, GLuint x, GL if(!initialized) return; +#ifdef _MSC_VER + struct Point + { + GLfloat x; + GLfloat y; + GLfloat s; + GLfloat t; + }; + Point* coords = new Point[6 * text.length()]; +#else struct Point { GLfloat x; @@ -170,7 +180,7 @@ void OpenGLPrinter::Print(const std::string& text, glm::vec4 color, GLuint x, GL GLfloat s; GLfloat t; } coords[6 * text.length()]; - +#endif memset(coords, 0, sizeof coords); unsigned int n = 0; @@ -209,13 +219,13 @@ void OpenGLPrinter::Print(const std::string& text, glm::vec4 color, GLuint x, GL if(!w || !h) continue; - - coords[n++] = (Point){x2, -y2, ch.offset, 0}; - coords[n++] = (Point){x2+w, -y2, ch.offset + ch.size.x/texWidth, 0}; - coords[n++] = (Point){x2, -y2-h, ch.offset, ch.size.y/texHeight}; - coords[n++] = (Point){x2+w, -y2, ch.offset + ch.size.x/texWidth, 0}; - coords[n++] = (Point){x2, -y2-h, ch.offset, ch.size.y/texHeight}; - coords[n++] = (Point){x2+w, -y2-h, ch.offset + ch.size.x/texWidth, ch.size.y/texHeight}; + + coords[n++] = Point({ x2, -y2, ch.offset, 0 }); + coords[n++] = Point({ x2 + w, -y2, ch.offset + ch.size.x / texWidth, 0 }); + coords[n++] = Point({ x2, -y2 - h, ch.offset, ch.size.y / texHeight }); + coords[n++] = Point({ x2 + w, -y2, ch.offset + ch.size.x / texWidth, 0 }); + coords[n++] = Point({ x2, -y2 - h, ch.offset, ch.size.y / texHeight }); + coords[n++] = Point({ x2 + w, -y2 - h, ch.offset + ch.size.x / texWidth, ch.size.y / texHeight }); } glBindBuffer(GL_ARRAY_BUFFER, fontVBO); @@ -235,6 +245,9 @@ void OpenGLPrinter::Print(const std::string& text, glm::vec4 color, GLuint x, GL OpenGLState::UnbindTexture(TEX_GUI1); OpenGLState::UseProgram(0); } +#ifdef _MSC_VER + delete[] coords; +#endif } GLuint OpenGLPrinter::TextLength(const std::string& text) diff --git a/Library/src/sensors/Sample.cpp b/Library/src/sensors/Sample.cpp index bdec7b2f..b5df8622 100644 --- a/Library/src/sensors/Sample.cpp +++ b/Library/src/sensors/Sample.cpp @@ -43,6 +43,18 @@ Sample::Sample(unsigned short nDimensions, Scalar* values, bool invalid, uint64_ timestamp = SimulationApp::getApp()->getSimulationManager()->getSimulationTime(); } +Sample::Sample(unsigned short nDimensions, bool invalid, uint64_t index) +{ + nDim = nDimensions > 0 ? nDimensions : 1; + data = new Scalar[nDim]; + std::memset(data, 0, sizeof(Scalar) * nDim); + id = index; + if (invalid) + timestamp = Scalar(-1); + else + timestamp = SimulationApp::getApp()->getSimulationManager()->getSimulationTime(); +} + Sample::Sample(const Sample& other, uint64_t index) { timestamp = other.timestamp; diff --git a/Library/src/sensors/ScalarSensor.cpp b/Library/src/sensors/ScalarSensor.cpp index 437e0c67..e4114a6b 100644 --- a/Library/src/sensors/ScalarSensor.cpp +++ b/Library/src/sensors/ScalarSensor.cpp @@ -52,10 +52,7 @@ Sample ScalarSensor::getLastSample() return Sample(*history.back()); else { - unsigned short chs = getNumOfChannels(); - Scalar values[chs]; - memset(values, 0, sizeof(Scalar) * chs); - return Sample(chs, values, true); + return Sample(getNumOfChannels(), true); } } diff --git a/Library/src/utils/ScientificFileUtil.cpp b/Library/src/utils/ScientificFileUtil.cpp index a7dd07b0..d12dc61e 100644 --- a/Library/src/utils/ScientificFileUtil.cpp +++ b/Library/src/utils/ScientificFileUtil.cpp @@ -158,7 +158,11 @@ ScientificData* LoadOctaveData(const std::string& path) if(file.eof()) break; +#ifdef _MSC_VER + char cname[_MAX_PATH]; +#else char cname[nameLen + 1]; +#endif cname[nameLen] = '\0'; file.read(cname, nameLen); @@ -211,7 +215,11 @@ ScientificData* LoadOctaveData(const std::string& path) int32_t typeLen = 0; file.read(reinterpret_cast(&typeLen), 4); +#ifdef _MSC_VER + char typeName[_MAX_PATH]; +#else char typeName[typeLen + 1]; +#endif typeName[typeLen] = '\0'; file.read(typeName, typeLen); diff --git a/Library/src/utils/SystemUtil.cpp b/Library/src/utils/SystemUtil.cpp new file mode 100644 index 00000000..6c154201 --- /dev/null +++ b/Library/src/utils/SystemUtil.cpp @@ -0,0 +1,82 @@ +/* + This file is a part of Stonefish. + + Stonefish is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Stonefish is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +// +// SystemUtil.cpp +// Stonefish +// +// Created by Patryk Cieslak on 8/24/13. +// Copyright (c) 2013-2018 Patryk Cieslak. All rights reserved. +// + +#include "utils/SystemUtil.hpp" + +#ifdef WIN32 + #define WINDOWS_LEAN_AND_MEAN + #include + #define PATH_MAX MAX_PATH +#endif + +namespace sf +{ + + void GetCWD(char* buffer, int length) + { + #ifdef _MSC_VER + GetCurrentDirectory(length, buffer); + #else + getcwd(buffer, length); + #endif + } + + const char* GetDataPathPrefix(const char* directory) + { + static char dataPathPrefix[PATH_MAX]; + + #ifdef __linux__ + + #elif __APPLE__ + CFStringRef dir = CFStringCreateWithCString(CFAllocatorGetDefault(), directory, kCFStringEncodingMacRoman); + + CFURLRef datafilesURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), dir, 0, 0); + + CFURLGetFileSystemRepresentation(datafilesURL, true, reinterpret_cast(dataPathPrefix), PATH_MAX); + + if(datafilesURL != NULL) + CFRelease(datafilesURL); + + CFRelease(dir); + #else //WINDOWS + char* envDataPath = 0; + + // get data path from environment var + envDataPath = getenv("STONEFISH_DATA_PATH"); + + // set data path prefix / base directory. This will + // be either from an environment variable, or from + // a compiled in default based on original configure + // options + if (envDataPath != 0) + strcpy(dataPathPrefix, envDataPath); + else + strcpy(dataPathPrefix, "CEGUI_SAMPLE_DATAPATH"); + #endif + + return dataPathPrefix; + } + +} diff --git a/Tests/FallingTest/main.cpp b/Tests/FallingTest/main.cpp index 40b8eac1..cd90ddd5 100644 --- a/Tests/FallingTest/main.cpp +++ b/Tests/FallingTest/main.cpp @@ -26,7 +26,7 @@ #include "FallingTestApp.h" #include "FallingTestManager.h" -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { sf::RenderSettings s; s.windowW = 1200; diff --git a/Tests/FloatingTest/main.cpp b/Tests/FloatingTest/main.cpp index 83cd9266..2fb6db5c 100644 --- a/Tests/FloatingTest/main.cpp +++ b/Tests/FloatingTest/main.cpp @@ -26,7 +26,7 @@ #include #include "FloatingTestManager.h" -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { sf::RenderSettings s; s.windowW = 1200; diff --git a/Tests/FlyingTest/main.cpp b/Tests/FlyingTest/main.cpp index f2f2e77b..463e0bd2 100644 --- a/Tests/FlyingTest/main.cpp +++ b/Tests/FlyingTest/main.cpp @@ -26,7 +26,7 @@ #include #include "FlyingTestManager.h" -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { sf::RenderSettings s; s.windowW = 1200; diff --git a/Tests/JointsTest/main.cpp b/Tests/JointsTest/main.cpp index b1f30a44..3e6a33f4 100644 --- a/Tests/JointsTest/main.cpp +++ b/Tests/JointsTest/main.cpp @@ -27,7 +27,7 @@ #include "JointsTestManager.h" #include "JointsTestApp.h" -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { sf::RenderSettings s; s.windowW = 800; diff --git a/Tests/SlidingTest/main.cpp b/Tests/SlidingTest/main.cpp index 3762d2f9..b555c829 100644 --- a/Tests/SlidingTest/main.cpp +++ b/Tests/SlidingTest/main.cpp @@ -26,7 +26,7 @@ #include "SlidingTestApp.h" #include "SlidingTestManager.h" -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { sf::RenderSettings s; s.windowW = 1200; diff --git a/Tests/UnderwaterTest/main.cpp b/Tests/UnderwaterTest/main.cpp index 7e30631f..782bf20c 100644 --- a/Tests/UnderwaterTest/main.cpp +++ b/Tests/UnderwaterTest/main.cpp @@ -27,7 +27,7 @@ #include "UnderwaterTestManager.h" #include -int main(int argc, const char * argv[]) +int main(int argc, char * argv[]) { //feenableexcept(FE_ALL_EXCEPT & ~FE_INEXACT); //feenableexcept(FE_INVALID | FE_OVERFLOW);