You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
784 B
45 lines
784 B
8 years ago
|
#include <SFML/Network.hpp>
|
||
|
#include <thread>
|
||
|
#include "Event.hpp"
|
||
|
#include "Pub_Sub.h"
|
||
|
#include <list>
|
||
|
|
||
|
struct CustomPacket {
|
||
|
|
||
|
char data[1024];
|
||
|
int position = 0;
|
||
|
int size = 12;
|
||
|
|
||
|
};
|
||
|
|
||
|
class NetworkInput : public VrEventPublisher {
|
||
|
public:
|
||
|
NetworkInput();
|
||
|
|
||
|
void listen_for_clients(int port);
|
||
|
void stop_listening_for_clients();
|
||
|
|
||
|
void recieve_from_clients();
|
||
|
void stop_recieving_from_clients();
|
||
|
|
||
|
void generate_events();
|
||
|
void dispatch_events();
|
||
|
|
||
|
|
||
|
private:
|
||
|
|
||
|
std::list<std::unique_ptr<vr::Event>> event_queue;
|
||
|
|
||
|
std::vector<sf::TcpSocket*> client_sockets;
|
||
|
sf::SocketSelector socket_selector;
|
||
|
|
||
|
std::thread *client_listener_thread;
|
||
|
std::thread *client_reciever_thread;
|
||
|
|
||
|
void threaded_client_listener(int port);
|
||
|
void threaded_client_reciever();
|
||
|
|
||
|
sf::TcpListener listener;
|
||
|
|
||
|
};
|