SFML packets have no documented structure so I had to packet them out myself. Low Energy
This commit is contained in:
@@ -236,7 +236,7 @@ __kernel void raycaster(
|
|||||||
// Determine where on the 2d plane the ray intersected
|
// Determine where on the 2d plane the ray intersected
|
||||||
|
|
||||||
float3 face_position = (float)(0);
|
float3 face_position = (float)(0);
|
||||||
float2 texture_position = (float)(0);
|
float2 tile_face_position = (float)(0);
|
||||||
|
|
||||||
|
|
||||||
// First determine the percent of the way the ray is towards the next intersection_t
|
// First determine the percent of the way the ray is towards the next intersection_t
|
||||||
@@ -249,7 +249,7 @@ __kernel void raycaster(
|
|||||||
// Since we intersected face x, we know that we are at the face (1.0)
|
// Since we intersected face x, we know that we are at the face (1.0)
|
||||||
// Not entirely sure what is causing the 1.0 vs 1.001 rendering bug
|
// Not entirely sure what is causing the 1.0 vs 1.001 rendering bug
|
||||||
face_position = (float3)(1.001f, y_percent, z_percent);
|
face_position = (float3)(1.001f, y_percent, z_percent);
|
||||||
texture_position = (float2)(y_percent, z_percent);
|
tile_face_position = (float2)(y_percent, z_percent);
|
||||||
}
|
}
|
||||||
else if (face_mask.y == -1) {
|
else if (face_mask.y == -1) {
|
||||||
|
|
||||||
@@ -257,7 +257,7 @@ __kernel void raycaster(
|
|||||||
float z_percent = (intersection_t.z - (intersection_t.y - delta_t.y)) / delta_t.z;
|
float z_percent = (intersection_t.z - (intersection_t.y - delta_t.y)) / delta_t.z;
|
||||||
|
|
||||||
face_position = (float3)(x_percent, 1.001f, z_percent);
|
face_position = (float3)(x_percent, 1.001f, z_percent);
|
||||||
texture_position = (float2)(x_percent, z_percent);
|
tile_face_position = (float2)(x_percent, z_percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (face_mask.z == -1) {
|
else if (face_mask.z == -1) {
|
||||||
@@ -266,7 +266,7 @@ __kernel void raycaster(
|
|||||||
float y_percent = (intersection_t.y - (intersection_t.z - delta_t.z)) / delta_t.y;
|
float y_percent = (intersection_t.y - (intersection_t.z - delta_t.z)) / delta_t.y;
|
||||||
|
|
||||||
face_position = (float3)(x_percent, y_percent, 1.001f);
|
face_position = (float3)(x_percent, y_percent, 1.001f);
|
||||||
texture_position = (float2)(x_percent, y_percent);
|
tile_face_position = (float2)(x_percent, y_percent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,26 +277,30 @@ __kernel void raycaster(
|
|||||||
|
|
||||||
if (ray_dir.x > 0) {
|
if (ray_dir.x > 0) {
|
||||||
face_position.x = -face_position.x + 1;
|
face_position.x = -face_position.x + 1;
|
||||||
texture_position.x = -texture_position.x + 1.0;
|
//tile_face_position.x = -tile_face_position.x + 1.0;
|
||||||
|
}
|
||||||
|
if (ray_dir.x < 0) {
|
||||||
|
//face_position.x = face_position.x + 0;
|
||||||
|
//tile_face_position.x = tile_face_position.x;
|
||||||
}
|
}
|
||||||
//if (ray_dir.x < 0)
|
|
||||||
// face_position.x = face_position.x + 0;
|
|
||||||
|
|
||||||
if (ray_dir.y > 0){
|
if (ray_dir.y > 0){
|
||||||
face_position.y = - face_position.y + 1;
|
face_position.y = - face_position.y + 1;
|
||||||
texture_position.y = -texture_position.y + 1.0;
|
//tile_face_position.y = -tile_face_position.y + 1.0;
|
||||||
|
}
|
||||||
|
if (ray_dir.y < 0) {
|
||||||
|
//face_position.y = face_position.y + 0;
|
||||||
|
//tile_face_position.y = -tile_face_position.y + 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (ray_dir.y < 0)
|
|
||||||
// face_position.y = face_position.y + 0;
|
|
||||||
|
|
||||||
if (ray_dir.z > 0) {
|
if (ray_dir.z > 0) {
|
||||||
face_position.z = - face_position.z + 1;
|
face_position.z = - face_position.z + 1;
|
||||||
texture_position.y = -texture_position.y + 1.0;
|
//tile_face_position.y = tile_face_position.y + 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (ray_dir.z < 0)
|
if (ray_dir.z < 0) {
|
||||||
// face_position.z = face_position.z + 0;
|
//face_position.z = face_position.z + 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Now either use the face position to retrieve a texture sample, or
|
// Now either use the face position to retrieve a texture sample, or
|
||||||
@@ -307,7 +311,7 @@ __kernel void raycaster(
|
|||||||
}
|
}
|
||||||
else if (voxel_data == 5) {
|
else if (voxel_data == 5) {
|
||||||
float2 tile_size = convert_float2(*atlas_dim / *tile_dim);
|
float2 tile_size = convert_float2(*atlas_dim / *tile_dim);
|
||||||
voxel_color = read_imagef(texture_atlas, convert_int2(texture_position * tile_size) + convert_int2((float2)(3, 0) * tile_size));
|
voxel_color = read_imagef(texture_atlas, convert_int2(tile_face_position * tile_size) + convert_int2((float2)(3, 0) * tile_size));
|
||||||
//voxel_color = (float4)(0.25, 0.52, 0.30, 0.1);
|
//voxel_color = (float4)(0.25, 0.52, 0.30, 0.1);
|
||||||
}
|
}
|
||||||
else if (voxel_data == 1) {
|
else if (voxel_data == 1) {
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ void Camera::recieve_event(VrEventPublisher* publisher, std::unique_ptr<vr::Even
|
|||||||
vr::KeyHeld *held_event = static_cast<vr::KeyHeld*>(event.get());
|
vr::KeyHeld *held_event = static_cast<vr::KeyHeld*>(event.get());
|
||||||
|
|
||||||
if (held_event->code == sf::Keyboard::LShift) {
|
if (held_event->code == sf::Keyboard::LShift) {
|
||||||
default_impulse = 0.1f;
|
default_impulse = 0.01f;
|
||||||
}
|
}
|
||||||
if (held_event->code == sf::Keyboard::RShift) {
|
if (held_event->code == sf::Keyboard::RShift) {
|
||||||
default_impulse = 1.0f;
|
default_impulse = 1.0f;
|
||||||
|
|||||||
62
src/main.cpp
62
src/main.cpp
@@ -26,6 +26,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include <SFML/Network.hpp>
|
||||||
#include "Old_Map.h"
|
#include "Old_Map.h"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "RayCaster.h"
|
#include "RayCaster.h"
|
||||||
@@ -40,8 +41,8 @@ const int WINDOW_X = 1000;
|
|||||||
const int WINDOW_Y = 1000;
|
const int WINDOW_Y = 1000;
|
||||||
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
||||||
|
|
||||||
const int MAP_X = 1024;
|
const int MAP_X = 256;
|
||||||
const int MAP_Y = 1024;
|
const int MAP_Y = 256;
|
||||||
const int MAP_Z = 256;
|
const int MAP_Z = 256;
|
||||||
|
|
||||||
float elap_time(){
|
float elap_time(){
|
||||||
@@ -64,9 +65,66 @@ sf::Texture window_texture;
|
|||||||
// Y: -1.57 is straight up
|
// Y: -1.57 is straight up
|
||||||
// Y: 1.57 is straight down
|
// Y: 1.57 is straight down
|
||||||
|
|
||||||
|
struct CustomPacket {
|
||||||
|
|
||||||
|
char data[1024];
|
||||||
|
int position = 0;
|
||||||
|
int size = 12;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Create a listener to wait for incoming connections on port 55001
|
||||||
|
sf::TcpListener listener;
|
||||||
|
listener.listen(5000);
|
||||||
|
|
||||||
|
// Wait for a connection
|
||||||
|
sf::TcpSocket socket;
|
||||||
|
listener.accept(socket);
|
||||||
|
std::cout << "New client connected: " << socket.getRemoteAddress() << std::endl;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Map _map(sf::Vector3i(0, 0, 0));
|
//Map _map(sf::Vector3i(0, 0, 0));
|
||||||
//_map.generate_octree();
|
//_map.generate_octree();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user