forked from capisce/mazecompositor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.h
217 lines (172 loc) · 5.31 KB
/
view.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
* Copyright (c) 2012 Samuel Rødal
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef VIEW_H
#define VIEW_H
#include <QOpenGLBuffer>
#include <QOpenGLFunctions>
#include <QOpenGLShaderProgram>
#include <QPair>
#include <QPolygonF>
#include <QTime>
#include <QTouchEvent>
#include <QWindow>
#include <QVector>
#include <QVector3D>
#include "camera.h"
#include "map.h"
#include "waylandcompositor.h"
#include "waylandsurface.h"
class Entity;
class Light;
class SurfaceItem;
class QOpenGLFramebufferObject;
class QOpenGLWindow : public QWindow
{
public:
QOpenGLWindow(const QRect &geometry);
QOpenGLContext *context() const;
private:
QOpenGLContext *m_context;
};
class View : public QOpenGLWindow, public WaylandCompositor
{
Q_OBJECT
public:
View(const QRect &geometry);
~View();
public slots:
void render();
void onLongPress();
private slots:
void surfaceDestroyed(QObject *surface);
void surfaceDamaged(const QRect &rect);
protected:
void surfaceCreated(WaylandSurface *surface);
private:
void resizeEvent(QResizeEvent *event);
void exposeEvent(QExposeEvent *event);
void generateScene();
void render(const Camera &camera, const QRect ¤tBounds, int zone = 0, int depth = 0);
void updateDrag(const QPoint &pos);
void handleTouchEvent(QTouchEvent *event);
#if 1
void handleTouchBegin(QTouchEvent *event);
void handleTouchUpdate(QTouchEvent *event);
void handleTouchEnd(QTouchEvent *event);
void handleCamera(QTouchEvent *event);
void updateWalking(const QPoint &touch);
#endif
bool event(QEvent *event);
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
bool handleKey(int code, bool pressed);
bool blocked(const QVector3D &pos) const;
bool tryMove(QVector3D &pos, const QVector3D &delta) const;
void move(Camera &camera, const QVector3D &pos);
QRectF dockItemRect(int i) const;
SurfaceItem *dockItemAt(const QPoint &pos);
void startFocus();
struct TraceResult {
int zone;
int tile;
SurfaceItem *item;
qreal u;
qreal v;
QVector3D pos;
};
enum TraceFlag {
NoTraceFlag = 0,
TraceKeepFocus = 1,
TraceIgnoreSurfaces = 2
};
Q_DECLARE_FLAGS(TraceFlags, TraceFlag)
TraceResult trace(const QPointF &pos, TraceFlags flags = NoTraceFlag);
void resizeTo(const QVector2D &local);
Camera portalize(const Camera &camera, int portal, bool clip = true) const;
uint m_vertexAttr;
uint m_normalAttr;
uint m_textureAttr;
uint m_matrixUniform;
uint m_textureUniform;
uint m_rustUniform;
uint m_wallUniform;
uint m_noiseUniform;
uint m_eyeUniform;
uint m_lightsUniform;
uint m_numLightsUniform;
uint m_eyeTextureId;
uint m_arrowsTextureId;
uint m_infoTextureId;
uint m_rustId;
uint m_textureId;
uint m_ditherId[4];
QOpenGLContext *m_context;
QOpenGLFunctions m_gl;
QOpenGLShaderProgram *m_program;
Camera m_camera;
QVector<QVector3D> m_normalBuffer;
QVector<QVector3D> m_vertexBuffer;
QVector<QVector2D> m_texCoordBuffer;
QVector<ushort> m_indexBuffer;
QVector<QPair<int, int> > m_indexBufferOffsets;
qreal m_walkingVelocity;
qreal m_strafingVelocity;
qreal m_turningSpeed;
qreal m_pitchSpeed;
qreal m_targetYaw;
qreal m_targetPitch;
long m_simulationTime;
long m_walkTime;
bool m_jumping;
qreal m_jumpVelocity;
QTime m_time;
typedef QHash<WaylandSurface *, SurfaceItem *> SurfaceHash;
SurfaceHash m_surfaces;
QList<SurfaceItem *> m_mappedSurfaces;
QList<SurfaceItem *> m_dockedSurfaces;
Map m_map;
WaylandInputDevice *m_input;
SurfaceItem *m_focus;
QVector2D m_resizeGrip;
QPolygonF m_portalPoly;
QRectF m_portalRect;
QOpenGLBuffer m_vertexData;
QOpenGLBuffer m_indexData;
SurfaceItem *m_dragItem;
bool m_wireframe;
bool m_mouseLook;
bool m_mouseWalk;
QPoint m_dragItemDelta;
bool m_dragAccepted;
int m_touchMoveId;
int m_touchLookId;
bool m_showInfo;
bool m_pressingInfo;
bool m_fullscreen;
QPoint m_mousePos;
QHash<int, bool> m_occupiedTiles;
QTimer *m_focusTimer;
QTimer *m_fullscreenTimer;
QTimer *m_animationTimer;
Entity *m_entity;
};
#endif