Did this work?

This commit is contained in:
2017-10-05 23:30:12 -07:00
parent 2d2a854f0f
commit 58ef1da02a
19 changed files with 366 additions and 428 deletions

View File

@@ -34,9 +34,8 @@
// Srsly people who macro error codes are the devil
#undef ERROR
#include "Logger.h"
#include "FrameWatcher.h"
class Application: private Gui {
class Application {
public:
const int WINDOW_X = 1536;
@@ -72,8 +71,6 @@ private:
Input input_handler;
std::shared_ptr<WindowHandler> window_handler;
FrameWatcher frame_watcher;
// The sfml imgui wrapper I'm using requires Update be called with sf::Time
// Might modify it to also accept seconds
sf::Clock sf_delta_clock;
@@ -93,9 +90,4 @@ private:
delta_time = 0.0,
accumulator_time = 0.0,
current_time = 0.0;
public:
virtual void render_gui() override;
virtual void update_gui() override;
};
};

View File

@@ -26,7 +26,7 @@ public:
int update(double delta_time);
void look_at(sf::Vector3f position);
void look_at_center();
sf::Vector2f* get_direction_pointer();
sf::Vector3f* get_position_pointer();

View File

@@ -57,12 +57,6 @@ namespace vr {
NetworkJoystickMoved,
NetworkJoystickConnected,
NetworkJoystickDisconnected,
Tick120Seconds,
Tick60Seconds,
Tick30Seconds,
Tick20Seconds,
Tick10Seconds,
Tick5Seconds,
Count
};
@@ -78,6 +72,8 @@ namespace vr {
};
class Closed : public Event {
public:
Closed() : Event(vr::Event::EventType::Closed) {};

View File

@@ -1,27 +0,0 @@
#pragma once
#include "Pub_Sub.h"
class FrameWatcher : public VrEventPublisher{
public:
FrameWatcher();
~FrameWatcher();
void do_tick();
private:
float get_elapsed_time();
float step_size = 0.0166f;
double frame_time = 0.0;
double elapsed_time = 0.0;
double delta_time = 0.0;
double accumulator_time = 0.0;
double current_time = 0.0;
};

View File

@@ -1,66 +1,66 @@
#pragma once
#include <mutex>
#include <Logger.h>
#include <list>
class Gui {
public:
Gui() {
container_lock.lock();
renderable_container.push_back(this);
container_lock.unlock();
};
virtual ~Gui() {
container_lock.lock();
renderable_container.remove(this);
container_lock.unlock();
};
virtual void render_gui() = 0;
virtual void update_gui() = 0;
// Instead of rendering nil, we can pass our render call if we would like
bool renderable() { return rendering; };
private:
// Whatever class that wants to call this must be a friend!!!
friend class Application;
static void do_render() {
for (auto i : renderable_container) {
i->update_gui();
if (i->renderable())
i->render_gui();
}
};
static std::mutex container_lock;
static std::list<Gui*> renderable_container;
protected:
bool rendering = true;
// Derived class will handle imgui calls
};
#pragma once
#include <mutex>
#include <Logger.h>
#include <list>
class Gui {
public:
Gui() {
container_lock.lock();
renderable_container.push_back(this);
container_lock.unlock();
};
virtual ~Gui() {
container_lock.lock();
renderable_container.remove(this);
container_lock.unlock();
};
virtual void render_gui() = 0;
virtual void update_gui() = 0;
// Instead of rendering nil, we can pass our render call if we would like
bool renderable() { return rendering; };
private:
// Whatever class that wants to call this must be a friend!!!
friend class Application;
static void do_render() {
for (auto i : renderable_container) {
i->update_gui();
if (i->renderable())
i->render_gui();
}
};
static std::mutex container_lock;
static std::list<Gui*> renderable_container;
protected:
bool rendering = false;
// Derived class will handle imgui calls
};

View File

@@ -21,7 +21,9 @@ public:
void consume_vr_events();
void handle_held_keys();
void dispatch_events();
virtual void render_gui() override;
virtual void update_gui() override;
@@ -40,10 +42,6 @@ private:
static const std::vector<std::string> key_strings;
std::list<std::unique_ptr<vr::Event>> event_queue;
protected:
virtual void generate_events() override;
};
class WindowHandler : public VrEventSubscriber {
@@ -55,13 +53,13 @@ public:
if (event.get()->type == vr::Event::Closed) {
window_ref->close();
} else if (event.get()->type == vr::Event::KeyPressed) {
vr::KeyPressed *key_event = static_cast<vr::KeyPressed*>(event.get());
if (key_event->code == sf::Keyboard::Escape) {
window_ref->close();
}
} else if (event.get()->type == vr::Event::KeyPressed) {
vr::KeyPressed *key_event = static_cast<vr::KeyPressed*>(event.get());
if (key_event->code == sf::Keyboard::Escape) {
window_ref->close();
}
}
};

View File

@@ -23,9 +23,13 @@ public:
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;

View File

@@ -3,7 +3,6 @@
#include <iostream>
#include "Event.hpp"
#include <memory>
#include <list>
class VrEventPublisher;
@@ -23,19 +22,12 @@ class VrEventPublisher {
public:
virtual ~VrEventPublisher() {};
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type) final;
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type) final;
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c) final;
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type);
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type);
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c);
virtual void notify_subscribers(std::unique_ptr<vr::Event> event);
private:
std::map<vr::Event::EventType, std::vector<VrEventSubscriber*>> subscribers;
protected:
virtual void notify_subscribers(std::unique_ptr<vr::Event> event) final;
virtual void dispatch_events() final;
virtual void generate_events() = 0;
std::list<std::unique_ptr<vr::Event>> event_queue;
};