Porting to linux

This commit is contained in:
Thorben Höhne
2025-02-19 19:30:16 +01:00
parent 0da9755ae6
commit d00448a422
40 changed files with 416 additions and 216 deletions

View File

@@ -38,7 +38,7 @@
#endif
#define FORCEINLINE __attribute__((always_inline))
#define FORCEINLINE inline
#elif defined(P_ARM_BUILD)

View File

@@ -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

View File

@@ -0,0 +1 @@
#include "Core/Logging/LoggingPCH.h"

View File

@@ -2,62 +2,9 @@
#pragma once
#include "Core/Math/MathPCH.h"
#ifdef P_BUILD_LIB
#include "PhanesEnginePCH.h"
#else
#include <type_traits>
#include <memory>
#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<typename T>
concept Arithmethic = std::is_arithmetic_v<T>;
// Alias for shared_ptr
template<typename T>
using Ref = std::shared_ptr<T>;
// Alias for make_shared
template<typename T, typename ...Args>
constexpr Ref<T> MakeRef(Args&& ...args)
{
return std::make_shared<T>(std::forward<Args>(args)...);
}
// Alias for unique ptr
template<typename T>
using Scope = std::unique_ptr<T>;
// Alias for make_unique
template<typename T, typename ...Args>
constexpr Scope<T> MakeScope(Args&& ...args)
{
return std::make_unique<T>(std::forward<Args>(args)...);
}
}

View File

@@ -46,6 +46,7 @@ namespace Phanes::Core::Math::Detail
{
static constexpr bool map(Phanes::Core::Math::TMatrix4<T, false>& r, const Phanes::Core::Math::TMatrix4<T, false>& m)
{
const TVector3<T, false>& a = reinterpret_cast<const TVector3<T, false>&>(m[0]);
const TVector3<T, false>& b = reinterpret_cast<const TVector3<T, false>&>(m[1]);
const TVector3<T, false>& c = reinterpret_cast<const TVector3<T, false>&>(m[2]);

View File

@@ -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<T, false>& 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);
}
};

View File

@@ -1,9 +1,5 @@
#pragma once
#ifndef P_DEBUG
#pragma warning(disable : 4244)
#endif
#include "Core/Math/MathFwd.h"

View File

@@ -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.

View File

@@ -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.

View File

@@ -9,11 +9,6 @@
#include "Core/Math/IntVector4.hpp"
#ifndef P_DEBUG
#pragma warning(disable : 4244)
#endif
#ifndef INTVECTOR3_H
#define INTVECTOR3_H

View File

@@ -9,10 +9,6 @@
#include "Core/Math/IntVector2.hpp"
#ifndef P_DEBUG
#pragma warning(disable : 4244)
#endif
#ifndef INTVECTOR4_H
#define INTVECTOR4_H

View File

@@ -47,8 +47,6 @@ namespace Phanes::Core::Math
template<RealType T>
TLine<T>& NormalizeV(TLine<T>& l1)
{
std::any
NormalizeV(l1.direction);
return l1;
}

View File

@@ -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<typename T>
inline T Sqrt(T s)
{
return sqrt(s);
}
} // phanes

View File

@@ -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"
#include <cmath>
#include <type_traits>
#include <memory>
#include <string>
#include <stdint.h>

View File

@@ -6,13 +6,9 @@
// @ref [FILE]MathUnitConversion //
// ============================================= //
#ifdef P_BUILD_LIB
#include "PhanesEnginePCH.h"
#else
#include <string>
#endif
#include "Core/Math/Boilerplate.h"
#include "Core/Math/MathPCH.h"
#include "Core/Math/MathAbstractTypes.h"
#include "Core/Math/Vector2.hpp"

View File

@@ -1,11 +1,6 @@
#pragma once
#ifdef P_BUILD_LIB
# include "PhanesEnginePCH.h"
#else
# define NOMINMAX
# include <stdint.h>
#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

View File

@@ -123,7 +123,7 @@ namespace Phanes::Core::Math {
}
FORCEINLINE TVector4<T, S>& operator[] (int m)
{
return (*reinterpret_cast<TVector4<T, S>*>(this->m[m]));
return (*reinterpret_cast<TVector4<T, S>*>(this->data[m]));
}
FORCEINLINE const T& operator() (int n, int m) const

View File

@@ -7,6 +7,8 @@
#include "Core/Math/SIMD/PhanesSIMDTypes.h"
#include <iostream>
namespace Phanes::Core::Math
{

View File

@@ -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"

View File

@@ -624,7 +624,7 @@ namespace Phanes::Core::Math {
TPlane<T, false> TranslateV(TPlane<T, false>& pl1, const TVector3<T, false>& v1)
{
pl1.d = DotP(this->normal, GetOrigin(pl1) + v1);
pl1.d = DotP(pl1.normal, GetOrigin(pl1) + v1);
return pl1;
}

View File

@@ -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<T, false>& 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<T, false>& 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<T, false>& v)
{
this->x = v.x;
this->y = v.y;
this->z = v.z;
this->w = v.w;
}
};
/**
* Calculates distance between two points.
*

View File

@@ -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

View File

@@ -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<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)
namespace Phanes::Core::Math {
@@ -466,6 +460,12 @@ namespace Phanes::Core::Math {
return v1;
}
template<RealType T, bool S>
T Distance(const TVector2<T, S>& v1, const TVector2<T, S>& v2)
{
return Magnitude(v2 - v1);
}
/**
* Binds a vector to a square with a radius
*

View File

@@ -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<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)
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<RealType T, bool S>
TVector3<T, S>& RefractV(TVector3<T, S>& v1, const TVector3<T, S>& 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<RealType T, bool S>
T Distance(const TVector3<T, S>& v1, const TVector3<T, S>& 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<RealType T, bool S>
TVector3<T, S> Refract(const TVector3<T, S>& v1, const TVector3<T, S>& 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.

View File

@@ -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<type, aligned>(0,0,0,0)
namespace Phanes::Core::Math
{
@@ -741,6 +743,12 @@ namespace Phanes::Core::Math
return v1;
}
template<RealType T, bool S>
T Distance(const TVector4<T, S>& v1, const TVector4<T, S>& v2)
{
return Magnitude(v1 - v2);
}
/// <summary>
/// Project vector v1 onto v2.
/// </summary>
@@ -863,5 +871,4 @@ namespace Phanes::Core::Math
}
}
#include "Core/Math/Vector4.inl"

View File

@@ -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

View File

@@ -0,0 +1 @@
#include "Core/Math/MathPCH.h"

View File

@@ -0,0 +1 @@
#include "Core/Math/PhanesMathPCH.h"

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1 @@
#include "Core/StartingPoint/StartingPointPCH.h"

View File

@@ -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()