16 _socket = std::make_shared<ClientSocket>();
17 _scenes[
"menu"] = std::make_unique<MenuScene>(
this, _socket);
18 _scenes[
"main"] = std::make_unique<MainScene>(
this, _socket);
19 _scenes[
"game"] = std::make_unique<GameScene>(
this, _socket);
20 _currentScene = _scenes[
"main"];
31 if (_socket->isInit())
33 bool init = _socket->init_client(ip, port);
45 _window.create(sf::VideoMode(800, 600),
"R-Type");
48 _window.setFramerateLimit(120);
50 while (_window.isOpen()) {
52 _socket->init_fd_set();
53 _currentScene->handleEvent(event, _window);
54 _currentScene->receiveData();
55 _currentScene->update();
56 _currentScene->display(_window);
59 if (_heartBeatThread.joinable())
60 _heartBeatThread.join();
81 _currentScene->continueScene =
false;
82 _currentScene->pauseScene();
83 _currentScene = getSceneByName(name);
84 _currentScene->continueScene =
true;
85 _currentScene->resumeScene();
95 std::unique_ptr<Packet> packet = std::make_unique<Packet>();
97 packet->code = HEARTBEAT;
98 packet->data_size =
sizeof(timeval);
99 packet->data = malloc(packet->data_size);
100 while (window.isOpen()) {
101 gettimeofday((timeval *)packet->data,
nullptr);
102 _socket->send(packet.get(), _socket->serv_addr);
103 std::this_thread::sleep_for(std::chrono::milliseconds(500));
115 return _currentScene;
124 if (_heartBeatThread.joinable())
125 _heartBeatThread.join();
126 _heartBeatThread = std::thread(&ClientCore::sendHeartBeat,
this, std::ref(_window));