diff options
| author | manuel <manuel@mausz.at> | 2011-05-05 00:57:07 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-05 00:57:07 +0200 |
| commit | ce48af53646cd9e7ec762fc1ac176b3aa620b11d (patch) | |
| tree | f8fbf2cae8c7d0cbac2696a8f4cf94410bfb4928 /pacman-c++/server/server.h | |
| parent | e54ccad07e256ba877bd41d70bd358bd0085bd1e (diff) | |
| download | foop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.tar.gz foop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.tar.bz2 foop-ce48af53646cd9e7ec762fc1ac176b3aa620b11d.zip | |
- refactorized the whole project and made a few subprojects
- replaced tcp with enet
- added connect dialog
- some smaller bugfixes
Diffstat (limited to 'pacman-c++/server/server.h')
| -rw-r--r-- | pacman-c++/server/server.h | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/pacman-c++/server/server.h b/pacman-c++/server/server.h new file mode 100644 index 0000000..857f23d --- /dev/null +++ b/pacman-c++/server/server.h | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | #ifndef SERVER_H | ||
| 2 | #define SERVER_H | ||
| 3 | |||
| 4 | #include "sceneholder.h" | ||
| 5 | #include "actor.h" | ||
| 6 | #include "pacman.pb.h" | ||
| 7 | #include <QtGui> | ||
| 8 | #include <QtNetwork/QHostAddress> | ||
| 9 | |||
| 10 | extern "C" { | ||
| 11 | #include "enet/enet.h" | ||
| 12 | } | ||
| 13 | |||
| 14 | class QTcpSocket; | ||
| 15 | |||
| 16 | class Server | ||
| 17 | : public SceneHolder | ||
| 18 | { | ||
| 19 | Q_OBJECT | ||
| 20 | public: | ||
| 21 | Server(QWidget *parent = 0); | ||
| 22 | ~Server(); | ||
| 23 | bool parseCommandline(); | ||
| 24 | bool run(); | ||
| 25 | |||
| 26 | protected slots: | ||
| 27 | void tick(); | ||
| 28 | |||
| 29 | /* receive updates of client */ | ||
| 30 | void keyPressUpdate(); | ||
| 31 | void keyPressUpdate(ENetEvent *event); | ||
| 32 | |||
| 33 | protected: | ||
| 34 | /* block until we have connections from all clients */ | ||
| 35 | bool waitForClientConnections(); | ||
| 36 | |||
| 37 | /* calculate updates of current tick for sending to client */ | ||
| 38 | Transmission::map_t calculateUpdates(); | ||
| 39 | |||
| 40 | /* update client maps */ | ||
| 41 | void sendUpdate(Transmission::map_t map, bool firstPacket = false); | ||
| 42 | |||
| 43 | QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint); | ||
| 44 | void colorizeBlocks(Transmission::map_t map); | ||
| 45 | void botCalculate(Actor *actor); | ||
| 46 | void initRoundMap(); | ||
| 47 | |||
| 48 | protected slots: | ||
| 49 | /* called when a round is started/finished */ | ||
| 50 | void startGame(); | ||
| 51 | void stopGame(bool delay = false); | ||
| 52 | void setFinishRound(); | ||
| 53 | |||
| 54 | protected: | ||
| 55 | ENetHost *m_host; | ||
| 56 | QMap<ENetPeer *, Color::Color> m_clientConnections; | ||
| 57 | QList<Color::Color> m_bots; | ||
| 58 | |||
| 59 | /* current movements. required to make pacmans continue their movement */ | ||
| 60 | QMap<Color::Color, Actor::Movement> m_actorMovements; | ||
| 61 | |||
| 62 | /* allocate as member variable as this packet is large and used often */ | ||
| 63 | ProtoBuf::MapUpdate m_updatepacket; | ||
| 64 | |||
| 65 | /* list of blocks */ | ||
| 66 | QList<QPoint> m_blocks; | ||
| 67 | /* currently colored blocks + tickcount before they will turn to non-colored back */ | ||
| 68 | QMap<QPoint, unsigned int> m_coloredBlocks; | ||
| 69 | |||
| 70 | QHostAddress m_bindaddress; | ||
| 71 | unsigned int m_port; | ||
| 72 | unsigned int m_maxplayers; | ||
| 73 | unsigned int m_numbots; | ||
| 74 | /* number of rounds (>= 1) */ | ||
| 75 | unsigned int m_rounds; | ||
| 76 | /* current round, starting at 0 */ | ||
| 77 | unsigned int m_curRound; | ||
| 78 | bool m_running; | ||
| 79 | bool m_finishRound; | ||
| 80 | |||
| 81 | QTimer *m_tickTimer; | ||
| 82 | |||
| 83 | }; | ||
| 84 | |||
| 85 | #endif // SERVER_H | ||
