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:
@@ -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(std::shared_ptr<Hardware_Caster> raycaster) : packed_data_array(reserved_count), open_list(reserved_count) {
|
||||
|
||||
std::iota(open_list.begin(), open_list.end(), 0);
|
||||
|
||||
raycaster->assign_lights(&packed_data_array);
|
||||
}
|
||||
|
||||
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;
|
||||
// //}
|
||||
//
|
||||
//
|
||||
//}
|
||||
std::unique_ptr<LightHandle> LightController::create_light(LightPrototype light_prototype) {
|
||||
|
||||
//LightHandle LightController::get_light_handle(std::string light_name) {
|
||||
unsigned int index = open_list.front();
|
||||
open_list.pop_front();
|
||||
|
||||
std::unique_ptr<PackedData> data(&packed_data_array.at(index));
|
||||
|
||||
//}
|
||||
|
||||
void LightController::set_position(sf::Vector3f position) {
|
||||
std::unique_ptr<LightHandle> handle(new LightHandle(this, index, light_prototype, std::move(data)));
|
||||
|
||||
return handle;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void LightController::remove_light(unsigned int light_index) {
|
||||
|
||||
// Sanitization is currently handled by the light handler
|
||||
open_list.push_front(light_index);
|
||||
|
||||
int LightController::update(double delta_time) {
|
||||
|
||||
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);
|
||||
|
||||
//movement *= static_cast<float>(1.0f * delta_time * multiplier);
|
||||
|
||||
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);
|
||||
|
||||
//light_controller.create_light(data, light_name);
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user