forked from Borf/NetworkEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkEngine.h
139 lines (106 loc) · 2.38 KB
/
NetworkEngine.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#pragma once
#include <VrLib/Application.h>
#include <VrLib/tien/Tien.h>
#include <VrLib/util.h>
#include <VrLib/ClusterData.h>
#include <glm/gtc/quaternion.hpp>
#include <VrLib/HtcVive.h>
#include <fstream>
namespace vrlib {
class Tunnel;
class Texture;
namespace tien { class Terrain; class Node; }
}
class Route;
class NetworkEngine;
std::map<std::string, std::function<void(NetworkEngine*, vrlib::Tunnel*, json &)>> &callbacks();
class RouteFollower
{
public:
vrlib::tien::Node* node;
Route* route;
float speed;
float offset;
std::string id = vrlib::util::getGuid();
enum class Rotate
{
XZ,
XYZ,
NONE,
} rotate = Rotate::NONE;
bool followHeight;
glm::quat rotateOffset;
glm::vec3 positionOffset;
};
class Mover
{
public:
vrlib::tien::Node* node;
glm::vec3 position;
bool followHeight;
enum class Rotate
{
XZ,
XYZ,
NONE,
} rotate = Rotate::NONE;
float speed;
float time;
enum class Interpolate
{
Linear,
Exponential
} interpolate = Interpolate::Linear;
glm::quat rotateOffset;
};
class NetworkData : public vrlib::SerializableObject
{
public:
std::vector<std::string> networkPackets;
virtual void writeObject(vrlib::BinaryStream & writer) override;
virtual void readObject(vrlib::BinaryStream & reader) override;
virtual int getEstimatedSize();
};
class NetworkEngine : public vrlib::Application
{
public:
std::string tunnelKey = "";
enum class DebugUniform
{
projectionMatrix,
modelViewMatrix,
};
vrlib::gl::Shader<DebugUniform>* debugShader;
vrlib::ClusterData<NetworkData> clusterData;
std::ofstream logFile;
std::vector<vrlib::Tunnel*> tunnels;
std::vector<Route*> routes;
bool showRoutes = true;
std::vector<glm::vec4> routeColors;
std::vector<RouteFollower> routeFollowers;
std::vector<Mover> movers;
vrlib::Vive vive;
enum CallbackMasks
{
LeftTrigger = 1,
LeftTouchPad = 2,
LeftApplication = 4,
LeftGrip = 8,
RightTrigger = 16,
RightTouchPad = 32,
RightApplication = 64,
RightGrip = 128,
};
int callbackMask = 0;
NetworkEngine();
~NetworkEngine();
vrlib::tien::Tien tien;
vrlib::tien::Terrain* terrain = nullptr;
double frameTime;
// Inherited via Demo
virtual void init() override;
virtual void preFrame(double frameTime, double totalTime) override;
virtual void latePreFrame();
virtual void draw(const glm::mat4 &projectionMatrix, const glm::mat4 &modelViewMatrix) override;
void reset();
};