Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FRAMEWORK_PIN
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Framework source required by the unified IInput adapter migration.
# Framework PR #292; replace with its merged commit before release.
689c27139ba8e0123e33cfb54f869d27f15c7001
4 changes: 4 additions & 0 deletions code/client/src/core/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ namespace MafiaMP::Core {
return _input.get();
}

bool IsLocalInputAvailable() const override {
return !AreControlsLocked() && Framework::Integrations::Client::Instance::IsLocalInputAvailable();
}

std::shared_ptr<MafiaMP::Game::GameInput> GetInput() const {
return _input;
}
Expand Down
24 changes: 14 additions & 10 deletions code/client/src/core/ui/devs/camera_studio.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <core_modules.h>
#include <input/input.h>

#include "camera_studio.h"

#include <algorithm>
Expand Down Expand Up @@ -187,8 +190,9 @@ namespace MafiaMP::Core::UI::Devs {
POINT mouse = {};
GetCursorPos(&mouse);

if (!_frozen) {
if ((GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0) {
const auto *input = Framework::CoreModules::GetInput();
if (!_frozen && input) {
if (input->IsKeyDown(FW_KEY_RBUTTON)) {
_yaw += static_cast<float>(mouse.x - _lastMousePos.x) * _sensitivity;
_pitch -= static_cast<float>(mouse.y - _lastMousePos.y) * _sensitivity;
_pitch = std::clamp(_pitch, -kMaxPitch, kMaxPitch);
Expand All @@ -198,10 +202,10 @@ namespace MafiaMP::Core::UI::Devs {
const SDK::ue::sys::math::C_Vector right = {std::cos(_yaw), -std::sin(_yaw), 0.0f};

float speed = _moveSpeed;
if (GetAsyncKeyState(VK_SHIFT) & 0x8000) {
if (input->IsKeyDown(FW_KEY_SHIFT)) {
speed *= 3.0f;
}
if (GetAsyncKeyState(VK_CONTROL) & 0x8000) {
if (input->IsKeyDown(FW_KEY_CONTROL)) {
speed *= 0.25f;
}
const float step = speed * deltaTime;
Expand All @@ -212,22 +216,22 @@ namespace MafiaMP::Core::UI::Devs {
_position.z += v.z * s;
};

if (GetAsyncKeyState('W') & 0x8000) {
if (input->IsKeyDown('W')) {
move(forward, step);
}
if (GetAsyncKeyState('S') & 0x8000) {
if (input->IsKeyDown('S')) {
move(forward, -step);
}
if (GetAsyncKeyState('D') & 0x8000) {
if (input->IsKeyDown('D')) {
move(right, step);
}
if (GetAsyncKeyState('A') & 0x8000) {
if (input->IsKeyDown('A')) {
move(right, -step);
}
if (GetAsyncKeyState(VK_SPACE) & 0x8000) {
if (input->IsKeyDown(FW_KEY_SPACE)) {
_position.z += step;
}
if (GetAsyncKeyState('C') & 0x8000) {
if (input->IsKeyDown('C')) {
_position.z -= step;
}
}
Expand Down
48 changes: 0 additions & 48 deletions code/client/src/game/helpers/game_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,6 @@
#include "core/application.h"

namespace MafiaMP::Game {
void GameInput::Update() {
for (int i = 0; i < 256; i++) {
_keysPressed[i] = false;
_keysReleased[i] = false;
}

for (int i = 0; i < 5; i++) {
_buttonsPressed[i] = false;
_buttonsReleased[i] = false;
}
}

uint32_t GameInput::MapKey(uint32_t key) const {
return key; // we map WndProc VK keys 1:1 to our input keys
}

void GameInput::ProcessEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
_keysDown[wParam] = true;
_keysPressed[wParam] = true;
break;
case WM_KEYUP:
case WM_SYSKEYUP:
_keysDown[wParam] = false;
_keysReleased[wParam] = true;
break;
case WM_LBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_MBUTTONDOWN:
_buttonsDown[wParam] = true;
_buttonsPressed[wParam] = true;
break;
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MBUTTONUP:
_buttonsDown[wParam] = false;
_buttonsReleased[wParam] = true;
break;
case WM_MOUSEMOVE:
_mousePosition[0] = LOWORD(lParam);
_mousePosition[1] = HIWORD(lParam);
break;
default: break;
}
}

bool GameInput::IsInputLocked() const {
return Core::gApplication->AreControlsLocked();
}
Expand Down
73 changes: 2 additions & 71 deletions code/client/src/game/helpers/game_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@

#include <utils/safe_win32.h>

#include <input/input.h>
#include <input/window_input.h>

namespace MafiaMP::Game {
class GameInput: public Framework::Input::IInput {
class GameInput final: public Framework::Input::WindowInput {
public:
GameInput() {}
~GameInput() = default;

void Update() override;

void GetMousePosition(int &x, int &y) const override {
x = _mousePosition[0];
y = _mousePosition[1];
};
void SetMousePosition(int x, int y) override {};
void SetMouseVisible(bool visible) override {
SetInputLocked(visible);
Expand All @@ -29,68 +23,5 @@ namespace MafiaMP::Game {
};
void SetInputLocked(bool locked) override;
bool IsInputLocked() const override;

bool IsKeyDown(int key) const override {
if (key < 0 || key > 255) {
return false;
}
return _keysDown[MapKey(key)];
};
bool IsKeyUp(int key) const override {
if (key < 0 || key > 255) {
return false;
}
return !_keysDown[MapKey(key)];
};
bool IsKeyPressed(int key) const override {
if (key < 0 || key > 255) {
return false;
}
return _keysPressed[MapKey(key)];
};
bool IsKeyReleased(int key) const override {
if (key < 0 || key > 255) {
return false;
}
return _keysReleased[MapKey(key)];
};

bool IsMouseButtonDown(int button) const override {
if (button < 0 || button > 4) {
return false;
}
return _buttonsDown[button];
};
bool IsMouseButtonUp(int button) const override {
if (button < 0 || button > 4) {
return false;
}
return !_buttonsDown[button];
};
bool IsMouseButtonPressed(int button) const override {
if (button < 0 || button > 4) {
return false;
}
return _buttonsPressed[button];
};
bool IsMouseButtonReleased(int button) const override {
if (button < 0 || button > 4) {
return false;
}
return _buttonsReleased[button];
};

uint32_t MapKey(uint32_t key) const override;

void ProcessEvent(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

private:
bool _keysDown[256] = {false};
bool _keysPressed[256] = {false};
bool _keysReleased[256] = {false};
bool _buttonsDown[5] = {false};
bool _buttonsPressed[5] = {false};
bool _buttonsReleased[5] = {false};
int _mousePosition[2] = {};
};
} // namespace MafiaMP::Game