• R/O
  • SSH

zandronum-sandbox-stable: Commit


Commit MetaInfo

Revision4f7d2f8c0d5582cd590793223296fd8065c7b0b7 (tree)
Time2023-03-11 02:10:13
AuthorAdam Kaminski <kaminskiadam9@gmai...>
CommiterAdam Kaminski

Log Message

Moved NetIDList and its member functions into "networkshared.h".

Change Summary

Incremental Difference

diff -r 5e482a1b887e -r 4f7d2f8c0d55 src/actor.h
--- a/src/actor.h Fri Mar 10 11:56:38 2023 -0500
+++ b/src/actor.h Fri Mar 10 12:10:13 2023 -0500
@@ -39,6 +39,8 @@
3939 #include "s_sound.h"
4040 #include "memarena.h"
4141 #include "g_level.h"
42+// [AK] New #includes.
43+#include "networkshared.h"
4244
4345 struct subsector_t;
4446 //
@@ -1342,89 +1344,14 @@
13421344
13431345 #define S_FREETARGMOBJ 1
13441346
1345-//==========================================================================
1346-//
1347-// NetIDList
1348-//
1349-// Manages IDs to reference a certain type of objects over the network.
1350-// Since it still mimics the old Actor ID mechanism, 0 is never assigned as
1351-// ID.
1352-//
1353-// @author Benjamin Berkels
1347+//*****************************************************************************
13541348 //
1355-//==========================================================================
1356-
1357-// [AK] Added a trait template struct to identify and count objects used by NetIDList.
1358-template <typename Type>
1359-struct NetIDTrait
1360-{
1361- // The name of the object.
1362- static const char *pszName;
1363-
1364- // Supposed to count all defined "objects" (with network IDs) when an error is thrown
1365- // because there's no more free network IDs.
1366- static void count( );
1367-};
1368-
1369-template <typename Type, int NumSlots>
1370-class NetIDList
1371-{
1372-private:
1373- // List of all possible network ID's for an object. Slot is true if it available for use.
1374- typedef struct
1375- {
1376- // Is this node occupied, or free to be used by a new object?
1377- bool bFree;
1378-
1379- // If this node is occupied, this is the object occupying it.
1380- Type *pObject;
1381-
1382- } IDNODE_t;
1349+// [AK] ActorNetIDList
1350+//
1351+// A template specialization of NetIDList specifically for AActor.
1352+//
1353+//*****************************************************************************
13831354
1384- IDNODE_t _entries[NumSlots];
1385- ULONG _firstFreeID;
1386-
1387- inline bool isIndexValid ( const LONG lNetID ) const
1388- {
1389- return ( lNetID >= 0 ) && ( lNetID < NumSlots );
1390- }
1391-public:
1392- void clear ( );
1393-
1394- NetIDList ( )
1395- {
1396- clear ( );
1397- }
1398-
1399- void useID ( const LONG lNetID, Type *pObject );
1400-
1401- void freeID ( const LONG lNetID )
1402- {
1403- if ( isIndexValid ( lNetID ) )
1404- {
1405- _entries[lNetID].bFree = true;
1406- _entries[lNetID].pObject = NULL;
1407- }
1408- }
1409-
1410- ULONG getNewID ( );
1411-
1412- // [AK] Returns the number of possible network IDs.
1413- ULONG getMaxID ( ) const { return NumSlots; }
1414-
1415- Type* findPointerByID ( const LONG lNetID ) const
1416- {
1417- if ( isIndexValid ( lNetID ) == false )
1418- return ( NULL );
1419-
1420- if (( _entries[lNetID].bFree == false ) && ( _entries[lNetID].pObject ))
1421- return ( _entries[lNetID].pObject );
1422-
1423- return ( NULL );
1424- }
1425-};
1426-
1427-// [AK] Template specialization of NetIDList, specifically for AActor.
14281355 class ActorNetIDList : public NetIDList<AActor, SHRT_MAX + 1>
14291356 {
14301357 public:
diff -r 5e482a1b887e -r 4f7d2f8c0d55 src/networkshared.h
--- a/src/networkshared.h Fri Mar 10 11:56:38 2023 -0500
+++ b/src/networkshared.h Fri Mar 10 12:10:13 2023 -0500
@@ -590,4 +590,136 @@
590590 }
591591 };
592592
593+//==========================================================================
594+//
595+// NetIDList
596+//
597+// Manages IDs to reference a certain type of objects over the network.
598+// Since it still mimics the old Actor ID mechanism, 0 is never assigned as
599+// ID.
600+//
601+// @author Benjamin Berkels, Adam Kaminski
602+//
603+//==========================================================================
604+
605+// [AK] Added a trait template struct to identify and count objects used by NetIDList.
606+template <typename Type>
607+struct NetIDTrait
608+{
609+ // The name of the object.
610+ static const char *pszName;
611+
612+ // Supposed to count all defined "objects" (with network IDs) when an error is thrown
613+ // because there's no more free network IDs.
614+ static void count( );
615+};
616+
617+template <typename Type, int NumSlots>
618+class NetIDList
619+{
620+private:
621+ // List of all possible network ID's for an object. Slot is true if it available for use.
622+ typedef struct
623+ {
624+ // Is this node occupied, or free to be used by a new object?
625+ bool bFree;
626+
627+ // If this node is occupied, this is the object occupying it.
628+ Type *pObject;
629+
630+ } IDNODE_t;
631+
632+ IDNODE_t _entries[NumSlots];
633+ ULONG _firstFreeID;
634+
635+ inline bool isIndexValid ( const LONG lNetID ) const
636+ {
637+ return ( lNetID >= 0 ) && ( lNetID < NumSlots );
638+ }
639+
640+public:
641+ NetIDList ( )
642+ {
643+ clear ( );
644+ }
645+
646+ void clear( )
647+ {
648+ for ( ULONG ulIdx = 0; ulIdx < NumSlots; ulIdx++ )
649+ freeID( ulIdx );
650+
651+ _firstFreeID = 1;
652+ }
653+
654+ void useID ( const LONG lNetID, Type *pObject )
655+ {
656+ if ( isIndexValid ( lNetID ) )
657+ {
658+ if ( ( _entries[lNetID].bFree == false ) && ( _entries[lNetID].pObject != pObject ) )
659+ SERVER_PrintWarning ( "NetIDList<Type, NumSlots, ErrorIsFatal>::useID is using an already used ID.\n" );
660+
661+ _entries[lNetID].bFree = false;
662+ _entries[lNetID].pObject = pObject;
663+ }
664+ }
665+
666+ void freeID ( const LONG lNetID )
667+ {
668+ if ( isIndexValid ( lNetID ) )
669+ {
670+ _entries[lNetID].bFree = true;
671+ _entries[lNetID].pObject = NULL;
672+ }
673+ }
674+
675+ ULONG getNewID ( )
676+ {
677+ // Object's network ID is the first availible net ID.
678+ ULONG ulID = _firstFreeID;
679+
680+ do
681+ {
682+ _firstFreeID++;
683+ if ( _firstFreeID >= NumSlots )
684+ _firstFreeID = 1;
685+
686+ if ( _firstFreeID == ulID )
687+ {
688+ // [BB] In case there is no free netID, the server has to abort the current game.
689+ if ( NETWORK_GetState( ) == NETSTATE_SERVER )
690+ {
691+ FString errorMessage;
692+ errorMessage.Format ( "Network ID limit reached (>=%d %ss)", NumSlots - 1, NetIDTrait<Type>::pszName );
693+
694+ // [BB] We can only have (NumSlots-2) objects with netID, because ID zero is reserved and
695+ // we already check that a new ID for the next object is available when assign a net ID.
696+ Printf ( "NetIDList<Type, NumSlots, ErrorIsFatal>: %s\n", errorMessage.GetChars( ) );
697+ NetIDTrait<Type>::count ( );
698+ I_Error ( "%s!\n", errorMessage.GetChars( ) );
699+ }
700+
701+ return ( 0 );
702+ }
703+ } while ( _entries[_firstFreeID].bFree == false );
704+
705+ return ( ulID );
706+ }
707+
708+ ULONG getMaxID ( ) const
709+ {
710+ return NumSlots;
711+ }
712+
713+ Type* findPointerByID ( const LONG lNetID ) const
714+ {
715+ if ( isIndexValid ( lNetID ) == false )
716+ return ( NULL );
717+
718+ if (( _entries[lNetID].bFree == false ) && ( _entries[lNetID].pObject ))
719+ return ( _entries[lNetID].pObject );
720+
721+ return ( NULL );
722+ }
723+};
724+
593725 #endif // __NETWORKSHARED_H__
diff -r 5e482a1b887e -r 4f7d2f8c0d55 src/p_mobj.cpp
--- a/src/p_mobj.cpp Fri Mar 10 11:56:38 2023 -0500
+++ b/src/p_mobj.cpp Fri Mar 10 12:10:13 2023 -0500
@@ -4746,68 +4746,6 @@
47464746 return false; // we did the splash ourselves
47474747 }
47484748
4749-//*****************************************************************************
4750-//
4751-template <typename Type, int NumSlots>
4752-void NetIDList<Type, NumSlots>::clear( void )
4753-{
4754- for ( ULONG ulIdx = 0; ulIdx < NumSlots; ulIdx++ )
4755- freeID ( ulIdx );
4756-
4757- _firstFreeID = 1;
4758-}
4759-
4760-//*****************************************************************************
4761-//
4762-template <typename Type, int NumSlots>
4763-void NetIDList<Type, NumSlots>::useID ( const LONG lNetID, Type *pObject )
4764-{
4765- if ( isIndexValid ( lNetID ) )
4766- {
4767- if ( ( _entries[lNetID].bFree == false ) && ( _entries[lNetID].pObject != pObject ) )
4768- SERVER_PrintWarning ( "NetIDList<Type, NumSlots, ErrorIsFatal>::useID is using an already used ID.\n" );
4769-
4770- _entries[lNetID].bFree = false;
4771- _entries[lNetID].pObject = pObject;
4772- }
4773-}
4774-
4775-//*****************************************************************************
4776-//
4777-template <typename Type, int NumSlots>
4778-ULONG NetIDList<Type, NumSlots>::getNewID( void )
4779-{
4780- // Object's network ID is the first availible net ID.
4781- ULONG ulID = _firstFreeID;
4782-
4783- do
4784- {
4785- _firstFreeID++;
4786- if ( _firstFreeID >= NumSlots )
4787- _firstFreeID = 1;
4788-
4789- if ( _firstFreeID == ulID )
4790- {
4791- // [BB] In case there is no free netID, the server has to abort the current game.
4792- if ( NETWORK_GetState( ) == NETSTATE_SERVER )
4793- {
4794- FString errorMessage;
4795- errorMessage.Format ( "Network ID limit reached (>=%d %ss)", NumSlots - 1, NetIDTrait<Type>::pszName );
4796-
4797- // [BB] We can only have (NumSlots-2) objects with netID, because ID zero is reserved and
4798- // we already check that a new ID for the next object is available when assign a net ID.
4799- Printf ( "NetIDList<Type, NumSlots, ErrorIsFatal>: %s\n", errorMessage.GetChars( ) );
4800- NetIDTrait<Type>::count ( );
4801- I_Error ( "%s!\n", errorMessage.GetChars( ) );
4802- }
4803-
4804- return ( 0 );
4805- }
4806- } while ( _entries[_firstFreeID].bFree == false );
4807-
4808- return ( ulID );
4809-}
4810-
48114749 //==========================================================================
48124750 //
48134751 // [BB/AK] NetIDTrait<AActor>::count
Show on old repository browser