From 0d31bf4b959636c92da2f7b276a0829252801988 Mon Sep 17 00:00:00 2001 From: Robert Peralta Date: Fri, 9 Dec 2022 01:53:10 -0400 Subject: [PATCH 1/2] Add missing _buttons to pad utils --- .../Core/Core/Brawlback/BrawlbackUtility.cpp | 3 +- Source/Core/Core/Brawlback/BrawlbackUtility.h | 10 ++- Source/Core/Core/HW/EXI/EXIBrawlback.cpp | 80 ++++++++++--------- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/Source/Core/Core/Brawlback/BrawlbackUtility.cpp b/Source/Core/Core/Brawlback/BrawlbackUtility.cpp index bc6eb4e8bb91..2a03c2c4fb22 100644 --- a/Source/Core/Core/Brawlback/BrawlbackUtility.cpp +++ b/Source/Core/Core/Brawlback/BrawlbackUtility.cpp @@ -92,6 +92,7 @@ namespace Brawlback { //bool frames = p1.frame == p2.frame; //bool idxs = p1.playerIdx == p2.playerIdx; + bool _buttons = p1.pad._buttons == p2.pad._buttons; bool buttons = p1.pad.buttons == p2.pad.buttons; bool holdButtons = p1.pad.holdButtons == p2.pad.holdButtons; bool rapidFireButtons = p1.pad.rapidFireButtons == p2.pad.rapidFireButtons; @@ -103,7 +104,7 @@ namespace Brawlback p1.pad.cStickY == p2.pad.cStickY; bool triggers = p1.pad.LTrigger == p2.pad.LTrigger && p1.pad.RTrigger == p2.pad.RTrigger; - return buttons && holdButtons && rapidFireButtons && releasedButtons && newPressedButtons && sticks && triggers; + return _buttons && buttons && holdButtons && rapidFireButtons && releasedButtons && newPressedButtons && sticks && triggers; } } diff --git a/Source/Core/Core/Brawlback/BrawlbackUtility.h b/Source/Core/Core/Brawlback/BrawlbackUtility.h index 13c84941fac1..978f60037e83 100644 --- a/Source/Core/Core/Brawlback/BrawlbackUtility.h +++ b/Source/Core/Core/Brawlback/BrawlbackUtility.h @@ -130,6 +130,7 @@ namespace Brawlback { inline bool isInputsEqual(const BrawlbackPad& p1, const BrawlbackPad& p2) { // TODO: this code is duplicated on the .cpp make it dry or I don't know + bool _buttons = p1._buttons == p2._buttons; bool buttons = p1.buttons == p2.buttons; bool holdButtons = p1.holdButtons == p2.holdButtons; bool rapidFireButtons = p1.rapidFireButtons == p2.rapidFireButtons; @@ -138,7 +139,7 @@ namespace Brawlback { bool triggers = p1.LTrigger == p2.LTrigger && p1.RTrigger == p2.RTrigger; bool analogSticks = p1.stickX == p2.stickX && p1.stickY == p2.stickY; bool cSticks = p1.cStickX == p2.cStickX && p1.cStickY == p2.cStickY; - return buttons && holdButtons && rapidFireButtons && releasedButtons && newPressedButtons && analogSticks && cSticks && triggers; + return _buttons && buttons && holdButtons && rapidFireButtons && releasedButtons && newPressedButtons && analogSticks && cSticks && triggers; //return memcmp(&p1, &p2, sizeof(BrawlbackPad)) == 0; } @@ -148,7 +149,12 @@ namespace Brawlback { ret.frame = frame; ret.playerIdx = pIdx; std::default_random_engine generator = std::default_random_engine((s32)Common::Timer::GetTimeUs()); - ret.pad.buttons = (u16)((generator() % 65535)); + ret.pad._buttons = (u16)((generator() % 65535)); + ret.pad.buttons = ret.pad._buttons; + ret.pad.holdButtons = 0; + ret.pad.rapidFireButtons = 0; + ret.pad.releasedButtons = 0; + ret.pad.newPressedButtons = 0; //ret.pad.stickX = (u8)(127-generator() % (127*2)); ret.pad.stickX = 0; ret.pad.stickY = (u8)(127-generator() % (127*2)); diff --git a/Source/Core/Core/HW/EXI/EXIBrawlback.cpp b/Source/Core/Core/HW/EXI/EXIBrawlback.cpp index df10e4aa9316..0f1a9fd44721 100644 --- a/Source/Core/Core/HW/EXI/EXIBrawlback.cpp +++ b/Source/Core/Core/HW/EXI/EXIBrawlback.cpp @@ -41,6 +41,42 @@ std::vector read_vector_from_disk(std::string file_path) return data; } + +const char* bit_rep[16] = { + "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", + "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", +}; +void print_byte(u8 byte) { INFO_LOG(BRAWLBACK, "%s%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]); } +void print_half(u16 half) +{ + u8 byte0 = half >> 8; + u8 byte1 = half & 0xFF; + + print_byte(byte0); + print_byte(byte1); +} + +void printInputs + (const BrawlbackPad& pad) +{ + INFO_LOG(BRAWLBACK, " -- Pad --\n"); + INFO_LOG(BRAWLBACK, "StickX: %hhu ", pad.stickX); + INFO_LOG(BRAWLBACK, "StickY: %hhu ", pad.stickY); + INFO_LOG(BRAWLBACK, "CStickX: %hhu ", pad.cStickX); + INFO_LOG(BRAWLBACK, "CStickY: %hhu\n", pad.cStickY); + INFO_LOG(BRAWLBACK, "Buttons: "); + INFO_LOG(BRAWLBACK, "_buttons: 0x%x\n", pad._buttons); + INFO_LOG(BRAWLBACK, "buttons: 0x%x\n", pad.buttons); + INFO_LOG(BRAWLBACK, "holdButtons: 0x%x\n", pad.holdButtons); + INFO_LOG(BRAWLBACK, "rapidFireButtons: 0x%x\n", pad.rapidFireButtons); + INFO_LOG(BRAWLBACK, "releasedButtons: 0x%x\n", pad.releasedButtons); + INFO_LOG(BRAWLBACK, "newPressedButtons: 0x%x\n", pad.newPressedButtons); + // print_half(pad.newPressedButtons); + INFO_LOG(BRAWLBACK, " LTrigger: %u RTrigger %u\n", pad.LTrigger, pad.RTrigger); + //OSReport(" ---------\n"); +} + + CEXIBrawlback::CEXIBrawlback() { INFO_LOG(BRAWLBACK, "------- %s\n", SConfig::GetInstance().GetGameID().c_str()); @@ -306,8 +342,11 @@ void CEXIBrawlback::handleLocalPadData(u8* data) u8 playerIdx = playerFramedata.playerIdx; playerFramedata.frame = frame; // properly switched endianness - if (frame == GAME_START_FRAME) + // TODO: is this really necessary? + if (frame >= GAME_START_FRAME && !this->hasGameStarted) { + INFO_LOG(BRAWLBACK, "Pushing empty frames for game start!\n"); + // push framedatas for first few delay frames for (int i = GAME_START_FRAME; i < FRAME_DELAY; i++) { @@ -315,6 +354,7 @@ void CEXIBrawlback::handleLocalPadData(u8* data) std::make_unique(CreateBlankPlayerFrameData(i, playerIdx))); this->localPlayerFrameData.push_back( std::make_unique(CreateBlankPlayerFrameData(i, playerIdx))); + } this->hasGameStarted = true; } @@ -561,7 +601,7 @@ void CEXIBrawlback::storeLocalInputs(PlayerFrameData* localPlayerFramedata) { } else { - // WARN_LOG(BRAWLBACK, "Didn't push local framedata for frame %u\n", pFD->frame); + WARN_LOG(BRAWLBACK, "Didn't push local framedata for frame %u\n", pFD->frame); } } @@ -674,33 +714,6 @@ void CEXIBrawlback::ProcessIndividualRemoteFrameData(PlayerFrameData* framedata) -} -const char* bit_rep[16] = { - "0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", - "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111", -}; -void print_byte(u8 byte) { INFO_LOG(BRAWLBACK, "%s%s", bit_rep[byte >> 4], bit_rep[byte & 0x0F]); } -void print_half(u16 half) -{ - u8 byte0 = half >> 8; - u8 byte1 = half & 0xFF; - - print_byte(byte0); - print_byte(byte1); -} - -void printInputs -(const BrawlbackPad& pad) -{ - INFO_LOG(BRAWLBACK, " -- Pad --\n"); - INFO_LOG(BRAWLBACK, "StickX: %hhu ", pad.stickX); - INFO_LOG(BRAWLBACK, "StickY: %hhu ", pad.stickY); - INFO_LOG(BRAWLBACK, "CStickX: %hhu ", pad.cStickX); - INFO_LOG(BRAWLBACK, "CStickY: %hhu\n", pad.cStickY); - INFO_LOG(BRAWLBACK, "Buttons: "); - print_half(pad.newPressedButtons); - INFO_LOG(BRAWLBACK, " LTrigger: %u RTrigger %u\n", pad.LTrigger, pad.RTrigger); - //OSReport(" ---------\n"); } void CEXIBrawlback::ProcessRemoteFrameData(PlayerFrameData* framedatas, u8 numFramedatas_u8) @@ -717,15 +730,6 @@ void CEXIBrawlback::ProcessRemoteFrameData(PlayerFrameData* framedatas, u8 numFr BroadcastFramedataAck(frame, playerIdx, this->netplay.get(), this->server); // --------------------- - // Just print for other player - if(this->isHost && playerIdx == 1) { - //INFO_LOG(BRAWLBACK, "Received remote inputs from %i", playerIdx); - if (mostRecentFramedata->sysPad.newPressedButtons > 0) - { - printInputs(mostRecentFramedata->sysPad); - - } - } // if (!this->remotePlayerFrameData[playerIdx].empty()) // INFO_LOG(BRAWLBACK, "Received remote inputs. Head frame %u received head frame %u\n", // this->remotePlayerFrameData[playerIdx].back()->frame, frame); From e7961a69c457d2b50ff7238fd3e1a98c7809880c Mon Sep 17 00:00:00 2001 From: Robert Peralta Date: Fri, 9 Dec 2022 01:54:11 -0400 Subject: [PATCH 2/2] Update gitmodule --- Source/Core/Core/Brawlback/include/brawlback-exi-structures | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Core/Core/Brawlback/include/brawlback-exi-structures b/Source/Core/Core/Brawlback/include/brawlback-exi-structures index 75c4e963049f..cc72922f8a94 160000 --- a/Source/Core/Core/Brawlback/include/brawlback-exi-structures +++ b/Source/Core/Core/Brawlback/include/brawlback-exi-structures @@ -1 +1 @@ -Subproject commit 75c4e963049fc5312fc6c1a375d741bfed4f5b29 +Subproject commit cc72922f8a94314c276f4e496a54336f9f055bdd