From dea95c7339948e6cc35c95dc1ade8d70f796d946 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Wed, 26 Mar 2025 19:47:40 +0100 Subject: [PATCH] Reduce transitive includes by moving a class --- src/client/particles.h | 1 + src/irrlichttypes.h | 5 ---- src/mapgen/mg_biome.h | 1 + src/mapsector.h | 1 + src/network/mtp/impl.h | 2 +- src/network/mtp/internal.h | 41 ++++++++++++++++++++---------- src/network/networkpacket.h | 2 ++ src/network/networkprotocol.h | 3 +-- src/nodedef.h | 1 + src/unittest/test_address.cpp | 1 + src/unittest/test_eventmanager.cpp | 3 ++- src/util/pointer.h | 19 ++------------ 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/client/particles.h b/src/client/particles.h index 72294a5522..fe7d684752 100644 --- a/src/client/particles.h +++ b/src/client/particles.h @@ -11,6 +11,7 @@ #include "SMeshBuffer.h" #include +#include #include #include #include "../particles.h" diff --git a/src/irrlichttypes.h b/src/irrlichttypes.h index 0994bbd94b..0474786a14 100644 --- a/src/irrlichttypes.h +++ b/src/irrlichttypes.h @@ -4,12 +4,7 @@ #pragma once -/* - * IrrlichtMt already includes stdint.h in irrTypes.h. This works everywhere - * we need it to (including recent MSVC), so should be fine here too. - */ #include - #include using namespace irr; diff --git a/src/mapgen/mg_biome.h b/src/mapgen/mg_biome.h index 8adce5db67..37e09136ef 100644 --- a/src/mapgen/mg_biome.h +++ b/src/mapgen/mg_biome.h @@ -8,6 +8,7 @@ #include "objdef.h" #include "nodedef.h" #include "noise.h" +#include "debug.h" // FATAL_ERROR_IF class Server; class Settings; diff --git a/src/mapsector.h b/src/mapsector.h index bc5a2a7314..d977bc63c8 100644 --- a/src/mapsector.h +++ b/src/mapsector.h @@ -8,6 +8,7 @@ #include "irr_v2d.h" #include "mapblock.h" #include +#include #include #include diff --git a/src/network/mtp/impl.h b/src/network/mtp/impl.h index a88012b222..3f81fe27b9 100644 --- a/src/network/mtp/impl.h +++ b/src/network/mtp/impl.h @@ -14,6 +14,7 @@ #include "network/networkprotocol.h" #include #include +#include #include namespace con @@ -24,7 +25,6 @@ class ConnectionSendThread; class Peer; -// FIXME: Peer refcounting should generally be replaced by std::shared_ptr class PeerHelper { public: diff --git a/src/network/mtp/internal.h b/src/network/mtp/internal.h index e3ad39bdee..dc3ad55d7f 100644 --- a/src/network/mtp/internal.h +++ b/src/network/mtp/internal.h @@ -33,7 +33,7 @@ channel: /* Packet types: -CONTROL: This is a packet used by the protocol. +PACKET_TYPE_CONTROL: This is a packet used by the protocol. - When this is processed, nothing is handed to the user. Header (2 byte): [0] u8 type @@ -48,25 +48,18 @@ controltype and data description: packet to get a reply CONTROLTYPE_DISCO */ -enum ControlType : u8 { - CONTROLTYPE_ACK = 0, - CONTROLTYPE_SET_PEER_ID = 1, - CONTROLTYPE_PING = 2, - CONTROLTYPE_DISCO = 3, -}; /* -ORIGINAL: This is a plain packet with no control and no error +PACKET_TYPE_ORIGINAL: This is a plain packet with no control and no error checking at all. - When this is processed, it is directly handed to the user. Header (1 byte): [0] u8 type */ -//#define TYPE_ORIGINAL 1 #define ORIGINAL_HEADER_SIZE 1 /* -SPLIT: These are sequences of packets forming one bigger piece of +PACKET_TYPE_SPLIT: These are sequences of packets forming one bigger piece of data. - When processed and all the packet_nums 0...packet_count-1 are present (this should be buffered), the resulting data shall be @@ -80,10 +73,9 @@ data. [3] u16 chunk_count [5] u16 chunk_num */ -//#define TYPE_SPLIT 2 /* -RELIABLE: Delivery of all RELIABLE packets shall be forced by ACKs, +PACKET_TYPE_RELIABLE: Delivery of all RELIABLE packets shall be forced by ACKs, and they shall be delivered in the same order as sent. This is done with a buffer in the receiving and transmitting end. - When this is processed, the contents of each packet is recursively @@ -93,15 +85,29 @@ with a buffer in the receiving and transmitting end. [1] u16 seqnum */ -//#define TYPE_RELIABLE 3 #define RELIABLE_HEADER_SIZE 3 #define SEQNUM_INITIAL 65500 #define SEQNUM_MAX 65535 +/****/ + +template +class ConstSharedPtr { +public: + ConstSharedPtr(T *ptr) : ptr(ptr) {} + ConstSharedPtr(const std::shared_ptr &ptr) : ptr(ptr) {} + + const T* get() const noexcept { return ptr.get(); } + const T& operator*() const noexcept { return *ptr.get(); } + const T* operator->() const noexcept { return ptr.get(); } + +private: + std::shared_ptr ptr; +}; + namespace con { - enum PacketType : u8 { PACKET_TYPE_CONTROL = 0, PACKET_TYPE_ORIGINAL = 1, @@ -110,6 +116,13 @@ enum PacketType : u8 { PACKET_TYPE_MAX }; +enum ControlType : u8 { + CONTROLTYPE_ACK = 0, + CONTROLTYPE_SET_PEER_ID = 1, + CONTROLTYPE_PING = 2, + CONTROLTYPE_DISCO = 3, +}; + inline bool seqnum_higher(u16 totest, u16 base) { if (totest > base) diff --git a/src/network/networkpacket.h b/src/network/networkpacket.h index d5e687c68d..107d07cfd4 100644 --- a/src/network/networkpacket.h +++ b/src/network/networkpacket.h @@ -8,6 +8,8 @@ #include "irrlichttypes_bloated.h" #include "networkprotocol.h" #include +#include +#include #include class NetworkPacket diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h index 152534cbec..5ce3f42217 100644 --- a/src/network/networkprotocol.h +++ b/src/network/networkprotocol.h @@ -4,8 +4,7 @@ #pragma once -#include "irrTypes.h" -using namespace irr; +#include "irrlichttypes.h" extern const u16 LATEST_PROTOCOL_VERSION; diff --git a/src/nodedef.h b/src/nodedef.h index 24bb0c4605..71a61896bc 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -7,6 +7,7 @@ #include "irrlichttypes_bloated.h" #include #include +#include // shared_ptr #include #include "mapnode.h" #include "nameidmapping.h" diff --git a/src/unittest/test_address.cpp b/src/unittest/test_address.cpp index 7ae7f85cff..364e82fad6 100644 --- a/src/unittest/test_address.cpp +++ b/src/unittest/test_address.cpp @@ -4,6 +4,7 @@ #include "test.h" +#include #include "log.h" #include "settings.h" #include "network/socket.h" diff --git a/src/unittest/test_eventmanager.cpp b/src/unittest/test_eventmanager.cpp index 0b1d3bbd1c..76019f7305 100644 --- a/src/unittest/test_eventmanager.cpp +++ b/src/unittest/test_eventmanager.cpp @@ -3,6 +3,7 @@ // Copyright (C) 2018 nerzhul, Loic BLOT #include +#include #include "test.h" #include "client/event_manager.h" @@ -94,4 +95,4 @@ void TestEventManager::testRealEventAfterDereg() // Push the new event & ensure we target the default value ev.put(new SimpleTriggerEvent(MtEvent::PLAYER_REGAIN_GROUND)); UASSERT(emt->getTestValue() == 0); -} \ No newline at end of file +} diff --git a/src/util/pointer.h b/src/util/pointer.h index fe90a38662..e260b4a5ca 100644 --- a/src/util/pointer.h +++ b/src/util/pointer.h @@ -5,26 +5,11 @@ #pragma once #include "irrlichttypes.h" -#include "debug.h" // For assert() +#include "util/basic_macros.h" +#include #include -#include // std::shared_ptr #include - -template -class ConstSharedPtr { -public: - ConstSharedPtr(T *ptr) : ptr(ptr) {} - ConstSharedPtr(const std::shared_ptr &ptr) : ptr(ptr) {} - - const T* get() const noexcept { return ptr.get(); } - const T& operator*() const noexcept { return *ptr.get(); } - const T* operator->() const noexcept { return ptr.get(); } - -private: - std::shared_ptr ptr; -}; - template class Buffer {