summaryrefslogtreecommitdiffstats
path: root/pacman-c++/server.h
blob: 8d73d24c0047e2f7a54a7bd42bf33d5afb0aa55a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef SERVER_H
#define SERVER_H

#include "sceneholder.h"

#include <QtGui>
#include "actor.h"
#include "pacman.pb.h"

class QTcpSocket;

class Server
  : public SceneHolder
{
  Q_OBJECT
public:
  Server(QWidget *parent = 0);

protected slots:
  void tick();

  // receive updates of client
  void keyPressUpdate();

protected:

  // block until we have connections from all clients
  void waitForClientConnections();

  // calculate updates of current tick for sending to client
  Transmission::map_t calculateUpdates();

  QSharedPointer<ProtoBuf::MapUpdate> createUpdatePacket(Transmission::map_t);

  // update client maps
  void sendUpdate(QSharedPointer<ProtoBuf::MapUpdate>);

  QMap<Color::Color, QTcpSocket *> m_clientConnections;

  // current movements. required to make pacmans continue their movement.
  QMap<Color::Color, Actor::Movement> m_actorMovements;
};

#endif // SERVER_H