RType
ClientCore.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** R-type
4 ** File description:
5 ** R-type
6 */
7 
8 #pragma once
9 
10 #include "Scenes/Game/GameScene.hpp"
11 #include "Scenes/IScene.hpp"
12 #include "Scenes/Menu/MainScene.hpp"
13 #include "Scenes/Menu/MenuScene.hpp"
14 #include "networking/client/ClientSocket.hpp"
15 #include <chrono>
16 #include <map>
17 #include <memory>
18 #include <sys/time.h>
19 #include <thread>
20 
22 {
23  public:
24 
25  /**
26  * @brief ClientCore, constructor of ClientCore
27  */
28  ClientCore();
29 
30  /**
31  * @brief ~ClientCore, destructor of ClientCore
32  */
33  ~ClientCore() = default;
34 
35  /**
36  * @brief init_socket, init the socket
37  *
38  * @param ip
39  * @param port
40  * @return true if the socket is init
41  */
42  bool init_socket(const std::string &ip, int port);
43 
44  /**
45  * @brief run, run the client
46  */
47  void run();
48 
49  /**
50  * @brief getSocket, get the socket
51  *
52  * @return std::shared_ptr<ClientSocket>
53  */
54  std::shared_ptr<IScene> getSceneByName(const std::string &name);
55 
56  /**
57  * @brief setCurrentScene, set the current scene
58  *
59  * @param name
60  */
61  void setCurrentScene(const std::string &name);
62 
63  /**
64  * @brief getCurrentScene, get the current scene
65  *
66  * @return std::shared_ptr<IScene>
67  */
68  std::shared_ptr<IScene> getCurrentScene() const;
69 
70  /**
71  * @brief sendHeartBeat, send the heart beat
72  *
73  * @param window
74  */
75  void sendHeartBeat(sf::RenderWindow &window);
76 
77 
78  /**
79  * @brief startHeartBeat, start the heart beat
80  */
81  void startHeartBeat();
82 
83  private:
84  std::shared_ptr<ClientSocket> _socket;
85  sf::RenderWindow _window;
86  std::map<std::string, std::shared_ptr<IScene>> _scenes;
87  std::shared_ptr<IScene> _currentScene;
88  std::thread _heartBeatThread;
89 };