Space Sim
Toggle main menu visibility
Loading...
Searching...
No Matches
src
mesh
mesh.h
Go to the documentation of this file.
1
#ifndef MESH_H
2
#define MESH_H
3
4
#include "
core/types.h
"
5
#include "uthash/uthash.h"
6
#include <stdio.h>
7
8
9
typedef
struct
{
10
int
x
,
y
,
z
;
11
}
CenterKey
;
12
13
typedef
struct
{
14
CenterKey
key
;
15
int
lod
;
16
UT_hash_handle
hh
;
17
}
AuthorityEntry
;
18
19
20
21
typedef
struct
ChunkKey
22
{
23
24
int
x
,
y
,
z
,
lod
;
25
26
}
ChunkKey
;
27
28
typedef
struct
ChunkHash
29
{
30
31
ChunkKey
key
;
32
int
id
;
33
UT_hash_handle
hh
;
34
35
}
ChunkHash
;
36
void
load_chunks
(
vec3
planet_origin
,
float
planet_radius
);
37
38
void
init_chunk_data
();
39
bool
free_parent
(
int
lod
,
int
i);
40
bool
free_child
(
int
lod
,
int
i);
41
bool
free_current_parent
(
int
lod
,
int
i);
42
43
float
calc_density
(
vec3
p);
44
void
mesh_atmosphere_sphere
();
45
void
create_new_planet_mesh
(
int
lod
,
ivec3
chunk_center,
int
chunk_id
,
bool
is_parent
);
46
float
fbm
(
vec3
p);
47
48
extern
AuthorityEntry
*
authority_map
;
49
extern
ChunkHash
*
hash_table
;
50
51
static
inline
int
get_current_lod
(
ivec3
center)
52
{
53
AuthorityEntry
* e;
54
CenterKey
k = {center.
x
, center.
y
, center.
z
};
55
56
HASH_FIND(hh,
authority_map
, &k,
sizeof
(k), e);
57
if
(!e)
return
-1;
58
59
return
e->
lod
;
60
}
61
62
static
inline
void
set_current_lod
(
ivec3
center,
int
lod
)
63
{
64
AuthorityEntry
* e = NULL;
65
CenterKey
k = {center.
x
, center.
y
, center.
z
};
66
67
HASH_FIND(hh,
authority_map
, &k,
sizeof
(k), e);
68
69
if
(!e) {
70
e = (
AuthorityEntry
*)malloc(
sizeof
(*e));
71
e->
key
= k;
72
HASH_ADD(hh,
authority_map
, key,
sizeof
(k), e);
73
}
74
75
e->
lod
=
lod
;
76
}
77
78
// find by center, return even if lod does not match
79
static
inline
ChunkHash
*
find_chunk_hash
(
ivec3
center,
int
lod
)
80
{
81
ChunkHash
* f = NULL;
82
83
ChunkKey
k = {(center.
x
), (center.
y
), (center.
z
),
lod
};
84
HASH_FIND(hh,
hash_table
, &k,
sizeof
(
ChunkKey
), f);
85
86
return
f;
87
}
88
static
inline
void
add_chunk_hash
(
ivec3
center,
int
lod
,
int
id
)
89
{
90
91
ChunkKey
k = {(center.
x
), (center.
y
), (center.
z
),
lod
};
92
ChunkHash
*a = (
ChunkHash
*)malloc(
sizeof
(
ChunkHash
));
93
memset(a, 0,
sizeof
(
ChunkHash
));
94
a->
key
= k;
95
a->
id
= id;
96
// a->hh = hh;
97
HASH_ADD(hh,
hash_table
, key,
sizeof
(
ChunkKey
), a);
98
99
}
100
101
static
inline
void
replace_chunk_hash
(
ivec3
center,
int
lod
,
int
id
)
102
{
103
104
ChunkKey
k = {(center.
x
), (center.
y
), (center.
z
),
lod
};
105
// a->hh = hh;
106
ChunkHash
* r = NULL;
107
// HASH_REPLACE(hh, hash_table, key, sizeof(ChunkKey), a, r);
108
HASH_FIND(hh,
hash_table
, &k,
sizeof
(k), r);
109
110
if
(!r) {
111
ChunkHash
*a = (
ChunkHash
*)malloc(
sizeof
(
ChunkHash
));
112
memset(a, 0,
sizeof
(
ChunkHash
));
113
a->
key
= k;
114
a->
id
= id;
115
HASH_ADD(hh,
hash_table
, key,
sizeof
(
ChunkKey
), a);
116
}
117
else
118
{
119
r->
id
= id;
120
r->
key
= k;
121
}
122
123
124
}
125
126
static
inline
void
delete_chunk_hash
(
ivec3
center,
int
lod
)
127
{
128
129
ChunkHash
* p = NULL;
130
ChunkKey
k = {(center.
x
), (center.
y
), (center.
z
),
lod
};
131
HASH_FIND(hh,
hash_table
, &k,
sizeof
(
ChunkKey
), p);
132
if
(p)
133
{
134
HASH_DEL(
hash_table
, p);
135
free(p);
136
}
137
else
138
{
139
// printf("NO DELETION HASH FOUND %d %d %d\n", center.x, center.y, center.z);
140
// exit(0);
141
}
142
}
143
#endif
chunk_id
uniform int chunk_id
Definition
density.comp:159
lod
uniform int lod
Definition
density.comp:154
fbm
float fbm(vec3 x)
Definition
density.comp:139
mesh_atmosphere_sphere
void mesh_atmosphere_sphere()
Creates an atmosphere sphere for rendering.
Definition
mesh.c:1741
init_chunk_data
void init_chunk_data()
Initializes and frees old ChunkData and hash tables.
Definition
mesh.c:796
free_parent
bool free_parent(int lod, int i)
Frees the parent of given LOD.
Definition
mesh.c:691
load_chunks
void load_chunks(vec3 planet_origin, float planet_radius)
Checks all chunks based on new Camera position, building a job list and then executing them based on ...
Definition
mesh.c:894
calc_density
float calc_density(vec3 p)
Copies the exact density function from the GPU to the CPU.
Definition
mesh.c:324
free_current_parent
bool free_current_parent(int lod, int i)
Frees the given LOD (as a parent).
Definition
mesh.c:662
free_child
bool free_child(int lod, int i)
Frees the child of given LOD.
Definition
mesh.c:725
create_new_planet_mesh
void create_new_planet_mesh(int lod, ivec3 chunk_center, int chunk_id, bool is_parent)
Creates a mesh for a certain chunk.
Definition
mesh.c:434
is_parent
uniform bool is_parent
Definition
indirect.comp:55
planet_origin
vec3 planet_origin
Definition
main.c:260
planet_radius
float planet_radius
Definition
main.c:262
authority_map
AuthorityEntry * authority_map
Definition
mesh.c:617
hash_table
ChunkHash * hash_table
Definition
mesh.c:618
AuthorityEntry::key
CenterKey key
Definition
mesh.h:14
AuthorityEntry::hh
UT_hash_handle hh
Definition
mesh.h:16
AuthorityEntry::lod
int lod
Definition
mesh.h:15
find_chunk_hash
ChunkHash * find_chunk_hash(ivec3 center, int lod)
Definition
mesh.h:79
ChunkKey::lod
int lod
Definition
mesh.h:24
ChunkHash::key
ChunkKey key
Definition
mesh.h:31
ChunkKey::x
int x
Definition
mesh.h:24
delete_chunk_hash
void delete_chunk_hash(ivec3 center, int lod)
Definition
mesh.h:126
ChunkKey::z
int z
Definition
mesh.h:24
CenterKey::x
int x
Definition
mesh.h:10
get_current_lod
int get_current_lod(ivec3 center)
Definition
mesh.h:51
ChunkKey::y
int y
Definition
mesh.h:24
ChunkHash::hh
UT_hash_handle hh
Definition
mesh.h:33
CenterKey::z
int z
Definition
mesh.h:10
add_chunk_hash
void add_chunk_hash(ivec3 center, int lod, int id)
Definition
mesh.h:88
set_current_lod
void set_current_lod(ivec3 center, int lod)
Definition
mesh.h:62
replace_chunk_hash
void replace_chunk_hash(ivec3 center, int lod, int id)
Definition
mesh.h:101
ChunkHash::id
int id
Definition
mesh.h:32
CenterKey::y
int y
Definition
mesh.h:10
AuthorityEntry
Definition
mesh.h:13
CenterKey
Definition
mesh.h:9
ChunkHash
Definition
mesh.h:29
ChunkKey
Definition
mesh.h:22
types.h
ivec3::y
int y
Definition
types.h:48
ivec3::z
int z
Definition
types.h:48
ivec3::x
int x
Definition
types.h:48
ivec3
Definition
types.h:48
vec3
Definition
main.h:5
Generated by
1.18.0