blob: ca2ea81910934f1672668d8adde054a4f0760ad9 (
plain) (
blame)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
#pragma once
#include <memory>
#include <string>
#include <vector>
#include <mutex>
#include <glm/mat4x4.hpp>
#include "Vector.hpp"
#include "World.hpp"
#include "Window.hpp"
class Packet;
class Entity;
struct TimeStatus {
double interpolatedTimeOfDay = 0;
long long worldAge = 0;
long long timeOfDay = 0;
bool doDaylightCycle = true;
};
struct GameStatus {
std::string levelType;
Vector spawnPosition;
int gamemode = 0;
int dimension = 0;
unsigned char difficulty = 0;
unsigned char maxPlayers = 0;
bool isGameStarted = false;
bool reducedDebugInfo = false;
};
struct PlayerStatus {
std::string uid;
std::string name;
float flyingSpeed = 0;
float fovModifier = 0;
float health = 0;
int eid = 0;
bool invulnerable = false;
bool flying = false;
bool allowFlying = false;
bool creativeMode = false;
};
struct SelectionStatus {
VectorF raycastHit;
Vector selectedBlock;
float distanceToSelectedBlock;
bool isBlockSelected;
};
class GameState {
Entity* player = nullptr;
World world;
TimeStatus timeStatus;
GameStatus gameStatus;
PlayerStatus playerStatus;
SelectionStatus selectionStatus;
Window playerInventory;
std::vector<Window> openedWindows;
bool receivedJoinGame = false;
bool receivedEnoughChunks = false;
bool receivedFirstPlayerPosAndLook = false;
std::shared_ptr<PacketRespawn> packetRespawn;
public:
void Update(double deltaTime);
void UpdatePacket(std::shared_ptr<Packet> ptr);
void StartDigging();
void FinishDigging();
void CancelDigging();
void PlaceBlock();
void PerformRespawn();
enum MoveType {
FORWARD, BACKWARD, LEFT, RIGHT, JUMP
};
void HandleMovement(GameState::MoveType direction, float deltaTime);
void HandleRotation(double yaw, double pitch);
glm::mat4 GetViewMatrix();
inline Entity *GetPlayer() {
return player;
}
inline const World &GetWorld() const {
return world;
}
inline const TimeStatus &GetTimeStatus() const {
return timeStatus;
}
inline const GameStatus &GetGameStatus() const {
return gameStatus;
}
inline const PlayerStatus &GetPlayerStatus() const {
return playerStatus;
}
inline const SelectionStatus &GetSelectionStatus() const {
return selectionStatus;
}
inline const Window &GetInventory() const {
return playerInventory;
}
};
|