From e364c5380d5135124687976fc6fa1b92cd9006a2 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sat, 11 Feb 2017 23:16:09 -0800 Subject: [PATCH] Lights are now working correctly. Need to update the kernel to account for multiple lights, and add sfEventSubscriber to the LightHandler --- include/LightController.h | 3 ++- include/LightHandle.h | 4 ++-- src/LightController.cpp | 9 ++++++--- src/LightHandle.cpp | 7 +++---- src/main.cpp | 15 +++------------ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/include/LightController.h b/include/LightController.h index d3e99f2..6d7b339 100644 --- a/include/LightController.h +++ b/include/LightController.h @@ -35,6 +35,7 @@ struct PackedData { position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) { } PackedData() {}; + ~PackedData() {}; sf::Vector4f rgbi; sf::Vector3f position; sf::Vector3f direction_cartesian; @@ -50,7 +51,7 @@ public: LightController(std::shared_ptr raycaster); ~LightController(); - std::unique_ptr create_light(LightPrototype light_prototype); + std::shared_ptr create_light(LightPrototype light_prototype); void remove_light(unsigned int light_index); void recieve_event(VrEventPublisher* p, std::unique_ptr event) override; diff --git a/include/LightHandle.h b/include/LightHandle.h index 2f2f370..e0995c2 100644 --- a/include/LightHandle.h +++ b/include/LightHandle.h @@ -55,7 +55,7 @@ public: private: - LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, std::unique_ptr data_reference); + LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, PackedData *const data_reference); // Reference to the LightController to handle deconstruction and removal using the light_id LightController *const light_controller_ref; @@ -67,5 +67,5 @@ private: sf::Vector3f movement; // Reference to the packed data in the LightController - std::unique_ptr data_reference; + PackedData *const data_reference; }; diff --git a/src/LightController.cpp b/src/LightController.cpp index bb596ee..8f10223 100644 --- a/src/LightController.cpp +++ b/src/LightController.cpp @@ -1,6 +1,7 @@ #include "LightController.h" #include "LightHandle.h" #include +#include @@ -9,20 +10,22 @@ LightController::LightController(std::shared_ptr raycaster) : p std::iota(open_list.begin(), open_list.end(), 0); raycaster->assign_lights(&packed_data_array); + } LightController::~LightController() { } -std::unique_ptr LightController::create_light(LightPrototype light_prototype) { + +std::shared_ptr LightController::create_light(LightPrototype light_prototype) { unsigned int index = open_list.front(); open_list.pop_front(); - std::unique_ptr data(&packed_data_array.data()[index]); + PackedData* data = &packed_data_array.data()[index]; - std::unique_ptr handle(new LightHandle(this, index, light_prototype, std::move(data))); + std::shared_ptr handle(new LightHandle(this, index, light_prototype, data)); return handle; diff --git a/src/LightHandle.cpp b/src/LightHandle.cpp index d313b8f..685c9bf 100644 --- a/src/LightHandle.cpp +++ b/src/LightHandle.cpp @@ -2,10 +2,8 @@ #include "LightController.h" -LightHandle::LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, std::unique_ptr data_reference) : - light_controller_ref(light_controller), light_id(light_id) { - - data_reference = std::move(data_reference); +LightHandle::LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, PackedData *const data_reference) : + light_controller_ref(light_controller), light_id(light_id), data_reference(data_reference) { friction_coefficient = light_prototype.friction; default_impulse = light_prototype.impulse; @@ -29,6 +27,7 @@ LightHandle::~LightHandle() { } + void LightHandle::set_friction(float friction) { diff --git a/src/main.cpp b/src/main.cpp index 5fcbbce..d186a72 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -132,17 +132,8 @@ int main() { sf::Vector3f(-1.0f, -1.0f, -1.5f), sf::Vector4f(1.0f, 1.0f, 1.0f, 1.0f) ); - - std::unique_ptr handle = light_controller.create_light(prototype); - - - // Light for the currently non functional Bling Phong shader - //std::unique_ptr asdf(raycaster); - //LightController light_controller(std::move(raycaster)); - - // *links* the lights to the GPU - //raycaster->assign_lights(); + std::shared_ptr handle(light_controller.create_light(prototype)); // Load in the spritesheet texture @@ -191,7 +182,7 @@ int main() { 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::MouseMoved); - camera->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved); + //camera->subscribe_to_publisher(&ni, vr::Event::EventType::JoystickMoved); WindowHandler win_hand(&window); win_hand.subscribe_to_publisher(&input_handler, vr::Event::EventType::Closed); @@ -203,7 +194,7 @@ int main() { input_handler.consume_sf_events(&window); input_handler.handle_held_keys(); input_handler.dispatch_events(); - ni.dispatch_events(); + //ni.dispatch_events(); if (sf::Keyboard::isKeyPressed(sf::Keyboard::F11)) {