Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
client.hpp
Go to the documentation of this file.
1#include "client/core.hpp"
2
3#include <iostream>
4#include <ostream>
5#include <utility>
6#include <unordered_map>
7#include <chrono>
8#include <map>
9
10#include <boost/asio/ip/tcp.hpp>
11#include <boost/asio/io_service.hpp>
12#include <boost/filesystem.hpp>
13
14#include "client/shader.hpp"
15#include "client/model.hpp"
16#include "client/util.hpp"
18#include "client/gui/gui.hpp"
19#include "client/camera.hpp"
21#include "client/constants.hpp"
22#include "client/animation.hpp"
24#include "client/bone.hpp"
25
33
34#define WINDOW_WIDTH Client::getWindowSize().x
35#define WINDOW_HEIGHT Client::getWindowSize().y
36
37// position something a "frac" of the way across the screen
38// e.g. WIDTH_FRAC(1, 4) -> a fourth of the way from the left
39// HEIGHT_FRAC(2, 3) -> two thirds of the way from the bottom
40#define FRAC_WINDOW_WIDTH(num, denom) Client::window_width * static_cast<float>(num) / static_cast<float>(denom)
41#define FRAC_WINDOW_HEIGHT(num, denom) Client::window_height * static_cast<float>(num) / static_cast<float>(denom)
42
43using namespace boost::asio::ip;
44
50class Client {
51
52public:
59 Client(boost::asio::io_service& io_service, GameConfig config);
60
64 ~Client();
65
71 bool init();
72
78 bool cleanup();
79
80 // Callbacks
86 void displayCallback();
87
93 void idleCallback();
94
99
109 void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
110
118 void mouseCallback(GLFWwindow* window, double xposIn, double yposIn);
119
127 void scrollCallback(GLFWwindow* window, double xposIn, double yposIn);
128
137 void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
138
145 void charCallback(GLFWwindow* window, unsigned int codepoint);
146
152 static glm::vec2 getWindowSize();
153
159 static time_t getTimeOfLastKeystroke();
160
161 // Getter / Setters
167 GLFWwindow* getWindow() { return window; }
168
174 bool connect(std::string ip_addr);
175
180
184 AnimationManager* getAnimManager() { return animManager; }
185
189 void setWorldPos();
190
198 void sendTrapEvent(bool hover, bool place, ModelType trapType);
199
201private:
210 void processServerInput(bool allow_defer);
211
212 GLuint gBuffer;
213 GLuint gPosition, gNormal, gAlbedoSpec;
214 GLuint quadVAO = 0;
215 GLuint quadVBO;
216 GLuint cubeVAO = 0;
217 GLuint cubeVBO = 0;
218
219 void configureGBuffer();
220
224 void draw();
225
231 void geometryPass();
232
237 void lightingPass();
238
243 void drawBbox(boost::optional<SharedObject> object);
244
245 /* Current game state */
246 SharedGameState gameState;
247
248 /* Stuff for the intro cutscene, contains a whole other SharedGameState */
249 std::optional<LoadIntroCutsceneEvent> intro_cutscene;
250
251 /* Shader objects for various */
252 std::shared_ptr<Shader> deferred_geometry_shader;
253 std::shared_ptr<Shader> deferred_lighting_shader;
254 std::shared_ptr<Shader> dm_deferred_lighting_shader;
255 std::shared_ptr<Shader> deferred_light_box_shader;
256
257 /* Character models and lighting objects, might need to move to different classes later */
258 std::unique_ptr<Model> fire_player_model;
259 std::unique_ptr<Model> lightning_player_model;
260 std::unique_ptr<Model> water_player_model;
261
262 std::unique_ptr<Model> bear_model;
263 std::unique_ptr<Model> torchlight_model;
264 std::unique_ptr<Model> torchpost_model;
265 std::unique_ptr<Model> wall_model;
266 std::unique_ptr<Model> pillar_model;
267 std::unique_ptr<Model> sungod_model;
268 std::unique_ptr<Model> slime_model;
269 std::unique_ptr<Model> python_model;
270 std::unique_ptr<Model> item_model;
271 std::unique_ptr<Model> spike_trap_model;
272 std::unique_ptr<Model> orb_model;
273 std::unique_ptr<Model> exit_model;
274 std::unique_ptr<Model> floor_model;
275 std::unique_ptr<Model> arrow_model;
276 std::unique_ptr<Model> arrow_trap_model;
277 std::unique_ptr<Model> lava_cross_model;
278 std::unique_ptr<Model> lava_vertical_model;
279 std::unique_ptr<Model> lava_horizontal_model;
280 std::unique_ptr<Model> lightning_model;
281 std::unique_ptr<Model> chest_model;
282 std::unique_ptr<Model> teleport_model;
283 std::unique_ptr<Model> mirror_model;
284
285 GLFWwindow *window;
286
287 /* GUI */
288 friend class gui::GUI;
290 gui::GUIState gui_state;
291
296 enum class LobbyPlayerState {
297 Connected,
298 SelectedRole,
299 Ready
300 };
301
306 LobbyPlayerState lobbyPlayerState;
307
312 enum class RadioButtonState {
313 NoneSelected,
314 FirstOption,
315 SecondOption
316 };
317
322 RadioButtonState roleSelection;
323
327 AudioManager* audioManager;
328
329 AnimationManager* animManager;
330
331 /* Camera object representing player's current position & orientation */
332 std::unique_ptr<Camera> cam;
333
334 /* Flags */
335 static int window_width;
336 static int window_height;
337
338 static time_t time_of_last_keystroke;
339
340 /* Key held flags */
341 bool is_held_up = false;
342 bool is_held_down = false;
343 bool is_held_right = false;
344 bool is_held_left = false;
345 bool is_held_space = false;
346
347 /* DM zooming in and out flags */
348 bool is_held_i = false;
349 bool is_held_o = false;
350
351 bool is_left_mouse_down = false;
352 bool is_right_mouse_down = false;
353
354 /* DM Trap Orientation Traps With Directions */
355 int orientation = 0;
356
357 /* Mouse position coordinates */
358 float mouse_xpos = 0.0f;
359 float mouse_ypos = 0.0f;
360
361 double lastTime = 0.0;
362 double lastFrameTime = 0.0;
363
364 GameConfig config;
365 tcp::resolver resolver;
366 tcp::socket socket;
367
368 LobbyFinder lobby_finder;
369
371 basic_resolver_results<class boost::asio::ip::tcp> endpoints;
372 std::shared_ptr<Session> session;
373
374 glm::vec3 world_pos; // stored world pause, calculated before the GUI is rendered
375
376 std::array<boost::optional<SharedObject>, MAX_POINT_LIGHTS> closest_light_sources;
377
378 std::deque<Event> events_received;
379
383 bool phase_change;
384
385 // id of last known player which is holding the orb
386 EntityID player_has_orb_global_id;
387};
388
Definition: animationmanager.hpp:19
Definition: audiomanager.hpp:15
A clsas that represents the client for the game. Contains all local information, including the Shared...
Definition: client.hpp:50
AnimationManager * getAnimManager()
get the reference to the Animation manager
Definition: client.hpp:184
static time_t getTimeOfLastKeystroke()
Get the time of last keystroke.
Definition: client.cpp:1879
int curr_fps
Definition: client.hpp:200
static glm::vec2 getWindowSize()
Get a vec2 representing <width, height> of the window size.
Definition: client.cpp:1875
GLFWwindow * getWindow()
Returns a pointer to the GLFWwindow object.
Definition: client.hpp:167
void sendPacketsToServer()
sends all queued packets to server
void charCallback(GLFWwindow *window, unsigned int codepoint)
Definition: client.cpp:1870
void displayCallback()
Display callback which handles the rendering of all local objects. Abstracts the logic of the main re...
Definition: client.cpp:341
~Client()
Destroys the Client object.
Definition: client.cpp:126
void keyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
Callback which handles keyboard inputs to the GLFWwindow. Binds to the GLFWwindow.
Definition: client.cpp:1538
void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
Callback which handles mouse button presses.
Definition: client.cpp:1828
bool init()
Initializes glfw, glew, shaders, and the GLFWwindow.
Definition: client.cpp:129
bool connect(std::string ip_addr)
Creates and connects to a Session at the specified IP address.
Definition: client.cpp:104
void setWorldPos()
the current position in the world the player is looking at
Definition: client.cpp:1810
AudioManager * getAudioManager()
get the reference to the Audio manager
Definition: client.cpp:100
void scrollCallback(GLFWwindow *window, double xposIn, double yposIn)
Callback which handles scrolling movement.
Definition: client.cpp:1751
bool cleanup()
Frees all pointers, deletes the GLFWwindow, and terminates glfw.
Definition: client.cpp:328
void mouseCallback(GLFWwindow *window, double xposIn, double yposIn)
Callback which handles mouse cursor movement. Does not include mouse button presses.
Definition: client.cpp:1799
void idleCallback()
Callback which handles all updates to the local SharedGameState, and sends events to the server based...
Definition: client.cpp:430
void sendTrapEvent(bool hover, bool place, ModelType trapType)
Send down a trap event to the server.
Definition: client.cpp:376
Definition: lobbyfinder.hpp:23
Definition: gui.hpp:63
unsigned int GLuint
Definition: glad.h:115
Definition: font.hpp:9
GUIState
Definition: gui.hpp:39
#define MAX_POINT_LIGHTS
Definition: constants.hpp:7
ModelType
Enumeration of every render model in the game.
Definition: sharedmodel.hpp:6
Definition: config.hpp:12
The SharedGameState is a representation of the ServerGameState instance maintained by the server and ...
Definition: sharedgamestate.hpp:167
uint32_t EntityID
Global Object ID (when the server or client references an object with a particular EntityID,...
Definition: typedefs.hpp:9