working on the frame controller, this might get messy

master
MitchellHansen 7 years ago
parent 4d6cecc7e0
commit 5fcf1c0e44

@ -26,7 +26,7 @@ public:
int update(double delta_time);
void look_at_center();
void look_at(sf::Vector3f position);
sf::Vector2f* get_direction_pointer();
sf::Vector3f* get_position_pointer();

@ -57,6 +57,12 @@ namespace vr {
NetworkJoystickMoved,
NetworkJoystickConnected,
NetworkJoystickDisconnected,
Tick120Seconds,
Tick60Seconds,
Tick30Seconds,
Tick20Seconds,
Tick10Seconds,
Tick5Seconds,
Count
};
@ -72,8 +78,6 @@ namespace vr {
};
class Closed : public Event {
public:
Closed() : Event(vr::Event::EventType::Closed) {};

@ -1,6 +1,7 @@
#pragma once
#include "Pub_Sub.h"
class FrameWatcher {
class FrameWatcher : public VrEventPublisher{

@ -21,8 +21,6 @@ public:
void consume_vr_events();
void handle_held_keys();
void dispatch_events();
virtual void render_gui() override;
virtual void update_gui() override;
@ -42,6 +40,10 @@ private:
static const std::vector<std::string> key_strings;
std::list<std::unique_ptr<vr::Event>> event_queue;
protected:
virtual void generate_events() override;
};
class WindowHandler : public VrEventSubscriber {

@ -23,13 +23,9 @@ public:
void stop_recieving_from_clients();
void generate_events();
void dispatch_events();
private:
std::list<std::unique_ptr<vr::Event>> event_queue;
std::vector<sf::TcpSocket*> client_sockets;
sf::SocketSelector socket_selector;

@ -3,6 +3,7 @@
#include <iostream>
#include "Event.hpp"
#include <memory>
#include <list>
class VrEventPublisher;
@ -22,12 +23,19 @@ class VrEventPublisher {
public:
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);
virtual void notify_subscribers(std::unique_ptr<vr::Event> event);
virtual void subscribe(VrEventSubscriber *subscriber, vr::Event::EventType type) final;
virtual void subscribe(VrEventSubscriber *subscriber, std::vector<vr::Event::EventType> type) final;
virtual void unsubscribe(VrEventSubscriber *s, vr::Event::EventType c) final;
private:
std::map<vr::Event::EventType, std::vector<VrEventSubscriber*>> subscribers;
protected:
virtual void notify_subscribers(std::unique_ptr<vr::Event> event) final;
virtual void dispatch_events() final;
virtual void generate_events() = 0;
std::list<std::unique_ptr<vr::Event>> event_queue;
};

@ -375,7 +375,7 @@ __kernel void raycaster(
bool shadow_ray = false;
// Andrew Woo's raycasting algo
while (distance_traveled < max_distance && bounce_count < 2) {
while (distance_traveled < max_distance && bounce_count < 4) {
// Fancy no branch version of the logic step
face_mask = intersection_t.xyz <= min(intersection_t.yzx, intersection_t.zxy);
@ -387,6 +387,7 @@ __kernel void raycaster(
voxel_data = 5;
voxel.xyz -= voxel_step.xyz * face_mask.xyz;
first_strike = mix(fog_color, voxel_color, 1.0 - max(distance_traveled / 700.0f, (float)0));
break;
}
@ -537,10 +538,10 @@ __kernel void raycaster(
texture_atlas,
convert_int2(tile_face_position * convert_float2(*atlas_dim / *tile_dim)) +
convert_int2((float2)(3, 4) * convert_float2(*atlas_dim / *tile_dim))
).xyz/2;
).xyz/4;
voxel_color.w += 0.3f;
max_distance = 500;
voxel_color -= 0.3f;
max_distance = 700;
distance_traveled = 0;
float3 hit_pos = convert_float3(voxel) + face_position;

@ -97,7 +97,7 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
default_impulse = 1.0f;
}
else if (held_event->code == sf::Keyboard::C) {
look_at_center();
look_at(sf::Vector3f(128, 128, 10));
}
else if (held_event->code == sf::Keyboard::Q) {
add_relative_impulse(Camera::DIRECTION::DOWN, default_impulse);
@ -230,9 +230,10 @@ void Camera::update_gui() {
rendering = true;
}
void Camera::look_at_center() {
void Camera::look_at(sf::Vector3f position)
{
direction = CartToNormalizedSphere(sf::Vector3f(60, 60, 35) - position);
direction = CartToNormalizedSphere(position - this->position);
}
sf::Vector2f* Camera::get_direction_pointer() {

@ -112,16 +112,6 @@ void Input::handle_held_keys() {
}
void Input::dispatch_events() {
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}
void Input::render_gui() {
ImGui::Begin("Input Debugger");
@ -396,4 +386,7 @@ const std::vector<std::string> Input::key_strings = {
"Pause"
};
void Input::generate_events() {
}

@ -26,14 +26,6 @@ void NetworkInput::recieve_from_clients()
}
void NetworkInput::dispatch_events()
{
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}
void NetworkInput::threaded_client_listener(int port) {
listener.listen(port);

@ -42,3 +42,10 @@ void VrEventPublisher::notify_subscribers(std::unique_ptr<vr::Event> event) {
}
}
void VrEventPublisher::dispatch_events() {
while (event_queue.size() != 0) {
notify_subscribers(std::move(event_queue.front()));
event_queue.pop_front();
}
}

@ -215,7 +215,7 @@ void Old_Map::generate_terrain() {
for (int x = dimensions.x / 2; x < dimensions.x / 2 + dimensions.x / 64; x++) {
for (int y = dimensions.x / 2; y < dimensions.y / 2 + dimensions.x / 64; y++) {
for (int z = 0; z < 5; z++) {
for (int z = 5; z < 15; z++) {
voxel_data[x + dimensions.x * (y + dimensions.z * z)] = 6;
}
@ -249,63 +249,63 @@ void Old_Map::generate_terrain() {
// Hand code in some constructions
std::vector<std::vector<int>> maze =
generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0));
//std::vector<std::vector<int>> maze =
// generate_maze(sf::Vector2i(8, 8), sf::Vector2i(0, 0));
for (int x = 0; x < maze.size(); x++) {
for (int y = 0; y < maze.at(0).size(); y++) {
switch(maze.at(x).at(y)) {
case 1: { // North
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5;
//voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
case 2: { // South
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
break;
}
case 3: { // East
voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
case 4: { // West
voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
//voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
break;
}
}
}
}
//for (int x = 0; x < dimensions.x; x++) {
// for (int y = 0; y < dimensions.y; y++) {
// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
//for (int x = 0; x < maze.size(); x++) {
// for (int y = 0; y < maze.at(0).size(); y++) {
//
// switch(maze.at(x).at(y)) {
//
// case 1: { // North
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 5;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
// case 2: { // South
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + dimensions.z * 1)] = 5;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// break;
// }
// case 3: { // East
// voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
// case 4: { // West
// voxel_data[x * 3 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 5;
// voxel_data[x * 3 + 1 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// voxel_data[x * 3 + 2 + dimensions.x * (y * 3 + 1 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + dimensions.z * 1)] = 6;
// //voxel_data[x * 3 + dimensions.x * (y * 3 + 2 + dimensions.z * 1)] = 6;
// break;
// }
//
// }
//
//
// }
//}
set_voxel(sf::Vector3i(45, 70, 6), 6);
set_voxel(sf::Vector3i(47, 70, 6), 6);
set_voxel(sf::Vector3i(100, 100, 50), 1);
////for (int x = 0; x < dimensions.x; x++) {
//// for (int y = 0; y < dimensions.y; y++) {
//// voxel_data[x + dimensions.x * (y + dimensions.z * 1)] = 6;
//// }
////}
//set_voxel(sf::Vector3i(45, 70, 6), 6);
//set_voxel(sf::Vector3i(47, 70, 6), 6);
//set_voxel(sf::Vector3i(100, 100, 50), 1);
}

Loading…
Cancel
Save