1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// SPDX-License-Identifier: BSD-2-Clause
// Copyright (c) 2025 Kirill Dmitrievich
// File: feature.cc
// Description: A world generation feature
#include "shared/pch.hh"
#include "shared/world/feature.hh"
#include "shared/world/chunk.hh"
#include "shared/world/dimension.hh"
#include "shared/world/voxel.hh"
#include "shared/coord.hh"
void Feature::place(const voxel_pos& vpos, Dimension* dimension) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
auto it_cpos = coord::to_chunk(it_vpos);
if(auto chunk = dimension->create_chunk(it_cpos)) {
auto it_lpos = coord::to_local(it_vpos);
auto it_index = coord::to_index(it_lpos);
if(chunk->get_voxel(it_index) && !overwrite) {
// There is something in the way
// and the called intentionally requested
// we do not force feature to overwrite voxels
continue;
}
chunk->set_voxel(voxel, it_index);
}
}
}
void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, Chunk& chunk) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
auto it_cpos = coord::to_chunk(it_vpos);
if(it_cpos == cpos) {
auto it_lpos = coord::to_local(it_vpos);
auto it_index = coord::to_index(it_lpos);
if(chunk.get_voxel(it_index) && !overwrite) {
// There is something in the way
// and the called intentionally requested
// we do not force feature to overwrite voxels
continue;
}
chunk.set_voxel(voxel, it_index);
}
}
}
void Feature::place(const voxel_pos& vpos, const chunk_pos& cpos, VoxelStorage& voxels) const
{
for(const auto [rpos, voxel, overwrite] : (*this)) {
auto it_vpos = vpos + rpos;
auto it_cpos = coord::to_chunk(it_vpos);
if(it_cpos == cpos) {
auto it_lpos = coord::to_local(it_vpos);
auto it_index = coord::to_index(it_lpos);
if(voxels[it_index] && !overwrite) {
// There is something in the way
// and the called intentionally requested
// we do not force feature to overwrite voxels
continue;
}
voxels[it_index] = voxel ? voxel->get_id() : NULL_VOXEL_ID;
}
}
}
|