1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Use BitField<> in core type masks

* All core types masks are now correctly marked as bitfields.
* The enum hacks in MouseButtonMask and many other types are gone. This ensures that binders to other languages non C++ can actually implement type safe bitmasks.
* Most bitmask operations replaced by functions in BitField<>
* Key is still a problem because its enum and mask at the same time. While it kind of works in C++, this most likely can't be implemented safely in other languages and will have to be changed at some point. Mostly left as-is.
* Documentation and API dump updated to reflect bitfields in core types.
This commit is contained in:
Juan Linietsky
2023-01-08 00:55:54 +01:00
parent fcba87e696
commit 2b815df3c1
69 changed files with 490 additions and 442 deletions

View File

@@ -59,7 +59,7 @@ JoypadLinux::Joypad::~Joypad() {
}
void JoypadLinux::Joypad::reset() {
dpad = HatMask::CENTER;
dpad = 0;
fd = -1;
for (int i = 0; i < MAX_ABS; i++) {
abs_map[i] = -1;
@@ -485,27 +485,33 @@ void JoypadLinux::process_joypads() {
case ABS_HAT0X:
if (joypad_event.value != 0) {
if (joypad_event.value < 0) {
joypad.dpad = (HatMask)((joypad.dpad | HatMask::LEFT) & ~HatMask::RIGHT);
joypad.dpad.set_flag(HatMask::LEFT);
joypad.dpad.clear_flag(HatMask::RIGHT);
} else {
joypad.dpad = (HatMask)((joypad.dpad | HatMask::RIGHT) & ~HatMask::LEFT);
joypad.dpad.set_flag(HatMask::RIGHT);
joypad.dpad.clear_flag(HatMask::LEFT);
}
} else {
joypad.dpad &= ~(HatMask::LEFT | HatMask::RIGHT);
joypad.dpad.clear_flag(HatMask::LEFT);
joypad.dpad.clear_flag(HatMask::RIGHT);
}
input->joy_hat(i, (HatMask)joypad.dpad);
input->joy_hat(i, joypad.dpad);
break;
case ABS_HAT0Y:
if (joypad_event.value != 0) {
if (joypad_event.value < 0) {
joypad.dpad = (HatMask)((joypad.dpad | HatMask::UP) & ~HatMask::DOWN);
joypad.dpad.set_flag(HatMask::UP);
joypad.dpad.clear_flag(HatMask::DOWN);
} else {
joypad.dpad = (HatMask)((joypad.dpad | HatMask::DOWN) & ~HatMask::UP);
joypad.dpad.set_flag(HatMask::DOWN);
joypad.dpad.clear_flag(HatMask::UP);
}
} else {
joypad.dpad &= ~(HatMask::UP | HatMask::DOWN);
joypad.dpad.clear_flag(HatMask::UP);
joypad.dpad.clear_flag(HatMask::DOWN);
}
input->joy_hat(i, (HatMask)joypad.dpad);
input->joy_hat(i, joypad.dpad);
break;
default: