Browse Source

Clean up sub folders using clang-tidy/Android Studio

pull/2319/merge
Anders Jenbo 5 years ago
parent
commit
2ca6e37c46
  1. 2
      Source/dvlnet/abstract_net.cpp
  2. 2
      Source/dvlnet/abstract_net.h
  3. 66
      Source/dvlnet/base.cpp
  4. 12
      Source/dvlnet/base.h
  5. 60
      Source/dvlnet/base_protocol.h
  6. 22
      Source/dvlnet/frame_queue.cpp
  7. 12
      Source/dvlnet/frame_queue.h
  8. 26
      Source/dvlnet/packet.cpp
  9. 34
      Source/dvlnet/packet.h
  10. 8
      Source/dvlnet/protocol_zt.cpp
  11. 28
      Source/dvlnet/tcp_client.cpp
  12. 6
      Source/dvlnet/tcp_client.h
  13. 112
      Source/dvlnet/tcp_server.cpp
  14. 36
      Source/dvlnet/tcp_server.h
  15. 8
      Source/engine/animationinfo.cpp
  16. 8
      Source/engine/animationinfo.h
  17. 14
      Source/engine/render/cel_render.cpp
  18. 18
      Source/engine/render/cel_render.hpp
  19. 6
      Source/engine/render/text_render.cpp
  20. 6
      Source/engine/render/text_render.hpp
  21. 2
      Source/miniwin/misc_msg.cpp
  22. 6
      Source/qol/common.cpp
  23. 2
      Source/qol/common.h
  24. 4
      Source/qol/xpbar.cpp
  25. 26
      Source/storm/storm.h
  26. 2
      Source/storm/storm_net.cpp
  27. 2
      Source/storm/storm_svid.cpp

2
Source/dvlnet/abstract_net.cpp

@ -17,7 +17,7 @@
namespace devilution {
namespace net {
std::unique_ptr<abstract_net> abstract_net::make_net(provider_t provider)
std::unique_ptr<abstract_net> abstract_net::MakeNet(provider_t provider)
{
#ifdef NONET
return std::make_unique<loopback>();

2
Source/dvlnet/abstract_net.h

@ -62,7 +62,7 @@ public:
return std::vector<std::string>();
}
static std::unique_ptr<abstract_net> make_net(provider_t provider);
static std::unique_ptr<abstract_net> MakeNet(provider_t provider);
};
} // namespace net

66
Source/dvlnet/base.cpp

@ -17,7 +17,7 @@ void base::setup_password(std::string pw)
pktfty = std::make_unique<packet_factory>(pw);
}
void base::run_event_handler(_SNETEVENT &ev)
void base::RunEventHandler(_SNETEVENT &ev)
{
auto f = registered_handlers[static_cast<event_type>(ev.eventid)];
if (f != nullptr) {
@ -25,35 +25,35 @@ void base::run_event_handler(_SNETEVENT &ev)
}
}
void base::disconnect_net(plr_t plr)
void base::DisconnectNet(plr_t plr)
{
}
void base::handle_accept(packet &pkt)
void base::HandleAccept(packet &pkt)
{
if (plr_self != PLR_BROADCAST) {
return; // already have player id
}
if (pkt.cookie() == cookie_self) {
plr_self = pkt.newplr();
if (pkt.Cookie() == cookie_self) {
plr_self = pkt.NewPlayer();
connected_table[plr_self] = true;
}
if (game_init_info != pkt.info()) {
if (pkt.info().size() != sizeof(GameData)) {
if (game_init_info != pkt.Info()) {
if (pkt.Info().size() != sizeof(GameData)) {
ABORT();
}
// we joined and did not create
game_init_info = pkt.info();
game_init_info = pkt.Info();
_SNETEVENT ev;
ev.eventid = EVENT_TYPE_PLAYER_CREATE_GAME;
ev.playerid = plr_self;
ev.data = const_cast<unsigned char *>(pkt.info().data());
ev.databytes = pkt.info().size();
run_event_handler(ev);
ev.data = const_cast<unsigned char *>(pkt.Info().data());
ev.databytes = pkt.Info().size();
RunEventHandler(ev);
}
}
void base::clear_msg(plr_t plr)
void base::ClearMsg(plr_t plr)
{
message_queue.erase(std::remove_if(message_queue.begin(),
message_queue.end(),
@ -63,38 +63,38 @@ void base::clear_msg(plr_t plr)
message_queue.end());
}
void base::recv_local(packet &pkt)
void base::RecvLocal(packet &pkt)
{
if (pkt.src() < MAX_PLRS) {
connected_table[pkt.src()] = true;
if (pkt.Source() < MAX_PLRS) {
connected_table[pkt.Source()] = true;
}
switch (pkt.type()) {
switch (pkt.Type()) {
case PT_MESSAGE:
message_queue.emplace_back(pkt.src(), pkt.message());
message_queue.emplace_back(pkt.Source(), pkt.Message());
break;
case PT_TURN:
turn_queue[pkt.src()].push_back(pkt.turn());
turn_queue[pkt.Source()].push_back(pkt.Turn());
break;
case PT_JOIN_ACCEPT:
handle_accept(pkt);
HandleAccept(pkt);
break;
case PT_CONNECT:
connected_table[pkt.newplr()] = true; // this can probably be removed
connected_table[pkt.NewPlayer()] = true; // this can probably be removed
break;
case PT_DISCONNECT:
if (pkt.newplr() != plr_self) {
if (connected_table[pkt.newplr()]) {
auto leaveinfo = pkt.leaveinfo();
if (pkt.NewPlayer() != plr_self) {
if (connected_table[pkt.NewPlayer()]) {
auto leaveinfo = pkt.LeaveInfo();
_SNETEVENT ev;
ev.eventid = EVENT_TYPE_PLAYER_LEAVE_GAME;
ev.playerid = pkt.newplr();
ev.playerid = pkt.NewPlayer();
ev.data = reinterpret_cast<unsigned char *>(&leaveinfo);
ev.databytes = sizeof(leaveinfo_t);
run_event_handler(ev);
connected_table[pkt.newplr()] = false;
disconnect_net(pkt.newplr());
clear_msg(pkt.newplr());
turn_queue[pkt.newplr()].clear();
RunEventHandler(ev);
connected_table[pkt.NewPlayer()] = false;
DisconnectNet(pkt.NewPlayer());
ClearMsg(pkt.NewPlayer());
turn_queue[pkt.NewPlayer()].clear();
}
} else {
ABORT(); // we were dropped by the owner?!?
@ -183,7 +183,7 @@ bool base::SNetSendTurn(char *data, unsigned int size)
std::memcpy(&turn, data, sizeof(turn));
auto pkt = pktfty->make_packet<PT_TURN>(plr_self, PLR_BROADCAST, turn);
send(*pkt);
turn_queue[plr_self].push_back(pkt->turn());
turn_queue[plr_self].push_back(pkt->Turn());
return true;
}
@ -236,11 +236,11 @@ bool base::SNetDropPlayer(int playerid, DWORD flags)
(plr_t)playerid,
(leaveinfo_t)flags);
send(*pkt);
recv_local(*pkt);
RecvLocal(*pkt);
return true;
}
plr_t base::get_owner()
plr_t base::GetOwner()
{
for (auto i = 0; i < MAX_PLRS; ++i) {
if (connected_table[i]) {
@ -252,7 +252,7 @@ plr_t base::get_owner()
bool base::SNetGetOwnerTurnsWaiting(DWORD *turns)
{
*turns = turn_queue[get_owner()].size();
*turns = turn_queue[GetOwner()].size();
return true;
}

12
Source/dvlnet/base.h

@ -33,7 +33,7 @@ public:
virtual void poll() = 0;
virtual void send(packet &pkt) = 0;
virtual void disconnect_net(plr_t plr);
virtual void DisconnectNet(plr_t plr);
void setup_gameinfo(buffer_t info);
@ -71,13 +71,13 @@ protected:
std::unique_ptr<packet_factory> pktfty;
void handle_accept(packet &pkt);
void recv_local(packet &pkt);
void run_event_handler(_SNETEVENT &ev);
void HandleAccept(packet &pkt);
void RecvLocal(packet &pkt);
void RunEventHandler(_SNETEVENT &ev);
private:
plr_t get_owner();
void clear_msg(plr_t plr);
plr_t GetOwner();
void ClearMsg(plr_t plr);
};
} // namespace net

60
Source/dvlnet/base_protocol.h

@ -20,7 +20,7 @@ public:
virtual int join(std::string addrstr, std::string passwd);
virtual void poll();
virtual void send(packet &pkt);
virtual void disconnect_net(plr_t plr);
virtual void DisconnectNet(plr_t plr);
virtual bool SNetLeaveGame(int type);
@ -73,7 +73,7 @@ bool base_protocol<P>::wait_network()
}
template <class P>
void base_protocol<P>::disconnect_net(plr_t plr)
void base_protocol<P>::DisconnectNet(plr_t plr)
{
proto.disconnect(peers[plr]);
peers[plr] = endpoint();
@ -100,7 +100,7 @@ void base_protocol<P>::send_info_request()
{
auto pkt = pktfty->make_packet<PT_INFO_REQUEST>(PLR_BROADCAST,
PLR_MASTER);
proto.send_oob_mc(pkt->data());
proto.send_oob_mc(pkt->Data());
}
template <class P>
@ -110,7 +110,7 @@ void base_protocol<P>::wait_join()
sizeof(cookie_t));
auto pkt = pktfty->make_packet<PT_JOIN_REQUEST>(PLR_BROADCAST,
PLR_MASTER, cookie_self, game_init_info);
proto.send(firstpeer, pkt->data());
proto.send(firstpeer, pkt->Data());
for (auto i = 0; i < 500; ++i) {
recv();
if (plr_self != PLR_BROADCAST)
@ -154,16 +154,16 @@ void base_protocol<P>::poll()
template <class P>
void base_protocol<P>::send(packet &pkt)
{
if (pkt.dest() < MAX_PLRS) {
if (pkt.dest() == MyPlayerId)
if (pkt.Destination() < MAX_PLRS) {
if (pkt.Destination() == MyPlayerId)
return;
if (peers[pkt.dest()])
proto.send(peers[pkt.dest()], pkt.data());
} else if (pkt.dest() == PLR_BROADCAST) {
if (peers[pkt.Destination()])
proto.send(peers[pkt.Destination()], pkt.Data());
} else if (pkt.Destination() == PLR_BROADCAST) {
for (auto &peer : peers)
if (peer)
proto.send(peer, pkt.data());
} else if (pkt.dest() == PLR_MASTER) {
proto.send(peer, pkt.Data());
} else if (pkt.Destination() == PLR_MASTER) {
throw dvlnet_exception();
} else {
throw dvlnet_exception();
@ -189,7 +189,7 @@ void base_protocol<P>::recv()
while (proto.get_disconnected(sender)) {
for (plr_t i = 0; i < MAX_PLRS; ++i) {
if (peers[i] == sender) {
disconnect_net(i);
DisconnectNet(i);
break;
}
}
@ -217,22 +217,22 @@ void base_protocol<P>::handle_join_request(packet &pkt, endpoint sender)
for (plr_t j = 0; j < MAX_PLRS; ++j) {
if ((j != plr_self) && (j != i) && peers[j]) {
auto infopkt = pktfty->make_packet<PT_CONNECT>(PLR_MASTER, PLR_BROADCAST, j, peers[j].serialize());
proto.send(sender, infopkt->data());
proto.send(sender, infopkt->Data());
}
}
auto reply = pktfty->make_packet<PT_JOIN_ACCEPT>(plr_self, PLR_BROADCAST,
pkt.cookie(), i,
pkt.Cookie(), i,
game_init_info);
proto.send(sender, reply->data());
proto.send(sender, reply->Data());
}
template <class P>
void base_protocol<P>::recv_decrypted(packet &pkt, endpoint sender)
{
if (pkt.src() == PLR_BROADCAST && pkt.dest() == PLR_MASTER && pkt.type() == PT_INFO_REPLY) {
if (pkt.Source() == PLR_BROADCAST && pkt.Destination() == PLR_MASTER && pkt.Type() == PT_INFO_REPLY) {
std::string pname;
pname.resize(pkt.info().size());
std::memcpy(&pname[0], pkt.info().data(), pkt.info().size());
pname.resize(pkt.Info().size());
std::memcpy(&pname[0], pkt.Info().data(), pkt.Info().size());
game_list[pname] = sender;
return;
}
@ -242,10 +242,10 @@ void base_protocol<P>::recv_decrypted(packet &pkt, endpoint sender)
template <class P>
void base_protocol<P>::recv_ingame(packet &pkt, endpoint sender)
{
if (pkt.src() == PLR_BROADCAST && pkt.dest() == PLR_MASTER) {
if (pkt.type() == PT_JOIN_REQUEST) {
if (pkt.Source() == PLR_BROADCAST && pkt.Destination() == PLR_MASTER) {
if (pkt.Type() == PT_JOIN_REQUEST) {
handle_join_request(pkt, sender);
} else if (pkt.type() == PT_INFO_REQUEST) {
} else if (pkt.Type() == PT_INFO_REQUEST) {
if ((plr_self != PLR_BROADCAST) && (get_master() == plr_self)) {
buffer_t buf;
buf.resize(gamename.size());
@ -253,24 +253,24 @@ void base_protocol<P>::recv_ingame(packet &pkt, endpoint sender)
auto reply = pktfty->make_packet<PT_INFO_REPLY>(PLR_BROADCAST,
PLR_MASTER,
buf);
proto.send_oob(sender, reply->data());
proto.send_oob(sender, reply->Data());
}
}
return;
} else if (pkt.src() == PLR_MASTER && pkt.type() == PT_CONNECT) {
} else if (pkt.Source() == PLR_MASTER && pkt.Type() == PT_CONNECT) {
// addrinfo packets
connected_table[pkt.newplr()] = true;
peers[pkt.newplr()].unserialize(pkt.info());
connected_table[pkt.NewPlayer()] = true;
peers[pkt.NewPlayer()].unserialize(pkt.Info());
return;
} else if (pkt.src() >= MAX_PLRS) {
} else if (pkt.Source() >= MAX_PLRS) {
// normal packets
ABORT();
}
connected_table[pkt.src()] = true;
peers[pkt.src()] = sender;
if (pkt.dest() != plr_self && pkt.dest() != PLR_BROADCAST)
connected_table[pkt.Source()] = true;
peers[pkt.Source()] = sender;
if (pkt.Destination() != plr_self && pkt.Destination() != PLR_BROADCAST)
return; //packet not for us, drop
recv_local(pkt);
RecvLocal(pkt);
}
template <class P>

22
Source/dvlnet/frame_queue.cpp

@ -7,12 +7,12 @@
namespace devilution {
namespace net {
framesize_t frame_queue::size() const
framesize_t frame_queue::Size() const
{
return current_size;
}
buffer_t frame_queue::read(framesize_t s)
buffer_t frame_queue::Read(framesize_t s)
{
if (current_size < s)
throw frame_queue_exception();
@ -36,35 +36,35 @@ buffer_t frame_queue::read(framesize_t s)
return ret;
}
void frame_queue::write(buffer_t buf)
void frame_queue::Write(buffer_t buf)
{
current_size += buf.size();
buffer_deque.push_back(std::move(buf));
}
bool frame_queue::packet_ready()
bool frame_queue::PacketReady()
{
if (nextsize == 0) {
if (size() < sizeof(framesize_t))
if (Size() < sizeof(framesize_t))
return false;
auto szbuf = read(sizeof(framesize_t));
auto szbuf = Read(sizeof(framesize_t));
std::memcpy(&nextsize, &szbuf[0], sizeof(framesize_t));
if (nextsize == 0)
throw frame_queue_exception();
}
return size() >= nextsize;
return Size() >= nextsize;
}
buffer_t frame_queue::read_packet()
buffer_t frame_queue::ReadPacket()
{
if (nextsize == 0 || size() < nextsize)
if (nextsize == 0 || Size() < nextsize)
throw frame_queue_exception();
auto ret = read(nextsize);
auto ret = Read(nextsize);
nextsize = 0;
return ret;
}
buffer_t frame_queue::make_frame(buffer_t packetbuf)
buffer_t frame_queue::MakeFrame(buffer_t packetbuf)
{
buffer_t ret;
if (packetbuf.size() > max_frame_size)

12
Source/dvlnet/frame_queue.h

@ -29,15 +29,15 @@ private:
std::deque<buffer_t> buffer_deque;
framesize_t nextsize = 0;
framesize_t size() const;
buffer_t read(framesize_t s);
framesize_t Size() const;
buffer_t Read(framesize_t s);
public:
bool packet_ready();
buffer_t read_packet();
void write(buffer_t buf);
bool PacketReady();
buffer_t ReadPacket();
void Write(buffer_t buf);
static buffer_t make_frame(buffer_t packetbuf);
static buffer_t MakeFrame(buffer_t packetbuf);
};
} // namespace net

26
Source/dvlnet/packet.cpp

@ -64,35 +64,35 @@ void CheckPacketTypeOneOf(std::initializer_list<packet_type> expectedTypes, std:
} // namespace
const buffer_t &packet::data()
const buffer_t &packet::Data()
{
if (!have_decrypted || !have_encrypted)
ABORT();
return encrypted_buffer;
}
packet_type packet::type()
packet_type packet::Type()
{
if (!have_decrypted)
ABORT();
return m_type;
}
plr_t packet::src() const
plr_t packet::Source() const
{
if (!have_decrypted)
ABORT();
return m_src;
}
plr_t packet::dest() const
plr_t packet::Destination() const
{
if (!have_decrypted)
ABORT();
return m_dest;
}
const buffer_t &packet::message()
const buffer_t &packet::Message()
{
if (!have_decrypted)
ABORT();
@ -100,7 +100,7 @@ const buffer_t &packet::message()
return m_message;
}
turn_t packet::turn()
turn_t packet::Turn()
{
if (!have_decrypted)
ABORT();
@ -108,7 +108,7 @@ turn_t packet::turn()
return m_turn;
}
cookie_t packet::cookie()
cookie_t packet::Cookie()
{
if (!have_decrypted)
ABORT();
@ -116,7 +116,7 @@ cookie_t packet::cookie()
return m_cookie;
}
plr_t packet::newplr()
plr_t packet::NewPlayer()
{
if (!have_decrypted)
ABORT();
@ -124,7 +124,7 @@ plr_t packet::newplr()
return m_newplr;
}
const buffer_t &packet::info()
const buffer_t &packet::Info()
{
if (!have_decrypted)
ABORT();
@ -132,7 +132,7 @@ const buffer_t &packet::info()
return m_info;
}
leaveinfo_t packet::leaveinfo()
leaveinfo_t packet::LeaveInfo()
{
if (!have_decrypted)
ABORT();
@ -140,7 +140,7 @@ leaveinfo_t packet::leaveinfo()
return m_leaveinfo;
}
void packet_in::create(buffer_t buf)
void packet_in::Create(buffer_t buf)
{
if (have_encrypted || have_decrypted)
ABORT();
@ -148,7 +148,7 @@ void packet_in::create(buffer_t buf)
have_encrypted = true;
}
void packet_in::decrypt()
void packet_in::Decrypt()
{
if (!have_encrypted)
ABORT();
@ -185,7 +185,7 @@ void packet_in::decrypt()
have_decrypted = true;
}
void packet_out::encrypt()
void packet_out::Encrypt()
{
if (!have_decrypted)
ABORT();

34
Source/dvlnet/packet.h

@ -88,17 +88,17 @@ public:
packet(const key_t &k)
: key(k) {};
const buffer_t &data();
packet_type type();
plr_t src() const;
plr_t dest() const;
const buffer_t &message();
turn_t turn();
cookie_t cookie();
plr_t newplr();
const buffer_t &info();
leaveinfo_t leaveinfo();
const buffer_t &Data();
packet_type Type();
plr_t Source() const;
plr_t Destination() const;
const buffer_t &Message();
turn_t Turn();
cookie_t Cookie();
plr_t NewPlayer();
const buffer_t &Info();
leaveinfo_t LeaveInfo();
};
template <class P>
@ -111,11 +111,11 @@ public:
class packet_in : public packet_proc<packet_in> {
public:
using packet_proc<packet_in>::packet_proc;
void create(buffer_t buf);
void Create(buffer_t buf);
void process_element(buffer_t &x);
template <class T>
void process_element(T &x);
void decrypt();
void Decrypt();
};
class packet_out : public packet_proc<packet_out> {
@ -132,7 +132,7 @@ public:
static const unsigned char *begin(const T &x);
template <class T>
static const unsigned char *end(const T &x);
void encrypt();
void Encrypt();
};
template <class P>
@ -343,8 +343,8 @@ public:
inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf)
{
auto ret = std::make_unique<packet_in>(key);
ret->create(std::move(buf));
ret->decrypt();
ret->Create(std::move(buf));
ret->Decrypt();
return ret;
}
@ -353,7 +353,7 @@ std::unique_ptr<packet> packet_factory::make_packet(Args... args)
{
auto ret = std::make_unique<packet_out>(key);
ret->create<t>(args...);
ret->encrypt();
ret->Encrypt();
return ret;
}

8
Source/dvlnet/protocol_zt.cpp

@ -88,7 +88,7 @@ bool protocol_zt::network_online()
bool protocol_zt::send(const endpoint &peer, const buffer_t &data)
{
peer_list[peer].send_queue.push_back(frame_queue::make_frame(data));
peer_list[peer].send_queue.push_back(frame_queue::MakeFrame(data));
return true;
}
@ -151,7 +151,7 @@ bool protocol_zt::recv_peer(const endpoint &peer)
while (true) {
auto len = lwip_recv(peer_list[peer].fd, buf, sizeof(buf), 0);
if (len >= 0) {
peer_list[peer].recv_queue.write(buffer_t(buf, buf + len));
peer_list[peer].recv_queue.Write(buffer_t(buf, buf + len));
} else {
return errno == EAGAIN || errno == EWOULDBLOCK;
}
@ -233,9 +233,9 @@ bool protocol_zt::recv(endpoint &peer, buffer_t &data)
}
for (auto &p : peer_list) {
if (p.second.recv_queue.packet_ready()) {
if (p.second.recv_queue.PacketReady()) {
peer = p.first;
data = p.second.recv_queue.read_packet();
data = p.second.recv_queue.ReadPacket();
return true;
}
}

28
Source/dvlnet/tcp_client.cpp

@ -21,7 +21,7 @@ int tcp_client::create(std::string addrstr, std::string passwd)
try {
auto port = sgOptions.Network.nPort;
local_server = std::make_unique<tcp_server>(ioc, addrstr, port, passwd);
return join(local_server->localhost_self(), passwd);
return join(local_server->LocalhostSelf(), passwd);
} catch (std::system_error &e) {
SDL_SetError("%s", e.what());
return -1;
@ -44,7 +44,7 @@ int tcp_client::join(std::string addrstr, std::string passwd)
SDL_SetError("%s", e.what());
return -1;
}
start_recv();
StartReceive();
{
randombytes_buf(reinterpret_cast<unsigned char *>(&cookie_self),
sizeof(cookie_t));
@ -77,7 +77,7 @@ void tcp_client::poll()
ioc.poll();
}
void tcp_client::handle_recv(const asio::error_code &error, size_t bytesRead)
void tcp_client::HandleReceive(const asio::error_code &error, size_t bytesRead)
{
if (error) {
// error in recv from server
@ -89,33 +89,33 @@ void tcp_client::handle_recv(const asio::error_code &error, size_t bytesRead)
throw std::runtime_error(_("error: read 0 bytes from server"));
}
recv_buffer.resize(bytesRead);
recv_queue.write(std::move(recv_buffer));
recv_queue.Write(std::move(recv_buffer));
recv_buffer.resize(frame_queue::max_frame_size);
while (recv_queue.packet_ready()) {
auto pkt = pktfty->make_packet(recv_queue.read_packet());
recv_local(*pkt);
while (recv_queue.PacketReady()) {
auto pkt = pktfty->make_packet(recv_queue.ReadPacket());
RecvLocal(*pkt);
}
start_recv();
StartReceive();
}
void tcp_client::start_recv()
void tcp_client::StartReceive()
{
sock.async_receive(
asio::buffer(recv_buffer),
std::bind(&tcp_client::handle_recv, this, std::placeholders::_1, std::placeholders::_2));
std::bind(&tcp_client::HandleReceive, this, std::placeholders::_1, std::placeholders::_2));
}
void tcp_client::handle_send(const asio::error_code &error, size_t bytesSent)
void tcp_client::HandleSend(const asio::error_code &error, size_t bytesSent)
{
// empty for now
}
void tcp_client::send(packet &pkt)
{
const auto *frame = new buffer_t(frame_queue::make_frame(pkt.data()));
const auto *frame = new buffer_t(frame_queue::MakeFrame(pkt.Data()));
auto buf = asio::buffer(*frame);
asio::async_write(sock, buf, [this, frame](const asio::error_code &error, size_t bytesSent) {
handle_send(error, bytesSent);
HandleSend(error, bytesSent);
delete frame;
});
}
@ -125,7 +125,7 @@ bool tcp_client::SNetLeaveGame(int type)
auto ret = base::SNetLeaveGame(type);
poll();
if (local_server != nullptr)
local_server->close();
local_server->Close();
sock.close();
return ret;
}

6
Source/dvlnet/tcp_client.h

@ -38,9 +38,9 @@ private:
asio::ip::tcp::socket sock = asio::ip::tcp::socket(ioc);
std::unique_ptr<tcp_server> local_server; // must be declared *after* ioc
void handle_recv(const asio::error_code &error, size_t bytesRead);
void start_recv();
void handle_send(const asio::error_code &error, size_t bytes_sent);
void HandleReceive(const asio::error_code &error, size_t bytesRead);
void StartReceive();
void HandleSend(const asio::error_code &error, size_t bytesSent);
};
} // namespace net

112
Source/dvlnet/tcp_server.cpp

@ -19,10 +19,10 @@ tcp_server::tcp_server(asio::io_context &ioc, const std::string &bindaddr,
auto addr = asio::ip::address::from_string(bindaddr);
auto ep = asio::ip::tcp::endpoint(addr, port);
acceptor = std::make_unique<asio::ip::tcp::acceptor>(ioc, ep, true);
start_accept();
StartAccept();
}
std::string tcp_server::localhost_self()
std::string tcp_server::LocalhostSelf()
{
auto addr = acceptor->local_endpoint().address();
if (addr.is_unspecified()) {
@ -37,12 +37,12 @@ std::string tcp_server::localhost_self()
return addr.to_string();
}
tcp_server::scc tcp_server::make_connection()
tcp_server::scc tcp_server::MakeConnection()
{
return std::make_shared<client_connection>(ioc);
}
plr_t tcp_server::next_free()
plr_t tcp_server::NextFree()
{
for (plr_t i = 0; i < MAX_PLRS; ++i)
if (!connections[i])
@ -50,7 +50,7 @@ plr_t tcp_server::next_free()
return PLR_BROADCAST;
}
bool tcp_server::empty()
bool tcp_server::Empty()
{
for (plr_t i = 0; i < MAX_PLRS; ++i)
if (connections[i])
@ -58,155 +58,155 @@ bool tcp_server::empty()
return true;
}
void tcp_server::start_recv(const scc &con)
void tcp_server::StartReceive(const scc &con)
{
con->socket.async_receive(
asio::buffer(con->recv_buffer),
std::bind(&tcp_server::handle_recv, this, con, std::placeholders::_1, std::placeholders::_2));
std::bind(&tcp_server::HandleReceive, this, con, std::placeholders::_1, std::placeholders::_2));
}
void tcp_server::handle_recv(const scc &con, const asio::error_code &ec,
void tcp_server::HandleReceive(const scc &con, const asio::error_code &ec,
size_t bytesRead)
{
if (ec || bytesRead == 0) {
drop_connection(con);
DropConnection(con);
return;
}
con->recv_buffer.resize(bytesRead);
con->recv_queue.write(std::move(con->recv_buffer));
con->recv_queue.Write(std::move(con->recv_buffer));
con->recv_buffer.resize(frame_queue::max_frame_size);
while (con->recv_queue.packet_ready()) {
while (con->recv_queue.PacketReady()) {
try {
auto pkt = pktfty.make_packet(con->recv_queue.read_packet());
auto pkt = pktfty.make_packet(con->recv_queue.ReadPacket());
if (con->plr == PLR_BROADCAST) {
handle_recv_newplr(con, *pkt);
HandleReceiveNewPlayer(con, *pkt);
} else {
con->timeout = timeout_active;
handle_recv_packet(*pkt);
HandleReceivePacket(*pkt);
}
} catch (dvlnet_exception &e) {
Log("Network error: {}", e.what());
drop_connection(con);
DropConnection(con);
return;
}
}
start_recv(con);
StartReceive(con);
}
void tcp_server::send_connect(const scc &con)
void tcp_server::SendConnect(const scc &con)
{
auto pkt = pktfty.make_packet<PT_CONNECT>(PLR_MASTER, PLR_BROADCAST,
con->plr);
send_packet(*pkt);
SendPacket(*pkt);
}
void tcp_server::handle_recv_newplr(const scc &con, packet &pkt)
void tcp_server::HandleReceiveNewPlayer(const scc &con, packet &pkt)
{
auto newplr = next_free();
auto newplr = NextFree();
if (newplr == PLR_BROADCAST)
throw server_exception();
if (empty())
game_init_info = pkt.info();
if (Empty())
game_init_info = pkt.Info();
auto reply = pktfty.make_packet<PT_JOIN_ACCEPT>(PLR_MASTER, PLR_BROADCAST,
pkt.cookie(), newplr,
pkt.Cookie(), newplr,
game_init_info);
start_send(con, *reply);
StartSend(con, *reply);
con->plr = newplr;
connections[newplr] = con;
con->timeout = timeout_active;
send_connect(con);
SendConnect(con);
}
void tcp_server::handle_recv_packet(packet &pkt)
void tcp_server::HandleReceivePacket(packet &pkt)
{
send_packet(pkt);
SendPacket(pkt);
}
void tcp_server::send_packet(packet &pkt)
void tcp_server::SendPacket(packet &pkt)
{
if (pkt.dest() == PLR_BROADCAST) {
if (pkt.Destination() == PLR_BROADCAST) {
for (auto i = 0; i < MAX_PLRS; ++i)
if (i != pkt.src() && connections[i])
start_send(connections[i], pkt);
if (i != pkt.Source() && connections[i])
StartSend(connections[i], pkt);
} else {
if (pkt.dest() >= MAX_PLRS)
if (pkt.Destination() >= MAX_PLRS)
throw server_exception();
if ((pkt.dest() != pkt.src()) && connections[pkt.dest()])
start_send(connections[pkt.dest()], pkt);
if ((pkt.Destination() != pkt.Source()) && connections[pkt.Destination()])
StartSend(connections[pkt.Destination()], pkt);
}
}
void tcp_server::start_send(const scc &con, packet &pkt)
void tcp_server::StartSend(const scc &con, packet &pkt)
{
const auto *frame = new buffer_t(frame_queue::make_frame(pkt.data()));
const auto *frame = new buffer_t(frame_queue::MakeFrame(pkt.Data()));
auto buf = asio::buffer(*frame);
asio::async_write(con->socket, buf,
[this, con, frame](const asio::error_code &ec, size_t bytesSent) {
handle_send(con, ec, bytesSent);
HandleSend(con, ec, bytesSent);
delete frame;
});
}
void tcp_server::handle_send(const scc &con, const asio::error_code &ec,
void tcp_server::HandleSend(const scc &con, const asio::error_code &ec,
size_t bytesSent)
{
// empty for now
}
void tcp_server::start_accept()
void tcp_server::StartAccept()
{
auto nextcon = make_connection();
auto nextcon = MakeConnection();
acceptor->async_accept(
nextcon->socket,
std::bind(&tcp_server::handle_accept, this, nextcon, std::placeholders::_1));
std::bind(&tcp_server::HandleAccept, this, nextcon, std::placeholders::_1));
}
void tcp_server::handle_accept(const scc &con, const asio::error_code &ec)
void tcp_server::HandleAccept(const scc &con, const asio::error_code &ec)
{
if (ec)
return;
if (next_free() == PLR_BROADCAST) {
drop_connection(con);
if (NextFree() == PLR_BROADCAST) {
DropConnection(con);
} else {
asio::ip::tcp::no_delay option(true);
con->socket.set_option(option);
con->timeout = timeout_connect;
start_recv(con);
start_timeout(con);
StartReceive(con);
StartTimeout(con);
}
start_accept();
StartAccept();
}
void tcp_server::start_timeout(const scc &con)
void tcp_server::StartTimeout(const scc &con)
{
con->timer.expires_after(std::chrono::seconds(1));
con->timer.async_wait(
std::bind(&tcp_server::handle_timeout, this, con, std::placeholders::_1));
std::bind(&tcp_server::HandleTimeout, this, con, std::placeholders::_1));
}
void tcp_server::handle_timeout(const scc &con, const asio::error_code &ec)
void tcp_server::HandleTimeout(const scc &con, const asio::error_code &ec)
{
if (ec) {
drop_connection(con);
DropConnection(con);
return;
}
if (con->timeout > 0)
con->timeout -= 1;
if (con->timeout <= 0) {
con->timeout = 0;
drop_connection(con);
DropConnection(con);
return;
}
start_timeout(con);
StartTimeout(con);
}
void tcp_server::drop_connection(const scc &con)
void tcp_server::DropConnection(const scc &con)
{
if (con->plr != PLR_BROADCAST) {
auto pkt = pktfty.make_packet<PT_DISCONNECT>(PLR_MASTER, PLR_BROADCAST,
con->plr, LEAVE_DROP);
connections[con->plr] = nullptr;
send_packet(*pkt);
SendPacket(*pkt);
// TODO: investigate if it is really ok for the server to
// drop a client directly.
}
@ -214,7 +214,7 @@ void tcp_server::drop_connection(const scc &con)
con->socket.close();
}
void tcp_server::close()
void tcp_server::Close()
{
acceptor->close();
}

36
Source/dvlnet/tcp_server.h

@ -27,8 +27,8 @@ class tcp_server {
public:
tcp_server(asio::io_context &ioc, const std::string &bindaddr,
unsigned short port, std::string pw);
std::string localhost_self();
void close();
std::string LocalhostSelf();
void Close();
virtual ~tcp_server();
private:
@ -57,22 +57,22 @@ private:
std::array<scc, MAX_PLRS> connections;
buffer_t game_init_info;
scc make_connection();
plr_t next_free();
bool empty();
void start_accept();
void handle_accept(const scc &con, const asio::error_code &ec);
void start_recv(const scc &con);
void handle_recv(const scc &con, const asio::error_code &ec, size_t bytesRead);
void handle_recv_newplr(const scc &con, packet &pkt);
void handle_recv_packet(packet &pkt);
void send_connect(const scc &con);
void send_packet(packet &pkt);
void start_send(const scc &con, packet &pkt);
void handle_send(const scc &con, const asio::error_code &ec, size_t bytes_sent);
void start_timeout(const scc &con);
void handle_timeout(const scc &con, const asio::error_code &ec);
void drop_connection(const scc &con);
scc MakeConnection();
plr_t NextFree();
bool Empty();
void StartAccept();
void HandleAccept(const scc &con, const asio::error_code &ec);
void StartReceive(const scc &con);
void HandleReceive(const scc &con, const asio::error_code &ec, size_t bytesRead);
void HandleReceiveNewPlayer(const scc &con, packet &pkt);
void HandleReceivePacket(packet &pkt);
void SendConnect(const scc &con);
void SendPacket(packet &pkt);
void StartSend(const scc &con, packet &pkt);
void HandleSend(const scc &con, const asio::error_code &ec, size_t bytesSent);
void StartTimeout(const scc &con);
void HandleTimeout(const scc &con, const asio::error_code &ec);
void DropConnection(const scc &con);
};
} //namespace net

8
Source/engine/animationinfo.cpp

@ -73,7 +73,7 @@ float AnimationInfo::GetAnimationProgress() const
return fAnimationFraction;
}
void AnimationInfo::SetNewAnimation(CelSprite *pCelSprite, int numberOfFrames, int ticksPerFrame, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/)
void AnimationInfo::SetNewAnimation(CelSprite *celSprite, int numberOfFrames, int ticksPerFrame, AnimationDistributionFlags flags /*= AnimationDistributionFlags::None*/, int numSkippedFrames /*= 0*/, int distributeFramesBeforeFrame /*= 0*/)
{
if ((flags & AnimationDistributionFlags::RepeatedAction) == AnimationDistributionFlags::RepeatedAction && distributeFramesBeforeFrame != 0 && NumberOfFrames == numberOfFrames && CurrentFrame >= distributeFramesBeforeFrame && CurrentFrame != NumberOfFrames) {
// We showed the same Animation (for example a melee attack) before but truncated the Animation.
@ -88,7 +88,7 @@ void AnimationInfo::SetNewAnimation(CelSprite *pCelSprite, int numberOfFrames, i
ticksPerFrame = 1;
}
this->pCelSprite = pCelSprite;
this->pCelSprite = celSprite;
NumberOfFrames = numberOfFrames;
CurrentFrame = 1 + numSkippedFrames;
TickCounterOfCurrentFrame = 0;
@ -161,7 +161,7 @@ void AnimationInfo::SetNewAnimation(CelSprite *pCelSprite, int numberOfFrames, i
}
}
void AnimationInfo::ChangeAnimationData(CelSprite *pCelSprite, int numberOfFrames, int delayLen)
void AnimationInfo::ChangeAnimationData(CelSprite *celSprite, int numberOfFrames, int delayLen)
{
if (numberOfFrames != NumberOfFrames || delayLen != TicksPerFrame) {
// Ensure that the CurrentFrame is still valid and that we disable ADL cause the calculcated values (for example TickModifier) could be wrong
@ -173,7 +173,7 @@ void AnimationInfo::ChangeAnimationData(CelSprite *pCelSprite, int numberOfFrame
RelevantFramesForDistributing = 0;
TickModifier = 0.0F;
}
this->pCelSprite = pCelSprite;
this->pCelSprite = celSprite;
TicksPerFrame = delayLen;
}

8
Source/engine/animationinfo.h

@ -74,22 +74,22 @@ public:
/**
* @brief Sets the new Animation with all relevant information for rendering
* @param pCelSprite Pointer to Animation Sprite
* @param celSprite Pointer to Animation Sprite
* @param numberOfFrames Number of Frames in Animation
* @param ticksPerFrame How many game ticks are needed to advance one Animation Frame
* @param flags Specifies what special logics are applied to this Animation
* @param numSkippedFrames Number of Frames that will be skipped (for example with modifier "faster attack")
* @param distributeFramesBeforeFrame Distribute the numSkippedFrames only before this frame
*/
void SetNewAnimation(CelSprite *pCelSprite, int numberOfFrames, int ticksPerFrame, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0);
void SetNewAnimation(CelSprite *celSprite, int numberOfFrames, int ticksPerFrame, AnimationDistributionFlags flags = AnimationDistributionFlags::None, int numSkippedFrames = 0, int distributeFramesBeforeFrame = 0);
/**
* @brief Changes the Animation Data on-the-fly. This is needed if a animation is currently in progress and the player changes his gear.
* @param pCelSprite Pointer to Animation Sprite
* @param celSprite Pointer to Animation Sprite
* @param numberOfFrames Number of Frames in Animation
* @param delayLen Delay after each Animation sequence
*/
void ChangeAnimationData(CelSprite *pCelSprite, int numberOfFrames, int delayLen);
void ChangeAnimationData(CelSprite *celSprite, int numberOfFrames, int delayLen);
/**
* @brief Process the Animation for a game tick (for example advances the frame)

14
Source/engine/render/cel_render.cpp

@ -659,13 +659,6 @@ void CelDrawItem(const ItemStruct &item, const Surface &out, Point position, con
}
}
void CelClippedDrawSafeTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{
int nDataSize;
const auto *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize);
CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame));
}
void CelClippedBlitLightTransTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{
int nDataSize;
@ -682,13 +675,6 @@ void CelClippedBlitLightTransTo(const Surface &out, Point position, const CelSpr
CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame));
}
void CelDrawLightRedSafeTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{
int nDataSize;
const auto *pRLEBytes = CelGetFrameClipped(cel.Data(), frame, &nDataSize);
RenderCelWithLightTable(out, position, pRLEBytes, nDataSize, cel.Width(frame), GetLightTable(1));
}
void CelDrawUnsafeTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{
int nDataSize;

18
Source/engine/render/cel_render.hpp

@ -93,24 +93,6 @@ void CelDrawLightRedTo(const Surface &out, Point position, const CelSprite &cel,
*/
void CelDrawItem(const ItemStruct &item, const Surface &out, Point position, const CelSprite &cel, int frame);
/**
* @brief Same as CelClippedDrawTo but checks for drawing outside the buffer
* @param out Target buffer
* @param position Target buffer coordinate
* @param cel CEL sprite
* @param frame CEL frame number
*/
void CelClippedDrawSafeTo(const Surface &out, Point position, const CelSprite &cel, int frame);
/**
* @brief Same as CelDrawLightRedTo but checks for drawing outside the buffer
* @param out Target buffer
* @param position Target buffer coordinate
* @param cel CEL sprite
* @param frame CEL frame number
*/
void CelDrawLightRedSafeTo(const Surface &out, Point position, const CelSprite &cel, int frame);
/**
* @brief Blit a solid colder shape one pixel larger than the given sprite shape, to the target buffer at the given coordianates
* @param out Target buffer

6
Source/engine/render/text_render.cpp

@ -271,7 +271,7 @@ void WordWrapGameString(char *text, size_t width, GameFontTables size, int spaci
/**
* @todo replace Rectangle with cropped Surface
*/
int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint16_t flags, int spacing, int lineHeight, bool drawTextCursor)
uint16_t DrawString(const Surface &out, const char *text, const Rectangle &rect, uint16_t flags, int spacing, int lineHeight, bool drawTextCursor)
{
GameFontTables size = GameFontSmall;
if ((flags & UIS_MED) != 0)
@ -312,7 +312,7 @@ int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint
if (lineHeight == -1)
lineHeight = LineHeights[size];
unsigned i = 0;
uint16_t i = 0;
for (; i < textLength; i++) {
uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]];
int symbolWidth = FontKern[size][frame];
@ -346,7 +346,7 @@ int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint
return i;
}
int PentSpn2Spin()
uint8_t PentSpn2Spin()
{
return (SDL_GetTicks() / 50) % 8 + 1;
}

6
Source/engine/render/text_render.hpp

@ -58,7 +58,7 @@ void WordWrapGameString(char *text, size_t width, GameFontTables size = GameFont
* @param drawTextCursor Whether to draw an animated cursor sprite at the end of the text (default is to display nothing).
* @return The number of characters rendered, including characters "drawn" outside the buffer.
*/
int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint16_t flags = 0, int spacing = 1, int lineHeight = -1, bool drawTextCursor = false);
uint16_t DrawString(const Surface &out, const char *text, const Rectangle &rect, uint16_t flags = 0, int spacing = 1, int lineHeight = -1, bool drawTextCursor = false);
/**
* @brief Draws a line of text at the given position relative to the origin of the output buffer.
@ -78,11 +78,11 @@ int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint
* @param drawTextCursor Whether to draw an animated cursor sprite at the end of the text (default is to display nothing).
* @return The number of characters rendered (could be less than the string length if it wrapped past the bottom of the buffer).
*/
inline int DrawString(const Surface &out, const char *text, const Point &position, uint16_t flags = 0, int spacing = 1, int lineHeight = -1, bool drawTextCursor = false)
inline uint16_t DrawString(const Surface &out, const char *text, const Point &position, uint16_t flags = 0, int spacing = 1, int lineHeight = -1, bool drawTextCursor = false)
{
return DrawString(out, text, { position, { out.w() - position.x, 0 } }, flags, spacing, lineHeight, drawTextCursor);
}
int PentSpn2Spin();
uint8_t PentSpn2Spin();
} // namespace devilution

2
Source/miniwin/misc_msg.cpp

@ -255,7 +255,7 @@ static int TranslateSdlKey(SDL_Keysym key)
namespace {
int32_t PositionForMouse(short x, short y)
int32_t PositionForMouse(int16_t x, int16_t y)
{
return (((uint16_t)(y & 0xFFFF)) << 16) | (uint16_t)(x & 0xFFFF);
}

6
Source/qol/common.cpp

@ -14,14 +14,14 @@
namespace devilution {
char *PrintWithSeparator(char *out, long long n)
char *PrintWithSeparator(char *out, int64_t n)
{
if (n < 1000) {
return out + sprintf(out, "%lld", n);
return out + sprintf(out, "%ld", n);
}
char *append = PrintWithSeparator(out, n / 1000);
return append + sprintf(append, ",%03lld", n % 1000);
return append + sprintf(append, ",%03ld", n % 1000);
}
void FreeQol()

2
Source/qol/common.h

@ -17,7 +17,7 @@ struct Surface;
* @param n Number to print
* @return Address of first character after printed number
*/
char *PrintWithSeparator(char *out, long long n);
char *PrintWithSeparator(char *out, int64_t n);
void FreeQol();
void InitQol();

4
Source/qol/xpbar.cpp

@ -80,7 +80,7 @@ void DrawXPBar(const Surface &out)
DrawArt(out, backX, backY, &xpbarArt);
const int charLevel = player._pLevel;
const int8_t charLevel = player._pLevel;
if (charLevel == MAXCHARLEVEL - 1) {
// Draw a nice golden bar for max level characters.
@ -123,7 +123,7 @@ bool CheckXPBarInfo()
const auto &player = Players[MyPlayerId];
const int charLevel = player._pLevel;
const int8_t charLevel = player._pLevel;
strcpy(tempstr, fmt::format(_("Level {:d}"), charLevel).c_str());
AddPanelString(tempstr);

26
Source/storm/storm.h

@ -159,32 +159,6 @@ bool SNetGetGameInfo(game_info type, void *dst, unsigned int length);
bool SNetGetTurnsInTransit(
DWORD *turns);
// Network provider structures
typedef struct _client_info {
DWORD dwSize; // 60
char *pszName;
char *pszVersion;
DWORD dwProduct;
DWORD dwVerbyte;
DWORD dwUnk5;
DWORD dwMaxPlayers;
DWORD dwUnk7;
DWORD dwUnk8;
DWORD dwUnk9;
DWORD dwUnk10; // 0xFF
char *pszCdKey;
char *pszCdOwner;
DWORD dwIsShareware;
DWORD dwLangId;
} client_info;
typedef struct _user_info {
DWORD dwSize; // 16
char *pszPlayerName;
char *pszUnknown;
DWORD dwUnknown;
} user_info;
bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid);
/* SNetLeaveGame @ 119

2
Source/storm/storm_net.cpp

@ -143,7 +143,7 @@ bool SNetInitializeProvider(uint32_t provider, struct GameData *gameData)
#ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif
dvlnet_inst = net::abstract_net::make_net(provider);
dvlnet_inst = net::abstract_net::MakeNet(provider);
return mainmenu_select_hero_dialog(gameData);
}

2
Source/storm/storm_svid.cpp

@ -179,7 +179,7 @@ bool SVidPlayBegin(const char *filename, int flags)
if (enableAudio && depth[0] != 0) {
sound_stop(); // Stop in-progress music and sound effects
smk_enable_audio(SVidSMK, 0, enableAudio ? 1 : 0);
smk_enable_audio(SVidSMK, 0, 1);
SVidAudioDepth = depth[0];
auto decoder = std::make_unique<PushAulibDecoder>(channels[0], rate[0]);
SVidAudioDecoder = decoder.get();

Loading…
Cancel
Save