Skip to content

Commit 9affb1a

Browse files
StephenCWillsAJenbo
authored andcommitted
Process network packets independent of the game's tick rate
1 parent bf2a8a6 commit 9affb1a

File tree

12 files changed

+35
-8
lines changed

12 files changed

+35
-8
lines changed

Source/diablo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,14 +917,15 @@ void RunGameLoop(interface_mode uMsg)
917917
if (!runGameLoop) {
918918
if (processInput)
919919
ProcessInput();
920+
DvlNet_ProcessNetworkPackets();
920921
if (!drawGame)
921922
continue;
922923
RedrawViewport();
923924
DrawAndBlit();
924925
continue;
925926
}
926927

927-
multi_process_network_packets();
928+
ProcessGameMessagePackets();
928929
if (game_loop(gbGameLoopStartup))
929930
diablo_color_cyc_logic();
930931
gbGameLoopStartup = false;

Source/dvlnet/abstract_net.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class abstract_net {
3434

3535
virtual std::string make_default_gamename() = 0;
3636

37+
virtual void process_network_packets()
38+
{
39+
}
40+
3741
virtual void setup_password(std::string passwd)
3842
{
3943
}

Source/dvlnet/base.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
namespace devilution {
1919
namespace net {
2020

21+
void base::process_network_packets()
22+
{
23+
tl::expected<void, PacketError> result = poll();
24+
if (!result.has_value()) {
25+
LogVerbose("Error polling network: {}", result.error().what());
26+
}
27+
}
28+
2129
void base::setup_gameinfo(buffer_t info)
2230
{
2331
game_init_info = std::move(info);
@@ -233,7 +241,7 @@ bool base::SNetReceiveMessage(uint8_t *sender, void **data, size_t *size)
233241
SendEchoRequest(i);
234242
lastEchoTime = now;
235243
}
236-
poll();
244+
process_network_packets();
237245
if (message_queue.empty())
238246
return false;
239247
message_last = message_queue.front();
@@ -292,7 +300,7 @@ bool base::AllTurnsArrived()
292300

293301
bool base::SNetReceiveTurns(char **data, size_t *size, uint32_t *status)
294302
{
295-
poll();
303+
process_network_packets();
296304

297305
for (size_t i = 0; i < Players.size(); ++i) {
298306
status[i] = 0;
@@ -528,7 +536,7 @@ plr_t base::GetOwner()
528536

529537
bool base::SNetGetOwnerTurnsWaiting(uint32_t *turns)
530538
{
531-
poll();
539+
process_network_packets();
532540

533541
const plr_t owner = GetOwner();
534542
const PlayerState &playerState = playerStateTable_[owner];

Source/dvlnet/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class base : public abstract_net {
3434
virtual tl::expected<void, PacketError> send(packet &pkt) = 0;
3535
virtual void DisconnectNet(plr_t plr);
3636

37+
void process_network_packets() override;
38+
3739
void setup_gameinfo(buffer_t info) override;
3840

3941
void setup_password(std::string pw) override;

Source/dvlnet/cdwrap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ int cdwrap::join(std::string_view addrstr)
3030
return dvlnet_wrap->join(addrstr);
3131
}
3232

33+
void cdwrap::process_network_packets()
34+
{
35+
dvlnet_wrap->process_network_packets();
36+
}
37+
3338
void cdwrap::setup_gameinfo(buffer_t info)
3439
{
3540
game_init_info = std::move(info);

Source/dvlnet/cdwrap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class cdwrap : public abstract_net {
4545
bool SNetDropPlayer(int playerid, net::leaveinfo_t flags) override;
4646
bool SNetGetOwnerTurnsWaiting(uint32_t *turns) override;
4747
bool SNetGetTurnsInTransit(uint32_t *turns) override;
48+
void process_network_packets() override;
4849
void setup_gameinfo(buffer_t info) override;
4950
std::string make_default_gamename() override;
5051
bool send_info_request() override;

Source/dvlnet/tcp_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ void tcp_client::DisconnectNet(plr_t plr)
240240
bool tcp_client::SNetLeaveGame(net::leaveinfo_t type)
241241
{
242242
auto ret = base::SNetLeaveGame(type);
243-
poll();
243+
process_network_packets();
244244
if (local_server != nullptr)
245245
local_server->Close();
246246
sock.close();

Source/msg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ int WaitForTurns()
509509
return 0;
510510
sgbDeltaChunks++;
511511
}
512-
multi_process_network_packets();
512+
ProcessGameMessagePackets();
513513
nthread_send_and_recv_turn(0, 0);
514514
if (nthread_has_500ms_passed()) {
515515
nthread_recv_turns();

Source/multi.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ bool multi_handle_delta()
684684
return true;
685685
}
686686

687-
void multi_process_network_packets()
687+
void ProcessGameMessagePackets()
688688
{
689689
ClearPlayerLeftState();
690690
ProcessTmsgs();

Source/multi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void multi_net_ping();
8181
* @return Always true for singleplayer
8282
*/
8383
bool multi_handle_delta();
84-
void multi_process_network_packets();
84+
void ProcessGameMessagePackets();
8585
void multi_send_zero_packet(uint8_t pnum, _cmd_id bCmd, const std::byte *data, size_t size);
8686
void NetClose();
8787
bool NetInit(bool bSinglePlayer);

0 commit comments

Comments
 (0)