Symphony Of Empires
client_network.hpp
Go to the documentation of this file.
1 // Symphony of Empires
2 // Copyright (C) 2021, Symphony of Empires contributors
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <https://www.gnu.org/licenses/>.
16 //
17 // ----------------------------------------------------------------------------
18 // Name:
19 // client/client_network.hpp
20 //
21 // Abstract:
22 // Does some important stuff.
23 // ----------------------------------------------------------------------------
24 
25 #pragma once
26 
27 #include <mutex>
28 #include <deque>
29 #include <thread>
30 #include <atomic>
31 
32 #include "eng3d/network.hpp"
33 #include "client/game_state.hpp"
34 
35 class ClientException : public std::exception {
36  std::string buffer;
37 public:
38  ClientException(const std::string& msg) {
39  buffer = msg;
40  }
41  virtual const char* what() const noexcept {
42  return buffer.c_str();
43  }
44 };
45 
46 class GameState;
48  std::thread net_thread;
49  std::atomic<bool> has_snapshot;
50  std::atomic<bool> run;
51  GameState& gs;
52 public:
53  Client(GameState& gs, std::string host, const unsigned port);
54  ~Client();
55  void netloop();
56  void wait_for_snapshot();
57 };
58 
59 extern Client* g_client;
ClientException(const std::string &msg)
virtual const char * what() const noexcept
void wait_for_snapshot()
Waits to receive the server initial world snapshot.
void netloop()
Client(GameState &gs, std::string host, const unsigned port)
Client * g_client