From 91d46d7f0bbe0211766276b83f7668663961e9c4 Mon Sep 17 00:00:00 2001 From: aiekick Date: Sun, 22 Oct 2023 21:07:24 +0200 Subject: [PATCH 01/10] - --- include/ctools/cTools.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index 23b45c1..dc8d6d8 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -54,6 +54,7 @@ SOFTWARE. #include #include #include +#include #include /* va_list, va_start, va_arg, va_end */ #include #include @@ -160,6 +161,46 @@ using namespace cocos2d; namespace ct // cTools { + +template +class SearchableVector { +private: + std::unordered_map m_Dico; + std::vector m_Array; + +public: + void clear() { + m_Dico.clear(); + m_Array.clear(); + } + bool empty() const { return m_Array.empty(); } + size_t size() const { return m_Array.size(); } + T& operator[](const size_t& vIdx) { return m_Array[vIdx]; } + T& at(const size_t& vIdx) { return m_Array.at(vIdx); } + T* data() { return m_Array.data(); } + typename std::vector::iterator begin() { return m_Array.begin(); } + typename std::vector::const_iterator begin() const { return m_Array.begin(); } + typename std::vector::iterator end() { return m_Array.end(); } + typename std::vector::const_iterator end() const { return m_Array.end(); } + bool try_add(T vKey) { + if (!exist(vKey)) { + m_Dico[vKey] = m_Array.size(); + m_Array.push_back(vKey); + return true; + } + return false; + } + bool try_set_existing(T vKey) { + if (exist(vKey)) { + auto row = m_Dico.at(vKey); + m_Array[row] = vKey; + return true; + } + return false; + } + bool exist(const T& vKey) const { return (m_Dico.find(vKey) != m_Dico.end()); } +}; + CTOOLS_API std::string toStr(const char* fmt, ...); CTOOLS_API std::string toUpper(const std::string& vStr, const std::locale& vLocale = std::locale()); From af8f71a7161f95f8f6d792ccd883be80dbaaf73a Mon Sep 17 00:00:00 2001 From: aiekick Date: Sun, 29 Oct 2023 08:56:14 +0100 Subject: [PATCH 02/10] - --- include/ctools/cTools.h | 36 ++++++++++++++++++++++++++- tests/CMakeLists.txt | 4 +++ tests/TestCode/cTools/Test_cTools.cpp | 32 +++++++++++++++++++++++- 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index dc8d6d8..f4711bb 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -162,6 +162,39 @@ using namespace cocos2d; namespace ct // cTools { +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// + +// is a user datas of type void* is used +// we cant do a dynamic_cast, so for test if we have the good class +// we can use a magic number, because this member will not cause compiling issue +// and if this is the good class, the magic_number will point to a random memory zone +// so will not have the good value + +inline int64_t EncodeId(const std::string& vArr) { + if (vArr.empty() || vArr.size() != 8U) { + return 0; + } + return vArr[0] | // + (vArr[1] << 8) | // + (vArr[2] << 16) | // + (vArr[3] << 24) | // + ((int64_t)(vArr[4]) << 32) | // + ((int64_t)(vArr[5]) << 40) | // + ((int64_t)(vArr[6]) << 48) | // + ((int64_t)(vArr[7]) << 56); +} + +inline bool IsIdEqualTo(const int64_t& vId, char vArr[8]) { + return (EncodeId(vArr) == vId); +} + +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// +///////////////////////////////////////////// + template class SearchableVector { private: @@ -198,7 +231,8 @@ class SearchableVector { } return false; } - bool exist(const T& vKey) const { return (m_Dico.find(vKey) != m_Dico.end()); } + bool exist(const T& vKey) const { + return (m_Dico.find(vKey) != m_Dico.end()); } }; CTOOLS_API std::string toStr(const char* fmt, ...); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b0e4178..aebaa0a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -483,3 +483,7 @@ AddTest("cTools.float.Plane.construtor.point_and_normal") AddTest("cTools.float.Plane.construtor.3_points") AddTest("cTools.float.Plane.get_plane_intersection") AddTest("cTools.float.Plane.is_on_plane") + +### TESTS for cTools.EncodeID + +AddTest("cTools.EncodeID") diff --git a/tests/TestCode/cTools/Test_cTools.cpp b/tests/TestCode/cTools/Test_cTools.cpp index f780027..6ddb0f9 100644 --- a/tests/TestCode/cTools/Test_cTools.cpp +++ b/tests/TestCode/cTools/Test_cTools.cpp @@ -2792,6 +2792,30 @@ int Test_cTools_float_double_Plane_run_test(const std::string& vTestCode) return 1; // error } + +/////////////////////////////////////////////////////////// +//// ENCODE ID //////////////////////////////////////////// +/////////////////////////////////////////////////////////// + +int Test_cTools_Encode_ID() { + if (ct::EncodeId("lgfkhklfgjhlgkfkjfghlkfgh") != 0) { // more than 8 + return 1; // error + } + if (ct::EncodeId("") != 0) { // empty + return 1; // error + } + if (ct::EncodeId("IProject") != 5282848185757557618) { + return 1; // error + } + if (!ct::IsIdEqualTo(5282848185757557618, "IProject")) { + return 1; // error + } + if (ct::IsIdEqualTo(5282848185757557618, "TOTO")) { + return 1; // error + } + return 0; // no error +} + /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// @@ -2876,7 +2900,13 @@ int Test_cTools_run_test(const std::string& vTestCode) else if (vTestCode.find("cTools.float.Plane.") != std::string::npos) { return Test_cTools_float_double_Plane_run_test(vTestCode); - } + } + + // Encode ID + + else if (vTestCode.find("cTools.EncodeID") != std::string::npos) { + return Test_cTools_Encode_ID(); + } return 1; // error } \ No newline at end of file From f426c7f5ad336093e1d45563699ff221fbf28817 Mon Sep 17 00:00:00 2001 From: aiekick Date: Mon, 30 Oct 2023 06:30:42 +0100 Subject: [PATCH 03/10] [FIX] : fix compilation warnings --- include/ctools/cTools.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index f4711bb..dab2311 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -3414,8 +3414,9 @@ ct::rect GetScreenRectWithSize(ct::vec2 vItemSize, ct::vec2 vMaxSize, b rc.h = (T)newY; } - if (std::is_same::value || std::is_same::value) + if constexpr (std::is_same::value || constexpr std::is_same::value) { rc = ct::floor(rc); + } const float newRatio = (float)rc.w / (float)rc.h; if (vLogError) @@ -3457,8 +3458,9 @@ ct::rect GetScreenRectWithRatio(float vRatio, ct::vec2 vMaxSize, bool vLog rc.h = (T)newY; } - if (std::is_same::value || std::is_same::value) + if constexpr (std::is_same::value || std::is_same::value) { rc = ct::floor(rc); + } const float newRatio = (float)rc.w / (float)rc.h; if (vLogError) From 03f8f57b26d99874d1562db625d2c1b0fd6167ba Mon Sep 17 00:00:00 2001 From: aiekick Date: Mon, 30 Oct 2023 19:28:48 +0100 Subject: [PATCH 04/10] - --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 219d97b..a673ae0 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,14 +68,14 @@ elseif(WIN32) endif() if(MSVC) - # Ignore 4055 for glad - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /IGNORE:4055") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /std:c++11") add_definitions(-D__STDC__) add_definitions(-DMSVC) + add_definitions(-DNOMINMAX) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++11 -Wunused-parameter -Wno-unknown-pragmas") endif () if (USE_SHARED_LIB_CTOOLS) From 2a34ed0cbbba114fcfa48467d13f1b6c1dc52ffd Mon Sep 17 00:00:00 2001 From: aiekick Date: Mon, 30 Oct 2023 19:32:38 +0100 Subject: [PATCH 05/10] - --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a673ae0..32393a8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ option(USE_SDL_CLIPBOARD "Use Clipboard via SDL2 (need SDL2)" OFF) option(USE_TESTING_CTOOLS "Enable Ctools Tests" OFF) option(USE_SHARED_LIB_CTOOLS "Enable Ctools Shared Lib" OFF) -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -68,14 +68,14 @@ elseif(WIN32) endif() if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /std:c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /std:c++17") add_definitions(-D__STDC__) add_definitions(-DMSVC) add_definitions(-DNOMINMAX) add_definitions(-D_CRT_SECURE_NO_WARNINGS) add_definitions(-D_CRT_SECURE_NO_DEPRECATE) else () - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++11 -Wunused-parameter -Wno-unknown-pragmas") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++17 -Wunused-parameter -Wno-unknown-pragmas") endif () if (USE_SHARED_LIB_CTOOLS) From e0e8a4bbf3d4496087bbea8ff42fbcc38c59cc91 Mon Sep 17 00:00:00 2001 From: aiekick Date: Mon, 30 Oct 2023 19:38:33 +0100 Subject: [PATCH 06/10] - --- include/ctools/cTools.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index dab2311..b0f7053 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -3414,7 +3414,7 @@ ct::rect GetScreenRectWithSize(ct::vec2 vItemSize, ct::vec2 vMaxSize, b rc.h = (T)newY; } - if constexpr (std::is_same::value || constexpr std::is_same::value) { + if constexpr (std::is_same::value || std::is_same::value) { rc = ct::floor(rc); } From b5f3c70d03d6fffc2e01cd430de5347088e43983 Mon Sep 17 00:00:00 2001 From: aiekick Date: Wed, 1 Nov 2023 00:44:48 +0100 Subject: [PATCH 07/10] - --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32393a8..ba8ce14 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ elseif(WIN32) endif() if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /std:c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /FR /std:c++17") add_definitions(-D__STDC__) add_definitions(-DMSVC) add_definitions(-DNOMINMAX) From eca0cdfcfe74c9e792c8ca255ee396cfc5ccf96b Mon Sep 17 00:00:00 2001 From: aiekick Date: Thu, 2 Nov 2023 00:18:42 +0100 Subject: [PATCH 08/10] - --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba8ce14..3d8ab19 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ elseif(WIN32) endif() if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /FR /std:c++17") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /std:c++17") add_definitions(-D__STDC__) add_definitions(-DMSVC) add_definitions(-DNOMINMAX) From bfbe248daf5f240bbc6740944aa417e6f9ee171b Mon Sep 17 00:00:00 2001 From: aiekick Date: Sat, 2 Dec 2023 03:12:13 +0100 Subject: [PATCH 09/10] - --- include/ctools/cTools.h | 8 ++++---- src/Logger.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index b0f7053..4bc9b89 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -2186,16 +2186,16 @@ struct rect // bottom left to top right vec2 center() const { return vec2((left + right) / (T)2, (top + bottom) / (T)2); } - vec2* vertices() { - vec2* buf = new vec2[4]; + std::array, 4> vertices() { + std::array, 4> buf; buf[0] = leftBottom(); buf[1] = leftTop(); buf[2] = rightTop(); buf[3] = rightBottom(); return buf; } - vec2* texCoords(T scaleX, T scaleY) { - vec2* buf = new vec2[4]; + std::array, 4> texCoords(T scaleX, T scaleY) { + std::array, 4> buf; buf[0] = vec2((T)0, (T)0); buf[1] = vec2((T)scaleX, (T)0); buf[2] = vec2(scaleX, scaleY); diff --git a/src/Logger.cpp b/src/Logger.cpp index 636327a..0bdfdb2 100644 --- a/src/Logger.cpp +++ b/src/Logger.cpp @@ -320,6 +320,7 @@ void Logger::Close() std::unique_lock lck(Logger::Logger_Mutex, std::defer_lock); lck.lock(); debugLogFile.close(); + debugLogFile.clear(); lck.unlock(); } From 999b6286027c5b71448c5253eca097636d59cc95 Mon Sep 17 00:00:00 2001 From: aiekick Date: Sun, 10 Mar 2024 08:15:50 +0100 Subject: [PATCH 10/10] - --- include/ctools/cTools.h | 335 +++++++++++++++++++++------------------- 1 file changed, 179 insertions(+), 156 deletions(-) diff --git a/include/ctools/cTools.h b/include/ctools/cTools.h index 4bc9b89..d3fbc2d 100644 --- a/include/ctools/cTools.h +++ b/include/ctools/cTools.h @@ -25,8 +25,7 @@ SOFTWARE. #pragma once #pragma warning(disable : 4251) -#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || \ - defined(_WIN64) || defined(_MSC_VER) +#if defined(__WIN32__) || defined(WIN32) || defined(_WIN32) || defined(__WIN64__) || defined(WIN64) || defined(_WIN64) || defined(_MSC_VER) #if defined(ctools_EXPORTS) #define CTOOLS_API __declspec(dllexport) #elif defined(BUILD_CTOOLS_SHARED_LIBS) @@ -176,14 +175,14 @@ inline int64_t EncodeId(const std::string& vArr) { if (vArr.empty() || vArr.size() != 8U) { return 0; } - return vArr[0] | // - (vArr[1] << 8) | // - (vArr[2] << 16) | // - (vArr[3] << 24) | // - ((int64_t)(vArr[4]) << 32) | // - ((int64_t)(vArr[5]) << 40) | // - ((int64_t)(vArr[6]) << 48) | // - ((int64_t)(vArr[7]) << 56); + return vArr[0] | // + (vArr[1] << 8) | // + (vArr[2] << 16) | // + (vArr[3] << 24) | // + ((int64_t)(vArr[4]) << 32) | // + ((int64_t)(vArr[5]) << 40) | // + ((int64_t)(vArr[6]) << 48) | // + ((int64_t)(vArr[7]) << 56); } inline bool IsIdEqualTo(const int64_t& vId, char vArr[8]) { @@ -206,15 +205,33 @@ class SearchableVector { m_Dico.clear(); m_Array.clear(); } - bool empty() const { return m_Array.empty(); } - size_t size() const { return m_Array.size(); } - T& operator[](const size_t& vIdx) { return m_Array[vIdx]; } - T& at(const size_t& vIdx) { return m_Array.at(vIdx); } - T* data() { return m_Array.data(); } - typename std::vector::iterator begin() { return m_Array.begin(); } - typename std::vector::const_iterator begin() const { return m_Array.begin(); } - typename std::vector::iterator end() { return m_Array.end(); } - typename std::vector::const_iterator end() const { return m_Array.end(); } + bool empty() const { + return m_Array.empty(); + } + size_t size() const { + return m_Array.size(); + } + T& operator[](const size_t& vIdx) { + return m_Array[vIdx]; + } + T& at(const size_t& vIdx) { + return m_Array.at(vIdx); + } + T* data() { + return m_Array.data(); + } + typename std::vector::iterator begin() { + return m_Array.begin(); + } + typename std::vector::const_iterator begin() const { + return m_Array.begin(); + } + typename std::vector::iterator end() { + return m_Array.end(); + } + typename std::vector::const_iterator end() const { + return m_Array.end(); + } bool try_add(T vKey) { if (!exist(vKey)) { m_Dico[vKey] = m_Array.size(); @@ -231,8 +248,9 @@ class SearchableVector { } return false; } - bool exist(const T& vKey) const { - return (m_Dico.find(vKey) != m_Dico.end()); } + bool exist(const T& vKey) const { + return (m_Dico.find(vKey) != m_Dico.end()); + } }; CTOOLS_API std::string toStr(const char* fmt, ...); @@ -366,13 +384,13 @@ template std::vector StringToNumberVector(const std::string& text, char delimiter) { std::vector arr; std::string::size_type start = 0; - std::string::size_type end = text.find(delimiter, start); + std::string::size_type end = text.find(delimiter, start); while (end != std::string::npos) { std::string token = text.substr(start, end - start); arr.emplace_back(StringToNumber(token)); start = end + 1; - end = text.find(delimiter, start); + end = text.find(delimiter, start); } arr.emplace_back(StringToNumber(text.substr(start).c_str())); return arr; @@ -544,7 +562,7 @@ template class cCyclicArray { private: std::vector puArray; - int puCount = 0; + int puCount = 0; T puDefaultValue = (T)0; public: @@ -553,7 +571,7 @@ class cCyclicArray { void Init(T vDefaultValue, int vCount) { puDefaultValue = vDefaultValue; - puCount = vCount; + puCount = vCount; for (int i = 0; i < puCount; ++i) { puArray.emplace_back(puDefaultValue); @@ -593,7 +611,7 @@ class cCyclicArray { } T GetMeanExceptValue(T vExceptValue) { - T value = puDefaultValue; + T value = puDefaultValue; int count = 0; for (auto it = puArray.begin(); it != puArray.end(); ++it) { if (*it != vExceptValue) { @@ -613,10 +631,10 @@ CTOOLS_API uint64_t GetTicks(); CTOOLS_API float GetTimeInterval(); class CTOOLS_API ActionTime { public: - uint64_t lastTick = 0; - uint64_t pauseTick = 0; + uint64_t lastTick = 0; + uint64_t pauseTick = 0; uint64_t resumeTick = 0; - bool play = true; + bool play = true; public: ActionTime(); @@ -662,11 +680,11 @@ class CTOOLS_API texture { surface = nullptr; #endif glTextureType = GL_TEXTURE_2D; - glTex = 0; + glTex = 0; - glformat = GL_RGBA; + glformat = GL_RGBA; glinternalformat = GL_RGBA32F; - gldatatype = GL_FLOAT; + gldatatype = GL_FLOAT; glWrapS = GL_CLAMP_TO_EDGE; glWrapT = GL_CLAMP_TO_EDGE; @@ -675,8 +693,8 @@ class CTOOLS_API texture { glMinFilter = GL_LINEAR; glMagFilter = GL_LINEAR; - flipY = false; - useMipMap = false; + flipY = false; + useMipMap = false; maxMipMapLvl = 0; } @@ -686,29 +704,29 @@ class CTOOLS_API texture { std::string format; std::string relativPath; - bool flipY = false; - bool useMipMap = false; + bool flipY = false; + bool useMipMap = false; int maxMipMapLvl = 0; GLenum glTextureType = GL_TEXTURE_2D; - GLenum glformat = GL_RGBA; + GLenum glformat = GL_RGBA; GLenum glinternalformat = GL_RGBA32F; - GLenum gldatatype = GL_FLOAT; + GLenum gldatatype = GL_FLOAT; - GLenum glWrapS = GL_CLAMP_TO_EDGE; // x - GLenum glWrapT = GL_CLAMP_TO_EDGE; // y - GLenum glWrapR = GL_CLAMP_TO_EDGE; // z + GLenum glWrapS = GL_CLAMP_TO_EDGE; // x + GLenum glWrapT = GL_CLAMP_TO_EDGE; // y + GLenum glWrapR = GL_CLAMP_TO_EDGE; // z GLenum glMinFilter = GL_LINEAR; GLenum glMagFilter = GL_LINEAR; size_t zOrder = 0; - size_t w = 0; - size_t h = 0; - size_t d = 0; // depth for texture 3d - size_t x = 0; - size_t y = 0; - size_t z = 0; // depth for texture 3d + size_t w = 0; + size_t h = 0; + size_t d = 0; // depth for texture 3d + size_t x = 0; + size_t y = 0; + size_t z = 0; // depth for texture 3d #ifdef SDL2 SDL_Surface* surface = nullptr; @@ -906,7 +924,7 @@ struct vec2 { y = def->y; } std::vector result = StringToNumberVector(vec, c); - const size_t s = result.size(); + const size_t s = result.size(); if (s > 0) x = result[0]; if (s > 1) @@ -1226,17 +1244,17 @@ template inline vec2 atan(vec2 a) { return vec2(atan(a.x), atan(a.y)); } -using dvec2 = vec2; -using fvec2 = vec2; -using bvec2 = vec2; -using i8vec2 = vec2; +using dvec2 = vec2; +using fvec2 = vec2; +using bvec2 = vec2; +using i8vec2 = vec2; using i16vec2 = vec2; -using ivec2 = vec2; +using ivec2 = vec2; using i32vec2 = vec2; using i64vec2 = vec2; -using u8vec2 = vec2; +using u8vec2 = vec2; using u16vec2 = vec2; -using uvec2 = vec2; +using uvec2 = vec2; using u32vec2 = vec2; using u64vec2 = vec2; @@ -1334,14 +1352,16 @@ inline vec2 operator*(const vec2& a, mat2 b) { return vec2( // ax * (x y) // ay * (z w) - a.x * b[0] + a.x * b[1], a.y * b[2] + a.y * b[3]); + a.x * b[0] + a.x * b[1], + a.y * b[2] + a.y * b[3]); } template inline vec2 operator*(const mat2& a, vec2 b) { return vec2( // (x y) * bx // (z w) * by - a[0] * b.x + a[1] * b.y, a[2] * b.x + a[3] * b.y); + a[0] * b.x + a[1] * b.y, + a[2] * b.x + a[3] * b.y); } typedef mat2 mat2f; typedef mat2 mat2d; @@ -1373,7 +1393,7 @@ struct vec3 { z = def->z; } std::vector result = StringToNumberVector(vec, c); - const size_t s = result.size(); + const size_t s = result.size(); if (s > 0) x = result[0]; if (s > 1) @@ -1675,18 +1695,18 @@ template inline vec3 cReflect(vec3 I, vec3 N) { return I - (T)2 * dotS(N, I) * N; } -using dvec3 = vec3; -using fvec3 = vec3; -using bvec3 = vec3; -using ivec3 = vec3; -using i8vec3 = vec3; +using dvec3 = vec3; +using fvec3 = vec3; +using bvec3 = vec3; +using ivec3 = vec3; +using i8vec3 = vec3; using i16vec3 = vec3; -using ivec3 = vec3; +using ivec3 = vec3; using i32vec3 = vec3; using i64vec3 = vec3; -using u8vec3 = vec3; +using u8vec3 = vec3; using u16vec3 = vec3; -using uvec3 = vec3; +using uvec3 = vec3; using u32vec3 = vec3; using u64vec3 = vec3; @@ -1741,7 +1761,7 @@ struct vec4 { w = def->w; } std::vector result = StringToNumberVector(vec, c); - const size_t s = result.size(); + const size_t s = result.size(); if (s > 0) x = result[0]; if (s > 1) @@ -1765,19 +1785,22 @@ struct vec4 { w = (T)0; } std::vector result = StringToNumberVector(vec, c); - const size_t s = result.size(); + const size_t s = result.size(); if ((int)s != n) { if (s == 1) { x = result[0]; y = result[0]; z = result[0]; w = result[0]; - } - if (s == 2) { + } else if (s == 2) { x = result[0]; y = result[0]; z = result[1]; w = result[1]; + } else if (s == 3) { + x = result[0]; + y = result[1]; + z = result[2]; } } else { if (s > 0) @@ -2091,18 +2114,18 @@ template inline vec4 tan(vec4 a) { return vec4(tan(a.x), tan(a.y), tan(a.z), tan(a.w)); } -using dvec4 = vec4; -using fvec4 = vec4; -using bvec4 = vec4; -using ivec4 = vec4; -using i8vec4 = vec4; +using dvec4 = vec4; +using fvec4 = vec4; +using bvec4 = vec4; +using ivec4 = vec4; +using i8vec4 = vec4; using i16vec4 = vec4; -using ivec4 = vec4; +using ivec4 = vec4; using i32vec4 = vec4; using i64vec4 = vec4; -using u8vec4 = vec4; +using u8vec4 = vec4; using u16vec4 = vec4; -using uvec4 = vec4; +using uvec4 = vec4; using u32vec4 = vec4; using u64vec4 = vec4; @@ -2162,13 +2185,13 @@ struct rect // bottom left to top right setRect(xy.x, xy.y, zw.x, zw.y); } void setRect(T vX, T vY, T vW, T vH) { - x = vX; - y = vY; - w = vW; - h = vH; - left = vX; - right = vX + vW; - top = vY + vH; + x = vX; + y = vY; + w = vW; + h = vH; + left = vX; + right = vX + vW; + top = vY + vH; bottom = vY; } vec2 rightBottom() const { @@ -2188,18 +2211,18 @@ struct rect // bottom left to top right } std::array, 4> vertices() { std::array, 4> buf; - buf[0] = leftBottom(); - buf[1] = leftTop(); - buf[2] = rightTop(); - buf[3] = rightBottom(); + buf[0] = leftBottom(); + buf[1] = leftTop(); + buf[2] = rightTop(); + buf[3] = rightBottom(); return buf; } std::array, 4> texCoords(T scaleX, T scaleY) { std::array, 4> buf; - buf[0] = vec2((T)0, (T)0); - buf[1] = vec2((T)scaleX, (T)0); - buf[2] = vec2(scaleX, scaleY); - buf[3] = vec2((T)0, scaleY); + buf[0] = vec2((T)0, (T)0); + buf[1] = vec2((T)scaleX, (T)0); + buf[2] = vec2(scaleX, scaleY); + buf[3] = vec2((T)0, scaleY); return buf; } void setWidth(T vw) { @@ -2312,8 +2335,8 @@ class plane { plane(vec3 a, vec3 b, vec3 c) { auto AB = b - a; auto AC = c - a; - n = cCross(AC, AB).GetNormalized(); - d = dotS(a, n); + n = cCross(AC, AB).GetNormalized(); + d = dotS(a, n); } plane(vec3 vn, double vd) : n(vn), d(vd) { } @@ -2327,10 +2350,10 @@ inline bool get_plane_intersection(const plane& a, const plane& b, const p vec3 m1 = vec3(a.n.x, b.n.x, c.n.x); vec3 m2 = vec3(a.n.y, b.n.y, c.n.y); vec3 m3 = vec3(a.n.z, b.n.z, c.n.z); - vec3 d = vec3(a.d, b.d, c.d); + vec3 d = vec3(a.d, b.d, c.d); vec3 u = cCross(m2, m3); - T denom = dotS(m1, u); + T denom = dotS(m1, u); if (fabs(denom) < std::numeric_limits::epsilon()) { // Planes don't actually intersect in a point @@ -2384,7 +2407,7 @@ struct AABB // copy of b2AABB struct AABB(std::string vec, char c) // may be in format "0.2f,0.3f,0.4f,0.8f" left, bottom, right, top { std::vector result = StringToNumberVector(vec, c); - const size_t s = result.size(); + const size_t s = result.size(); if (s > 0) lowerBound.x = result[0]; if (s > 1) @@ -2845,11 +2868,11 @@ class variant { std::string datatype; // real type corresponding to the data std::string string_value; - bool bool_value = false; - int int_value = 0; - float float_value = 0.0f; - double double_value = 0.0; - long long_value = 0; + bool bool_value = false; + int int_value = 0; + float float_value = 0.0f; + double double_value = 0.0; + long long_value = 0; uint32_t uint32_t_value = 0; // uint64_t uint64_t_value = 0; Color color_value; @@ -2867,105 +2890,105 @@ class variant { public: variant() { - bool_value = false; - int_value = 0; - float_value = 0.0f; - double_value = 0.0; - long_value = 0; + bool_value = false; + int_value = 0; + float_value = 0.0f; + double_value = 0.0; + long_value = 0; uint32_t_value = 0; } variant(const int& v) { int_value = v; inputtype = "int"; - datatype = inputtype; + datatype = inputtype; } variant(const long& v) { long_value = v; - inputtype = "long"; - datatype = inputtype; + inputtype = "long"; + datatype = inputtype; } // variant(const uint64_t& v) { uint64_t_value = v; inputtype = "uint64_t"; datatype = inputtype; } variant(const uint32_t& v) { uint32_t_value = v; - inputtype = "uint32_t"; - datatype = inputtype; + inputtype = "uint32_t"; + datatype = inputtype; } variant(const float& v) { float_value = v; - inputtype = "float"; - datatype = inputtype; + inputtype = "float"; + datatype = inputtype; } variant(const double& v) { double_value = v; - inputtype = "double"; - datatype = inputtype; + inputtype = "double"; + datatype = inputtype; } variant(const std::string& v, const std::string& dt) { string_value = v; - inputtype = "string"; - datatype = dt; + inputtype = "string"; + datatype = dt; } variant(const std::string& v) { string_value = v; - inputtype = "string"; - datatype = inputtype; + inputtype = "string"; + datatype = inputtype; } variant(const bool& v) { bool_value = v; - inputtype = "bool"; - datatype = inputtype; + inputtype = "bool"; + datatype = inputtype; } variant(const Color& c) { color_value = c; - inputtype = "Color"; - datatype = inputtype; + inputtype = "Color"; + datatype = inputtype; } #ifdef USE_OPENGL variant(const texture& c) { texture_value = c; - inputtype = "texture"; - datatype = inputtype; + inputtype = "texture"; + datatype = inputtype; } #endif variant(const vec2& c) { point_value = c; - inputtype = "vec2"; - datatype = inputtype; + inputtype = "vec2"; + datatype = inputtype; } variant(const vec3& c) { - v3_value = c; + v3_value = c; inputtype = "vec3"; - datatype = inputtype; + datatype = inputtype; } variant(const vec4& c) { rect_value = c; - inputtype = "vec4"; - datatype = inputtype; + inputtype = "vec4"; + datatype = inputtype; } variant(const AABB& c) { aabb_value = c; - inputtype = "AABB"; - datatype = inputtype; + inputtype = "AABB"; + datatype = inputtype; } variant(const std::vector& c) { vector_double_value = c; - inputtype = "vectorDouble"; - datatype = inputtype; + inputtype = "vectorDouble"; + datatype = inputtype; } variant(const std::vector& c) { vector_float_value = c; - inputtype = "vectorFloat"; - datatype = inputtype; + inputtype = "vectorFloat"; + datatype = inputtype; } variant(const std::vector& c) { vector_string_value = c; - inputtype = "vectorString"; - datatype = inputtype; + inputtype = "vectorString"; + datatype = inputtype; } variant(const std::set& c) { set_string_value = c; - inputtype = "setString"; - datatype = inputtype; + inputtype = "setString"; + datatype = inputtype; } std::string GetInputType() const { @@ -3237,7 +3260,7 @@ void DeleteObjectsAndClearPointerList(std::list& lst) { if (!lst.empty()) { for (typename std::list::iterator it = lst.begin(); it != lst.end(); ++it) { T* type = nullptr; - type = *it; + type = *it; if (type != nullptr) { delete type; *it = 0; @@ -3252,7 +3275,7 @@ void DeleteObjectsAndClearPointerVector(std::vector& vec) { if (!vec.empty()) { for (typename std::vector::iterator it = vec.begin(); it != vec.end(); ++it) { T* type = nullptr; - type = *it; + type = *it; if (type != nullptr) { delete type; *it = 0; @@ -3266,11 +3289,11 @@ void DeleteObjectsAndClearPointerVector(std::vector& vec) { template std::string VectorToString(std::vector& vec, char vCharDelimiter); template -std::string VectorVec2ToString(std::vector >& vec, char vCharDelimiter); // vec2> give an error in osx... must be vec2 > +std::string VectorVec2ToString(std::vector>& vec, char vCharDelimiter); // vec2> give an error in osx... must be vec2 > template -std::string VectorVec3ToString(std::vector >& vec, char vCharDelimiter); // vec3> give an error in osx... must be vec3 > +std::string VectorVec3ToString(std::vector>& vec, char vCharDelimiter); // vec3> give an error in osx... must be vec3 > template -std::string VectorVec4ToString(std::vector >& vec, char vCharDelimiter); // vec4> give an error in osx... must be vec4 > +std::string VectorVec4ToString(std::vector>& vec, char vCharDelimiter); // vec4> give an error in osx... must be vec4 > // return "vParamName=\"" + toStr(vValue) + "\"; template @@ -3305,9 +3328,9 @@ vec2 clamp(const vec2& vValue, const vec2& vInf, const vec2& vSup); template vec3 clamp(const vec3& vValue, const vec3& vInf, const vec3& vSup) { ct::vec3 vUniform = vValue; - vUniform.x = ct::clamp(vUniform.x, vInf.x, vSup.x); - vUniform.y = ct::clamp(vUniform.y, vInf.y, vSup.y); - vUniform.z = ct::clamp(vUniform.z, vInf.z, vSup.z); + vUniform.x = ct::clamp(vUniform.x, vInf.x, vSup.x); + vUniform.y = ct::clamp(vUniform.y, vInf.y, vSup.y); + vUniform.z = ct::clamp(vUniform.z, vInf.z, vSup.z); return vUniform; } template @@ -3315,16 +3338,16 @@ vec4 clamp(const vec4& vValue, const vec4& vInf, const vec4& vSup); template vec2 clamp(const vec2& vValue, T vInf, T vSup) { ct::vec2 vUniform = vValue; - vUniform.x = ct::clamp(vUniform.x, vInf, vSup); - vUniform.y = ct::clamp(vUniform.y, vInf, vSup); + vUniform.x = ct::clamp(vUniform.x, vInf, vSup); + vUniform.y = ct::clamp(vUniform.y, vInf, vSup); return vUniform; } template vec3 clamp(const vec3& vValue, T vInf, T vSup) { ct::vec3 vUniform = vValue; - vUniform.x = ct::clamp(vUniform.x, vInf, vSup); - vUniform.y = ct::clamp(vUniform.y, vInf, vSup); - vUniform.z = ct::clamp(vUniform.z, vInf, vSup); + vUniform.x = ct::clamp(vUniform.x, vInf, vSup); + vUniform.y = ct::clamp(vUniform.y, vInf, vSup); + vUniform.z = ct::clamp(vUniform.z, vInf, vSup); return vUniform; } template