Still wrestling with a good way to hide the packing

This commit is contained in:
MitchellHansen
2017-02-03 18:06:29 -08:00
parent effed8a2bf
commit a01b089d12
8 changed files with 71 additions and 156 deletions

View File

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

View File

@@ -3,24 +3,35 @@
#include <SFML/System/Vector2.hpp>
#include "util.hpp"
#include "Pub_Sub.h"
#include "RayCaster.h"
class LightController : public VrEventSubscriber {
public:
enum DIRECTION { FORWARD, REARWARD, LEFT, RIGHT, UP, DOWN };
struct Light {
Light(sf::Vector3f position, sf::Vector3f direction_cartesian, sf::Vector4f rgbi) :
position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) {
// Packed data structure for passing raw light data to the caster
struct PackedData {
PackedData(sf::Vector3f position, sf::Vector3f direction_cartesian, sf::Vector4f rgbi) :
position(position), direction_cartesian(direction_cartesian), rgbi(rgbi) {
}
Light();
PackedData();
sf::Vector3f position;
sf::Vector3f direction_cartesian;
sf::Vector4f rgbi;
};
LightController();
LightController(sf::Vector3f position, sf::Vector3f direction, 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();
void set_position(sf::Vector3f position);
@@ -34,17 +45,21 @@ public:
void recieve_event(VrEventPublisher* p, std::unique_ptr<vr::Event> event) override;
static void erase_light();
std::vector<LightController::Light>* get_lights();
void erase_light();
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(Light);
int packed_size = sizeof(PackedData);
// Index that this light is in the packed data
int packed_index;
std::vector<LightController::Light> packed_data;
std::vector<PackedData> packed_data_array;
std::unordered_map<std::string, Light> light_map;
std::shared_ptr<RayCaster> raycaster;
};

View File

@@ -25,7 +25,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> *lights) = 0;
virtual void assign_lights(std::vector<LightController::PackedData> *data) = 0;
virtual void validate() = 0;
// draw will abstract the gl sharing and software rendering
@@ -40,7 +40,7 @@ protected:
Old_Map * map = nullptr;
Camera *camera = nullptr;
std::vector<LightController::Light> *lights;
std::vector<LightController::PackedData> *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> *lights) override;
void assign_lights(std::vector<LightController::PackedData> *data) override;
void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override;
void validate() override;