partway through some documentation and bug fixing
This commit is contained in:
@@ -150,6 +150,11 @@ public:
|
||||
|
||||
// Save the chosen device config to a file
|
||||
void save_config();
|
||||
|
||||
// Set a
|
||||
void
|
||||
|
||||
|
||||
// ================================== DEBUG =======================================
|
||||
|
||||
// Re compile the kernel and revalidate the args
|
||||
@@ -282,6 +287,7 @@ private:
|
||||
// Containers holding the kernels and buffers
|
||||
std::map<std::string, cl_kernel> kernel_map;
|
||||
std::map<std::string, cl_mem> buffer_map;
|
||||
std::vector<std::pair<std::string, unsigned int>> settings_index_map;
|
||||
std::unordered_map<std::string, std::pair<sf::Sprite, std::unique_ptr<sf::Texture>>> image_map;
|
||||
|
||||
// Hardware caster holds and renders its own textures
|
||||
|
||||
@@ -6,28 +6,46 @@
|
||||
#include <cmath>
|
||||
#include "Gui.h"
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Camera
|
||||
*
|
||||
* Camera provides a convenient way to create 3d vectors and positions which represent a camera. It provides physics
|
||||
* to move the camera around in 3d space as well as impulse and friction control to alter its movement characteristics
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class Camera : public VrEventSubscriber, private Gui{
|
||||
|
||||
public:
|
||||
|
||||
enum DIRECTION { FORWARD, REARWARD, LEFT, RIGHT, UP, DOWN };
|
||||
|
||||
Camera();
|
||||
// TODO: Remove dependency on getting a window ptr. Instead provide window interface to get and set mouse position
|
||||
Camera(sf::Vector3f position, sf::Vector2f direction, sf::RenderWindow *window);
|
||||
~Camera();
|
||||
|
||||
int set_position(sf::Vector3f position);
|
||||
|
||||
// Apply an incoming impule to the velocity vector
|
||||
int add_static_impulse(sf::Vector3f impulse);
|
||||
|
||||
// Apply an impulse in one of the 6 relative directions with a certain magnitude
|
||||
int add_relative_impulse(DIRECTION direction, float speed);
|
||||
|
||||
int slew_camera(sf::Vector2f input);
|
||||
void set_camera(sf::Vector2f input);
|
||||
void set_camera(sf::Vector3f input);
|
||||
void set_camera_direction(sf::Vector2f input);
|
||||
void set_camera_direction(sf::Vector3f input);
|
||||
|
||||
int update(double delta_time);
|
||||
|
||||
void look_at_center();
|
||||
|
||||
// TODO: Raw ptr's SHARED_PTR with CL, bad idea
|
||||
sf::Vector2f* get_direction_pointer();
|
||||
sf::Vector3f* get_position_pointer();
|
||||
sf::Vector3f* get_movement_pointer();
|
||||
|
||||
@@ -3,6 +3,19 @@
|
||||
#include <Logger.h>
|
||||
#include <list>
|
||||
|
||||
/**
|
||||
*
|
||||
* GUI
|
||||
*
|
||||
* Any class that wants to have an interactive GUI rendered to the window may
|
||||
* inherit GUI and override the render_gui() and update_gui() methods
|
||||
*
|
||||
* ImGui operations must be completely wrapped in Begins and Ends
|
||||
*
|
||||
* You may enable and disable rendering by setting the 'rendering' flag to true or false
|
||||
*
|
||||
*/
|
||||
|
||||
class Gui {
|
||||
|
||||
public:
|
||||
|
||||
@@ -7,6 +7,22 @@
|
||||
#include "Gui.h"
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
*
|
||||
* Input
|
||||
*
|
||||
* For each frame the Application must call
|
||||
*
|
||||
* consume_sf_events(*window)
|
||||
* handle_held_keys()
|
||||
* dispatch_events()
|
||||
*
|
||||
* which will pull all the events from the sfml event queue, transpose them over
|
||||
* to vr:events, compare to the last frame and create held key events for keys held
|
||||
* for longer than one frame, and finally dispatch the events to the relevent VrEventListener's
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class Input : public VrEventPublisher, private Gui{
|
||||
public:
|
||||
@@ -14,9 +30,6 @@ public:
|
||||
Input();
|
||||
~Input();
|
||||
|
||||
// Keep track of keys that are not released
|
||||
// Keep track of mouse up and downs in conjunction with dragging
|
||||
// Keep track of joystick buttons
|
||||
void consume_sf_events(sf::RenderWindow *window);
|
||||
void consume_vr_events();
|
||||
|
||||
@@ -34,6 +47,7 @@ private:
|
||||
std::vector<sf::Keyboard::Key> held_keys;
|
||||
std::vector<sf::Mouse::Button> held_mouse_buttons;
|
||||
|
||||
// TODO: What the hell was I using these for?
|
||||
std::vector<bool> keyboard_flags;
|
||||
std::vector<bool> mouse_flags;
|
||||
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
#include "Pub_Sub.h"
|
||||
#include <list>
|
||||
|
||||
/**
|
||||
*
|
||||
* NetworkInput
|
||||
*
|
||||
* Prototype network joystick, listens to clients connecting to a certain port and reads
|
||||
* packets pertaining to, in the case of the lights, xyz movement. This could in theory
|
||||
* provide a very generic way to listen to network input and generate events from received
|
||||
* packets.
|
||||
*
|
||||
*/
|
||||
|
||||
struct CustomPacket {
|
||||
|
||||
char data[1024];
|
||||
|
||||
@@ -9,19 +9,24 @@ class VrEventPublisher;
|
||||
|
||||
class VrEventSubscriber {
|
||||
public:
|
||||
virtual ~VrEventSubscriber() {};
|
||||
virtual ~VrEventSubscriber();
|
||||
virtual void recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Event> event) = 0;
|
||||
void subscribe_to_publisher(VrEventPublisher* publisher, vr::Event::EventType type);
|
||||
void subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type);
|
||||
void unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type);
|
||||
protected:
|
||||
std::vector<vr::Event::EventType> subscribed_event_types;
|
||||
|
||||
// When we destroy a subscriber we need to be able to notify the publishers
|
||||
// We have to keep track of every EventType because of the way EventTypes
|
||||
// are mapped to subscribers in the publisher
|
||||
std::map<VrEventPublisher*, std::vector<vr::Event::EventType>> subscriptions;
|
||||
};
|
||||
|
||||
|
||||
class VrEventPublisher {
|
||||
public:
|
||||
|
||||
virtual ~VrEventPublisher() {};
|
||||
virtual ~VrEventPublisher();
|
||||
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type);
|
||||
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type);
|
||||
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c);
|
||||
|
||||
@@ -30,22 +30,22 @@ bool Application::init_clcaster() {
|
||||
abort();
|
||||
|
||||
map = std::make_shared<Map>(MAP_X);
|
||||
|
||||
// TODO: Implement this
|
||||
sf::Image bitmap = map->GenerateHeightBitmap(sf::Vector3i(MAP_X, MAP_Y, MAP_Z));
|
||||
map->ApplyHeightmap(bitmap);
|
||||
|
||||
map->octree.CastRayOctree(sf::Vector2f(1.57f, 0.0001f), sf::Vector3f(0.5f, 0.5f, 0.5f));
|
||||
//map->octree.CastRayOctree(sf::Vector2f(1.57f, 0.0001f), sf::Vector3f(0.5f, 0.5f, 0.5f));
|
||||
|
||||
// TODO: Consolidate this to one call
|
||||
raycaster->assign_octree(map);
|
||||
raycaster->assign_map(map);
|
||||
|
||||
// Create a new camera with (starting position, direction)
|
||||
camera = std::make_shared<Camera>(
|
||||
sf::Vector3f(3.5f, 3.5f, 3.5f),
|
||||
sf::Vector2f(1.57f, 0.0f),
|
||||
sf::Vector3f(3.5f, 3.5f, 3.5f), // Starting position
|
||||
sf::Vector2f(1.57f, 0.0f), // Direction
|
||||
window.get()
|
||||
);
|
||||
|
||||
// *link* the camera to the GPU
|
||||
raycaster->assign_camera(camera);
|
||||
|
||||
// Generate and send the viewport to the GPU. Also creates the viewport texture
|
||||
@@ -63,7 +63,6 @@ bool Application::init_clcaster() {
|
||||
light_handle = light_controller->create_light(prototype);
|
||||
|
||||
// Load in the spritesheet texture
|
||||
|
||||
if (!spritesheet.loadFromFile("../assets/textures/minecraft_tiles.png"))
|
||||
Logger::log("Failed to load spritesheet from file", Logger::LogLevel::WARN);
|
||||
raycaster->create_texture_atlas(&spritesheet, sf::Vector2i(16, 16));
|
||||
|
||||
@@ -12,7 +12,6 @@ CLCaster::~CLCaster() {
|
||||
//release_viewport();
|
||||
|
||||
delete[] viewport_matrix;
|
||||
delete[] viewport_image;
|
||||
delete[] viewport_image;
|
||||
|
||||
camera.reset();
|
||||
@@ -720,13 +719,19 @@ bool CLCaster::compile_kernel(std::string kernel_source, bool is_path, std::stri
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try and build the program
|
||||
// "-cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations"
|
||||
|
||||
// need a ref to the oct dimensions
|
||||
//std::string oct_dimensions = std::to_string(map->getDimensions().x);
|
||||
std::stringstream build_string_stream;
|
||||
|
||||
// walk the settings index's and add them to the defines
|
||||
for (auto i: settings_index_map){
|
||||
build_string_stream << " -D" << i.first << "=" << std::to_string(i.second);
|
||||
}
|
||||
|
||||
build_string_stream << "-DOCTDIM=" << std::to_string(Application::MAP_X);
|
||||
build_string_stream << " -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations";
|
||||
|
||||
std::string build_string = build_string_stream.str();
|
||||
|
||||
std::string build_string = "-DOCTDIM=" + std::to_string(Application::MAP_X) + " -cl-finite-math-only -cl-fast-relaxed-math -cl-unsafe-math-optimizations";
|
||||
error = clBuildProgram(program, 1, &device_id, build_string.c_str(), NULL, NULL);
|
||||
|
||||
// Check to see if it error'd out
|
||||
|
||||
@@ -65,11 +65,11 @@ int Camera::slew_camera(sf::Vector2f input) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void Camera::set_camera(sf::Vector2f input) {
|
||||
void Camera::set_camera_direction(sf::Vector2f input) {
|
||||
direction = input;
|
||||
}
|
||||
|
||||
void Camera::set_camera(sf::Vector3f input) {
|
||||
void Camera::set_camera_direction(sf::Vector3f input) {
|
||||
direction = CartToNormalizedSphere(input);
|
||||
}
|
||||
|
||||
@@ -101,10 +101,10 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
||||
auto held_event = static_cast<vr::KeyHeld*>(event.get());
|
||||
|
||||
if (held_event->code == sf::Keyboard::LShift) {
|
||||
default_impulse = 0.01f;
|
||||
setSpeed(0.01f);
|
||||
}
|
||||
else if (held_event->code == sf::Keyboard::RShift) {
|
||||
default_impulse = 1.0f;
|
||||
setSpeed(0.3f);
|
||||
}
|
||||
else if (held_event->code == sf::Keyboard::C) {
|
||||
look_at_center();
|
||||
@@ -151,7 +151,6 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
||||
|
||||
vr::MouseMoved *mouse_event = static_cast<vr::MouseMoved*>(event.get());
|
||||
|
||||
//deltas = fixed - sf::Mouse::getPosition();
|
||||
deltas = fixed - sf::Vector2i(mouse_event->x, mouse_event->y);
|
||||
if (deltas != sf::Vector2i(0, 0) && mouse_enabled == true) {
|
||||
|
||||
@@ -271,7 +270,7 @@ sf::Vector2f Camera::get_direction() {
|
||||
}
|
||||
|
||||
void Camera::setSpeed(float speed) {
|
||||
default_impulse = speed;;
|
||||
default_impulse = speed;
|
||||
}
|
||||
|
||||
float Camera::getSpeed() {
|
||||
|
||||
@@ -147,7 +147,6 @@ void Input::render_gui() {
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
|
||||
float offset = ImGui::GetColumnWidth(i);
|
||||
|
||||
draw_list->AddLine(ImVec2(p.x + 0 + offset * i, p.y + 50), ImVec2(p.x + 100 + offset * i, p.y + 50), col32, 1.0);
|
||||
@@ -284,8 +283,7 @@ void Input::transpose_sf_events(std::list<sf::Event> sf_event_queue) {
|
||||
break;
|
||||
};
|
||||
default: {
|
||||
std::cout << "Event not recognized";
|
||||
abort();
|
||||
Logger::log("Event not recognized", Logger::LogLevel::WARN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,14 +3,53 @@
|
||||
#include "Pub_Sub.h"
|
||||
|
||||
|
||||
/**
|
||||
* Subscriber
|
||||
*/
|
||||
|
||||
VrEventSubscriber::~VrEventSubscriber() {
|
||||
|
||||
// Cycles through the publishers we're subscribed to
|
||||
for (auto const& publisher : subscriptions) {
|
||||
|
||||
// And one by one remove the EventTypes we're subscribed to
|
||||
for (auto event_type: publisher.second) {
|
||||
publisher.first->unsubscribe(this, event_type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VrEventSubscriber::subscribe_to_publisher(VrEventPublisher* publisher, vr::Event::EventType type) {
|
||||
|
||||
publisher->subscribe(this, type);
|
||||
|
||||
subscriptions[publisher].push_back(type);
|
||||
}
|
||||
|
||||
void VrEventSubscriber::subscribe_to_publisher(VrEventPublisher* publisher, std::vector<vr::Event::EventType> type) {
|
||||
|
||||
publisher->subscribe(this, type);
|
||||
|
||||
subscriptions[publisher].insert(subscriptions[publisher].end(), type.begin(), type.end());
|
||||
}
|
||||
|
||||
void VrEventSubscriber::unsubscribe(VrEventPublisher* publisher, vr::Event::EventType type){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Publisher
|
||||
*/
|
||||
VrEventPublisher::~VrEventPublisher() {
|
||||
|
||||
// Cycle through the subscribers that are listening to us
|
||||
for (auto const& subscriber_bucket : subscribers) {
|
||||
|
||||
// And one by one remove the
|
||||
for (auto subscriber: subscriber_bucket.second){
|
||||
subscriber.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VrEventPublisher::subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type) {
|
||||
@@ -42,3 +81,4 @@ void VrEventPublisher::notify_subscribers(std::unique_ptr<vr::Event> event) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user