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

master
MitchellHansen 8 years ago
parent 0047db0a65
commit bfb6d922a3

@ -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 {
class LightController : public VrEventSubscriber {
public:
sf::Vector3f position;
sf::Vector3f direction_cartesian;
sf::Vector4f rgbi;
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();
sf::Vector3f movement;
float impulse = 1.0f;
float friction = 1.0f;
};
//void create_light(LightController::PackedData light_data, std::string light_name);
// LightHandle get_light_handle(std::string light_name);
// 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;
};
void set_position(sf::Vector3f position);
class LightHandle;
class Hardware_Caster;
class LightController : public VrEventSubscriber {
public:
int update(double delta_time);
LightController(std::shared_ptr<Hardware_Caster> raycaster);
~LightController();
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;
};

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

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

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

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

@ -1,48 +1,39 @@
#include "LightController.h"
#include "LightHandle.h"
#include <numeric>
//LightController::LightController(std::shared_ptr<RayCaster> raycaster) {
// //:raycaster(raycaster) {
//
//
//
// //packed_index = packed_data.size() / packed_size;
//}
LightController::~LightController() {
}
//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;
// //}
//
//
//}
LightController::LightController(std::shared_ptr<Hardware_Caster> raycaster) : packed_data_array(reserved_count), open_list(reserved_count) {
//LightHandle LightController::get_light_handle(std::string light_name) {
std::iota(open_list.begin(), open_list.end(), 0);
//}
raycaster->assign_lights(&packed_data_array);
}
void LightController::set_position(sf::Vector3f position) {
LightController::~LightController() {
}
std::unique_ptr<LightHandle> LightController::create_light(LightPrototype light_prototype) {
unsigned int index = open_list.front();
open_list.pop_front();
std::unique_ptr<PackedData> data(&packed_data_array.at(index));
int LightController::update(double delta_time) {
std::unique_ptr<LightHandle> handle(new LightHandle(this, index, light_prototype, std::move(data)));
return handle;
}
double multiplier = 40;
//position.x += static_cast<float>(movement.x * delta_time * multiplier);
//position.y += static_cast<float>(movement.y * delta_time * multiplier);
//position.z += static_cast<float>(movement.z * delta_time * multiplier);
void LightController::remove_light(unsigned int light_index) {
//movement *= static_cast<float>(1.0f * delta_time * multiplier);
// Sanitization is currently handled by the light handler
open_list.push_front(light_index);
return 1;
}
void LightController::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event) {
@ -69,17 +60,3 @@ void LightController::recieve_event(VrEventPublisher* publisher, std::unique_ptr
}
}
void LightController::erase_light() {
//packed_data.emplace_back(PackedData(position, direction, rgbi));
}
//std::vector<LightController::PackedData>* LightController::get_lights() {
// return &packed_data_array;
//}
void LightController::look_at_center() {
//direction_cartesian = CartToNormalizedSphere(sf::Vector3f(75, 75, 75) - position);
}

@ -1,18 +1,60 @@
#include "LightHandle.h"
#include "LightController.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);
LightHandle::LightHandle(LightController *const light_controller, unsigned int light_id, LightPrototype light_prototype, std::unique_ptr<PackedData> data_reference) :
light_controller_ref(light_controller), data_reference(std::move(data_reference)) {
friction_coefficient = light_prototype.friction;
default_impulse = light_prototype.impulse;
movement = light_prototype.movement;
//light_controller.create_light(data, light_name);
}
LightHandle::~LightHandle() {
// Sanitize data here, or in the controller?
data_reference->direction_cartesian = sf::Vector3f(0, 0, 0);
data_reference->position = sf::Vector3f(0, 0, 0);
data_reference->rgbi = sf::Vector4f(0, 0, 0, 0);
light_controller_ref->remove_light(light_id);
}
void LightHandle::set_friction(float friction)
{
}
void LightHandle::set_impulse(float impulse)
{
}
void LightHandle::set_movement(sf::Vector3f movement)
{
}
void LightHandle::add_movement(sf::Vector3f movement)
{
}
void LightHandle::set_position(sf::Vector3f position)
{
}
void LightHandle::set_direction(sf::Vector3f direction)
{
}
void LightHandle::set_rgbi(sf::Vector4f rgbi)
{
}

@ -18,39 +18,7 @@ void NetworkInput::stop_listening_for_clients() {
void NetworkInput::recieve_from_clients()
{
//// Receive a message from the client
//char buffer[1024];
//std::vector<CustomPacket> packets;
//sf::TcpSocket::Status status;
//do {
// std::size_t received = 0;
// status = socket.receive(buffer, 1024, received);
// while (received < 12) {
// std::size_t tack_on;
// status = socket.receive(&buffer[received], 1024 - received, tack_on);
// received += tack_on;
// }
// int position = 0;
// while (position < received) {
// CustomPacket p;
// memcpy(p.data, &buffer[position], p.size);
// packets.push_back(p);
// position += p.size;
// }
// std::cout << "packet_count = " << packets.size() << std::endl;
// int left_over = 12 - (position - received);
// memcpy(buffer, &buffer[received - left_over], left_over);
//} while (status != sf::TcpSocket::Status::Disconnected);
}
void NetworkInput::dispatch_events()
@ -128,7 +96,7 @@ void NetworkInput::threaded_client_listener(int port) {
std::cout << "packet_count = " << packets.size() << std::endl;
int left_over = 12 - (position - received);
int left_over = 12 - static_cast<int>(position - received);
std::memcpy(buffer, &buffer[received - left_over], left_over);
} while (status != sf::TcpSocket::Status::Done);

@ -15,8 +15,8 @@ Old_Map::~Old_Map() {
void generate_at(int x, int y, std::vector<std::vector<int>> *grid) {
int x_bound = grid->size();
int y_bound = grid->at(0).size();
size_t x_bound = grid->size();
size_t y_bound = grid->at(0).size();
// N S E W
std::vector<int> t = { 1, 2, 3, 4 };

@ -32,7 +32,6 @@
#include "raycaster/Hardware_Caster.h"
#include "Vector4.hpp"
#include "Camera.h"
#include "raycaster/Software_Caster.h"
#include "Input.h"
#include "Pub_Sub.h"
#include "NetworkInput.h"
@ -92,7 +91,8 @@ int main() {
// Start up the raycaster
//Hardware_Caster *raycaster = new Hardware_Caster();
std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster());
Hardware_Caster *raycaster = new Hardware_Caster();
//std::shared_ptr<Hardware_Caster> raycaster(new Hardware_Caster());
if (raycaster->init() != 1) {
abort();
@ -129,8 +129,8 @@ int main() {
*/
// Light for the currently non functional Bling Phong shader
std::shared_ptr<RayCaster> asdf;
//LightController l(asdf);
//std::unique_ptr<RayCaster> asdf(raycaster);
//LightController light_controller(std::move(raycaster));
// *links* the lights to the GPU
//raycaster->assign_lights();

@ -1,5 +1,6 @@
#include "raycaster/Hardware_Caster.h"
#include <raycaster/RayCaster.h>
#include "LightController.h"
Hardware_Caster::Hardware_Caster() {
@ -35,7 +36,7 @@ int Hardware_Caster::init() {
return error;
}
srand(time(NULL));
srand(time(nullptr));
int *seed_memory = new int[1920*1080];
@ -209,14 +210,14 @@ void Hardware_Caster::create_viewport(int width, int height, float v_fov, float
//
//}
void Hardware_Caster::assign_lights(std::vector<char> *data) {
void Hardware_Caster::assign_lights(std::vector<PackedData> *data) {
// Get a pointer to the packed light data
// this->lights = data;
light_count = static_cast<int>(lights->size());
size_t packed_size = sizeof(LightController::PackedData);
cl_uint packed_size = 0;// sizeof(PackedData);
create_buffer("lights", packed_size * light_count, lights->data(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);

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

Loading…
Cancel
Save