-
Notifications
You must be signed in to change notification settings - Fork 25
/
vm.h
137 lines (109 loc) · 3.78 KB
/
vm.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
#ifndef VM_H
#define VM_H
#include "instruction.h"
#include "coordinate.h"
#include "noise_gen.h"
#include <vector>
#include "../templates/tarray1.h"
#include "../vectortypes.h"
struct TileCoord
{
unsigned int x,y;
};
struct CoordPair
{
double x,y;
};
namespace anl
{
struct SVMOutput
{
double outfloat_;
SRGBA outrgba_;
SVMOutput() : outfloat_(0), outrgba_(0,0,0,0)
{
}
SVMOutput(double v) : outfloat_(v), outrgba_(v,v,v,1)
{
}
SVMOutput(double v, SRGBA rgba)
{
outfloat_=v;
outrgba_=rgba;
}
SVMOutput(const SVMOutput &rhs) : outfloat_(rhs.outfloat_), outrgba_(rhs.outrgba_)
{
}
void set(double v)
{
outfloat_=v;
outrgba_.r=outrgba_.g=outrgba_.b=v;
outrgba_.a=1;
}
void set(SRGBA v)
{
outrgba_=v;
outfloat_=0.2126*v.r + 0.7152*v.g + 0.0722*v.b;
}
SVMOutput operator-(const SVMOutput &rhs) const
{
return SVMOutput(outfloat_-rhs.outfloat_, outrgba_-rhs.outrgba_);
}
SVMOutput operator+(const SVMOutput &rhs) const
{
return SVMOutput(outfloat_+rhs.outfloat_, outrgba_+rhs.outrgba_);
}
SVMOutput operator*(const SVMOutput &rhs) const
{
return SVMOutput(outfloat_*rhs.outfloat_, outrgba_*rhs.outrgba_);
}
SVMOutput operator/(const SVMOutput &rhs) const
{
return SVMOutput(outfloat_/rhs.outfloat_, outrgba_/rhs.outrgba_);
}
SVMOutput operator*(double rhs) const
{
return SVMOutput(outfloat_*rhs, outrgba_*rhs);
}
void set(const SVMOutput &rhs)
{
outfloat_=rhs.outfloat_;
outrgba_=rhs.outrgba_;
}
};
typedef std::vector<SInstruction> InstructionListType;
typedef std::vector<bool> EvaluatedType;
typedef std::vector<CCoordinate> CoordCacheType;
typedef std::vector<SVMOutput> CacheType;
class CNoiseExecutor
{
public:
CNoiseExecutor(CKernel &kernel);
~CNoiseExecutor();
SVMOutput evaluate(CCoordinate &coord);
SVMOutput evaluateAt(CCoordinate &coord, CInstructionIndex index);
double evaluateScalar(double x, double y, CInstructionIndex idx);
double evaluateScalar(double x, double y, double z, CInstructionIndex idx);
double evaluateScalar(double x, double y, double z, double w, CInstructionIndex idx);
double evaluateScalar(double x, double y, double z, double w, double u, double v, CInstructionIndex idx);
SRGBA evaluateColor(double x, double y, CInstructionIndex idx);
SRGBA evaluateColor(double x, double y, double z, CInstructionIndex idx);
SRGBA evaluateColor(double x, double y, double z, double w, CInstructionIndex idx);
SRGBA evaluateColor(double x, double y, double z, double w, double u, double v, CInstructionIndex idx);
private:
void seedSource(InstructionListType &kernel, EvaluatedType &evaluated, unsigned int index, unsigned int &seed);
void evaluateInstruction(InstructionListType &kernel, EvaluatedType &evaluated, CoordCacheType &coordcache, CacheType &cache, unsigned int index, CCoordinate &coord);
double evaluateParameter(InstructionListType &kernel, EvaluatedType &evaluated, CoordCacheType &coordcache, CacheType &cache, unsigned int index, CCoordinate &coord);
SVMOutput evaluateBoth(InstructionListType &kernel, EvaluatedType &evaluated, CoordCacheType &coordcache, CacheType &cache, unsigned int index, CCoordinate &coord);
SRGBA evaluateRGBA(InstructionListType &kernel, EvaluatedType &evaluated, CoordCacheType &coordcache, CacheType &cache, unsigned int index, CCoordinate &coord);
TileCoord calcHexPointTile(float px, float py);
CoordPair calcHexTileCenter(int tx, int ty);
InstructionListType *prepare();
//InstructionListType *kernel_;
CKernel &kernel_;
EvaluatedType evaluated_;
CoordCacheType coordcache_;
CacheType cache_;
};
};
#endif