Wrestling with the compiler to pass these shared_ptr's

master
MitchellHansen 8 years ago
parent a01b089d12
commit fa047f9e3a

@ -50,8 +50,7 @@ public:
// Both will create the view matrix, view res buffer // Both will create the view matrix, view res buffer
void create_viewport(int width, int height, float v_fov, float h_fov) override; void create_viewport(int width, int height, float v_fov, float h_fov) override;
void assign_lights(std::vector<LightController::PackedData> *data) override; void assign_lights(std::vector<char> *data) override;
void assign_lights();
void assign_map(Old_Map *map) override; void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override; void assign_camera(Camera *camera) override;
void validate() override; void validate() override;

@ -4,6 +4,7 @@
#include "util.hpp" #include "util.hpp"
#include "Pub_Sub.h" #include "Pub_Sub.h"
#include "RayCaster.h" #include "RayCaster.h"
#include "LightHandle.h"
class LightController : public VrEventSubscriber { class LightController : public VrEventSubscriber {
public: public:
@ -15,29 +16,21 @@ public:
PackedData(sf::Vector3f position, sf::Vector3f direction_cartesian, sf::Vector4f rgbi) : PackedData(sf::Vector3f position, sf::Vector3f direction_cartesian, sf::Vector4f rgbi) :
position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) { position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) {
} }
PackedData(); PackedData() {};
sf::Vector3f position; sf::Vector3f position;
sf::Vector3f direction_cartesian; sf::Vector3f direction_cartesian;
sf::Vector4f rgbi; sf::Vector4f rgbi;
}; };
// Data that enables "camera" style movement. I can't really use inheritance easily because // LightController(std::shared_ptr<RayCaster> raycaster);
// of the data packing requirements LightController();
struct Light {
Light();
int packed_index;
float friction_coefficient = 0.1f;
float default_impulse = 1.0f;
sf::Vector3f movement;
};
LightController(std::shared_ptr<RayCaster> 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); 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); int update(double delta_time);
@ -46,19 +39,19 @@ public:
void recieve_event(VrEventPublisher* p, std::unique_ptr<vr::Event> event) override; void recieve_event(VrEventPublisher* p, std::unique_ptr<vr::Event> event) override;
void erase_light(); void erase_light();
std::vector<LightController::PackedData>* get_lights(); //std::vector<LightController::PackedData>* get_lights();
private: private:
// Need to allow N byte light class to be packed into 10 byte packets //// Need to allow N byte light class to be packed into 10 byte packets
int packed_size = sizeof(PackedData); //int packed_size = sizeof(PackedData);
// Index that this light is in the packed data
int packed_index;
std::vector<PackedData> packed_data_array; //std::vector<PackedData> packed_data_array;
std::unordered_map<std::string, Light> light_map; //
std::shared_ptr<RayCaster> raycaster; //
//std::unordered_map<std::string, LightHandle> light_map;
//
//std::shared_ptr<RayCaster> raycaster;
}; };

@ -0,0 +1,32 @@
#pragma once
#include <SFML/Graphics.hpp>
#include <util.hpp>
#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<sf::Vector3f> position;
std::shared_ptr<sf::Vector3f> direction_cartesian;
std::shared_ptr<sf::Vector4f> rgbi;
};

@ -6,7 +6,6 @@
#include "Camera.h" #include "Camera.h"
#include "LightController.h" #include "LightController.h"
class RayCaster { class RayCaster {
public: public:
@ -25,7 +24,7 @@ public:
virtual void assign_map(Old_Map *map) = 0; virtual void assign_map(Old_Map *map) = 0;
virtual void assign_camera(Camera *camera) = 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 create_viewport(int width, int height, float v_fov, float h_fov) = 0;
virtual void assign_lights(std::vector<LightController::PackedData> *data) = 0; virtual void assign_lights(std::vector<char> *data) = 0;
virtual void validate() = 0; virtual void validate() = 0;
// draw will abstract the gl sharing and software rendering // draw will abstract the gl sharing and software rendering
@ -40,7 +39,8 @@ protected:
Old_Map * map = nullptr; Old_Map * map = nullptr;
Camera *camera = nullptr; Camera *camera = nullptr;
std::vector<LightController::PackedData> *lights; // std::vector<LightController::PackedData> *lights;
std::vector<char> *lights;
int light_count = 0; int light_count = 0;
sf::Uint8 *viewport_image = nullptr; sf::Uint8 *viewport_image = nullptr;
sf::Vector4f *viewport_matrix = nullptr; sf::Vector4f *viewport_matrix = nullptr;

@ -15,7 +15,7 @@ public:
// Both will create the view matrix, view res buffer // Both will create the view matrix, view res buffer
void create_viewport(int width, int height, float v_fov, float h_fov) override; void create_viewport(int width, int height, float v_fov, float h_fov) override;
void assign_lights(std::vector<LightController::PackedData> *data) override; void assign_lights(std::vector<char> *data) override;
void assign_map(Old_Map *map) override; void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override; void assign_camera(Camera *camera) override;
void validate() override; void validate() override;

@ -210,10 +210,10 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float
// //
//} //}
void Hardware_Caster::assign_lights(std::vector<LightController::PackedData> *data) { void Hardware_Caster::assign_lights(std::vector<char> *data) {
// Get a pointer to the packed light data // Get a pointer to the packed light data
this->lights = data; // this->lights = data;
light_count = static_cast<int>(lights->size()); light_count = static_cast<int>(lights->size());
@ -223,8 +223,6 @@ void Hardware_Caster::assign_lights(std::vector<LightController::PackedData> *da
create_buffer("light_count", sizeof(int), &light_count); create_buffer("light_count", sizeof(int), &light_count);
} }
void Hardware_Caster::draw(sf::RenderWindow* window) { void Hardware_Caster::draw(sf::RenderWindow* window) {

@ -1,60 +1,36 @@
#pragma once #pragma once
#include "LightController.h" #include "LightController.h"
#include "Pub_Sub.h"
//LightController::LightController(std::shared_ptr<RayCaster> raycaster) {
LightController::LightController(std::shared_ptr<RayCaster> raycaster) : // //:raycaster(raycaster) {
raycaster(raycaster) { //
//
//
// //packed_index = packed_data.size() / packed_size;
//packed_index = packed_data.size() / packed_size; //}
}
LightController::~LightController() { 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) { void LightController::set_position(sf::Vector3f position) {
// 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;
} }
//movement += SphereToCart(dir);
//movement *= speed;
return 1;
}
int LightController::update(double delta_time) { int LightController::update(double delta_time) {
@ -99,9 +75,9 @@ void LightController::erase_light() {
//packed_data.emplace_back(PackedData(position, direction, rgbi)); //packed_data.emplace_back(PackedData(position, direction, rgbi));
} }
std::vector<LightController::PackedData>* LightController::get_lights() { //std::vector<LightController::PackedData>* LightController::get_lights() {
return &packed_data; // return &packed_data_array;
} //}
void LightController::look_at_center() { void LightController::look_at_center() {

@ -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() {
}

@ -82,9 +82,9 @@ void Software_Caster::create_viewport(int width, int height, float v_fov, float
} }
void Software_Caster::assign_lights(std::vector<LightController::PackedData> *data) { void Software_Caster::assign_lights(std::vector<char> *data) {
this->lights = data; // this->lights = data;
int light_count = static_cast<int>(data->size()); int light_count = static_cast<int>(data->size());
} }

@ -130,10 +130,11 @@ int main() {
*/ */
// Light for the currently non functional Bling Phong shader // Light for the currently non functional Bling Phong shader
LightController l(raycaster); std::shared_ptr<RayCaster> asdf;
//LightController l(asdf);
// *links* the lights to the GPU // *links* the lights to the GPU
raycaster->assign_lights(); //raycaster->assign_lights();
// Load in the spritesheet texture // Load in the spritesheet texture

Loading…
Cancel
Save