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,153 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Input/Linux/KeyboardLinux.h>
#include <Window/ApplicationWindowLinux.h>
KeyboardLinux::~KeyboardLinux()
{
Shutdown();
}
bool KeyboardLinux::Initialize(ApplicationWindow *inWindow)
{
mWindow = static_cast<ApplicationWindowLinux *>(inWindow);
mWindow->SetEventListener([this](const XEvent &inEvent) { HandleEvent(inEvent); });
return true;
}
void KeyboardLinux::Shutdown()
{
if (mWindow != nullptr)
{
mWindow->SetEventListener({});
mWindow = nullptr;
}
}
void KeyboardLinux::Poll()
{
// Reset the keys pressed
memset(mKeysPressed, 0, sizeof(mKeysPressed));
Display *display = mWindow->GetDisplay();
// Get pressed keys
char keymap[32];
XQueryKeymap(display, keymap);
for (int i = 0; i < 32; ++i)
{
// Iterate 8 bits at a time
uint keycode = i << 3;
uint32 value = uint8(keymap[i]);
while (value != 0)
{
// Get the next bit
uint lz = CountTrailingZeros(value);
keycode += lz;
// Convert to key
KeySym keysym = XkbKeycodeToKeysym(display, keycode, 0, 0);
EKey key = ToKey(keysym);
if (key != EKey::Unknown)
mKeysPressed[(int)key] = true;
// Skip this bit
keycode++;
value >>= lz + 1;
}
}
// Make the pending buffer the active buffer
mKeyBuffer = mPendingKeyBuffer;
mPendingKeyBuffer.clear();
}
EKey KeyboardLinux::GetFirstKey()
{
mCurrentKey = 0;
return GetNextKey();
}
EKey KeyboardLinux::GetNextKey()
{
if (mCurrentKey < mKeyBuffer.size())
return mKeyBuffer[mCurrentKey++];
return EKey::Invalid;
}
void KeyboardLinux::HandleEvent(const XEvent &inEvent)
{
// If this is a key press event and the buffer is not yet full
if (inEvent.type == KeyPress && mPendingKeyBuffer.size() < mPendingKeyBuffer.capacity())
{
// Convert to key
KeySym keysym = XkbKeycodeToKeysym(mWindow->GetDisplay(), inEvent.xkey.keycode, 0, 0);
EKey key = ToKey(keysym);
if (key != EKey::Unknown)
mPendingKeyBuffer.push_back(key);
}
}
EKey KeyboardLinux::ToKey(int inValue) const
{
switch (inValue)
{
case XK_a: return EKey::A;
case XK_b: return EKey::B;
case XK_c: return EKey::C;
case XK_d: return EKey::D;
case XK_e: return EKey::E;
case XK_f: return EKey::F;
case XK_g: return EKey::G;
case XK_h: return EKey::H;
case XK_i: return EKey::I;
case XK_j: return EKey::J;
case XK_k: return EKey::K;
case XK_l: return EKey::L;
case XK_m: return EKey::M;
case XK_n: return EKey::N;
case XK_o: return EKey::O;
case XK_p: return EKey::P;
case XK_q: return EKey::Q;
case XK_r: return EKey::R;
case XK_s: return EKey::S;
case XK_t: return EKey::T;
case XK_u: return EKey::U;
case XK_v: return EKey::V;
case XK_w: return EKey::W;
case XK_x: return EKey::X;
case XK_y: return EKey::Y;
case XK_z: return EKey::Z;
case XK_0: return EKey::Num0;
case XK_1: return EKey::Num1;
case XK_2: return EKey::Num2;
case XK_3: return EKey::Num3;
case XK_4: return EKey::Num4;
case XK_5: return EKey::Num5;
case XK_6: return EKey::Num6;
case XK_7: return EKey::Num7;
case XK_8: return EKey::Num8;
case XK_9: return EKey::Num9;
case XK_space: return EKey::Space;
case XK_comma: return EKey::Comma;
case XK_period: return EKey::Period;
case XK_Escape: return EKey::Escape;
case XK_Shift_L: return EKey::LShift;
case XK_Shift_R: return EKey::RShift;
case XK_Control_L: return EKey::LControl;
case XK_Control_R: return EKey::RControl;
case XK_Alt_L: return EKey::LAlt;
case XK_Alt_R: return EKey::RAlt;
case XK_Left: return EKey::Left;
case XK_Right: return EKey::Right;
case XK_Up: return EKey::Up;
case XK_Down: return EKey::Down;
case XK_Return: return EKey::Return;
default: return EKey::Unknown;
}
}

View File

@@ -0,0 +1,42 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
#include <Input/Keyboard.h>
#include <Jolt/Core/StaticArray.h>
class ApplicationWindowLinux;
/// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
class KeyboardLinux : public Keyboard
{
public:
/// Destructor
virtual ~KeyboardLinux() override;
/// Initialization / shutdown
virtual bool Initialize(ApplicationWindow *inWindow) override;
virtual void Shutdown() override;
/// Update the keyboard state
virtual void Poll() override;
/// Checks if a key is pressed or not
virtual bool IsKeyPressed(EKey inKey) const override { return mKeysPressed[(int)inKey]; }
/// Buffered keyboard input, returns EKey::Invalid for none
virtual EKey GetFirstKey() override;
virtual EKey GetNextKey() override;
private:
void HandleEvent(const XEvent &inEvent);
EKey ToKey(int inKey) const;
ApplicationWindowLinux * mWindow = nullptr;
bool mKeysPressed[(int)EKey::NumKeys] = { };
StaticArray<EKey, 128> mPendingKeyBuffer;
StaticArray<EKey, 128> mKeyBuffer;
uint mCurrentKey = 0;
};

View File

@@ -0,0 +1,76 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#include <TestFramework.h>
#include <Input/Linux/MouseLinux.h>
#include <Window/ApplicationWindowLinux.h>
MouseLinux::MouseLinux()
{
Reset();
}
MouseLinux::~MouseLinux()
{
Shutdown();
}
bool MouseLinux::Initialize(ApplicationWindow *inWindow)
{
ApplicationWindowLinux *window = static_cast<ApplicationWindowLinux *>(inWindow);
mDisplay = window->GetDisplay();
mWindow = window->GetWindow();
// Poll once and reset the deltas
Poll();
mDX = 0;
mDY = 0;
return true;
}
void MouseLinux::Shutdown()
{
mWindow = 0;
mDisplay = nullptr;
}
void MouseLinux::Reset()
{
mX = 0;
mY = 0;
mDX = 0;
mDY = 0;
mLeftPressed = false;
mRightPressed = false;
mMiddlePressed = false;
}
void MouseLinux::Poll()
{
Window root_return, child_return;
int root_x, root_y, win_x, win_y;
unsigned int mask;
if (XQueryPointer(mDisplay, mWindow, &root_return, &child_return, &root_x, &root_y, &win_x, &win_y, &mask))
{
mDX = win_x - mX;
mDY = win_y - mY;
mX = win_x;
mY = win_y;
mLeftPressed = mask & Button1Mask;
mRightPressed = mask & Button3Mask;
mMiddlePressed = mask & Button2Mask;
}
else
Reset();
}
void MouseLinux::HideCursor()
{
}
void MouseLinux::ShowCursor()
{
}

View File

@@ -0,0 +1,49 @@
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
// SPDX-License-Identifier: MIT
#pragma once
#include <Input/Mouse.h>
/// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse.
class MouseLinux : public Mouse
{
public:
/// Constructor
MouseLinux();
virtual ~MouseLinux() override;
/// Initialization / shutdown
virtual bool Initialize(ApplicationWindow *inWindow) override;
virtual void Shutdown() override;
/// Update the mouse state
virtual void Poll() override;
virtual int GetX() const override { return mX; }
virtual int GetY() const override { return mY; }
virtual int GetDX() const override { return mDX; }
virtual int GetDY() const override { return mDY; }
virtual bool IsLeftPressed() const override { return mLeftPressed; }
virtual bool IsRightPressed() const override { return mRightPressed; }
virtual bool IsMiddlePressed() const override { return mMiddlePressed; }
virtual void HideCursor() override;
virtual void ShowCursor() override;
private:
void Reset();
Display * mDisplay;
Window mWindow;
int mX;
int mY;
int mDX;
int mDY;
bool mLeftPressed;
bool mRightPressed;
bool mMiddlePressed;
};