@@ -20,90 +20,94 @@ with this program; if not, write to the Free Software Foundation, Inc.,
20
20
#include " numeric.h"
21
21
#include " mathconstants.h"
22
22
23
- #include " ../ log.h"
23
+ #include " log.h"
24
24
#include " ../constants.h" // BS, MAP_BLOCKSIZE
25
25
#include < string.h>
26
26
#include < iostream>
27
27
28
+ std::map<u16, std::vector<v3s16> > FacePositionCache::m_cache;
28
29
// Calculate the borders of a "d-radius" cube
29
- void getFacePositions ( std::list <v3s16> &list, u16 d)
30
+ std::vector <v3s16> FacePositionCache::getFacePositions ( u16 d)
30
31
{
31
- if (d == 0 )
32
- {
33
- list.push_back (v3s16 (0 ,0 ,0 ));
32
+ if (m_cache.find (d) != m_cache.end ())
33
+ return m_cache[d];
34
+
35
+ generateFacePosition (d);
36
+ return m_cache[d];
37
+
38
+ }
39
+
40
+ void FacePositionCache::generateFacePosition (u16 d)
41
+ {
42
+ m_cache[d] = std::vector<v3s16>();
43
+ if (d == 0 ) {
44
+ m_cache[d].push_back (v3s16 (0 ,0 ,0 ));
34
45
return ;
35
46
}
36
- if (d == 1 )
37
- {
47
+ if (d == 1 ) {
38
48
/*
39
49
This is an optimized sequence of coordinates.
40
50
*/
41
- list .push_back (v3s16 ( 0 , 1 , 0 )); // top
42
- list .push_back (v3s16 ( 0 , 0 , 1 )); // back
43
- list .push_back (v3s16 (-1 , 0 , 0 )); // left
44
- list .push_back (v3s16 ( 1 , 0 , 0 )); // right
45
- list .push_back (v3s16 ( 0 , 0 ,-1 )); // front
46
- list .push_back (v3s16 ( 0 ,-1 , 0 )); // bottom
51
+ m_cache[d] .push_back (v3s16 ( 0 , 1 , 0 )); // top
52
+ m_cache[d] .push_back (v3s16 ( 0 , 0 , 1 )); // back
53
+ m_cache[d] .push_back (v3s16 (-1 , 0 , 0 )); // left
54
+ m_cache[d] .push_back (v3s16 ( 1 , 0 , 0 )); // right
55
+ m_cache[d] .push_back (v3s16 ( 0 , 0 ,-1 )); // front
56
+ m_cache[d] .push_back (v3s16 ( 0 ,-1 , 0 )); // bottom
47
57
// 6
48
- list .push_back (v3s16 (-1 , 0 , 1 )); // back left
49
- list .push_back (v3s16 ( 1 , 0 , 1 )); // back right
50
- list .push_back (v3s16 (-1 , 0 ,-1 )); // front left
51
- list .push_back (v3s16 ( 1 , 0 ,-1 )); // front right
52
- list .push_back (v3s16 (-1 ,-1 , 0 )); // bottom left
53
- list .push_back (v3s16 ( 1 ,-1 , 0 )); // bottom right
54
- list .push_back (v3s16 ( 0 ,-1 , 1 )); // bottom back
55
- list .push_back (v3s16 ( 0 ,-1 ,-1 )); // bottom front
56
- list .push_back (v3s16 (-1 , 1 , 0 )); // top left
57
- list .push_back (v3s16 ( 1 , 1 , 0 )); // top right
58
- list .push_back (v3s16 ( 0 , 1 , 1 )); // top back
59
- list .push_back (v3s16 ( 0 , 1 ,-1 )); // top front
58
+ m_cache[d] .push_back (v3s16 (-1 , 0 , 1 )); // back left
59
+ m_cache[d] .push_back (v3s16 ( 1 , 0 , 1 )); // back right
60
+ m_cache[d] .push_back (v3s16 (-1 , 0 ,-1 )); // front left
61
+ m_cache[d] .push_back (v3s16 ( 1 , 0 ,-1 )); // front right
62
+ m_cache[d] .push_back (v3s16 (-1 ,-1 , 0 )); // bottom left
63
+ m_cache[d] .push_back (v3s16 ( 1 ,-1 , 0 )); // bottom right
64
+ m_cache[d] .push_back (v3s16 ( 0 ,-1 , 1 )); // bottom back
65
+ m_cache[d] .push_back (v3s16 ( 0 ,-1 ,-1 )); // bottom front
66
+ m_cache[d] .push_back (v3s16 (-1 , 1 , 0 )); // top left
67
+ m_cache[d] .push_back (v3s16 ( 1 , 1 , 0 )); // top right
68
+ m_cache[d] .push_back (v3s16 ( 0 , 1 , 1 )); // top back
69
+ m_cache[d] .push_back (v3s16 ( 0 , 1 ,-1 )); // top front
60
70
// 18
61
- list .push_back (v3s16 (-1 , 1 , 1 )); // top back-left
62
- list .push_back (v3s16 ( 1 , 1 , 1 )); // top back-right
63
- list .push_back (v3s16 (-1 , 1 ,-1 )); // top front-left
64
- list .push_back (v3s16 ( 1 , 1 ,-1 )); // top front-right
65
- list .push_back (v3s16 (-1 ,-1 , 1 )); // bottom back-left
66
- list .push_back (v3s16 ( 1 ,-1 , 1 )); // bottom back-right
67
- list .push_back (v3s16 (-1 ,-1 ,-1 )); // bottom front-left
68
- list .push_back (v3s16 ( 1 ,-1 ,-1 )); // bottom front-right
71
+ m_cache[d] .push_back (v3s16 (-1 , 1 , 1 )); // top back-left
72
+ m_cache[d] .push_back (v3s16 ( 1 , 1 , 1 )); // top back-right
73
+ m_cache[d] .push_back (v3s16 (-1 , 1 ,-1 )); // top front-left
74
+ m_cache[d] .push_back (v3s16 ( 1 , 1 ,-1 )); // top front-right
75
+ m_cache[d] .push_back (v3s16 (-1 ,-1 , 1 )); // bottom back-left
76
+ m_cache[d] .push_back (v3s16 ( 1 ,-1 , 1 )); // bottom back-right
77
+ m_cache[d] .push_back (v3s16 (-1 ,-1 ,-1 )); // bottom front-left
78
+ m_cache[d] .push_back (v3s16 ( 1 ,-1 ,-1 )); // bottom front-right
69
79
// 26
70
80
return ;
71
81
}
72
82
73
83
// Take blocks in all sides, starting from y=0 and going +-y
74
- for (s16 y=0 ; y<=d-1 ; y++)
75
- {
84
+ for (s16 y=0 ; y<=d-1 ; y++) {
76
85
// Left and right side, including borders
77
- for (s16 z=-d; z<=d; z++)
78
- {
79
- list.push_back (v3s16 (d,y,z));
80
- list.push_back (v3s16 (-d,y,z));
81
- if (y != 0 )
82
- {
83
- list.push_back (v3s16 (d,-y,z));
84
- list.push_back (v3s16 (-d,-y,z));
86
+ for (s16 z=-d; z<=d; z++) {
87
+ m_cache[d].push_back (v3s16 (d,y,z));
88
+ m_cache[d].push_back (v3s16 (-d,y,z));
89
+ if (y != 0 ) {
90
+ m_cache[d].push_back (v3s16 (d,-y,z));
91
+ m_cache[d].push_back (v3s16 (-d,-y,z));
85
92
}
86
93
}
87
94
// Back and front side, excluding borders
88
- for (s16 x=-d+1 ; x<=d-1 ; x++)
89
- {
90
- list.push_back (v3s16 (x,y,d));
91
- list.push_back (v3s16 (x,y,-d));
92
- if (y != 0 )
93
- {
94
- list.push_back (v3s16 (x,-y,d));
95
- list.push_back (v3s16 (x,-y,-d));
95
+ for (s16 x=-d+1 ; x<=d-1 ; x++) {
96
+ m_cache[d].push_back (v3s16 (x,y,d));
97
+ m_cache[d].push_back (v3s16 (x,y,-d));
98
+ if (y != 0 ) {
99
+ m_cache[d].push_back (v3s16 (x,-y,d));
100
+ m_cache[d].push_back (v3s16 (x,-y,-d));
96
101
}
97
102
}
98
103
}
99
104
100
105
// Take the bottom and top face with borders
101
106
// -d<x<d, y=+-d, -d<z<d
102
107
for (s16 x=-d; x<=d; x++)
103
- for (s16 z=-d; z<=d; z++)
104
- {
105
- list.push_back (v3s16 (x,-d,z));
106
- list.push_back (v3s16 (x,d,z));
108
+ for (s16 z=-d; z<=d; z++) {
109
+ m_cache[d].push_back (v3s16 (x,-d,z));
110
+ m_cache[d].push_back (v3s16 (x,d,z));
107
111
}
108
112
}
109
113
0 commit comments