Ajout de Jolt Physics + 1ere version des factory entitecomposants - camera, transform, rigidbody, collider, renderer

This commit is contained in:
Tom Ray
2026-03-22 00:28:03 +01:00
parent 6695d46bcd
commit 48348936a8
1147 changed files with 214331 additions and 353 deletions

View File

@@ -0,0 +1,56 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/AssetStream.h>
#include <Utils/Log.h>
JPH_SUPPRESS_WARNINGS_STD_BEGIN
#include <filesystem>
#ifdef JPH_PLATFORM_LINUX
#include <unistd.h>
#endif
JPH_SUPPRESS_WARNINGS_STD_END
String AssetStream::sGetAssetsBasePath()
{
static String result = []() {
// Start with the application path
#ifdef JPH_PLATFORM_WINDOWS
char application_path[MAX_PATH] = { 0 };
GetModuleFileName(nullptr, application_path, MAX_PATH);
#elif defined(JPH_PLATFORM_LINUX)
char application_path[PATH_MAX] = { 0 };
int count = readlink("/proc/self/exe", application_path, PATH_MAX);
if (count > 0)
application_path[count] = 0;
#else
#error Unsupported platform
#endif
// Find the asset path
filesystem::path asset_path(application_path);
while (!asset_path.empty())
{
filesystem::path parent_path = asset_path.parent_path();
if (parent_path == asset_path)
break;
asset_path = parent_path;
if (filesystem::exists(asset_path / "Assets"))
break;
}
asset_path /= "Assets";
asset_path /= "";
return String(asset_path.string());
}();
return result;
}
AssetStream::AssetStream(const char *inFileName, std::ios_base::openmode inOpenMode) :
mStream((sGetAssetsBasePath() + inFileName).c_str(), inOpenMode)
{
if (!mStream.is_open())
FatalError("Failed to open file %s", inFileName);
}

View File

@@ -0,0 +1,27 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
JPH_SUPPRESS_WARNINGS_STD_BEGIN
#include <fstream>
JPH_SUPPRESS_WARNINGS_STD_END
/// An istream interface that reads data from a file in the Assets folder
class AssetStream
{
public:
/// Constructor
AssetStream(const char *inFileName, std::ios_base::openmode inOpenMode);
AssetStream(const String &inFileName, std::ios_base::openmode inOpenMode) : AssetStream(inFileName.c_str(), inOpenMode) { }
/// Get the path to the assets folder
static String sGetAssetsBasePath();
/// Get the stream
std::istream & Get() { return mStream; }
private:
std::ifstream mStream;
};

View File

@@ -0,0 +1,24 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/AssetStream.h>
#include <Utils/Log.h>
#include <Cocoa/Cocoa.h>
String AssetStream::sGetAssetsBasePath()
{
NSBundle *bundle = [NSBundle mainBundle];
String path = [[[bundle resourceURL] path] cStringUsingEncoding: NSUTF8StringEncoding];
path += "/";
return path;
}
AssetStream::AssetStream(const char *inFileName, std::ios_base::openmode inOpenMode) :
mStream((sGetAssetsBasePath() + inFileName).c_str(), inOpenMode)
{
if (!mStream.is_open())
FatalError("Failed to open file %s", inFileName);
}

View File

@@ -0,0 +1,139 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/CustomMemoryHook.h>
#ifdef JPH_CUSTOM_MEMORY_HOOK_ENABLED
// Global to turn checking on/off
static bool sEnableCustomMemoryHook = false;
// Local to temporarily disable checking
static thread_local int sDisableCustomMemoryHook = 1;
// Local to keep track if we're coming through the custom allocator
static thread_local bool sInCustomAllocator = false;
// Struct to put on the stack to flag that we're in the custom memory allocator
struct InCustomAllocator
{
InCustomAllocator()
{
JPH_ASSERT(!sInCustomAllocator);
sInCustomAllocator = true;
}
~InCustomAllocator()
{
JPH_ASSERT(sInCustomAllocator);
sInCustomAllocator = false;
}
};
// Add a tag to an allocation to track if it is aligned / unaligned
static void *TagAllocation(void *inPointer, size_t inAlignment, char inMode)
{
if (inPointer == nullptr)
return nullptr;
uint8 *p = reinterpret_cast<uint8 *>(inPointer);
*p = inMode;
return p + inAlignment;
}
// Remove tag from allocation
static void *UntagAllocation(void *inPointer, size_t inAlignment, char inMode)
{
if (inPointer == nullptr)
return nullptr;
uint8 *p = reinterpret_cast<uint8 *>(inPointer) - inAlignment;
JPH_ASSERT(*p == inMode);
*p = 0;
return p;
}
static void *AllocateHook(size_t inSize)
{
JPH_ASSERT(inSize > 0);
InCustomAllocator ica;
return TagAllocation(malloc(inSize + 16), 16, 'U');
}
static void *ReallocateHook(void *inBlock, size_t inOldSize, size_t inNewSize)
{
JPH_ASSERT(inNewSize > 0);
InCustomAllocator ica;
return TagAllocation(realloc(UntagAllocation(inBlock, 16, 'U'), inNewSize + 16), 16, 'U');
}
static void FreeHook(void *inBlock)
{
InCustomAllocator ica;
free(UntagAllocation(inBlock, 16, 'U'));
}
static void *AlignedAllocateHook(size_t inSize, size_t inAlignment)
{
JPH_ASSERT(inSize > 0 && inAlignment > 0 && inAlignment <= 64);
InCustomAllocator ica;
return TagAllocation(_aligned_malloc(inSize + 64, inAlignment), 64, 'A');
}
static void AlignedFreeHook(void *inBlock)
{
InCustomAllocator ica;
_aligned_free(UntagAllocation(inBlock, 64, 'A'));
}
static int MyAllocHook(int nAllocType, void *pvData, size_t nSize, int nBlockUse, long lRequest, const unsigned char * szFileName, int nLine) noexcept
{
JPH_ASSERT(!sEnableCustomMemoryHook || sDisableCustomMemoryHook <= 0 || sInCustomAllocator);
return true;
}
void RegisterCustomMemoryHook()
{
Allocate = AllocateHook;
Reallocate = ReallocateHook;
Free = FreeHook;
AlignedAllocate = AlignedAllocateHook;
AlignedFree = AlignedFreeHook;
_CrtSetAllocHook(MyAllocHook);
}
void EnableCustomMemoryHook(bool inEnable)
{
sEnableCustomMemoryHook = inEnable;
}
bool IsCustomMemoryHookEnabled()
{
return sEnableCustomMemoryHook;
}
DisableCustomMemoryHook::DisableCustomMemoryHook()
{
sDisableCustomMemoryHook--;
}
DisableCustomMemoryHook::~DisableCustomMemoryHook()
{
sDisableCustomMemoryHook++;
}
#else
DisableCustomMemoryHook::DisableCustomMemoryHook()
{
}
DisableCustomMemoryHook::~DisableCustomMemoryHook()
{
}
#endif // JPH_CUSTOM_MEMORY_HOOK_ENABLED

View File

@@ -0,0 +1,32 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
#if defined(JPH_PLATFORM_WINDOWS) && defined(_DEBUG) && !defined(JPH_DISABLE_CUSTOM_ALLOCATOR) && !defined(JPH_COMPILER_MINGW)
/// Enable this define to signal that the custom memory hook is enabled
#define JPH_CUSTOM_MEMORY_HOOK_ENABLED
/// Register hook that detects allocations that aren't made through the custom allocator
void RegisterCustomMemoryHook();
/// Enable the custom memory hook to detect allocations not made through the custom allocator
void EnableCustomMemoryHook(bool inEnable);
/// Check if the hook is currently checking allocations
bool IsCustomMemoryHookEnabled();
#else
inline void RegisterCustomMemoryHook() { RegisterDefaultAllocator(); }
#endif // _DEBUG && !JPH_DISABLE_CUSTOM_ALLOCATOR && !JPH_COMPILER_MINGW
/// Struct that, when put on the stack, temporarily disables checking that all allocations go through the custom memory allocator
struct DisableCustomMemoryHook
{
DisableCustomMemoryHook();
~DisableCustomMemoryHook();
};

View File

@@ -0,0 +1,61 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/Log.h>
#include <cstdarg>
// Trace to TTY
void TraceImpl(const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[2048];
vsnprintf(buffer, sizeof(buffer) - 1 /* leave space for newline char */, inFMT, list);
va_end(list);
#ifdef JPH_PLATFORM_WINDOWS
// Log to the output window
strcat_s(buffer, "\n");
OutputDebugStringA(buffer);
#else
// Log to the console
printf("%s\n", buffer);
#endif
}
void Alert(const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), inFMT, list);
va_end(list);
Trace("Alert: %s", buffer);
#ifdef JPH_PLATFORM_WINDOWS
MessageBoxA(nullptr, buffer, "Alert", MB_OK);
#endif // JPH_PLATFORM_WINDOWS
}
void FatalError [[noreturn]] (const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), inFMT, list);
va_end(list);
Trace("Fatal Error: %s", buffer);
#ifdef JPH_PLATFORM_WINDOWS
MessageBoxA(nullptr, buffer, "Fatal Error", MB_OK);
#endif // JPH_PLATFORM_WINDOWS
exit(1);
}

View File

@@ -0,0 +1,14 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
/// Pop up an alert
extern void Alert(const char *inFMT, ...);
/// Print an error message and terminate the application
extern void FatalError [[noreturn]] (const char *inFMT, ...);
/// Implementation of trace that traces to the TTY
extern void TraceImpl(const char *inFMT, ...);

View File

@@ -0,0 +1,57 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2025 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/Log.h>
#include <cstdarg>
#include <Cocoa/Cocoa.h>
// Trace to TTY
void TraceImpl(const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), inFMT, list);
va_end(list);
// Log to the console
printf("%s\n", buffer);
}
void Alert(const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), inFMT, list);
va_end(list);
Trace("Alert: %s", buffer);
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
alert.messageText = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
[alert runModal];
}
void FatalError [[noreturn]] (const char *inFMT, ...)
{
// Format the message
va_list list;
va_start(list, inFMT);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer), inFMT, list);
va_end(list);
Trace("Fatal Error: %s", buffer);
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
alert.messageText = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
[alert runModal];
exit(1);
}

View File

@@ -0,0 +1,28 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Utils/ReadData.h>
#include <Utils/Log.h>
#include <Utils/AssetStream.h>
JPH_SUPPRESS_WARNINGS_STD_BEGIN
#include <fstream>
JPH_SUPPRESS_WARNINGS_STD_END
// Read file contents
Array<uint8> ReadData(const char *inFileName)
{
Array<uint8> data;
AssetStream asset_stream(inFileName, std::ios::in | std::ios::binary);
std::istream &input = asset_stream.Get();
input.seekg(0, ios_base::end);
ifstream::pos_type length = input.tellg();
input.seekg(0, ios_base::beg);
data.resize(size_t(length));
input.read((char *)&data[0], length);
if (!input)
FatalError("Unable to read file: %s", inFileName);
return data;
}

View File

@@ -0,0 +1,8 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
/// Read file contents into byte vector
Array<uint8> ReadData(const char *inFileName);