-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathWOGManager.h
More file actions
111 lines (82 loc) · 2.4 KB
/
Copy pathWOGManager.h
File metadata and controls
111 lines (82 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
* WOGManager.h
*
* Created on: May 11, 2016
* Author: Bernd Doser <bernd.doser@h-its.org>
*/
#pragma once
#include "Galaxy.h"
#include "octree.h"
#include "jsoncons/json.hpp"
#include <array>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstdlib>
#include <iostream>
#include <string>
#include <stdexcept>
struct sockaddr_in;
/**
* War of Galaxies (WOG)
* - Store galaxy type which can be released
* - Control interconnection via UNIX socket
* - Add and remove particles to running simulation
*/
class WOGManager
{
public:
/// Constructor opening sockets and reading input galaxies
WOGManager(octree *tree, std::string const& path, int port, int window_width, int window_height, real fovy,
real farZ, real camera_distance, real deletion_radius_factor);
/// Constructor closing the sockets
~WOGManager();
/// Execute a client request
void execute();
/// Must be called by glutReshapeFunc
void reshape(int width, int height);
/// Return camera distance
real get_camera_distance() const { return camera_distance; }
private:
/// Read all galaxy types
void read_galaxies(std::string const& path);
/// Remove particles continuously
void remove_particles();
/// Execute a client request
jsoncons::json execute_json(std::string const& buffer);
octree *tree;
int server_socket;
int client_socket;
/// Number of users
static constexpr auto number_of_users = 4;
/// Buffer size for socket data transmission
static constexpr auto buffer_size = 1024;
/// Maximal number of particles of a user
static constexpr auto max_number_of_particles_of_user = 100000;
/// Number of particles of user
my_dev::dev_mem<uint> user_particles;
/// Dimension of the window
int window_width;
int window_height;
/// OpenGL viewing angle
real fovy;
/// OpenGL distance of clipping plane
real farZ;
/// Distance of the OpenGL camera
real camera_distance;
/// Dimension of the window
real simulation_plane_width;
real simulation_plane_height;
/// Scaling factor for deletion sphere.
real deletion_radius_factor;
/// Squared radius of deletion sphere. Particles leaving this sphere will be removed.
real deletion_radius_square;
/// Galaxy types which can be released
std::vector<Galaxy> galaxies;
};