mirror of
https://github.com/Relintai/godot_voxel.git
synced 2024-11-19 02:47:18 +01:00
Use std::vector for speed
This commit is contained in:
parent
faefde721a
commit
66d4a913bd
@ -231,7 +231,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelBuffer &bu
|
|||||||
{
|
{
|
||||||
int append_index = arrays.positions.size();
|
int append_index = arrays.positions.size();
|
||||||
arrays.positions.resize(arrays.positions.size() + vertex_count);
|
arrays.positions.resize(arrays.positions.size() + vertex_count);
|
||||||
Vector3 *w = arrays.positions.ptrw() + append_index;
|
Vector3 *w = arrays.positions.data() + append_index;
|
||||||
for (unsigned int i = 0; i < vertex_count; ++i) {
|
for (unsigned int i = 0; i < vertex_count; ++i) {
|
||||||
w[i] = rv[i] + pos;
|
w[i] = rv[i] + pos;
|
||||||
}
|
}
|
||||||
@ -240,13 +240,13 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelBuffer &bu
|
|||||||
{
|
{
|
||||||
int append_index = arrays.uvs.size();
|
int append_index = arrays.uvs.size();
|
||||||
arrays.uvs.resize(arrays.uvs.size() + vertex_count);
|
arrays.uvs.resize(arrays.uvs.size() + vertex_count);
|
||||||
memcpy(arrays.uvs.ptrw() + append_index, rt.ptr(), vertex_count * sizeof(Vector2));
|
memcpy(arrays.uvs.data() + append_index, rt.ptr(), vertex_count * sizeof(Vector2));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
int append_index = arrays.normals.size();
|
int append_index = arrays.normals.size();
|
||||||
arrays.normals.resize(arrays.normals.size() + vertex_count);
|
arrays.normals.resize(arrays.normals.size() + vertex_count);
|
||||||
Vector3 *w = arrays.normals.ptrw() + append_index;
|
Vector3 *w = arrays.normals.data() + append_index;
|
||||||
for (unsigned int i = 0; i < vertex_count; ++i) {
|
for (unsigned int i = 0; i < vertex_count; ++i) {
|
||||||
w[i] = Cube::g_side_normals[side].to_vec3();
|
w[i] = Cube::g_side_normals[side].to_vec3();
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelBuffer &bu
|
|||||||
|
|
||||||
int append_index = arrays.colors.size();
|
int append_index = arrays.colors.size();
|
||||||
arrays.colors.resize(arrays.colors.size() + vertex_count);
|
arrays.colors.resize(arrays.colors.size() + vertex_count);
|
||||||
Color *w = arrays.colors.ptrw() + append_index;
|
Color *w = arrays.colors.data() + append_index;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < vertex_count; ++i) {
|
for (unsigned int i = 0; i < vertex_count; ++i) {
|
||||||
Vector3 v = rv[i];
|
Vector3 v = rv[i];
|
||||||
@ -290,7 +290,7 @@ void VoxelMesherBlocky::build(VoxelMesher::Output &output, const VoxelBuffer &bu
|
|||||||
{
|
{
|
||||||
int i = arrays.indices.size();
|
int i = arrays.indices.size();
|
||||||
arrays.indices.resize(arrays.indices.size() + index_count);
|
arrays.indices.resize(arrays.indices.size() + index_count);
|
||||||
int *w = arrays.indices.ptrw();
|
int *w = arrays.indices.data();
|
||||||
for (unsigned int j = 0; j < index_count; ++j) {
|
for (unsigned int j = 0; j < index_count; ++j) {
|
||||||
w[i++] = index_offset + ri[j];
|
w[i++] = index_offset + ri[j];
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include "../voxel_mesher.h"
|
#include "../voxel_mesher.h"
|
||||||
#include <core/reference.h>
|
#include <core/reference.h>
|
||||||
#include <scene/resources/mesh.h>
|
#include <scene/resources/mesh.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class VoxelMesherBlocky : public VoxelMesher {
|
class VoxelMesherBlocky : public VoxelMesher {
|
||||||
GDCLASS(VoxelMesherBlocky, VoxelMesher)
|
GDCLASS(VoxelMesherBlocky, VoxelMesher)
|
||||||
@ -33,13 +34,14 @@ protected:
|
|||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO Replace those with std::vector, it's faster
|
// Using std::vector because they make this mesher twice as fast than Godot Vectors.
|
||||||
|
// See why: https://github.com/godotengine/godot/issues/24731
|
||||||
struct Arrays {
|
struct Arrays {
|
||||||
Vector<Vector3> positions;
|
std::vector<Vector3> positions;
|
||||||
Vector<Vector3> normals;
|
std::vector<Vector3> normals;
|
||||||
Vector<Vector2> uvs;
|
std::vector<Vector2> uvs;
|
||||||
Vector<Color> colors;
|
std::vector<Color> colors;
|
||||||
Vector<int> indices;
|
std::vector<int> indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ref<VoxelLibrary> _library;
|
Ref<VoxelLibrary> _library;
|
||||||
|
Loading…
Reference in New Issue
Block a user