52 lines
1.2 KiB
C++
52 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "core/math/rect2.h"
|
|
#include "core/os/mutex.h"
|
|
#include "core/os/thread.h"
|
|
#include "core/templates/vector.h"
|
|
#include "scene/main/node.h"
|
|
class TerrainChunkMesh;
|
|
class TerrainModifier;
|
|
|
|
class Terrain : public Node {
|
|
GDCLASS(Terrain, Node);
|
|
static void _bind_methods();
|
|
void child_order_changed();
|
|
void update_meshes();
|
|
|
|
protected:
|
|
void _notification(int what);
|
|
static void generate_meshes_thread(void *terrain);
|
|
|
|
public:
|
|
void construct_chunk_grid();
|
|
float height_at(Vector2 world_coordinate);
|
|
void push_changed(Rect2 area);
|
|
void mesh_dirty(TerrainChunkMesh *mesh);
|
|
|
|
private:
|
|
Vector<TerrainChunkMesh *> workload{};
|
|
bool threads_stop{ false };
|
|
Mutex workload_lock;
|
|
|
|
Vector<TerrainChunkMesh *> dirty_meshes{};
|
|
Mutex dirty_meshes_lock{};
|
|
|
|
Vector<TerrainChunkMesh *> meshes{};
|
|
Vector<TerrainModifier *> modifiers{};
|
|
LocalVector<Thread> threads{};
|
|
|
|
size_t side_length{ 200 };
|
|
size_t chunk_size{ 50 };
|
|
size_t detail{ 1 };
|
|
|
|
public:
|
|
void set_side_length(size_t length);
|
|
size_t get_side_length() const;
|
|
void set_chunk_size(size_t size);
|
|
size_t get_chunk_size() const;
|
|
void set_detail(size_t detail);
|
|
size_t get_detail() const;
|
|
void set_thread_count(size_t num);
|
|
size_t get_thread_count() const;
|
|
};
|