Wrestling with the compiler to pass these shared_ptr's

This commit is contained in:
MitchellHansen
2017-02-04 22:34:09 -08:00
parent a01b089d12
commit fa047f9e3a
10 changed files with 102 additions and 85 deletions

View File

@@ -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<LightController::PackedData> *data) override;
void assign_lights();
void assign_lights(std::vector<char> *data) override;
void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override;
void validate() override;

View File

@@ -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> raycaster);
// 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);
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<vr::Event> event) override;
void erase_light();
std::vector<LightController::PackedData>* get_lights();
//std::vector<LightController::PackedData>* 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<PackedData> packed_data_array;
std::unordered_map<std::string, Light> light_map;
std::shared_ptr<RayCaster> raycaster;
//std::vector<PackedData> packed_data_array;
//
//
//std::unordered_map<std::string, LightHandle> light_map;
//
//std::shared_ptr<RayCaster> raycaster;
};

32
include/LightHandle.h Normal file
View File

@@ -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;
};

View File

@@ -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<LightController::PackedData> *data) = 0;
virtual void assign_lights(std::vector<char> *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<LightController::PackedData> *lights;
// std::vector<LightController::PackedData> *lights;
std::vector<char> *lights;
int light_count = 0;
sf::Uint8 *viewport_image = nullptr;
sf::Vector4f *viewport_matrix = nullptr;

View File

@@ -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<LightController::PackedData> *data) override;
void assign_lights(std::vector<char> *data) override;
void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override;
void validate() override;