From fa047f9e3a83b880dd473fd6f3faae6fa64699d3 Mon Sep 17 00:00:00 2001 From: MitchellHansen Date: Sat, 4 Feb 2017 22:34:09 -0800 Subject: [PATCH] Wrestling with the compiler to pass these shared_ptr's --- include/Hardware_Caster.h | 3 +- include/LightController.h | 39 +++++++++------------ include/LightHandle.h | 32 +++++++++++++++++ include/RayCaster.h | 6 ++-- include/Software_Caster.h | 2 +- src/Hardware_Caster.cpp | 6 ++-- src/LightController.cpp | 72 +++++++++++++-------------------------- src/LightHandle.cpp | 18 ++++++++++ src/Software_Caster.cpp | 4 +-- src/main.cpp | 5 +-- 10 files changed, 102 insertions(+), 85 deletions(-) create mode 100644 include/LightHandle.h create mode 100644 src/LightHandle.cpp diff --git a/include/Hardware_Caster.h b/include/Hardware_Caster.h index 55bd42f..ee6bf4e 100644 --- a/include/Hardware_Caster.h +++ b/include/Hardware_Caster.h @@ -50,8 +50,7 @@ public: // Both will create the view matrix, view res buffer void create_viewport(int width, int height, float v_fov, float h_fov) override; - void assign_lights(std::vector *data) override; - void assign_lights(); + void assign_lights(std::vector *data) override; void assign_map(Old_Map *map) override; void assign_camera(Camera *camera) override; void validate() override; diff --git a/include/LightController.h b/include/LightController.h index d0a394f..c45372f 100644 --- a/include/LightController.h +++ b/include/LightController.h @@ -4,6 +4,7 @@ #include "util.hpp" #include "Pub_Sub.h" #include "RayCaster.h" +#include "LightHandle.h" class LightController : public VrEventSubscriber { public: @@ -15,29 +16,21 @@ public: PackedData(sf::Vector3f position, sf::Vector3f direction_cartesian, sf::Vector4f rgbi) : position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) { } - PackedData(); + PackedData() {}; sf::Vector3f position; sf::Vector3f direction_cartesian; sf::Vector4f rgbi; }; - // Data that enables "camera" style movement. I can't really use inheritance easily because - // of the data packing requirements - struct Light { - Light(); - int packed_index; - float friction_coefficient = 0.1f; - float default_impulse = 1.0f; - sf::Vector3f movement; - }; - - LightController(std::shared_ptr raycaster); +// LightController(std::shared_ptr raycaster); + LightController(); ~LightController(); + //void create_light(LightController::PackedData light_data, std::string light_name); +// LightHandle get_light_handle(std::string light_name); + void set_position(sf::Vector3f position); - int add_static_impulse(sf::Vector3f impulse); - int add_relative_impulse(DIRECTION direction, float speed); int update(double delta_time); @@ -46,19 +39,19 @@ public: void recieve_event(VrEventPublisher* p, std::unique_ptr event) override; void erase_light(); - std::vector* get_lights(); + //std::vector* get_lights(); private: - // Need to allow N byte light class to be packed into 10 byte packets - int packed_size = sizeof(PackedData); - - // Index that this light is in the packed data - int packed_index; + //// Need to allow N byte light class to be packed into 10 byte packets + //int packed_size = sizeof(PackedData); - std::vector packed_data_array; - std::unordered_map light_map; - std::shared_ptr raycaster; + //std::vector packed_data_array; + // + // + //std::unordered_map light_map; + // + //std::shared_ptr raycaster; }; diff --git a/include/LightHandle.h b/include/LightHandle.h new file mode 100644 index 0000000..a11f155 --- /dev/null +++ b/include/LightHandle.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include +#include "LightController.h" + +// We need to be able to : +// - Allow lights to exist outside the context of a LightController +// - i.e we can have a prototype light or similar +// - Preserve the existence of lights upon object destruction +// - No need to keep track of an object only used upon special use cases +// - Maintain an X*N byte array, X = size of packed data, N = Light number +// - But still allow classes of size Y bytes +// - Preserve X packed bytes in an array which are pointed to by an array of shared pointers + + +class LightHandle { + +public: + LightHandle(); + //LightHandle(LightController light_controller, std::string light_name); + ~LightHandle(); + +private: + + float friction_coefficient = 0.1f; + float default_impulse = 1.0f; + sf::Vector3f movement; + + std::shared_ptr position; + std::shared_ptr direction_cartesian; + std::shared_ptr rgbi; +}; diff --git a/include/RayCaster.h b/include/RayCaster.h index a84c6c5..6a356e5 100644 --- a/include/RayCaster.h +++ b/include/RayCaster.h @@ -6,7 +6,6 @@ #include "Camera.h" #include "LightController.h" - class RayCaster { public: @@ -25,7 +24,7 @@ public: virtual void assign_map(Old_Map *map) = 0; virtual void assign_camera(Camera *camera) = 0; virtual void create_viewport(int width, int height, float v_fov, float h_fov) = 0; - virtual void assign_lights(std::vector *data) = 0; + virtual void assign_lights(std::vector *data) = 0; virtual void validate() = 0; // draw will abstract the gl sharing and software rendering @@ -40,7 +39,8 @@ protected: Old_Map * map = nullptr; Camera *camera = nullptr; - std::vector *lights; +// std::vector *lights; + std::vector *lights; int light_count = 0; sf::Uint8 *viewport_image = nullptr; sf::Vector4f *viewport_matrix = nullptr; diff --git a/include/Software_Caster.h b/include/Software_Caster.h index 3b8ca65..f2c28d4 100644 --- a/include/Software_Caster.h +++ b/include/Software_Caster.h @@ -15,7 +15,7 @@ public: // Both will create the view matrix, view res buffer void create_viewport(int width, int height, float v_fov, float h_fov) override; - void assign_lights(std::vector *data) override; + void assign_lights(std::vector *data) override; void assign_map(Old_Map *map) override; void assign_camera(Camera *camera) override; void validate() override; diff --git a/src/Hardware_Caster.cpp b/src/Hardware_Caster.cpp index 06cfa04..6a4bd2c 100644 --- a/src/Hardware_Caster.cpp +++ b/src/Hardware_Caster.cpp @@ -210,10 +210,10 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float // //} -void Hardware_Caster::assign_lights(std::vector *data) { +void Hardware_Caster::assign_lights(std::vector *data) { // Get a pointer to the packed light data - this->lights = data; +// this->lights = data; light_count = static_cast(lights->size()); @@ -223,8 +223,6 @@ void Hardware_Caster::assign_lights(std::vector *da create_buffer("light_count", sizeof(int), &light_count); - - } void Hardware_Caster::draw(sf::RenderWindow* window) { diff --git a/src/LightController.cpp b/src/LightController.cpp index d1cb811..b4240e1 100644 --- a/src/LightController.cpp +++ b/src/LightController.cpp @@ -1,60 +1,36 @@ #pragma once #include "LightController.h" -#include "Pub_Sub.h" - -LightController::LightController(std::shared_ptr raycaster) : - raycaster(raycaster) { - - - - //packed_index = packed_data.size() / packed_size; -} + +//LightController::LightController(std::shared_ptr raycaster) { +// //:raycaster(raycaster) { +// +// +// +// //packed_index = packed_data.size() / packed_size; +//} LightController::~LightController() { } -void LightController::set_position(sf::Vector3f position) { +//void LightController::create_light(LightController::PackedData light_data, std::string light_name) { +// +// //if (light_map.count(light_name) == 1) { +// // // light already exists, TODO: error out +// // return; +// //} +// +// +//} -} +//LightHandle LightController::get_light_handle(std::string light_name) { -int LightController::add_static_impulse(sf::Vector3f impulse) { - return 1; -} +//} -int LightController::add_relative_impulse(DIRECTION impulse_direction, float speed) { - - // No sense in doing fancy dot products, adding Pi's will suffice - // Always add PI/2 to X initially to avoid negative case - sf::Vector2f dir; - - switch (impulse_direction) { - - case DIRECTION::FORWARD: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y, packed_data_array.at(packed_index).direction_cartesian.x); - break; - case DIRECTION::REARWARD: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y, packed_data_array.at(packed_index).direction_cartesian.x + PI_F); - break; - case DIRECTION::LEFT: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y + PI_F + PI_F / 2, PI_F / 2); - break; - case DIRECTION::RIGHT: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y + PI_F / 2, PI_F / 2); - break; - case DIRECTION::UP: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y, packed_data_array.at(packed_index).direction_cartesian.x + PI_F / 2); - break; - case DIRECTION::DOWN: - dir = sf::Vector2f(packed_data_array.at(packed_index).direction_cartesian.y + PI_F, (packed_data_array.at(packed_index).direction_cartesian.x * -1) + PI_F / 2); - break; +void LightController::set_position(sf::Vector3f position) { - } +} - //movement += SphereToCart(dir); - //movement *= speed; - return 1; -} int LightController::update(double delta_time) { @@ -99,9 +75,9 @@ void LightController::erase_light() { //packed_data.emplace_back(PackedData(position, direction, rgbi)); } -std::vector* LightController::get_lights() { - return &packed_data; -} +//std::vector* LightController::get_lights() { +// return &packed_data_array; +//} void LightController::look_at_center() { diff --git a/src/LightHandle.cpp b/src/LightHandle.cpp new file mode 100644 index 0000000..cf58253 --- /dev/null +++ b/src/LightHandle.cpp @@ -0,0 +1,18 @@ +#include "LightHandle.h" + + +LightHandle::LightHandle() { + + // init an empty light + LightController::PackedData data; + data.direction_cartesian = sf::Vector3f(0, 0, 0); + data.position = sf::Vector3f(0, 0, 0); + data.rgbi = sf::Vector4f(0, 0, 0, 0); + + //light_controller.create_light(data, light_name); +} + +LightHandle::~LightHandle() { + +} + diff --git a/src/Software_Caster.cpp b/src/Software_Caster.cpp index d471534..5e664b4 100644 --- a/src/Software_Caster.cpp +++ b/src/Software_Caster.cpp @@ -82,9 +82,9 @@ void Software_Caster::create_viewport(int width, int height, float v_fov, float } -void Software_Caster::assign_lights(std::vector *data) { +void Software_Caster::assign_lights(std::vector *data) { - this->lights = data; +// this->lights = data; int light_count = static_cast(data->size()); } diff --git a/src/main.cpp b/src/main.cpp index 802e308..9210b1d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,10 +130,11 @@ int main() { */ // Light for the currently non functional Bling Phong shader - LightController l(raycaster); + std::shared_ptr asdf; + //LightController l(asdf); // *links* the lights to the GPU - raycaster->assign_lights(); + //raycaster->assign_lights(); // Load in the spritesheet texture