-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcover_positions_compiler.h
101 lines (79 loc) · 2.76 KB
/
cover_positions_compiler.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
#pragma once
#include "cover_positions_compiler.h"
#include "lib/gl_structs.h"
#include "CoverConfig.h"
#include "config.h"
#include "utils.h"
struct CoverPosInfo { // When changing this you have to update CompiledCPInfo::version
glVectorf position;
struct {
float a;
glVectorf axis;
} rotation;
struct {
float x;
float y;
} alignment;
struct {
float w;
float h;
} sizeLim;
static CoverPosInfo interpolate(const CoverPosInfo& a, const CoverPosInfo& b,
float bWeight);
private:
static inline float interpolF(float a, float b, float bWeight) {
return a * (1 - bWeight) + b * bWeight;
}
};
class CompiledCPInfo {
public:
static const int tableRes = 20; // if you change this, you have to change version
static const int version = 1;
bool showMirrorPlane{};
glVectord mirrorNormal; // guaranteed to have length 1
glVectord mirrorCenter;
glVectord cameraPos;
glVectord lookAt;
glVectord upVector;
int firstCover{};
int lastCover{};
fovAspectBehaviour aspectBehaviour{};
// this has to be the last Member!
pfc::array_t<CoverPosInfo> coverPosInfos;
CoverPosInfo getCoverPosInfo(float coverIdx) {
float idx = coverIdx - firstCover;
idx *= tableRes;
int iPart = static_cast<int>(idx);
float fPart = idx - iPart;
return CoverPosInfo::interpolate(
coverPosInfos[iPart], coverPosInfos[iPart + 1], fPart);
}
void serialize(stream_writer* p_stream, abort_callback& p_abort) {
p_stream->write_lendian_t(version, p_abort);
p_stream->write_object( // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
static_cast<void*>(this), offsetof(CompiledCPInfo, coverPosInfos), p_abort);
t_size c = coverPosInfos.get_size();
p_stream->write_lendian_t(c, p_abort);
p_stream->write_object(
static_cast<void*>(coverPosInfos.get_ptr()), sizeof(CoverPosInfo) * c, p_abort);
}
static void unserialize(CompiledCPInfo& out, stream_reader* p_stream,
abort_callback& p_abort) {
int fileVer;
p_stream->read_lendian_t(fileVer, p_abort);
PFC_ASSERT(fileVer == version);
p_stream->read_object( // NOLINTNEXTLINE(cppcoreguidelines-pro-type-cstyle-cast)
static_cast<void*>(&out), offsetof(CompiledCPInfo, coverPosInfos), p_abort);
t_size c;
p_stream->read_lendian_t(c, p_abort);
auto tmp = make_unique<CoverPosInfo[]>(c);
p_stream->read_object(
static_cast<void*>(tmp.get()), sizeof(CoverPosInfo) * c, p_abort);
out.coverPosInfos.set_data_fromptr(tmp.get(), c);
}
};
struct script_error : public std::runtime_error {
using std::runtime_error::runtime_error;
static script_error from_com_error(const class _com_error&);
};
CompiledCPInfo compileCPScript(const char*);