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: 2 additions & 1 deletion Source/Core/Core/Brawlback/BrawlbackUtility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

}
Expand Down
10 changes: 8 additions & 2 deletions Source/Core/Core/Brawlback/BrawlbackUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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));
Expand Down
80 changes: 42 additions & 38 deletions Source/Core/Core/HW/EXI/EXIBrawlback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,42 @@ std::vector<u8> 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());
Expand Down Expand Up @@ -306,15 +342,19 @@ 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++)
{
this->remotePlayerFrameData[playerIdx].push_back(
std::make_unique<PlayerFrameData>(CreateBlankPlayerFrameData(i, playerIdx)));
this->localPlayerFrameData.push_back(
std::make_unique<PlayerFrameData>(CreateBlankPlayerFrameData(i, playerIdx)));

}
this->hasGameStarted = true;
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down