removed a few bugs relating to terminating sockets prior to program end.

master
MitchellHansen 8 years ago
parent 44db8dcaf8
commit f60c475531

@ -40,5 +40,6 @@ private:
void threaded_client_reciever(); void threaded_client_reciever();
sf::TcpListener listener; sf::TcpListener listener;
bool listening = true;
}; };

@ -13,7 +13,12 @@ void NetworkInput::listen_for_clients(int port) {
} }
void NetworkInput::stop_listening_for_clients() { void NetworkInput::stop_listening_for_clients() {
delete client_listener_thread; listening = false;
listener.close();
socket_selector.clear();
client_listener_thread->join();
} }
void NetworkInput::recieve_from_clients() void NetworkInput::recieve_from_clients()
@ -34,11 +39,12 @@ void NetworkInput::threaded_client_listener(int port) {
listener.listen(port); listener.listen(port);
socket_selector.add(listener); socket_selector.add(listener);
while (true) while (listening)
{ {
// Make the selector wait for data on any socket // Make the selector wait for data on any socket
if (socket_selector.wait()) if (socket_selector.wait(sf::Time(sf::milliseconds(100))))
{ {
// Test the listener // Test the listener
if (socket_selector.isReady(listener)) if (socket_selector.isReady(listener))
{ {

@ -72,19 +72,27 @@ sf::Texture window_texture;
int main() { int main() {
// Keep at this at the top of main. I think it has to do with it and
// sf::RenderWindow stepping on each others feet
glewInit();
// The socket listener for interacting with the TCP streaming android controller
NetworkInput ni; NetworkInput ni;
ni.listen_for_clients(5000); ni.listen_for_clients(5000);
//Map _map(sf::Vector3i(0, 0, 0)); // Currently just close it right away for debug
//_map.generate_octree(); ni.stop_listening_for_clients();
glewInit();
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML"); sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
window.setMouseCursorVisible(false); window.setMouseCursorVisible(false);
// =============================
Map _map(sf::Vector3i(0, 0, 0));
_map.generate_octree();
// =============================
/*GL_Testing t; /*GL_Testing t;
t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT); t.compile_shader("../shaders/passthrough.frag", GL_Testing::Shader_Type::FRAGMENT);
t.compile_shader("../shaders/passthrough.vert", GL_Testing::Shader_Type::VERTEX); t.compile_shader("../shaders/passthrough.vert", GL_Testing::Shader_Type::VERTEX);
@ -92,8 +100,6 @@ int main() {
t.create_buffers();*/ t.create_buffers();*/
// Start up the raycaster // Start up the raycaster
//Hardware_Caster *raycaster = new Hardware_Caster();
//Hardware_Caster *raycaster = new Hardware_Caster();
std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster()); std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster());
if (raycaster->init() != 1) { if (raycaster->init() != 1) {
@ -165,22 +171,12 @@ int main() {
accumulator_time = 0.0, accumulator_time = 0.0,
current_time = 0.0; current_time = 0.0;
// Mouse capture
sf::Vector2i deltas;
sf::Vector2i fixed(window.getSize());
sf::Vector2i prev_pos;
bool mouse_enabled = true;
bool reset = false;
double timer_accumulator = 0.0;
Input input_handler; Input input_handler;
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyHeld); camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyHeld);
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed); camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::KeyPressed);
camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::MouseMoved); camera->subscribe_to_publisher(&input_handler, vr::Event::EventType::MouseMoved);
//camera->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved);
handle->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved); handle->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved);
WindowHandler win_hand(&window); WindowHandler win_hand(&window);
@ -195,35 +191,9 @@ int main() {
input_handler.dispatch_events(); input_handler.dispatch_events();
ni.dispatch_events(); ni.dispatch_events();
if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) {
while (raycaster->debug_quick_recompile() != 0); while (raycaster->debug_quick_recompile() != 0);
} }
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
// light_vec.at(0).position.x -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
// light_vec.at(0).position.x += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
// light_vec.at(0).position.y += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
// light_vec.at(0).position.y -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::Home)) {
// light_vec.at(0).position.z += delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::End)) {
// light_vec.at(0).position.z -= delta_time * 100;
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) {
// light_vec.at(0).position = camera->get_position();
// light_vec.at(0).direction_cartesian = SphereToCart(camera->get_direction());
//}
//if (sf::Keyboard::isKeyPressed(sf::Keyboard::O)) {
// light_vec.at(0).orbit_around_center(timer_accumulator += delta_time);
//}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num0)) { if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num0)) {
std::string path = "../assets/"; std::string path = "../assets/";

Loading…
Cancel
Save