From 5fcf1c0e44dee85c86a5f66db3dd238c10af467b Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sun, 1 Oct 2017 17:01:05 -0700 Subject: [PATCH] working on the frame controller, this might get messy --- include/Camera.h | 2 +- include/Event.hpp | 8 ++- include/FrameWatcher.h | 7 ++- include/Input.h | 6 +- include/NetworkInput.h | 4 -- include/Pub_Sub.h | 16 ++++-- kernels/ray_caster_kernel.cl | 9 +-- src/Camera.cpp | 7 ++- src/Input.cpp | 13 +---- src/NetworkInput.cpp | 8 --- src/Pub_Sub.cpp | 7 +++ src/map/Old_Map.cpp | 108 +++++++++++++++++------------------ 12 files changed, 100 insertions(+), 95 deletions(-) diff --git a/include/Camera.h b/include/Camera.h index 04c00aa..b4695bf 100644 --- a/include/Camera.h +++ b/include/Camera.h @@ -26,7 +26,7 @@ public: int update(double delta_time); - void look_at_center(); + void look_at(sf::Vector3f position); sf::Vector2f* get_direction_pointer(); sf::Vector3f* get_position_pointer(); diff --git a/include/Event.hpp b/include/Event.hpp index 4d5b6e5..31d65b3 100644 --- a/include/Event.hpp +++ b/include/Event.hpp @@ -57,6 +57,12 @@ namespace vr { NetworkJoystickMoved, NetworkJoystickConnected, NetworkJoystickDisconnected, + Tick120Seconds, + Tick60Seconds, + Tick30Seconds, + Tick20Seconds, + Tick10Seconds, + Tick5Seconds, Count }; @@ -72,8 +78,6 @@ namespace vr { }; - - class Closed : public Event { public: Closed() : Event(vr::Event::EventType::Closed) {}; diff --git a/include/FrameWatcher.h b/include/FrameWatcher.h index 3ff7bbc..7fac42c 100644 --- a/include/FrameWatcher.h +++ b/include/FrameWatcher.h @@ -1,6 +1,7 @@ +#pragma once +#include "Pub_Sub.h" - -class FrameWatcher { +class FrameWatcher : public VrEventPublisher{ @@ -23,4 +24,4 @@ private: double current_time = 0.0; -}; \ No newline at end of file +}; diff --git a/include/Input.h b/include/Input.h index 883a96b..57cf61c 100644 --- a/include/Input.h +++ b/include/Input.h @@ -21,9 +21,7 @@ public: void consume_vr_events(); void handle_held_keys(); - void dispatch_events(); - virtual void render_gui() override; virtual void update_gui() override; @@ -42,6 +40,10 @@ private: static const std::vector key_strings; std::list> event_queue; + +protected: + virtual void generate_events() override; + }; class WindowHandler : public VrEventSubscriber { diff --git a/include/NetworkInput.h b/include/NetworkInput.h index dd1b017..6bce081 100644 --- a/include/NetworkInput.h +++ b/include/NetworkInput.h @@ -23,13 +23,9 @@ public: void stop_recieving_from_clients(); void generate_events(); - void dispatch_events(); - private: - std::list> event_queue; - std::vector client_sockets; sf::SocketSelector socket_selector; diff --git a/include/Pub_Sub.h b/include/Pub_Sub.h index 7ea3aaf..bdadef3 100644 --- a/include/Pub_Sub.h +++ b/include/Pub_Sub.h @@ -3,6 +3,7 @@ #include #include "Event.hpp" #include +#include class VrEventPublisher; @@ -22,12 +23,19 @@ class VrEventPublisher { public: virtual ~VrEventPublisher() {}; - virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type); - virtual void subscribe(VrEventSubscriber *subscriber, std::vector type); - virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c); - virtual void notify_subscribers(std::unique_ptr event); + virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type) final; + virtual void subscribe(VrEventSubscriber *subscriber, std::vector type) final; + virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c) final; + private: + std::map> subscribers; + +protected: + virtual void notify_subscribers(std::unique_ptr event) final; + virtual void dispatch_events() final; + virtual void generate_events() = 0; + std::list> event_queue; }; diff --git a/kernels/ray_caster_kernel.cl b/kernels/ray_caster_kernel.cl index 9c5986e..066a82f 100644 --- a/kernels/ray_caster_kernel.cl +++ b/kernels/ray_caster_kernel.cl @@ -375,7 +375,7 @@ __kernel void raycaster( bool shadow_ray = false; // Andrew Woo's raycasting algo - while (distance_traveled < max_distance && bounce_count < 2) { + while (distance_traveled < max_distance && bounce_count < 4) { // Fancy no branch version of the logic step face_mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy); @@ -387,6 +387,7 @@ __kernel void raycaster( voxel_data = 5; voxel.xyz -= voxel_step.xyz * face_mask.xyz; first_strike = mix(fog_color, voxel_color, 1.0 - max(distance_traveled / 700.0f, (float)0)); + break; } @@ -537,10 +538,10 @@ __kernel void raycaster( texture_atlas, convert_int2(tile_face_position * convert_float2(*atlas_dim / *tile_dim)) + convert_int2((float2)(3, 4) * convert_float2(*atlas_dim / *tile_dim)) - ).xyz/2; + ).xyz/4; - voxel_color.w += 0.3f; - max_distance = 500; + voxel_color -= 0.3f; + max_distance = 700; distance_traveled = 0; float3 hit_pos = convert_float3(voxel) + face_position; diff --git a/src/Camera.cpp b/src/Camera.cpp index 1aa3e94..6956b16 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -97,7 +97,7 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptrcode == sf::Keyboard::C) { - look_at_center(); + look_at(sf::Vector3f(128, 128, 10)); } else if (held_event->code == sf::Keyboard::Q) { add_relative_impulse(Camera::DIRECTION::DOWN, default_impulse); @@ -230,9 +230,10 @@ void Camera::update_gui() { rendering = true; } -void Camera::look_at_center() { +void Camera::look_at(sf::Vector3f position) +{ - direction = CartToNormalizedSphere(sf::Vector3f(60, 60, 35) - position); + direction = CartToNormalizedSphere(position - this->position); } sf::Vector2f* Camera::get_direction_pointer() { diff --git a/src/Input.cpp b/src/Input.cpp index 98010ff..4f0b292 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -112,16 +112,6 @@ void Input::handle_held_keys() { } -void Input::dispatch_events() { - - while (event_queue.size() != 0) { - notify_subscribers(std::move(event_queue.front())); - event_queue.pop_front(); - } - -} - - void Input::render_gui() { ImGui::Begin("Input Debugger"); @@ -396,4 +386,7 @@ const std::vector Input::key_strings = { "Pause" }; +void Input::generate_events() { +} + diff --git a/src/NetworkInput.cpp b/src/NetworkInput.cpp index b3b59e9..d04d9fb 100644 --- a/src/NetworkInput.cpp +++ b/src/NetworkInput.cpp @@ -26,14 +26,6 @@ void NetworkInput::recieve_from_clients() } -void NetworkInput::dispatch_events() -{ - while (event_queue.size() != 0) { - notify_subscribers(std::move(event_queue.front())); - event_queue.pop_front(); - } -} - void NetworkInput::threaded_client_listener(int port) { listener.listen(port); diff --git a/src/Pub_Sub.cpp b/src/Pub_Sub.cpp index 2a9f376..37e8ffa 100644 --- a/src/Pub_Sub.cpp +++ b/src/Pub_Sub.cpp @@ -42,3 +42,10 @@ void VrEventPublisher::notify_subscribers(std::unique_ptr event) { } } + +void VrEventPublisher::dispatch_events() { + while (event_queue.size() != 0) { + notify_subscribers(std::move(event_queue.front())); + event_queue.pop_front(); + } +} diff --git a/src/map/Old_Map.cpp b/src/map/Old_Map.cpp index 51889ac..bc52087 100644 --- a/src/map/Old_Map.cpp +++ b/src/map/Old_Map.cpp @@ -215,7 +215,7 @@ void Old_Map::generate_terrain() { for (int x = dimensions.x / 2; x < dimensions.x / 2 + dimensions.x / 64; x++) { for (int y = dimensions.x / 2; y < dimensions.y / 2 + dimensions.x / 64; y++) { - for (int z = 0; z < 5; z++) { + for (int z = 5; z < 15; z++) { voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 6; } @@ -249,63 +249,63 @@ void Old_Map::generate_terrain() { // Hand code in some constructions - std::vector> maze = - generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0)); - - for (int x = 0; x < maze.size(); x++) { - for (int y = 0; y < maze.at(0).size(); y++) { - - switch(maze.at(x).at(y)) { - - case 1: { // North - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5; - //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; - break; - } - case 2: { // South - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; - break; - } - case 3: { // East - voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5; - //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; - break; - } - case 4: { // West - voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5; - voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; - //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; - break; - } - - } - - - } - } - + //std::vector> maze = + // generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0)); - //for (int x = 0; x < dimensions.x; x++) { - // for (int y = 0; y < dimensions.y; y++) { - // voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6; + //for (int x = 0; x < maze.size(); x++) { + // for (int y = 0; y < maze.at(0).size(); y++) { + // + // switch(maze.at(x).at(y)) { + // + // case 1: { // North + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5; + // //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; + // break; + // } + // case 2: { // South + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; + // break; + // } + // case 3: { // East + // voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5; + // //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; + // break; + // } + // case 4: { // West + // voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5; + // voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6; + // //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6; + // break; + // } + // + // } + // + // // } //} - set_voxel(sf::Vector3i(45, 70, 6), 6); - set_voxel(sf::Vector3i(47, 70, 6), 6); - set_voxel(sf::Vector3i(100, 100, 50), 1); + + ////for (int x = 0; x < dimensions.x; x++) { + //// for (int y = 0; y < dimensions.y; y++) { + //// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6; + //// } + ////} + + //set_voxel(sf::Vector3i(45, 70, 6), 6); + //set_voxel(sf::Vector3i(47, 70, 6), 6); + //set_voxel(sf::Vector3i(100, 100, 50), 1); }