-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.h
106 lines (83 loc) · 2.35 KB
/
Client.h
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef _CLIENT_H
#define _CLIENT_H
#include <Ogre.h>
#include <OgreApplicationContext.h>
#include <OgreInput.h>
#include <OgreRTShaderSystem.h>
#include <OgreCameraMan.h>
#include <OgreTrays.h>
#include <OgreAdvancedRenderControls.h>
#include <OgreConfigDialog.h>
#include <iostream>
#include <string>
#include "Messages.h"
#include "Tile.h"
#include "Tank.h"
class Game;
class Client
{
public:
Client(std::string ip, int port, Game* game, Ogre::SceneManager* sceneManager, OgreBites::TrayManager* trayManager);
~Client();
void handleClick(Ogre::Camera* camera, Ogre::Vector3 cameraPosition, OgreBites::MouseButtonEvent event, Ogre::Vector3 direction);
void update(Ogre::SceneNode* cameraNode, int clientMode);
Unit* checkIfRayIntersectsWithUnits(Ogre::Ray);
void addUnitCreationToQueue(int type);
void tellClientUserAskedToQueueUnit(int type);
private:
struct UnitsToUpdate
{
int id = -1;
Ogre::Vector3 position;
Ogre::Vector3 directionFacing;
int playerID;
int type;
bool isAlive;
};
struct BuildingsToUpdateData
{
int id = -1;
Ogre::Vector3 position;
int playerID;
int type;
std::vector<int> queue;
bool isDestroyed;
};
struct ProjectilesToUpdate
{
int id = -1;
Ogre::Vector3 position;
int playerID;
bool isDestroyed;
};
void processInitialMessage(char* message);
void getInitialInfo();
void receiveMessages();
void tellServerToDeterminePath(int unitID, Ogre::Vector2 gridCoords);
void tellServerToDeterminePathAndLockOnToTarget(int enemyUnitID, int unitID);
void tellServerToDeterminePathAndLockOnToTargetBuilding(int buildingID, int unitID);
SOCKET sock;
struct sockaddr_in connection;
Game* game;
int playerID;
Ogre::SceneManager* sceneManager;
std::thread* messageRecievingThread;
std::vector<Unit*>* localCopyOfUnits;
std::mutex unitsLock;
std::mutex unitsToUpdateLock;
std::vector<UnitsToUpdate>* unitsToUpdate;
Unit* selectedUnit;
std::vector<Building*>* localCopyOfBuildings;
std::mutex buildingsLock;
Building* selectedBuilding;
std::vector<BuildingsToUpdateData>* buildingsToUpdate;
std::mutex buildingsToUpdateLock;
OgreBites::TrayManager* trayManager;
std::mutex selectedUnitLock;
std::mutex selectedBuildingLock;
std::vector<Projectile*>* localCopyOfProjectiles;
std::mutex projectilesLock;
std::vector<ProjectilesToUpdate>* projectilesToUpdate;
std::mutex projectilesToUpdateLock;
};
#endif