From ce48af53646cd9e7ec762fc1ac176b3aa620b11d Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 5 May 2011 00:57:07 +0200 Subject: - refactorized the whole project and made a few subprojects - replaced tcp with enet - added connect dialog - some smaller bugfixes --- pacman-c++/server/server.h | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 pacman-c++/server/server.h (limited to 'pacman-c++/server/server.h') 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 @@ +#ifndef SERVER_H +#define SERVER_H + +#include "sceneholder.h" +#include "actor.h" +#include "pacman.pb.h" +#include +#include + +extern "C" { +#include "enet/enet.h" +} + +class QTcpSocket; + +class Server + : public SceneHolder +{ + Q_OBJECT +public: + Server(QWidget *parent = 0); + ~Server(); + bool parseCommandline(); + bool run(); + +protected slots: + void tick(); + + /* receive updates of client */ + void keyPressUpdate(); + void keyPressUpdate(ENetEvent *event); + +protected: + /* block until we have connections from all clients */ + bool waitForClientConnections(); + + /* calculate updates of current tick for sending to client */ + Transmission::map_t calculateUpdates(); + + /* update client maps */ + void sendUpdate(Transmission::map_t map, bool firstPacket = false); + + QPoint addRandomPoint(Transmission::map_t map, Transmission::field_t type = Transmission::bonuspoint); + void colorizeBlocks(Transmission::map_t map); + void botCalculate(Actor *actor); + void initRoundMap(); + +protected slots: + /* called when a round is started/finished */ + void startGame(); + void stopGame(bool delay = false); + void setFinishRound(); + +protected: + ENetHost *m_host; + QMap m_clientConnections; + QList m_bots; + + /* current movements. required to make pacmans continue their movement */ + QMap m_actorMovements; + + /* allocate as member variable as this packet is large and used often */ + ProtoBuf::MapUpdate m_updatepacket; + + /* list of blocks */ + QList m_blocks; + /* currently colored blocks + tickcount before they will turn to non-colored back */ + QMap m_coloredBlocks; + + QHostAddress m_bindaddress; + unsigned int m_port; + unsigned int m_maxplayers; + unsigned int m_numbots; + /* number of rounds (>= 1) */ + unsigned int m_rounds; + /* current round, starting at 0 */ + unsigned int m_curRound; + bool m_running; + bool m_finishRound; + + QTimer *m_tickTimer; + +}; + +#endif // SERVER_H -- cgit v1.2.3