Skip to content

Commit 095f826

Browse files
numberZerolhofhansl
authored andcommittedNov 26, 2020
Batch cloud drawing
1 parent f1349be commit 095f826

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed
 

‎src/client/clouds.cpp

+23-24
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ void Clouds::render()
170170

171171
// Read noise
172172

173-
bool *grid = new bool[m_cloud_radius_i * 2 * m_cloud_radius_i * 2];
174-
173+
std::vector<char> grid(m_cloud_radius_i * 2 * m_cloud_radius_i * 2); // vector<bool> is broken
174+
std::vector<video::S3DVertex> vertices;
175+
vertices.reserve(16 * m_cloud_radius_i * m_cloud_radius_i);
175176

176177
for(s16 zi = -m_cloud_radius_i; zi < m_cloud_radius_i; zi++) {
177178
u32 si = (zi + m_cloud_radius_i) * m_cloud_radius_i * 2 + m_cloud_radius_i;
@@ -195,12 +196,7 @@ void Clouds::render()
195196
{
196197
s16 zi = zi0;
197198
s16 xi = xi0;
198-
// Draw from front to back (needed for transparency)
199-
/*if(zi <= 0)
200-
zi = -m_cloud_radius_i - zi;
201-
if(xi <= 0)
202-
xi = -m_cloud_radius_i - xi;*/
203-
// Draw from back to front
199+
// Draw from back to front for proper transparency
204200
if(zi >= 0)
205201
zi = m_cloud_radius_i - zi - 1;
206202
if(xi >= 0)
@@ -220,17 +216,10 @@ void Clouds::render()
220216
video::S3DVertex(0,0,0, 0,0,0, c_top, 0, 0)
221217
};
222218

223-
/*if(zi <= 0 && xi <= 0){
224-
v[0].Color.setBlue(255);
225-
v[1].Color.setBlue(255);
226-
v[2].Color.setBlue(255);
227-
v[3].Color.setBlue(255);
228-
}*/
229-
230-
f32 rx = cloud_size / 2.0f;
219+
const f32 rx = cloud_size / 2.0f;
231220
// if clouds are flat, the top layer should be at the given height
232-
f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f;
233-
f32 rz = cloud_size / 2;
221+
const f32 ry = m_enable_3d ? m_params.thickness * BS : 0.0f;
222+
const f32 rz = cloud_size / 2;
234223

235224
for(int i=0; i<num_faces_to_draw; i++)
236225
{
@@ -320,15 +309,25 @@ void Clouds::render()
320309
v3f pos(p0.X, m_params.height * BS, p0.Y);
321310
pos -= intToFloat(m_camera_offset, BS);
322311

323-
for (video::S3DVertex &vertex : v)
312+
for (video::S3DVertex &vertex : v) {
324313
vertex.Pos += pos;
325-
u16 indices[] = {0,1,2,2,3,0};
326-
driver->drawVertexPrimitiveList(v, 4, indices, 2,
327-
video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
314+
vertices.push_back(vertex);
315+
}
328316
}
329317
}
330-
331-
delete[] grid;
318+
int quad_count = vertices.size() / 4;
319+
std::vector<u16> indices;
320+
indices.reserve(quad_count * 6);
321+
for (int k = 0; k < quad_count; k++) {
322+
indices.push_back(4 * k + 0);
323+
indices.push_back(4 * k + 1);
324+
indices.push_back(4 * k + 2);
325+
indices.push_back(4 * k + 2);
326+
indices.push_back(4 * k + 3);
327+
indices.push_back(4 * k + 0);
328+
}
329+
driver->drawVertexPrimitiveList(vertices.data(), vertices.size(), indices.data(), 2 * quad_count,
330+
video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
332331

333332
// Restore fog settings
334333
driver->setFog(fog_color, fog_type, fog_start, fog_end, fog_density,

0 commit comments

Comments
 (0)
Please sign in to comment.