1 | /*! |
---|
2 | * @file network_manager.h |
---|
3 | * Main interface for the network module. Manages all the modules |
---|
4 | */ |
---|
5 | |
---|
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*/ |
---|
8 | #ifndef _NETWORK_MANAGER |
---|
9 | #define _NETWORK_MANAGER |
---|
10 | |
---|
11 | /* include this file, it contains some default definitions */ |
---|
12 | #include "netdefs.h" |
---|
13 | #include "shared_network_data.h" |
---|
14 | |
---|
15 | /* include base_object.h since all classes are derived from this one */ |
---|
16 | #include "base_object.h" |
---|
17 | |
---|
18 | |
---|
19 | /* forward declarations for the header file (include the header via #include "bla.h" in the source file) */ |
---|
20 | class NetworkStream; |
---|
21 | class Synchronizeable; |
---|
22 | template<typename> |
---|
23 | class tList; |
---|
24 | |
---|
25 | /* and here is the class itsself*/ |
---|
26 | class NetworkManager : public BaseObject |
---|
27 | { |
---|
28 | |
---|
29 | public: |
---|
30 | |
---|
31 | inline static NetworkManager* getInstance() { if (!NetworkManager::singletonRef) NetworkManager::singletonRef = new NetworkManager(); |
---|
32 | return NetworkManager::singletonRef; } |
---|
33 | virtual ~NetworkManager(); |
---|
34 | |
---|
35 | void initialize(); |
---|
36 | void shutdown(); |
---|
37 | |
---|
38 | int establishConnection( const std::string & name, unsigned int port); |
---|
39 | int createServer(unsigned int port); |
---|
40 | |
---|
41 | /** Returns the hostID @return The hostID of the object */ |
---|
42 | inline int getHostID() { return this->sharedNetworkData->getHostID(); } |
---|
43 | inline bool isGameServer() { return this->sharedNetworkData->isGameServer(); } |
---|
44 | |
---|
45 | |
---|
46 | void connectSynchronizeable(Synchronizeable& sync); |
---|
47 | void synchronize(float dtS); |
---|
48 | |
---|
49 | void debug(); |
---|
50 | |
---|
51 | |
---|
52 | private: |
---|
53 | NetworkManager(); |
---|
54 | |
---|
55 | |
---|
56 | private: |
---|
57 | const std::list<BaseObject*>* netStreamList; // list with refs to all network streams |
---|
58 | const std::list<BaseObject*>* syncList; // list of synchronizeables |
---|
59 | static NetworkManager* singletonRef; //!< Pointer to the only instance of this Class |
---|
60 | NetworkStream* defaultSyncStream; //!< FIXME: this is only for testing purposes |
---|
61 | |
---|
62 | SharedNetworkData* sharedNetworkData; //!< reference to the shared data |
---|
63 | float elapsedTime; //!< elapsed time since the last network update |
---|
64 | }; |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | #endif /* _NETWORK_MANAGER */ |
---|