parent
735758f9cd
commit
a5214f942e
@ -0,0 +1,29 @@ |
|||||||
|
#include "control.hpp" |
||||||
|
#include "constants.hpp" |
||||||
|
#include <fmt/core.h> |
||||||
|
#include <optional> |
||||||
|
#include <SFML/Window/Mouse.hpp> |
||||||
|
|
||||||
|
void CtrlSocket::listen() { |
||||||
|
auto status = $socket.bind(port); |
||||||
|
|
||||||
|
if(status == sf::Socket::Status::Error) { |
||||||
|
fmt::println("Error binding UDP port {}", port); |
||||||
|
} |
||||||
|
|
||||||
|
$socket.setBlocking(false); |
||||||
|
|
||||||
|
fmt::println("Focus listener on port {}", port); |
||||||
|
} |
||||||
|
|
||||||
|
CtrlCommand CtrlSocket::receive() { |
||||||
|
uint32_t cmd = uint32_t(CtrlCommand::NONE); |
||||||
|
size_t received = 0; |
||||||
|
std::optional<sf::IpAddress> sender; |
||||||
|
|
||||||
|
if($socket.receive(&cmd, sizeof cmd, received, sender, port) == sf::Socket::Status::Done) { |
||||||
|
fmt::println("sender {} sent {}", sender->toString(), cmd); |
||||||
|
} |
||||||
|
|
||||||
|
return static_cast<CtrlCommand>(cmd); |
||||||
|
} |
||||||
@ -0,0 +1,23 @@ |
|||||||
|
#pragma once |
||||||
|
|
||||||
|
#include <SFML/Network/UdpSocket.hpp> |
||||||
|
#include <SFML/Graphics/RenderWindow.hpp> |
||||||
|
|
||||||
|
enum class CtrlCommand { |
||||||
|
FOCUS, |
||||||
|
FULL_SCREEN, |
||||||
|
MOVE_LEFT, |
||||||
|
MOVE_RIGHT, |
||||||
|
NEXT_SLIDE, |
||||||
|
PREV_SLIDE, |
||||||
|
QUIT, |
||||||
|
NONE |
||||||
|
}; |
||||||
|
|
||||||
|
struct CtrlSocket { |
||||||
|
unsigned short port=9898; |
||||||
|
sf::UdpSocket $socket{}; |
||||||
|
|
||||||
|
void listen(); |
||||||
|
CtrlCommand receive(); |
||||||
|
}; |
||||||
Loading…
Reference in new issue