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 devilution {
namespace net { 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 #ifdef NONET
return std::make_unique<loopback>(); return std::make_unique<loopback>();

2
Source/dvlnet/abstract_net.h

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

12
Source/dvlnet/base.h

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

60
Source/dvlnet/base_protocol.h

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

22
Source/dvlnet/frame_queue.cpp

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

12
Source/dvlnet/frame_queue.h

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

26
Source/dvlnet/packet.cpp

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

34
Source/dvlnet/packet.h

@ -88,17 +88,17 @@ public:
packet(const key_t &k) packet(const key_t &k)
: key(k) {}; : key(k) {};
const buffer_t &data(); const buffer_t &Data();
packet_type type(); packet_type Type();
plr_t src() const; plr_t Source() const;
plr_t dest() const; plr_t Destination() const;
const buffer_t &message(); const buffer_t &Message();
turn_t turn(); turn_t Turn();
cookie_t cookie(); cookie_t Cookie();
plr_t newplr(); plr_t NewPlayer();
const buffer_t &info(); const buffer_t &Info();
leaveinfo_t leaveinfo(); leaveinfo_t LeaveInfo();
}; };
template <class P> template <class P>
@ -111,11 +111,11 @@ public:
class packet_in : public packet_proc<packet_in> { class packet_in : public packet_proc<packet_in> {
public: public:
using packet_proc<packet_in>::packet_proc; using packet_proc<packet_in>::packet_proc;
void create(buffer_t buf); void Create(buffer_t buf);
void process_element(buffer_t &x); void process_element(buffer_t &x);
template <class T> template <class T>
void process_element(T &x); void process_element(T &x);
void decrypt(); void Decrypt();
}; };
class packet_out : public packet_proc<packet_out> { class packet_out : public packet_proc<packet_out> {
@ -132,7 +132,7 @@ public:
static const unsigned char *begin(const T &x); static const unsigned char *begin(const T &x);
template <class T> template <class T>
static const unsigned char *end(const T &x); static const unsigned char *end(const T &x);
void encrypt(); void Encrypt();
}; };
template <class P> template <class P>
@ -343,8 +343,8 @@ public:
inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf) inline std::unique_ptr<packet> packet_factory::make_packet(buffer_t buf)
{ {
auto ret = std::make_unique<packet_in>(key); auto ret = std::make_unique<packet_in>(key);
ret->create(std::move(buf)); ret->Create(std::move(buf));
ret->decrypt(); ret->Decrypt();
return ret; return ret;
} }
@ -353,7 +353,7 @@ std::unique_ptr<packet> packet_factory::make_packet(Args... args)
{ {
auto ret = std::make_unique<packet_out>(key); auto ret = std::make_unique<packet_out>(key);
ret->create<t>(args...); ret->create<t>(args...);
ret->encrypt(); ret->Encrypt();
return ret; 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) 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; return true;
} }
@ -151,7 +151,7 @@ bool protocol_zt::recv_peer(const endpoint &peer)
while (true) { while (true) {
auto len = lwip_recv(peer_list[peer].fd, buf, sizeof(buf), 0); auto len = lwip_recv(peer_list[peer].fd, buf, sizeof(buf), 0);
if (len >= 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 { } else {
return errno == EAGAIN || errno == EWOULDBLOCK; return errno == EAGAIN || errno == EWOULDBLOCK;
} }
@ -233,9 +233,9 @@ bool protocol_zt::recv(endpoint &peer, buffer_t &data)
} }
for (auto &p : peer_list) { for (auto &p : peer_list) {
if (p.second.recv_queue.packet_ready()) { if (p.second.recv_queue.PacketReady()) {
peer = p.first; peer = p.first;
data = p.second.recv_queue.read_packet(); data = p.second.recv_queue.ReadPacket();
return true; return true;
} }
} }

28
Source/dvlnet/tcp_client.cpp

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

6
Source/dvlnet/tcp_client.h

@ -38,9 +38,9 @@ private:
asio::ip::tcp::socket sock = asio::ip::tcp::socket(ioc); asio::ip::tcp::socket sock = asio::ip::tcp::socket(ioc);
std::unique_ptr<tcp_server> local_server; // must be declared *after* 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 HandleReceive(const asio::error_code &error, size_t bytesRead);
void start_recv(); void StartReceive();
void handle_send(const asio::error_code &error, size_t bytes_sent); void HandleSend(const asio::error_code &error, size_t bytesSent);
}; };
} // namespace net } // 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 addr = asio::ip::address::from_string(bindaddr);
auto ep = asio::ip::tcp::endpoint(addr, port); auto ep = asio::ip::tcp::endpoint(addr, port);
acceptor = std::make_unique<asio::ip::tcp::acceptor>(ioc, ep, true); 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(); auto addr = acceptor->local_endpoint().address();
if (addr.is_unspecified()) { if (addr.is_unspecified()) {
@ -37,12 +37,12 @@ std::string tcp_server::localhost_self()
return addr.to_string(); return addr.to_string();
} }
tcp_server::scc tcp_server::make_connection() tcp_server::scc tcp_server::MakeConnection()
{ {
return std::make_shared<client_connection>(ioc); 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) for (plr_t i = 0; i < MAX_PLRS; ++i)
if (!connections[i]) if (!connections[i])
@ -50,7 +50,7 @@ plr_t tcp_server::next_free()
return PLR_BROADCAST; return PLR_BROADCAST;
} }
bool tcp_server::empty() bool tcp_server::Empty()
{ {
for (plr_t i = 0; i < MAX_PLRS; ++i) for (plr_t i = 0; i < MAX_PLRS; ++i)
if (connections[i]) if (connections[i])
@ -58,155 +58,155 @@ bool tcp_server::empty()
return true; return true;
} }
void tcp_server::start_recv(const scc &con) void tcp_server::StartReceive(const scc &con)
{ {
con->socket.async_receive( con->socket.async_receive(
asio::buffer(con->recv_buffer), 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) size_t bytesRead)
{ {
if (ec || bytesRead == 0) { if (ec || bytesRead == 0) {
drop_connection(con); DropConnection(con);
return; return;
} }
con->recv_buffer.resize(bytesRead); 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); con->recv_buffer.resize(frame_queue::max_frame_size);
while (con->recv_queue.packet_ready()) { while (con->recv_queue.PacketReady()) {
try { 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) { if (con->plr == PLR_BROADCAST) {
handle_recv_newplr(con, *pkt); HandleReceiveNewPlayer(con, *pkt);
} else { } else {
con->timeout = timeout_active; con->timeout = timeout_active;
handle_recv_packet(*pkt); HandleReceivePacket(*pkt);
} }
} catch (dvlnet_exception &e) { } catch (dvlnet_exception &e) {
Log("Network error: {}", e.what()); Log("Network error: {}", e.what());
drop_connection(con); DropConnection(con);
return; 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, auto pkt = pktfty.make_packet<PT_CONNECT>(PLR_MASTER, PLR_BROADCAST,
con->plr); 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) if (newplr == PLR_BROADCAST)
throw server_exception(); throw server_exception();
if (empty()) if (Empty())
game_init_info = pkt.info(); game_init_info = pkt.Info();
auto reply = pktfty.make_packet<PT_JOIN_ACCEPT>(PLR_MASTER, PLR_BROADCAST, auto reply = pktfty.make_packet<PT_JOIN_ACCEPT>(PLR_MASTER, PLR_BROADCAST,
pkt.cookie(), newplr, pkt.Cookie(), newplr,
game_init_info); game_init_info);
start_send(con, *reply); StartSend(con, *reply);
con->plr = newplr; con->plr = newplr;
connections[newplr] = con; connections[newplr] = con;
con->timeout = timeout_active; 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) for (auto i = 0; i < MAX_PLRS; ++i)
if (i != pkt.src() && connections[i]) if (i != pkt.Source() && connections[i])
start_send(connections[i], pkt); StartSend(connections[i], pkt);
} else { } else {
if (pkt.dest() >= MAX_PLRS) if (pkt.Destination() >= MAX_PLRS)
throw server_exception(); throw server_exception();
if ((pkt.dest() != pkt.src()) && connections[pkt.dest()]) if ((pkt.Destination() != pkt.Source()) && connections[pkt.Destination()])
start_send(connections[pkt.dest()], pkt); 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); auto buf = asio::buffer(*frame);
asio::async_write(con->socket, buf, asio::async_write(con->socket, buf,
[this, con, frame](const asio::error_code &ec, size_t bytesSent) { [this, con, frame](const asio::error_code &ec, size_t bytesSent) {
handle_send(con, ec, bytesSent); HandleSend(con, ec, bytesSent);
delete frame; 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) size_t bytesSent)
{ {
// empty for now // empty for now
} }
void tcp_server::start_accept() void tcp_server::StartAccept()
{ {
auto nextcon = make_connection(); auto nextcon = MakeConnection();
acceptor->async_accept( acceptor->async_accept(
nextcon->socket, 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) if (ec)
return; return;
if (next_free() == PLR_BROADCAST) { if (NextFree() == PLR_BROADCAST) {
drop_connection(con); DropConnection(con);
} else { } else {
asio::ip::tcp::no_delay option(true); asio::ip::tcp::no_delay option(true);
con->socket.set_option(option); con->socket.set_option(option);
con->timeout = timeout_connect; con->timeout = timeout_connect;
start_recv(con); StartReceive(con);
start_timeout(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.expires_after(std::chrono::seconds(1));
con->timer.async_wait( 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) { if (ec) {
drop_connection(con); DropConnection(con);
return; return;
} }
if (con->timeout > 0) if (con->timeout > 0)
con->timeout -= 1; con->timeout -= 1;
if (con->timeout <= 0) { if (con->timeout <= 0) {
con->timeout = 0; con->timeout = 0;
drop_connection(con); DropConnection(con);
return; 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) { if (con->plr != PLR_BROADCAST) {
auto pkt = pktfty.make_packet<PT_DISCONNECT>(PLR_MASTER, PLR_BROADCAST, auto pkt = pktfty.make_packet<PT_DISCONNECT>(PLR_MASTER, PLR_BROADCAST,
con->plr, LEAVE_DROP); con->plr, LEAVE_DROP);
connections[con->plr] = nullptr; connections[con->plr] = nullptr;
send_packet(*pkt); SendPacket(*pkt);
// TODO: investigate if it is really ok for the server to // TODO: investigate if it is really ok for the server to
// drop a client directly. // drop a client directly.
} }
@ -214,7 +214,7 @@ void tcp_server::drop_connection(const scc &con)
con->socket.close(); con->socket.close();
} }
void tcp_server::close() void tcp_server::Close()
{ {
acceptor->close(); acceptor->close();
} }

36
Source/dvlnet/tcp_server.h

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

8
Source/engine/animationinfo.cpp

@ -73,7 +73,7 @@ float AnimationInfo::GetAnimationProgress() const
return fAnimationFraction; 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) { 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. // 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; ticksPerFrame = 1;
} }
this->pCelSprite = pCelSprite; this->pCelSprite = celSprite;
NumberOfFrames = numberOfFrames; NumberOfFrames = numberOfFrames;
CurrentFrame = 1 + numSkippedFrames; CurrentFrame = 1 + numSkippedFrames;
TickCounterOfCurrentFrame = 0; 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) { 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 // 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; RelevantFramesForDistributing = 0;
TickModifier = 0.0F; TickModifier = 0.0F;
} }
this->pCelSprite = pCelSprite; this->pCelSprite = celSprite;
TicksPerFrame = delayLen; TicksPerFrame = delayLen;
} }

8
Source/engine/animationinfo.h

@ -74,22 +74,22 @@ public:
/** /**
* @brief Sets the new Animation with all relevant information for rendering * @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 numberOfFrames Number of Frames in Animation
* @param ticksPerFrame How many game ticks are needed to advance one Animation Frame * @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 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 numSkippedFrames Number of Frames that will be skipped (for example with modifier "faster attack")
* @param distributeFramesBeforeFrame Distribute the numSkippedFrames only before this frame * @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. * @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 numberOfFrames Number of Frames in Animation
* @param delayLen Delay after each Animation sequence * @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) * @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) void CelClippedBlitLightTransTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{ {
int nDataSize; int nDataSize;
@ -682,13 +675,6 @@ void CelClippedBlitLightTransTo(const Surface &out, Point position, const CelSpr
CelBlitSafeTo(out, position, pRLEBytes, nDataSize, cel.Width(frame)); 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) void CelDrawUnsafeTo(const Surface &out, Point position, const CelSprite &cel, int frame)
{ {
int nDataSize; 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); 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 * @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 * @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 * @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; GameFontTables size = GameFontSmall;
if ((flags & UIS_MED) != 0) if ((flags & UIS_MED) != 0)
@ -312,7 +312,7 @@ int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint
if (lineHeight == -1) if (lineHeight == -1)
lineHeight = LineHeights[size]; lineHeight = LineHeights[size];
unsigned i = 0; uint16_t i = 0;
for (; i < textLength; i++) { for (; i < textLength; i++) {
uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]]; uint8_t frame = FontFrame[size][FontIndex[static_cast<uint8_t>(text[i])]];
int symbolWidth = FontKern[size][frame]; int symbolWidth = FontKern[size][frame];
@ -346,7 +346,7 @@ int DrawString(const Surface &out, const char *text, const Rectangle &rect, uint
return i; return i;
} }
int PentSpn2Spin() uint8_t PentSpn2Spin()
{ {
return (SDL_GetTicks() / 50) % 8 + 1; 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). * @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. * @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. * @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). * @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). * @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); return DrawString(out, text, { position, { out.w() - position.x, 0 } }, flags, spacing, lineHeight, drawTextCursor);
} }
int PentSpn2Spin(); uint8_t PentSpn2Spin();
} // namespace devilution } // namespace devilution

2
Source/miniwin/misc_msg.cpp

@ -255,7 +255,7 @@ static int TranslateSdlKey(SDL_Keysym key)
namespace { 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); return (((uint16_t)(y & 0xFFFF)) << 16) | (uint16_t)(x & 0xFFFF);
} }

6
Source/qol/common.cpp

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

2
Source/qol/common.h

@ -17,7 +17,7 @@ struct Surface;
* @param n Number to print * @param n Number to print
* @return Address of first character after printed number * @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 FreeQol();
void InitQol(); void InitQol();

4
Source/qol/xpbar.cpp

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

26
Source/storm/storm.h

@ -159,32 +159,6 @@ bool SNetGetGameInfo(game_info type, void *dst, unsigned int length);
bool SNetGetTurnsInTransit( bool SNetGetTurnsInTransit(
DWORD *turns); 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); bool SNetJoinGame(char *gameName, char *gamePassword, int *playerid);
/* SNetLeaveGame @ 119 /* SNetLeaveGame @ 119

2
Source/storm/storm_net.cpp

@ -143,7 +143,7 @@ bool SNetInitializeProvider(uint32_t provider, struct GameData *gameData)
#ifndef NONET #ifndef NONET
std::lock_guard<SdlMutex> lg(storm_net_mutex); std::lock_guard<SdlMutex> lg(storm_net_mutex);
#endif #endif
dvlnet_inst = net::abstract_net::make_net(provider); dvlnet_inst = net::abstract_net::MakeNet(provider);
return mainmenu_select_hero_dialog(gameData); 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) { if (enableAudio && depth[0] != 0) {
sound_stop(); // Stop in-progress music and sound effects 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]; SVidAudioDepth = depth[0];
auto decoder = std::make_unique<PushAulibDecoder>(channels[0], rate[0]); auto decoder = std::make_unique<PushAulibDecoder>(channels[0], rate[0]);
SVidAudioDecoder = decoder.get(); SVidAudioDecoder = decoder.get();

Loading…
Cancel
Save