From e9d6ab657235ebbf3eb9fcb35537c9b2181a1360 Mon Sep 17 00:00:00 2001 From: Jon Bergli Heier Date: Sat, 9 Apr 2011 14:31:18 +0200 Subject: Moved from dynamic LOD to chunked loading. --- quadtree.h | 67 +++++++++++++++++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) (limited to 'quadtree.h') diff --git a/quadtree.h b/quadtree.h index b927dee..d6d1e8e 100644 --- a/quadtree.h +++ b/quadtree.h @@ -3,64 +3,59 @@ #include "vector.h" -#include +#include class Quadtree { public: - - struct UpdateThread { - Quadtree *tree; - float *buffer; - UpdateThread(Quadtree *t, float *b); - void operator()(); - }; + struct QuadChunk; struct QuadNode { - Quadtree *tree; - QuadNode *parent; - QuadNode *children[4]; - int elems; + QuadChunk *chunk; float x, y, width, height; - int level; - float *vertex_array; + float vertex_array[15]; - QuadNode(Quadtree *tree, QuadNode *parent, float x, float y, float width, float height, int level, bool leaf); + QuadNode(QuadChunk *chunk, float x, float y, float width, float height); virtual ~QuadNode(); float distance(float px, float pz); void fill(); - void fix_cracks(); - void subdivide(bool leaf = true); - void merge(); void draw(); void draw_grid(); float get_height(float px, float py); Vector3 get_normal(int index); }; + struct QuadChunk { + Quadtree *tree; + QuadChunk *children[4]; + QuadNode **nodes; + float x, y, width, height; + size_t buf_size; + unsigned int vbo_object; + unsigned int node_count; + unsigned int vertices; + float init_time; + + QuadChunk(Quadtree *tree, float x, float y, float width, float height); + ~QuadChunk(); + + float distance(float px, float pz); + void make_vbo(); + QuadNode *find(float x, float y); + }; + + static const int chunk_size = 32; + + QuadChunk *root; float *heights; - float *thread_buffer; - size_t buf_size; - bool thread_done, thread_running; - boost::mutex vbo_lock; - boost::mutex node_lock; - int width, height, levels; + Vector3 *normals; + int width, height; float init_time; - QuadNode *root; - unsigned int temp_vbo; - unsigned int vbo_object; - unsigned int nodes; - unsigned int vertices; - Quadtree(int width, int height, float *heightmap, int levels); + Quadtree(int width, int height, float *heightmap); virtual ~Quadtree(); void update(float x, float z); - void fix_cracks(); - void create_nodes(int levels); - unsigned int count_nodes(); - void make_vbo(); - void update_vbo(); - QuadNode *find(float x, float y, int level = -1); + QuadNode *find(float x, float y); QuadNode *get_left(QuadNode *node); QuadNode *get_right(QuadNode *node); QuadNode *get_up(QuadNode *node); -- cgit v1.2.3