[5521] | 1 | /*! |
---|
| 2 | * @file network_manager.h |
---|
| 3 | * Main interface for the network module. Manages all the modules |
---|
| 4 | */ |
---|
| 5 | |
---|
[5533] | 6 | /* you will want to add such a a line at your header file also, since it will |
---|
| 7 | prevent c++ from including your code twice*/ |
---|
[6695] | 8 | #ifndef _NETWORK_MANAGER |
---|
[5521] | 9 | #define _NETWORK_MANAGER |
---|
| 10 | |
---|
[5647] | 11 | /* include this file, it contains some default definitions */ |
---|
| 12 | #include "netdefs.h" |
---|
[6695] | 13 | #include "shared_network_data.h" |
---|
[5533] | 14 | |
---|
| 15 | /* include base_object.h since all classes are derived from this one */ |
---|
[5521] | 16 | #include "base_object.h" |
---|
| 17 | |
---|
[5647] | 18 | |
---|
[5572] | 19 | /* forward declarations for the header file (include the header via #include "bla.h" in the source file) */ |
---|
[5566] | 20 | class NetworkStream; |
---|
[5572] | 21 | class Synchronizeable; |
---|
[5996] | 22 | template<typename> |
---|
| 23 | class tList; |
---|
[5521] | 24 | |
---|
[5566] | 25 | /* and here is the class itsself*/ |
---|
[5521] | 26 | class NetworkManager : public BaseObject |
---|
| 27 | { |
---|
| 28 | |
---|
[5996] | 29 | public: |
---|
[5521] | 30 | |
---|
[5996] | 31 | inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager(); |
---|
| 32 | return NetworkManager::singletonRef; } |
---|
[6981] | 33 | virtual ~NetworkManager(); |
---|
[5533] | 34 | |
---|
[5996] | 35 | void initialize(); |
---|
| 36 | void shutdown(); |
---|
[5804] | 37 | |
---|
[7256] | 38 | int establishConnection( const std::string & name, unsigned int port); |
---|
[5996] | 39 | int createServer(unsigned int port); |
---|
[5804] | 40 | |
---|
[5997] | 41 | /** Returns the hostID @return The hostID of the object */ |
---|
[9059] | 42 | inline int getHostID() { return SharedNetworkData::getInstance()->getHostID(); } |
---|
| 43 | inline bool isGameServer() { return SharedNetworkData::getInstance()->isGameServer(); } |
---|
[5997] | 44 | |
---|
[6139] | 45 | |
---|
[5996] | 46 | void connectSynchronizeable(Synchronizeable& sync); |
---|
[7954] | 47 | void synchronize(float dtS); |
---|
[5804] | 48 | |
---|
[6695] | 49 | void debug(); |
---|
| 50 | |
---|
| 51 | |
---|
[6139] | 52 | private: |
---|
[5996] | 53 | NetworkManager(); |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | private: |
---|
[6139] | 57 | static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class |
---|
[8228] | 58 | NetworkStream* networkStream; //!< pointer to network stream |
---|
[5996] | 59 | |
---|
[7954] | 60 | float elapsedTime; //!< elapsed time since the last network update |
---|
[5521] | 61 | }; |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | #endif /* _NETWORK_MANAGER */ |
---|