SI_DeviceGBA: Use std::array class members instead of C arrays

This commit is contained in:
Lioncash 2017-03-13 13:59:43 -04:00
parent ea59d30e9f
commit 64aa7f3b8f
2 changed files with 13 additions and 11 deletions

View File

@ -4,6 +4,7 @@
#include "Core/HW/SI/SI_DeviceGBA.h" #include "Core/HW/SI/SI_DeviceGBA.h"
#include <cstddef>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <queue> #include <queue>
@ -237,7 +238,7 @@ void GBASockServer::Send(const u8* si_buffer)
if (!GetAvailableSock(client)) if (!GetAvailableSock(client))
return; return;
for (int i = 0; i < 5; i++) for (size_t i = 0; i < send_data.size(); i++)
send_data[i] = si_buffer[i ^ 3]; send_data[i] = si_buffer[i ^ 3];
cmd = (u8)send_data[0]; cmd = (u8)send_data[0];
@ -250,9 +251,9 @@ void GBASockServer::Send(const u8* si_buffer)
client->setBlocking(false); client->setBlocking(false);
sf::Socket::Status status; sf::Socket::Status status;
if (cmd == CMD_WRITE) if (cmd == CMD_WRITE)
status = client->send(send_data, sizeof(send_data)); status = client->send(send_data.data(), send_data.size());
else else
status = client->send(send_data, 1); status = client->send(send_data.data(), 1);
if (cmd != CMD_STATUS) if (cmd != CMD_STATUS)
booted = true; booted = true;
@ -282,7 +283,7 @@ int GBASockServer::Receive(u8* si_buffer)
Selector.wait(sf::milliseconds(1000)); Selector.wait(sf::milliseconds(1000));
} }
sf::Socket::Status recv_stat = client->receive(recv_data, sizeof(recv_data), num_received); sf::Socket::Status recv_stat = client->receive(recv_data.data(), recv_data.size(), num_received);
if (recv_stat == sf::Socket::Disconnected) if (recv_stat == sf::Socket::Disconnected)
{ {
Disconnect(); Disconnect();
@ -292,8 +293,8 @@ int GBASockServer::Receive(u8* si_buffer)
if (recv_stat == sf::Socket::NotReady) if (recv_stat == sf::Socket::NotReady)
num_received = 0; num_received = 0;
if (num_received > sizeof(recv_data)) if (num_received > recv_data.size())
num_received = sizeof(recv_data); num_received = recv_data.size();
if (num_received > 0) if (num_received > 0)
{ {
@ -312,7 +313,7 @@ int GBASockServer::Receive(u8* si_buffer)
} }
#endif #endif
for (int i = 0; i < 5; i++) for (size_t i = 0; i < recv_data.size(); i++)
si_buffer[i ^ 3] = recv_data[i]; si_buffer[i ^ 3] = recv_data[i];
} }
@ -333,7 +334,7 @@ int CSIDevice_GBA::RunBuffer(u8* _pBuffer, int _iLength)
{ {
if (!waiting_for_response) if (!waiting_for_response)
{ {
for (int i = 0; i < 5; i++) for (size_t i = 0; i < send_data.size(); i++)
send_data[i] = _pBuffer[i ^ 3]; send_data[i] = _pBuffer[i ^ 3];
num_data_received = 0; num_data_received = 0;

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array>
#include <memory> #include <memory>
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
@ -33,8 +34,8 @@ public:
private: private:
std::unique_ptr<sf::TcpSocket> client; std::unique_ptr<sf::TcpSocket> client;
std::unique_ptr<sf::TcpSocket> clock_sync; std::unique_ptr<sf::TcpSocket> clock_sync;
char send_data[5] = {}; std::array<char, 5> send_data{};
char recv_data[5] = {}; std::array<char, 5> recv_data{};
u64 time_cmd_sent = 0; u64 time_cmd_sent = 0;
u64 last_time_slice = 0; u64 last_time_slice = 0;
@ -55,7 +56,7 @@ public:
bool GetData(u32& _Hi, u32& _Low) override { return false; } bool GetData(u32& _Hi, u32& _Low) override { return false; }
void SendCommand(u32 _Cmd, u8 _Poll) override {} void SendCommand(u32 _Cmd, u8 _Poll) override {}
private: private:
u8 send_data[5] = {}; std::array<u8, 5> send_data{};
int num_data_received = 0; int num_data_received = 0;
u64 timestamp_sent = 0; u64 timestamp_sent = 0;
bool waiting_for_response = false; bool waiting_for_response = false;