Ported the basic test biome generation method to a new BiomeBase class.

This commit is contained in:
Relintai 2020-05-23 22:01:38 +02:00
parent 74722edc82
commit 14c239fd87
4 changed files with 165 additions and 0 deletions

2
SCsub
View File

@ -11,6 +11,8 @@ module_env = env.Clone()
sources = [
"register_types.cpp",
"biome_base.cpp"
]
if ARGUMENTS.get('custom_modules_shared', 'no') == 'yes':

117
biome_base.cpp Normal file
View File

@ -0,0 +1,117 @@
/*
Copyright (c) 2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "biome_base.h"
#include "core/math/math_funcs.h"
#include "core/engine.h"
#include "../voxelman/world/default/voxel_chunk_default.h"
#include "../voxelman/world/voxel_chunk.h"
#include "../entity_spell_system/singletons/ess.h"
#include "../entity_spell_system/spawners/ess_entity_spawner.h"
#include "../opensimplex/open_simplex_noise.h"
void BiomeBase::generate_simple_terrarin(Ref<VoxelChunk> chunk, bool spawn_mobs) {
Ref<OpenSimplexNoise> noise;
noise.instance();
noise->set_seed(10 * get_current_seed());
noise->set_octaves(4);
noise->set_period(280.0);
noise->set_persistence(0.8);
Ref<OpenSimplexNoise> terr_noise;
terr_noise.instance();
terr_noise->set_seed(10 * 321 + 112 * get_current_seed());
terr_noise->set_octaves(4);
terr_noise->set_period(90.0);
terr_noise->set_persistence(0.9);
Ref<OpenSimplexNoise> det_noise;
det_noise.instance();
det_noise->set_seed(10 * 3231 + 112 * get_current_seed());
det_noise->set_octaves(6);
det_noise->set_period(80.0);
det_noise->set_persistence(0.3);
for (int x = -chunk->get_margin_start(); x < chunk->get_size_x() + chunk->get_margin_end(); ++x) {
for (int z = -chunk->get_margin_start(); z < chunk->get_size_z() + chunk->get_margin_end(); ++z) {
float val = noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
val *= val;
val *= 200.0;
val += 2.0;
float tv = terr_noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
tv *= tv * tv * tv;
val += tv * 2.0;
float dval = noise->get_noise_2d(x + (chunk->get_position_x() * chunk->get_size_x()), z + (chunk->get_position_z() * chunk->get_size_z()));
val += dval * 6.0;
int v = (int(val));
v -= chunk->get_position_y() * (chunk->get_size_y());
if (v > chunk->get_size_y() + chunk->get_margin_end())
v = chunk->get_size_y() + chunk->get_margin_end();
for (int y = -chunk->get_margin_start(); y < v; y++) {
Math::seed(x + (chunk->get_position_x() * chunk->get_size_x()) + z + (chunk->get_position_z() * chunk->get_size_z()) + y + (chunk->get_position_y() * chunk->get_size_y()));
if (v < 2)
chunk->set_voxel(1, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
else if (v == 2)
chunk->set_voxel(3, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
else
chunk->set_voxel(2, x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
float val2 = (val - static_cast<int>(val)) * 4.0;
val2 = static_cast<int>(val2);
val2 /= 4.0;
chunk->set_voxel(static_cast<int>(255.0 * val2), x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_ISOLEVEL);
}
}
}
//if (!Engine::get_singleton()->is_editor_hint() && chunk->get_position_y() == 0 && spawn_mobs) {
// Vector3 v = Vector3(chunk->get_position_x() * chunk->get_size_x() * chunk->get_voxel_scale() + chunk->get_size_x() / 2,
// (chunk->get_position_y() + 1) * chunk->get_size_y() * chunk->get_voxel_scale(),
// chunk->get_position_z()) *
// (chunk->get_size_z() * chunk->get_voxel_scale() + chunk->get_size_z() / 2);
//
// ESS::get_singleton()->get_entity_spawner()->call("spawn_mob", 0, Math::rand() % 3, v);
// }
}
BiomeBase::BiomeBase() {
}
BiomeBase::~BiomeBase() {
}
void BiomeBase::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_simple_terrarin", "chunk", "spawn_mobs"), &BiomeBase::generate_simple_terrarin);
}

43
biome_base.h Normal file
View File

@ -0,0 +1,43 @@
/*
Copyright (c) 2020 Péter Magyar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef BIOME_BASE_H
#define BIOME_BASE_H
#include "../world_generator/main/biome.h"
class VoxelChunk;
class BiomeBase : public Biome {
GDCLASS(BiomeBase, Biome);
public:
void generate_simple_terrarin(Ref<VoxelChunk> chunk, bool spawn_mobs);
BiomeBase();
~BiomeBase();
protected:
static void _bind_methods();
};
#endif

View File

@ -24,7 +24,10 @@ SOFTWARE.
*/
#include "biome_base.h"
void register_broken_seals_module_types() {
ClassDB::register_class<BiomeBase>();
}
void unregister_broken_seals_module_types() {