Working on lights, I'm conceeding and just using a fixed array. I think it will be faster in the long run, as I won't have to rebind the lights when I add/remove one. Also wrestling with really lame compiler erros with these templated pointers

This commit is contained in:
MitchellHansen
2017-02-08 23:17:10 -08:00
parent 0047db0a65
commit bfb6d922a3
12 changed files with 154 additions and 144 deletions

View File

@@ -4,56 +4,55 @@
#include "util.hpp"
#include "Pub_Sub.h"
#include "raycaster/RayCaster.h"
#include "LightHandle.h"
#include <list>
#include "raycaster/Hardware_Caster.h"
struct LightPrototype {
sf::Vector3f position;
sf::Vector3f direction_cartesian;
sf::Vector4f rgbi;
sf::Vector3f movement;
float impulse = 1.0f;
float friction = 1.0f;
};
// 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) {
}
PackedData() {};
sf::Vector3f position;
sf::Vector3f direction_cartesian;
sf::Vector4f rgbi;
};
class LightHandle;
class Hardware_Caster;
class LightController : public VrEventSubscriber {
public:
enum DIRECTION { FORWARD, REARWARD, LEFT, RIGHT, UP, DOWN };
// 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) {
}
PackedData() {};
sf::Vector3f position;
sf::Vector3f direction_cartesian;
sf::Vector4f rgbi;
};
// LightController(std::shared_ptr<RayCaster> raycaster);
LightController();
LightController(std::shared_ptr<Hardware_Caster> raycaster);
~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 update(double delta_time);
void look_at_center();
std::unique_ptr<LightHandle> create_light(LightPrototype light_prototype);
void remove_light(unsigned int light_index);
void recieve_event(VrEventPublisher* p, std::unique_ptr<vr::Event> event) override;
void erase_light();
//std::vector<LightController::PackedData>* get_lights();
private:
// Set the static arrays size
int reserved_count = 8;
//// Need to allow N byte light class to be packed into 10 byte packets
//int packed_size = sizeof(PackedData);
// Indices available in the light array
std::list<unsigned int> open_list;
std::vector<PackedData> packed_data_array;
//
//
std::unordered_map<std::string, LightHandle> light_map;
//
//std::shared_ptr<RayCaster> raycaster;
};

View File

@@ -3,6 +3,7 @@
#include <util.hpp>
#include <memory>
// 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
@@ -12,21 +13,37 @@
// - 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
struct LightPrototype;
class LightController;
struct PackedData;
class LightHandle {
public:
LightHandle();
//LightHandle(LightController light_controller, std::string light_name);
friend class LightController;
~LightHandle();
void set_friction(float friction);
void set_impulse(float impulse);
void set_movement(sf::Vector3f movement);
void add_movement(sf::Vector3f movement);
void set_position(sf::Vector3f position);
void set_direction(sf::Vector3f direction);
void set_rgbi(sf::Vector4f rgbi);
private:
LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, std::unique_ptr<PackedData> data_reference);
LightController *const light_controller_ref;
unsigned int light_id;
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;
std::unique_ptr<PackedData> data_reference;
};

View File

@@ -36,6 +36,8 @@ struct device {
cl_uint comp_units;
};
struct PackedData;
class Hardware_Caster : public RayCaster
{
public:
@@ -50,7 +52,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<char> *data) override;
void assign_lights(std::vector<PackedData> *data) override;
void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override;
void validate() override;

View File

@@ -4,7 +4,8 @@
#include <Map.h>
#include "Old_Map.h"
#include "Camera.h"
#include "LightController.h"
struct PackedData;
class RayCaster {
public:
@@ -24,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<char> *data) = 0;
virtual void assign_lights(std::vector<PackedData> *data) = 0;
virtual void validate() = 0;
// draw will abstract the gl sharing and software rendering

View File

@@ -1,6 +1,9 @@
#include "RayCaster.h"
#pragma once
#include "raycaster/RayCaster.h"
#include <thread>
struct PackedData;
class Software_Caster : public RayCaster
{
public:
@@ -15,7 +18,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<char> *data) override;
void assign_lights(std::vector<PackedData> *data) override;
void assign_map(Old_Map *map) override;
void assign_camera(Camera *camera) override;
void validate() override;