From d00448a42282770bcddb9cdc58614d20e913f1c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20H=C3=B6hne?= <77296181+THoehne@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:30:16 +0100 Subject: [PATCH] Porting to linux --- .gitignore | 20 +--- DevPlayground/premake5.lua | 18 ++++ Engine/Source/Runtime/Core/Core.h | 2 +- .../Source/Runtime/Core/Logging/premake5.lua | 11 ++ .../Core/Logging/private/LoggingPCH.cpp | 1 + Engine/Source/Runtime/Core/Math/Boilerplate.h | 81 +------------- .../Runtime/Core/Math/Detail/Matrix4Decl.inl | 1 + .../Runtime/Core/Math/Detail/Vector3Decl.inl | 3 +- Engine/Source/Runtime/Core/Math/Include.h | 4 - Engine/Source/Runtime/Core/Math/IntPoint.hpp | 5 - .../Source/Runtime/Core/Math/IntVector2.hpp | 4 - .../Source/Runtime/Core/Math/IntVector3.hpp | 5 - .../Source/Runtime/Core/Math/IntVector4.hpp | 4 - Engine/Source/Runtime/Core/Math/Line.hpp | 2 - .../Source/Runtime/Core/Math/MathCommon.hpp | 8 ++ Engine/Source/Runtime/Core/Math/MathPCH.h | 33 ++---- .../Runtime/Core/Math/MathTypeConversion.hpp | 6 +- Engine/Source/Runtime/Core/Math/MathTypes.h | 13 +-- Engine/Source/Runtime/Core/Math/Matrix4.hpp | 2 +- Engine/Source/Runtime/Core/Math/Matrix4.inl | 2 + .../Source/Runtime/Core/Math/PhanesMathPCH.h | 27 +++++ Engine/Source/Runtime/Core/Math/Plane.hpp | 2 +- Engine/Source/Runtime/Core/Math/Point.hpp | 30 +++++- .../Source/Runtime/Core/Math/SIMD/Platform.h | 2 - Engine/Source/Runtime/Core/Math/Vector2.hpp | 22 ++-- Engine/Source/Runtime/Core/Math/Vector3.hpp | 83 ++++++++++++-- Engine/Source/Runtime/Core/Math/Vector4.hpp | 11 +- Engine/Source/Runtime/Core/Math/Vector4.inl | 1 - .../Runtime/Core/Math/private/MathPCH.cpp | 1 + .../Core/Math/private/PhanesMathPCH.cpp | 1 + .../Runtime/Core/StartingPoint/EntryPoint.h | 17 +-- .../Runtime/Core/StartingPoint/premake5.lua | 9 ++ .../Core/StartingPoint/private/EntryPoint.cpp | 22 ++++ .../private/StartingPointPCH.cpp | 1 + Engine/Source/Runtime/Core/premake5.lua | 17 +++ MathTestFPU/main.cpp | 21 ++-- MathTestFPU/pch.cpp | 2 + MathTestFPU/premake5.lua | 29 +++++ MathTestFPU/test.cpp | 7 +- premake5.lua | 102 +++++++++++++++++- 40 files changed, 416 insertions(+), 216 deletions(-) create mode 100644 DevPlayground/premake5.lua create mode 100644 Engine/Source/Runtime/Core/Logging/premake5.lua create mode 100644 Engine/Source/Runtime/Core/Logging/private/LoggingPCH.cpp create mode 100644 Engine/Source/Runtime/Core/Math/PhanesMathPCH.h create mode 100644 Engine/Source/Runtime/Core/Math/private/MathPCH.cpp create mode 100644 Engine/Source/Runtime/Core/Math/private/PhanesMathPCH.cpp create mode 100644 Engine/Source/Runtime/Core/StartingPoint/premake5.lua create mode 100644 Engine/Source/Runtime/Core/StartingPoint/private/EntryPoint.cpp create mode 100644 Engine/Source/Runtime/Core/StartingPoint/private/StartingPointPCH.cpp create mode 100644 Engine/Source/Runtime/Core/premake5.lua create mode 100644 MathTestFPU/pch.cpp create mode 100644 MathTestFPU/premake5.lua diff --git a/.gitignore b/.gitignore index 27d2c7c..c6e44e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,28 +1,14 @@ # Exclude folders bin/ -bin-int/ +int/ external/ # Frequently edited tests Tests/TestProject/ -# CMake Build Files -CMakeLists.txt.user -CMakeCache.txt -CMakeFiles/ -CMakeScripts/ -Testing/ -Makefile -cmake_install.cmake -install_manifest.txt -compile_commands.json -CTestTestfile.cmake -_deps/ -CMakeUserPresets.json +# Premake Build Files build/ - - -# Exclude files +Makefile # C++ # Prerequisites diff --git a/DevPlayground/premake5.lua b/DevPlayground/premake5.lua new file mode 100644 index 0000000..9ea35e6 --- /dev/null +++ b/DevPlayground/premake5.lua @@ -0,0 +1,18 @@ +project "DevPlayground" + kind "ConsoleApp" + + boilerplate() + + files { + phanesRoot .. "/DevPlayground/**.h", + phanesRoot .. "/DevPlayground/**.cpp", + } + + -- Linking PhanesCore + links { "PhanesCore" } + dependson { "PhanesCore" } + + links{"fmt"} + dependson {"fmt"} + + includedirs { PhanesRuntime } \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Core.h b/Engine/Source/Runtime/Core/Core.h index 9567148..6936fc4 100644 --- a/Engine/Source/Runtime/Core/Core.h +++ b/Engine/Source/Runtime/Core/Core.h @@ -38,7 +38,7 @@ #endif - #define FORCEINLINE __attribute__((always_inline)) + #define FORCEINLINE inline #elif defined(P_ARM_BUILD) diff --git a/Engine/Source/Runtime/Core/Logging/premake5.lua b/Engine/Source/Runtime/Core/Logging/premake5.lua new file mode 100644 index 0000000..5c2207b --- /dev/null +++ b/Engine/Source/Runtime/Core/Logging/premake5.lua @@ -0,0 +1,11 @@ +function includeLogging() + files { + PhanesRuntime .. "/Core/Logging/**.h", + PhanesRuntime .. "/Core/Logging/**.cpp", + } + + -- includedirs { PhanesThirdParty .. "/spdlog/include" } + + pchheader (PhanesRuntime .. "/Core/Logging/LoggingPCH.h") + pchsource (PhanesRuntime .. "/Core/Logging/private/LoggingPCH.cpp") +end \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Logging/private/LoggingPCH.cpp b/Engine/Source/Runtime/Core/Logging/private/LoggingPCH.cpp new file mode 100644 index 0000000..74d9278 --- /dev/null +++ b/Engine/Source/Runtime/Core/Logging/private/LoggingPCH.cpp @@ -0,0 +1 @@ +#include "Core/Logging/LoggingPCH.h" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Math/Boilerplate.h b/Engine/Source/Runtime/Core/Math/Boilerplate.h index 1184937..32ef702 100644 --- a/Engine/Source/Runtime/Core/Math/Boilerplate.h +++ b/Engine/Source/Runtime/Core/Math/Boilerplate.h @@ -2,62 +2,9 @@ #pragma once +#include "Core/Math/MathPCH.h" - - -#ifdef P_BUILD_LIB - #include "PhanesEnginePCH.h" - -#else - #include - #include -#endif - - -#ifdef P_WIN_BUILD - - #ifdef P_DEBUG - - #define P_DEBUGBREAK DebugBreak(); - - #else - - #define P_DEBUGBREAK - - #endif // P_DEBUG - - #define FORCEINLINE __forceinline - -#elif defined(P_LINUX_BUILD) - - #ifdef P_DEBUG - - #define P_DEBUGBREAK __builtin_trap(); - - #else - - #define P_DEBUGBREAK - - #endif // P_DEBUG - - #define FORCEINLINE inline __attribute__((always_inline)) - -#elif defined(P_ARM_BUILD) - - #error Only Windows is supported at the moment. - -#else - - #error The target system must be defined. (See https://github.com/scorpioblood/PhanesEngine for more information) - -#endif // P_WIN_BUILD - - - - - - - +#include "Core/Core.h" namespace Phanes::Core::Math @@ -74,28 +21,4 @@ namespace Phanes::Core::Math // Typenames with Arithmethic constrain have to be number. template concept Arithmethic = std::is_arithmetic_v; - - - - // Alias for shared_ptr - template - using Ref = std::shared_ptr; - - // Alias for make_shared - template - constexpr Ref MakeRef(Args&& ...args) - { - return std::make_shared(std::forward(args)...); - } - - // Alias for unique ptr - template - using Scope = std::unique_ptr; - - // Alias for make_unique - template - constexpr Scope MakeScope(Args&& ...args) - { - return std::make_unique(std::forward(args)...); - } } \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Math/Detail/Matrix4Decl.inl b/Engine/Source/Runtime/Core/Math/Detail/Matrix4Decl.inl index 9408cbb..aee019b 100644 --- a/Engine/Source/Runtime/Core/Math/Detail/Matrix4Decl.inl +++ b/Engine/Source/Runtime/Core/Math/Detail/Matrix4Decl.inl @@ -46,6 +46,7 @@ namespace Phanes::Core::Math::Detail { static constexpr bool map(Phanes::Core::Math::TMatrix4& r, const Phanes::Core::Math::TMatrix4& m) { + const TVector3& a = reinterpret_cast&>(m[0]); const TVector3& b = reinterpret_cast&>(m[1]); const TVector3& c = reinterpret_cast&>(m[2]); diff --git a/Engine/Source/Runtime/Core/Math/Detail/Vector3Decl.inl b/Engine/Source/Runtime/Core/Math/Detail/Vector3Decl.inl index 0d7f8da..f721d16 100644 --- a/Engine/Source/Runtime/Core/Math/Detail/Vector3Decl.inl +++ b/Engine/Source/Runtime/Core/Math/Detail/Vector3Decl.inl @@ -1,6 +1,7 @@ #pragma once #include "Core/Math/Boilerplate.h" +#include "Core/Math/MathCommon.hpp" namespace Phanes::Core::Math::Detail { @@ -259,7 +260,7 @@ namespace Phanes::Core::Math::Detail { static constexpr T map(const Phanes::Core::Math::TVector3& v1) { - return sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z); + return Phanes::Core::Math::Sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z); } }; diff --git a/Engine/Source/Runtime/Core/Math/Include.h b/Engine/Source/Runtime/Core/Math/Include.h index 1eaf3fb..685a538 100644 --- a/Engine/Source/Runtime/Core/Math/Include.h +++ b/Engine/Source/Runtime/Core/Math/Include.h @@ -1,9 +1,5 @@ #pragma once -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - #include "Core/Math/MathFwd.h" diff --git a/Engine/Source/Runtime/Core/Math/IntPoint.hpp b/Engine/Source/Runtime/Core/Math/IntPoint.hpp index 60d8c19..261aba6 100644 --- a/Engine/Source/Runtime/Core/Math/IntPoint.hpp +++ b/Engine/Source/Runtime/Core/Math/IntPoint.hpp @@ -9,11 +9,6 @@ #include "Core/Math/IntVector2.hpp" #include "Core/Math/IntVector3.hpp" #include "Core/Math/IntVector4.hpp" - -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - /** * General annonation: The Point is the same as a vector. The type exists, to ensure a * easy differentiation between the two. diff --git a/Engine/Source/Runtime/Core/Math/IntVector2.hpp b/Engine/Source/Runtime/Core/Math/IntVector2.hpp index c5b11fa..aab21b7 100644 --- a/Engine/Source/Runtime/Core/Math/IntVector2.hpp +++ b/Engine/Source/Runtime/Core/Math/IntVector2.hpp @@ -7,10 +7,6 @@ #include "Core/Math/SIMD/Storage.h" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - /** * Note: Some function are deleted, because, their unusable with int types, except very specific cases. * To keep the library verbose, these functions are explicitly marked as deleted. diff --git a/Engine/Source/Runtime/Core/Math/IntVector3.hpp b/Engine/Source/Runtime/Core/Math/IntVector3.hpp index 90c0b07..c2fca17 100644 --- a/Engine/Source/Runtime/Core/Math/IntVector3.hpp +++ b/Engine/Source/Runtime/Core/Math/IntVector3.hpp @@ -9,11 +9,6 @@ #include "Core/Math/IntVector4.hpp" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - - #ifndef INTVECTOR3_H #define INTVECTOR3_H diff --git a/Engine/Source/Runtime/Core/Math/IntVector4.hpp b/Engine/Source/Runtime/Core/Math/IntVector4.hpp index c3334b4..a31bce6 100644 --- a/Engine/Source/Runtime/Core/Math/IntVector4.hpp +++ b/Engine/Source/Runtime/Core/Math/IntVector4.hpp @@ -9,10 +9,6 @@ #include "Core/Math/IntVector2.hpp" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - #ifndef INTVECTOR4_H #define INTVECTOR4_H diff --git a/Engine/Source/Runtime/Core/Math/Line.hpp b/Engine/Source/Runtime/Core/Math/Line.hpp index 5c948cc..0a82d47 100644 --- a/Engine/Source/Runtime/Core/Math/Line.hpp +++ b/Engine/Source/Runtime/Core/Math/Line.hpp @@ -47,8 +47,6 @@ namespace Phanes::Core::Math template TLine& NormalizeV(TLine& l1) { - std::any - NormalizeV(l1.direction); return l1; } diff --git a/Engine/Source/Runtime/Core/Math/MathCommon.hpp b/Engine/Source/Runtime/Core/Math/MathCommon.hpp index 0f12d76..4dcbce1 100644 --- a/Engine/Source/Runtime/Core/Math/MathCommon.hpp +++ b/Engine/Source/Runtime/Core/Math/MathCommon.hpp @@ -1,5 +1,7 @@ #pragma once +#include "Core/Math/MathPCH.h" + #define P_FLT_INAC_LARGE 0.0001f // large float inaccuracy (1*10^-4); #define P_FLT_INAC 0.00001f // float inaccuracy (1*10^-5); #define P_FLT_INAC_SMALL 0.000001f // small float inaccuracy (1*10^-6); @@ -131,6 +133,12 @@ namespace Phanes::Core::Math { return abs(s); } + template + inline T Sqrt(T s) + { + return sqrt(s); + } + } // phanes diff --git a/Engine/Source/Runtime/Core/Math/MathPCH.h b/Engine/Source/Runtime/Core/Math/MathPCH.h index eb2ff3e..d789e5b 100644 --- a/Engine/Source/Runtime/Core/Math/MathPCH.h +++ b/Engine/Source/Runtime/Core/Math/MathPCH.h @@ -1,27 +1,10 @@ -// Header file containing all files to be compiled to use core math. -// Should be included in PCH file of project to use. +// PCH for STL. This is a precompiled header file for the Standard Template Library used in math. +// For a PCH for this submodule see PhanesMathPCH.h -#pragma once +#define NOMINMAX -#include "Core/Math/Point.hpp" -#include "Core/Math/Plane.hpp" -#include "Core/Math/Line.hpp" -#include "Core/Math/Ray.hpp" - - -#include "Core/Math/Vector2.hpp" -#include "Core/Math/Vector3.hpp" -#include "Core/Math/Vector4.hpp" - -#include "Core/Math/IntPoint.hpp" -#include "Core/Math/IntVector2.hpp" -#include "Core/Math/IntVector3.hpp" -#include "Core/Math/IntVector4.hpp" - -#include "Core/Math/Matrix2.hpp" -#include "Core/Math/Matrix3.hpp" -#include "Core/Math/Matrix4.hpp" - -#include "Core/Math/MathCommon.hpp" -#include "Core/Math/MathTypeConversion.hpp" -#include "Core/Math/MathUnitConversion.hpp" \ No newline at end of file +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Math/MathTypeConversion.hpp b/Engine/Source/Runtime/Core/Math/MathTypeConversion.hpp index 0c7ce35..b668050 100644 --- a/Engine/Source/Runtime/Core/Math/MathTypeConversion.hpp +++ b/Engine/Source/Runtime/Core/Math/MathTypeConversion.hpp @@ -6,13 +6,9 @@ // @ref [FILE]MathUnitConversion // // ============================================= // -#ifdef P_BUILD_LIB - #include "PhanesEnginePCH.h" -#else - #include -#endif #include "Core/Math/Boilerplate.h" +#include "Core/Math/MathPCH.h" #include "Core/Math/MathAbstractTypes.h" #include "Core/Math/Vector2.hpp" diff --git a/Engine/Source/Runtime/Core/Math/MathTypes.h b/Engine/Source/Runtime/Core/Math/MathTypes.h index d56898b..bc18e39 100644 --- a/Engine/Source/Runtime/Core/Math/MathTypes.h +++ b/Engine/Source/Runtime/Core/Math/MathTypes.h @@ -1,11 +1,6 @@ #pragma once -#ifdef P_BUILD_LIB -# include "PhanesEnginePCH.h" -#else -# define NOMINMAX -# include -#endif +#include "Core/Math/MathPCH.h" // ============================================= // // Turn os specific types into global types. // @@ -23,6 +18,12 @@ namespace Phanes::Core::Types typedef _FLOAT128 float128; +#elif defined(P_LINUX_BUILD) + + // Linux specific types + + typedef __float128 float128; + #endif diff --git a/Engine/Source/Runtime/Core/Math/Matrix4.hpp b/Engine/Source/Runtime/Core/Math/Matrix4.hpp index eedbef6..f44f613 100644 --- a/Engine/Source/Runtime/Core/Math/Matrix4.hpp +++ b/Engine/Source/Runtime/Core/Math/Matrix4.hpp @@ -123,7 +123,7 @@ namespace Phanes::Core::Math { } FORCEINLINE TVector4& operator[] (int m) { - return (*reinterpret_cast*>(this->m[m])); + return (*reinterpret_cast*>(this->data[m])); } FORCEINLINE const T& operator() (int n, int m) const diff --git a/Engine/Source/Runtime/Core/Math/Matrix4.inl b/Engine/Source/Runtime/Core/Math/Matrix4.inl index ab7c57d..a38cc9a 100644 --- a/Engine/Source/Runtime/Core/Math/Matrix4.inl +++ b/Engine/Source/Runtime/Core/Math/Matrix4.inl @@ -7,6 +7,8 @@ #include "Core/Math/SIMD/PhanesSIMDTypes.h" +#include + namespace Phanes::Core::Math { diff --git a/Engine/Source/Runtime/Core/Math/PhanesMathPCH.h b/Engine/Source/Runtime/Core/Math/PhanesMathPCH.h new file mode 100644 index 0000000..eb2ff3e --- /dev/null +++ b/Engine/Source/Runtime/Core/Math/PhanesMathPCH.h @@ -0,0 +1,27 @@ +// Header file containing all files to be compiled to use core math. +// Should be included in PCH file of project to use. + +#pragma once + +#include "Core/Math/Point.hpp" +#include "Core/Math/Plane.hpp" +#include "Core/Math/Line.hpp" +#include "Core/Math/Ray.hpp" + + +#include "Core/Math/Vector2.hpp" +#include "Core/Math/Vector3.hpp" +#include "Core/Math/Vector4.hpp" + +#include "Core/Math/IntPoint.hpp" +#include "Core/Math/IntVector2.hpp" +#include "Core/Math/IntVector3.hpp" +#include "Core/Math/IntVector4.hpp" + +#include "Core/Math/Matrix2.hpp" +#include "Core/Math/Matrix3.hpp" +#include "Core/Math/Matrix4.hpp" + +#include "Core/Math/MathCommon.hpp" +#include "Core/Math/MathTypeConversion.hpp" +#include "Core/Math/MathUnitConversion.hpp" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Math/Plane.hpp b/Engine/Source/Runtime/Core/Math/Plane.hpp index d75671a..893a0fd 100644 --- a/Engine/Source/Runtime/Core/Math/Plane.hpp +++ b/Engine/Source/Runtime/Core/Math/Plane.hpp @@ -624,7 +624,7 @@ namespace Phanes::Core::Math { TPlane TranslateV(TPlane& pl1, const TVector3& v1) { - pl1.d = DotP(this->normal, GetOrigin(pl1) + v1); + pl1.d = DotP(pl1.normal, GetOrigin(pl1) + v1); return pl1; } diff --git a/Engine/Source/Runtime/Core/Math/Point.hpp b/Engine/Source/Runtime/Core/Math/Point.hpp index ccc6a83..3f721e6 100644 --- a/Engine/Source/Runtime/Core/Math/Point.hpp +++ b/Engine/Source/Runtime/Core/Math/Point.hpp @@ -9,10 +9,6 @@ #include "Core/Math/Vector2.hpp" #include "Core/Math/Vector3.hpp" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - /** * The Point is the same as a vector. The type exists, to ensure * differentiation between the two types. @@ -46,6 +42,14 @@ namespace Phanes::Core::Math { this->y = p.y; } + /// @brief Creates Point2 from Vector2 + /// @param v + TPoint2(const TVector2& v) + { + this->x = v.x; + this->y = v.y; + } + /** * Creates Point2 from Point4's xy * @@ -102,6 +106,15 @@ namespace Phanes::Core::Math { this->z = 0; } + /// @brief Creates Point3 from Vector3 + /// @param v + TPoint3(const TVector3& v) + { + this->x = v.x; + this->y = v.y; + this->z = v.z; + } + /** * Creates Point3 from Point4's xyz * @@ -171,8 +184,17 @@ namespace Phanes::Core::Math { this->z = p.z; this->w = 0; } + + TPoint4(const TVector4& v) + { + this->x = v.x; + this->y = v.y; + this->z = v.z; + this->w = v.w; + } }; + /** * Calculates distance between two points. * diff --git a/Engine/Source/Runtime/Core/Math/SIMD/Platform.h b/Engine/Source/Runtime/Core/Math/SIMD/Platform.h index 4e56ddf..0f64941 100644 --- a/Engine/Source/Runtime/Core/Math/SIMD/Platform.h +++ b/Engine/Source/Runtime/Core/Math/SIMD/Platform.h @@ -207,7 +207,6 @@ // G++ #elif defined(__GNUC__) || defined(__MINGW32__) -# error PhanesEngine only supports MSVC -> Visual Studio # if __GNUC__ >= 14 # define P_COMPILER P_COMPILER_GCC14 # elif __GNUC__ >= 13 @@ -312,7 +311,6 @@ # define P_AVX2__ 0 # define P_AVX__ 0 # define P_SSE__ 0 -# define P_SSE__ 0 #else # if (P_AVX__ == 1) && (P_AVX2__ == 0) # define P_INTRINSICS P_INTRINSICS_AVX diff --git a/Engine/Source/Runtime/Core/Math/Vector2.hpp b/Engine/Source/Runtime/Core/Math/Vector2.hpp index 94dcfb2..90aa0c1 100644 --- a/Engine/Source/Runtime/Core/Math/Vector2.hpp +++ b/Engine/Source/Runtime/Core/Math/Vector2.hpp @@ -7,21 +7,15 @@ #include "Core/Math/SIMD/Storage.h" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - -#pragma warning(disable: 4661) - #ifndef VECTOR2_H #define VECTOR2_H -#define PZeroVector2(type, aligned) Phanes::Core::Math::TVector2<##type, ##aligned>(0,0) -#define PVectorSouth2(type, aligned) Phanes::Core::Math::TVector2<##type, ##aligned>(0,-1) -#define PVectorNorth2(type, aligned) Phanes::Core::Math::TVector2<##type, ##aligned>(0,1) -#define PVectorEast2(type, aligned) Phanes::Core::Math::TVector2<##type, ##aligned>(1,0) -#define PVectorWest2(type, aligned) Phanes::Core::Math::TVector2<##type, ##aligned>(-1,0) +#define PZeroVector2(type, aligned) Phanes::Core::Math::TVector2(0,0) +#define PVectorSouth2(type, aligned) Phanes::Core::Math::TVector2(0,-1) +#define PVectorNorth2(type, aligned) Phanes::Core::Math::TVector2(0,1) +#define PVectorEast2(type, aligned) Phanes::Core::Math::TVector2(1,0) +#define PVectorWest2(type, aligned) Phanes::Core::Math::TVector2(-1,0) namespace Phanes::Core::Math { @@ -466,6 +460,12 @@ namespace Phanes::Core::Math { return v1; } + template + T Distance(const TVector2& v1, const TVector2& v2) + { + return Magnitude(v2 - v1); + } + /** * Binds a vector to a square with a radius * diff --git a/Engine/Source/Runtime/Core/Math/Vector3.hpp b/Engine/Source/Runtime/Core/Math/Vector3.hpp index ddc35bf..f4591a2 100644 --- a/Engine/Source/Runtime/Core/Math/Vector3.hpp +++ b/Engine/Source/Runtime/Core/Math/Vector3.hpp @@ -11,20 +11,16 @@ #include "Core/Math/Vector4.hpp" -#ifndef P_DEBUG -#pragma warning(disable : 4244) -#endif - #ifndef VECTOR3_H #define VECTOR3_H -#define PZeroVector3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(0,0,0) -#define PVectorForward3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(1,0,0) -#define PVectorBackward3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(-1,0,0) -#define PVectorEast3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(0,1,0) -#define PVectorWest3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(0,-1,0) -#define PVectorUp3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(0,0,1) -#define PVectorDown3(type, aligned) Phanes::Core::Math::TVector3<##type, ##aligned>(0,0,-1) +#define PZeroVector3(type, aligned) Phanes::Core::Math::TVector3(0,0,0) +#define PVectorForward3(type, aligned) Phanes::Core::Math::TVector3(1,0,0) +#define PVectorBackward3(type, aligned) Phanes::Core::Math::TVector3(-1,0,0) +#define PVectorEast3(type, aligned) Phanes::Core::Math::TVector3(0,1,0) +#define PVectorWest3(type, aligned) Phanes::Core::Math::TVector3(0,-1,0) +#define PVectorUp3(type, aligned) Phanes::Core::Math::TVector3(0,0,1) +#define PVectorDown3(type, aligned) Phanes::Core::Math::TVector3(0,0,-1) namespace Phanes::Core::Math { @@ -413,6 +409,46 @@ namespace Phanes::Core::Math { return v1; } + + /** + * Refracts a vector + * + * @param(v1) Vector one + * @param(normal) Normal of surface + * @param(eta) Refraction index + */ + template + TVector3& RefractV(TVector3& v1, const TVector3& normal, T eta) + { + T dot = DotP(v1, normal); + T k = 1.0f - eta * eta * (1.0f - dot * dot); + + if (k < 0.0f) + { + v1 = PZeroVector3(T, false); + } + else + { + v1 = eta * v1 - (eta * dot + sqrt(k)) * normal; + } + + return v1; + } + + /** + * Gets distance between two vectors + * + * @param(v1) Vector one + * @param(v2) Vector two + * + * @return Distance between vectors + */ + template + T Distance(const TVector3& v1, const TVector3& v2) + { + return Magnitude(v2 - v1); + } + /** * Gets angle between two vectors * @@ -920,6 +956,31 @@ namespace Phanes::Core::Math { return (2 * DotP(v1, normal) * normal) - v1; } + /** + * Refracts a vector + * + * @param (v1) Vector one + * @param (normal) Normal of surface + * @param (eta) Refraction index + * + * @return Refracted vector + */ + template + TVector3 Refract(const TVector3& v1, const TVector3& normal, T eta) + { + T dot = DotP(v1, normal); + T k = 1.0f - eta * eta * (1.0f - dot * dot); + + if (k < 0.0f) + { + return PZeroVector3(T, false); + } + else + { + return eta * v1 - (eta * dot + sqrt(k)) * normal; + } + } + /** * Performes perspective divide on vector. diff --git a/Engine/Source/Runtime/Core/Math/Vector4.hpp b/Engine/Source/Runtime/Core/Math/Vector4.hpp index 2d3f536..af130e6 100644 --- a/Engine/Source/Runtime/Core/Math/Vector4.hpp +++ b/Engine/Source/Runtime/Core/Math/Vector4.hpp @@ -10,7 +10,9 @@ #include "Core/Math/Vector2.hpp" #include "Core/Math/Vector3.hpp" -#define PZeroVector4(type, aligned) Phanes::Core::Math::TVector4<##type, ##aligned>(0,0,0,0) + + +#define PZeroVector4(type, aligned) Phanes::Core::Math::TVector4(0,0,0,0) namespace Phanes::Core::Math { @@ -741,6 +743,12 @@ namespace Phanes::Core::Math return v1; } + template + T Distance(const TVector4& v1, const TVector4& v2) + { + return Magnitude(v1 - v2); + } + /// /// Project vector v1 onto v2. /// @@ -863,5 +871,4 @@ namespace Phanes::Core::Math } } - #include "Core/Math/Vector4.inl" diff --git a/Engine/Source/Runtime/Core/Math/Vector4.inl b/Engine/Source/Runtime/Core/Math/Vector4.inl index 73309e8..9b02472 100644 --- a/Engine/Source/Runtime/Core/Math/Vector4.inl +++ b/Engine/Source/Runtime/Core/Math/Vector4.inl @@ -5,7 +5,6 @@ #include "Core/Math/Detail/Vector4Decl.inl" #include "Core/Math/SIMD/SIMDIntrinsics.h" - #include "Core/Math/SIMD/PhanesSIMDTypes.h" namespace Phanes::Core::Math diff --git a/Engine/Source/Runtime/Core/Math/private/MathPCH.cpp b/Engine/Source/Runtime/Core/Math/private/MathPCH.cpp new file mode 100644 index 0000000..ddee0b0 --- /dev/null +++ b/Engine/Source/Runtime/Core/Math/private/MathPCH.cpp @@ -0,0 +1 @@ +#include "Core/Math/MathPCH.h" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/Math/private/PhanesMathPCH.cpp b/Engine/Source/Runtime/Core/Math/private/PhanesMathPCH.cpp new file mode 100644 index 0000000..b5e9d08 --- /dev/null +++ b/Engine/Source/Runtime/Core/Math/private/PhanesMathPCH.cpp @@ -0,0 +1 @@ +#include "Core/Math/PhanesMathPCH.h" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h b/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h index 1ba4209..255f5e7 100644 --- a/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h +++ b/Engine/Source/Runtime/Core/StartingPoint/EntryPoint.h @@ -3,21 +3,6 @@ #if defined(P_LINUX_BUILD) -extern Phanes::Core::Application::PhanesProject* Phanes::Core::Application::CreatePhanesGame(); - -int main(int argc, char** argv) -{ - Phanes::Core::Logging::Logger::Init(); - PENGINE_LOG_INFO("Logger initialized!"); - PENGINE_LOG_INFO("Welcome to PhanesEngine!"); - - auto phanes_game = Phanes::Core::Application::CreatePhanesGame(); - - phanes_game->Run(); - - delete phanes_game; - - return 0; -} +int main(); #endif \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/StartingPoint/premake5.lua b/Engine/Source/Runtime/Core/StartingPoint/premake5.lua new file mode 100644 index 0000000..81f21a5 --- /dev/null +++ b/Engine/Source/Runtime/Core/StartingPoint/premake5.lua @@ -0,0 +1,9 @@ +function includeStartingPoint() + files { + PhanesRuntime .. "/Core/StartingPoint/**.h", + PhanesRuntime .. "/Core/StartingPoint/**.cpp", + } + + pchheader (PhanesRuntime .. "/Core/StartingPoint/StartingPointPCH.h") + pchsource (PhanesRuntime .. "/Core/StartingPoint/private/StartingPointPCH.cpp") +end \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/StartingPoint/private/EntryPoint.cpp b/Engine/Source/Runtime/Core/StartingPoint/private/EntryPoint.cpp new file mode 100644 index 0000000..329a9a4 --- /dev/null +++ b/Engine/Source/Runtime/Core/StartingPoint/private/EntryPoint.cpp @@ -0,0 +1,22 @@ +#include "Core/Include.h" + +#if defined(P_LINUX_BUILD) + +extern Phanes::Core::Application::PhanesProject* Phanes::Core::Application::CreatePhanesGame(); + +int main() +{ + Phanes::Core::Logging::Logger::Init(); + PENGINE_LOG_INFO("Logger initialized!"); + PENGINE_LOG_INFO("Welcome to PhanesEngine!"); + + auto phanes_game = Phanes::Core::Application::CreatePhanesGame(); + + phanes_game->Run(); + + delete phanes_game; + + return 0; +} + +#endif \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/StartingPoint/private/StartingPointPCH.cpp b/Engine/Source/Runtime/Core/StartingPoint/private/StartingPointPCH.cpp new file mode 100644 index 0000000..0405a93 --- /dev/null +++ b/Engine/Source/Runtime/Core/StartingPoint/private/StartingPointPCH.cpp @@ -0,0 +1 @@ +#include "Core/StartingPoint/StartingPointPCH.h" \ No newline at end of file diff --git a/Engine/Source/Runtime/Core/premake5.lua b/Engine/Source/Runtime/Core/premake5.lua new file mode 100644 index 0000000..8afd905 --- /dev/null +++ b/Engine/Source/Runtime/Core/premake5.lua @@ -0,0 +1,17 @@ +include (PhanesRuntime .. "/Core/StartingPoint/premake5.lua") +include (PhanesRuntime .. "/Core/Logging/premake5.lua") + + +project "PhanesCore" + kind "StaticLib" + + boilerplate() + + files { + PhanesRuntime .. "/Core/Core.h" + } + + includedirs { PhanesRuntime } + + includeStartingPoint() + includeLogging() \ No newline at end of file diff --git a/MathTestFPU/main.cpp b/MathTestFPU/main.cpp index 6975e17..991d461 100644 --- a/MathTestFPU/main.cpp +++ b/MathTestFPU/main.cpp @@ -1,12 +1,21 @@ #include - #include "Core/Math/Include.h" -int main(int argc, char **argv) { - Phanes::Core::Math::Vector3 v1(1.0f, 2.0f, 3.0f); - Phanes::Core::Math::Vector3 v2(1.0f, 2.0f, 3.0f); +namespace PMath = Phanes::Core::Math; - Phanes::Core::Math::Vector3 v3 = v1 + v2; +int main() +{ + PMath::Matrix4 m0 = PMath::Matrix4(1.0f, 5.0f, 3.0f, 4.0f, + 2.0f, 6.0f, 4.0f, 1.0f, + 2.0f, -3.0f, 5.0f, 3.0f, + 8.0f, -4.0f, 6.0f, -2.0f); - std::cout << "v3: " << Phanes::Core::Math::ToString(v3) << std::endl; + + PMath::Matrix4 m2; + + std::cout << std::to_string(PMath::InverseV(m0)) << std::endl; + + std::cout << PMath::ToString(m0) << std::endl; + + return 0; } \ No newline at end of file diff --git a/MathTestFPU/pch.cpp b/MathTestFPU/pch.cpp new file mode 100644 index 0000000..ce9b739 --- /dev/null +++ b/MathTestFPU/pch.cpp @@ -0,0 +1,2 @@ +#include "pch.h" + diff --git a/MathTestFPU/premake5.lua b/MathTestFPU/premake5.lua new file mode 100644 index 0000000..0bf65ef --- /dev/null +++ b/MathTestFPU/premake5.lua @@ -0,0 +1,29 @@ +project "MathTestFPU" + kind "ConsoleApp" + boilerplate() + + files { + phanesRoot .. "/MathTestFPU/test.cpp" + } + + buildoptions {"-Wno-unused-variable", "-w", "-fpermissive"} + + pchheader "pch.h" + pchsource "pch.cpp" + + includedirs { + phanesRoot .. "/MathTestFPU", + PhanesRuntime + } + +project "Test" + kind "ConsoleApp" + boilerplate() + + files { + phanesRoot .. "/MathTestFPU/main.cpp" + } + + includedirs { + PhanesRuntime + } \ No newline at end of file diff --git a/MathTestFPU/test.cpp b/MathTestFPU/test.cpp index a092999..53a30c9 100644 --- a/MathTestFPU/test.cpp +++ b/MathTestFPU/test.cpp @@ -1,9 +1,12 @@ #include "pch.h" -#include "Core/public/Math/Include.h" +#include "Core/Math/Include.h" #include "Core/Core.h" +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-fpermissive" + namespace PMath = Phanes::Core::Math; using namespace Phanes::Core::Math::UnitLiterals; @@ -1263,7 +1266,7 @@ namespace Plane TEST(Plane, OperatorTests) { PMath::Plane pl1(3.0f / 5.4772255750f, -2.0f / 5.4772255750f, -3.0f / 5.4772255750f, 4.0f); - PMath::Plane pl2(-0.526316f, -0.442105f, -0.726316f, 6.0f); + PMath::Plane pl2 = PMath::Plane(-0.526316f, -0.442105f, -0.726316f, 6.0f); } } \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index abd0b09..c60c7ce 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,2 +1,102 @@ +-- Phanes build configuration +VERSION = "1.0.0" + +-- Override with specific platform if necessary +PLATFORM = os.target() + +-- architecture. +ARCH = "x86_64" + +-- SSE options: +-- SSE4: SSE +-- AVX: AVX +-- AVX2: AVX2 +-- No SSE: FPU +-- None: Automatically detect SSE during build +SSE = "None" + + +phanesRoot = path.getabsolute(".") +phanesBin = path.join(phanesRoot, "bin") +phanesInt = path.join(phanesRoot, ".int") +phanesBuildFiles = path.join(phanesRoot, "build") + +PhanesEngine = path.join(phanesRoot, "Engine") +PhanesRuntime = path.join(PhanesEngine, "Source/Runtime") +PhanesThirdParty = path.join(PhanesEngine, "Source/ThirdParty") + + + workspace "PhanesEngine" - configurations { "Debug", "Release" } \ No newline at end of file + cppdialect "C++20" + architecture (ARCH) + toolset "gcc" + flags { "MultiProcessorCompile" } + clangtidy "On" + llvmversion "19.0" + configurations { "Debug", "Release" } + + +function linux_sse() + if SSE == "SSE" then + defines {"P_SSE__"} + buildoptions {"-msse4", "-msse2", "-msse3"} + elseif SSE == "AVX" then + defines { "P_AVX__" } + buildoptions {"-mavx", "-msse4", "-msse2", "-msse3"} + elseif SSE == "AVX2" then + defines { "P_AVX2__" } + buildoptions {"-mavx2", "-mavx", "-msse4", "-msse2", "-msse3"} + elseif SSE == "FPU" then + defines { "P_FORCE_FPU" } + end + +end + +function boilerplate() + language "C++" + + location (phanesBuildFiles .. "/%{prj.name}") + targetdir (phanesBin .. "/" .. VERSION .. "/%{cfg.buildcfg}/%{prj.name}") + objdir (phanesInt .. "/" .. VERSION .. "/%{cfg.buildcfg}/%{prj.name}") + + if PLATFORM == "linux" then + defines { "P_LINUX_BUILD" } + linux_sse() + buildoptions { "-Wno-unused-parameter" , "-fms-extensions" } + end + + filter "configurations:Debug" + defines { "DEBUG", "TRACE", "P_DEBUG"} + symbols "On" + buildmessage("Building %{prj.name} in debug mode") + + filter "configurations:Release" + defines { "NDEBUG", "P_RELEASE" } + linktimeoptimization "On" + optimize "On" + intrinsics "On" + buildmessage("Building %{prj.name} in release mode") + + filter{} +end + +-- actions + +function action_clean() + os.rmdir(phanesBin) + os.rmdir(phanesInt) + os.rmdir(phanesBuildFiles) + os.remove(phanesRoot .. "/Makefile") +end + +newaction { + trigger = "clean", + description = "Clean the build", + execute = action_clean, +} + +-- includeProjects here +include "Engine/Source/Runtime/Core/premake5.lua" +include "DevPlayground/premake5.lua" +include "MathTestFPU/premake5.lua" \ No newline at end of file