Ajout de Jolt Physics + 1ere version des factory entitecomposants - camera, transform, rigidbody, collider, renderer
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Input/Keyboard.h>
|
||||
|
||||
/// Keyboard interface class which keeps track on the status of all keys and keeps track of the list of keys pressed.
|
||||
class KeyboardMacOS : public Keyboard
|
||||
{
|
||||
public:
|
||||
/// 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 mKeyPressed[(int)inKey]; }
|
||||
|
||||
/// Buffered keyboard input, returns EKey::Invalid for none
|
||||
virtual EKey GetFirstKey() override;
|
||||
virtual EKey GetNextKey() override;
|
||||
|
||||
/// Handle a key press event
|
||||
void OnKeyPressed(EKey inKey, bool inPressed);
|
||||
|
||||
private:
|
||||
bool mKeyPressed[(int)EKey::NumKeys] = { };
|
||||
StaticArray<EKey, 128> mPendingKeyBuffer;
|
||||
StaticArray<EKey, 128> mKeyBuffer;
|
||||
uint mCurrentKey = 0;
|
||||
};
|
||||
143
lib/All/JoltPhysics/TestFramework/Input/MacOS/KeyboardMacOS.mm
Normal file
143
lib/All/JoltPhysics/TestFramework/Input/MacOS/KeyboardMacOS.mm
Normal file
@@ -0,0 +1,143 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <TestFramework.h>
|
||||
|
||||
#include <Input/MacOS/KeyboardMacOS.h>
|
||||
#import <GameController/GameController.h>
|
||||
|
||||
static EKey sToKey(GCKeyCode inValue)
|
||||
{
|
||||
if (inValue == GCKeyCodeKeyA) return EKey::A;
|
||||
if (inValue == GCKeyCodeKeyB) return EKey::B;
|
||||
if (inValue == GCKeyCodeKeyC) return EKey::C;
|
||||
if (inValue == GCKeyCodeKeyD) return EKey::D;
|
||||
if (inValue == GCKeyCodeKeyE) return EKey::E;
|
||||
if (inValue == GCKeyCodeKeyF) return EKey::F;
|
||||
if (inValue == GCKeyCodeKeyG) return EKey::G;
|
||||
if (inValue == GCKeyCodeKeyH) return EKey::H;
|
||||
if (inValue == GCKeyCodeKeyI) return EKey::I;
|
||||
if (inValue == GCKeyCodeKeyJ) return EKey::J;
|
||||
if (inValue == GCKeyCodeKeyK) return EKey::K;
|
||||
if (inValue == GCKeyCodeKeyL) return EKey::L;
|
||||
if (inValue == GCKeyCodeKeyM) return EKey::M;
|
||||
if (inValue == GCKeyCodeKeyN) return EKey::N;
|
||||
if (inValue == GCKeyCodeKeyO) return EKey::O;
|
||||
if (inValue == GCKeyCodeKeyP) return EKey::P;
|
||||
if (inValue == GCKeyCodeKeyQ) return EKey::Q;
|
||||
if (inValue == GCKeyCodeKeyR) return EKey::R;
|
||||
if (inValue == GCKeyCodeKeyS) return EKey::S;
|
||||
if (inValue == GCKeyCodeKeyT) return EKey::T;
|
||||
if (inValue == GCKeyCodeKeyU) return EKey::U;
|
||||
if (inValue == GCKeyCodeKeyV) return EKey::V;
|
||||
if (inValue == GCKeyCodeKeyW) return EKey::W;
|
||||
if (inValue == GCKeyCodeKeyX) return EKey::X;
|
||||
if (inValue == GCKeyCodeKeyY) return EKey::Y;
|
||||
if (inValue == GCKeyCodeKeyZ) return EKey::Z;
|
||||
if (inValue == GCKeyCodeZero) return EKey::Num0;
|
||||
if (inValue == GCKeyCodeOne) return EKey::Num1;
|
||||
if (inValue == GCKeyCodeTwo) return EKey::Num2;
|
||||
if (inValue == GCKeyCodeThree) return EKey::Num3;
|
||||
if (inValue == GCKeyCodeFour) return EKey::Num4;
|
||||
if (inValue == GCKeyCodeFive) return EKey::Num5;
|
||||
if (inValue == GCKeyCodeSix) return EKey::Num6;
|
||||
if (inValue == GCKeyCodeSeven) return EKey::Num7;
|
||||
if (inValue == GCKeyCodeEight) return EKey::Num8;
|
||||
if (inValue == GCKeyCodeNine) return EKey::Num9;
|
||||
if (inValue == GCKeyCodeSpacebar) return EKey::Space;
|
||||
if (inValue == GCKeyCodeComma) return EKey::Comma;
|
||||
if (inValue == GCKeyCodePeriod) return EKey::Period;
|
||||
if (inValue == GCKeyCodeEscape) return EKey::Escape;
|
||||
if (inValue == GCKeyCodeLeftShift) return EKey::LShift;
|
||||
if (inValue == GCKeyCodeRightShift) return EKey::RShift;
|
||||
if (inValue == GCKeyCodeLeftControl) return EKey::LControl;
|
||||
if (inValue == GCKeyCodeRightControl) return EKey::RControl;
|
||||
if (inValue == GCKeyCodeLeftAlt) return EKey::LAlt;
|
||||
if (inValue == GCKeyCodeRightAlt) return EKey::RAlt;
|
||||
if (inValue == GCKeyCodeLeftArrow) return EKey::Left;
|
||||
if (inValue == GCKeyCodeRightArrow) return EKey::Right;
|
||||
if (inValue == GCKeyCodeUpArrow) return EKey::Up;
|
||||
if (inValue == GCKeyCodeDownArrow) return EKey::Down;
|
||||
if (inValue == GCKeyCodeReturnOrEnter) return EKey::Return;
|
||||
return EKey::Unknown;
|
||||
}
|
||||
|
||||
// This class receives keyboard connect callbacks
|
||||
@interface KeyboardDelegate : NSObject
|
||||
@end
|
||||
|
||||
@implementation KeyboardDelegate
|
||||
{
|
||||
KeyboardMacOS *mKeyboard;
|
||||
}
|
||||
|
||||
- (KeyboardDelegate *)init:(KeyboardMacOS *)Keyboard
|
||||
{
|
||||
mKeyboard = Keyboard;
|
||||
|
||||
[NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown handler:^NSEvent *(NSEvent *event) {
|
||||
// Ignore all keystrokes except Command-Q (Quit).
|
||||
if ((event.modifierFlags & NSEventModifierFlagCommand) && [event.charactersIgnoringModifiers isEqual:@"q"])
|
||||
return event;
|
||||
else
|
||||
return nil;
|
||||
}];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)keyboardDidConnect:(NSNotification *)notification
|
||||
{
|
||||
GCKeyboard *keyboard = (GCKeyboard *)notification.object;
|
||||
if (!keyboard)
|
||||
return;
|
||||
|
||||
__block KeyboardDelegate *weakSelf = self;
|
||||
keyboard.keyboardInput.keyChangedHandler = ^(GCKeyboardInput *keyboard, GCControllerButtonInput *key, GCKeyCode keyCode, BOOL pressed) {
|
||||
KeyboardDelegate *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
EKey ekey = sToKey(keyCode);
|
||||
if (ekey != EKey::Invalid)
|
||||
strongSelf->mKeyboard->OnKeyPressed(ekey, pressed);
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
bool KeyboardMacOS::Initialize(ApplicationWindow *inWindow)
|
||||
{
|
||||
KeyboardDelegate *delegate = [[KeyboardDelegate alloc] init: this];
|
||||
[NSNotificationCenter.defaultCenter addObserver: delegate selector: @selector(keyboardDidConnect:) name: GCKeyboardDidConnectNotification object: nil];
|
||||
return true;
|
||||
}
|
||||
|
||||
void KeyboardMacOS::Poll()
|
||||
{
|
||||
// Make the pending buffer the active buffer
|
||||
mKeyBuffer = mPendingKeyBuffer;
|
||||
mPendingKeyBuffer.clear();
|
||||
}
|
||||
|
||||
EKey KeyboardMacOS::GetFirstKey()
|
||||
{
|
||||
mCurrentKey = 0;
|
||||
return GetNextKey();
|
||||
}
|
||||
|
||||
EKey KeyboardMacOS::GetNextKey()
|
||||
{
|
||||
if (mCurrentKey < mKeyBuffer.size())
|
||||
return mKeyBuffer[mCurrentKey++];
|
||||
return EKey::Invalid;
|
||||
}
|
||||
|
||||
void KeyboardMacOS::OnKeyPressed(EKey inKey, bool inPressed)
|
||||
{
|
||||
if (inPressed && mPendingKeyBuffer.size() < mPendingKeyBuffer.capacity())
|
||||
mPendingKeyBuffer.push_back(inKey);
|
||||
|
||||
mKeyPressed[(int)inKey] = inPressed;
|
||||
}
|
||||
54
lib/All/JoltPhysics/TestFramework/Input/MacOS/MouseMacOS.h
Normal file
54
lib/All/JoltPhysics/TestFramework/Input/MacOS/MouseMacOS.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Input/Mouse.h>
|
||||
|
||||
class ApplicationWindowMacOS;
|
||||
|
||||
/// Mouse interface class, keeps track of the mouse button state and of the absolute and relative movements of the mouse.
|
||||
class MouseMacOS : public Mouse
|
||||
{
|
||||
public:
|
||||
/// 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 mDeltaX; }
|
||||
virtual int GetDY() const override { return mDeltaY; }
|
||||
|
||||
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 { }
|
||||
|
||||
/// Internal callbacks
|
||||
void OnMouseMoved(int inX, int inY) { mX = inX; mY = inY; }
|
||||
void OnMouseDelta(int inDX, int inDY) { mDeltaXAcc += inDX; mDeltaYAcc += inDY; }
|
||||
void SetLeftPressed(bool inPressed) { mLeftPressed = inPressed; }
|
||||
void SetRightPressed(bool inPressed) { mRightPressed = inPressed; }
|
||||
void SetMiddlePressed(bool inPressed) { mMiddlePressed = inPressed; }
|
||||
|
||||
private:
|
||||
ApplicationWindowMacOS * mWindow = nullptr;
|
||||
|
||||
int mX = 0;
|
||||
int mY = 0;
|
||||
int mDeltaX = 0;
|
||||
int mDeltaY = 0;
|
||||
int mDeltaXAcc = 0;
|
||||
int mDeltaYAcc = 0;
|
||||
|
||||
bool mLeftPressed = false;
|
||||
bool mRightPressed = false;
|
||||
bool mMiddlePressed = false;
|
||||
};
|
||||
103
lib/All/JoltPhysics/TestFramework/Input/MacOS/MouseMacOS.mm
Normal file
103
lib/All/JoltPhysics/TestFramework/Input/MacOS/MouseMacOS.mm
Normal file
@@ -0,0 +1,103 @@
|
||||
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
|
||||
// SPDX-FileCopyrightText: 2024 Jorrit Rouwe
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <TestFramework.h>
|
||||
|
||||
#include <Input/MacOS/MouseMacOS.h>
|
||||
#include <Window/ApplicationWindowMacOS.h>
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <GameController/GameController.h>
|
||||
|
||||
// This class receives mouse connect callbacks
|
||||
@interface MouseDelegate : NSObject
|
||||
@end
|
||||
|
||||
@implementation MouseDelegate
|
||||
{
|
||||
MouseMacOS *mMouse;
|
||||
}
|
||||
|
||||
- (MouseDelegate *)init:(MouseMacOS *)mouse
|
||||
{
|
||||
mMouse = mouse;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)mouseDidConnect:(NSNotification *)notification
|
||||
{
|
||||
GCMouse *mouse = (GCMouse *)notification.object;
|
||||
if (mouse == nil)
|
||||
return;
|
||||
|
||||
GCMouseInput *mouseInput = mouse.mouseInput;
|
||||
if (mouseInput == nil)
|
||||
return;
|
||||
|
||||
__block MouseDelegate *weakSelf = self;
|
||||
mouseInput.mouseMovedHandler = ^(GCMouseInput *mouse, float deltaX, float deltaY) {
|
||||
MouseDelegate *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
strongSelf->mMouse->OnMouseDelta(deltaX, -deltaY);
|
||||
};
|
||||
|
||||
mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
MouseDelegate *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
strongSelf->mMouse->SetLeftPressed(pressed);
|
||||
};
|
||||
|
||||
mouseInput.rightButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
MouseDelegate *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
strongSelf->mMouse->SetRightPressed(pressed);
|
||||
};
|
||||
|
||||
mouseInput.middleButton.pressedChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
MouseDelegate *strongSelf = weakSelf;
|
||||
if (strongSelf == nil)
|
||||
return;
|
||||
|
||||
strongSelf->mMouse->SetMiddlePressed(pressed);
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
bool MouseMacOS::Initialize(ApplicationWindow *inWindow)
|
||||
{
|
||||
mWindow = static_cast<ApplicationWindowMacOS *>(inWindow);
|
||||
|
||||
// Install listener for mouse move callbacks
|
||||
mWindow->SetMouseMovedCallback([this](int inX, int inY) { OnMouseMoved(inX, inY); });
|
||||
|
||||
// Install listener for mouse delta callbacks (will work also when mouse is outside the window or at the edge of the screen)
|
||||
MouseDelegate *delegate = [[MouseDelegate alloc] init: this];
|
||||
[NSNotificationCenter.defaultCenter addObserver: delegate selector: @selector(mouseDidConnect:) name: GCMouseDidConnectNotification object:nil];
|
||||
return true;
|
||||
}
|
||||
|
||||
void MouseMacOS::Shutdown()
|
||||
{
|
||||
if (mWindow != nullptr)
|
||||
{
|
||||
mWindow->SetMouseMovedCallback({});
|
||||
mWindow = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MouseMacOS::Poll()
|
||||
{
|
||||
mDeltaX = mDeltaXAcc;
|
||||
mDeltaY = mDeltaYAcc;
|
||||
|
||||
mDeltaXAcc = 0;
|
||||
mDeltaYAcc = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user