Added a flat level generator.

This commit is contained in:
Relintai 2020-04-17 15:29:36 +02:00
parent 59b5086113
commit ba0c1bc820
5 changed files with 162 additions and 2 deletions

1
SCsub
View File

@ -54,6 +54,7 @@ sources = [
"meshers/cubic_mesher/voxel_cube_points.cpp",
"level_generator/voxelman_level_generator.cpp",
"level_generator/voxelman_level_generator_flat.cpp",
"areas/world_area.cpp",

View File

@ -15,6 +15,7 @@ def get_doc_classes():
"VoxelLight",
"VoxelmanLevelGenerator",
"VoxelmanLevelGeneratorFlat",
"VoxelSurfaceMerger",
"VoxelSurfaceSimple",
@ -39,8 +40,8 @@ def get_doc_classes():
"VoxelWorld",
"VoxelMesherBlocky",
"VoxelWorldBlocky",
"VoxelChunkBlocky",
"VoxelWorldBlocky",
"VoxelChunkBlocky",
]
def get_doc_path():

View File

@ -0,0 +1,103 @@
/*
Copyright (c) 2019-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 "voxelman_level_generator_flat.h"
#include "../world/voxel_chunk.h"
int VoxelmanLevelGeneratorFlat::get_floor_position() const {
return _floor_position;
}
void VoxelmanLevelGeneratorFlat::set_floor_position(const int floor_height) {
_floor_position = floor_height;
}
Dictionary VoxelmanLevelGeneratorFlat::get_channel_map() {
return _channel_map;
}
void VoxelmanLevelGeneratorFlat::set_channel_map(const Dictionary &map) {
_channel_map = map;
}
void VoxelmanLevelGeneratorFlat::_generate_chunk(Ref<VoxelChunk> chunk) {
int dymin = chunk->get_position_y() * chunk->get_size_y();
int dymax = dymin + chunk->get_size_y() + chunk->get_margin_end();
if (_floor_position < dymin)
return;
if (_floor_position > dymax) {
Variant key;
while (_channel_map.next(&key)) {
int k = key;
int value = _channel_map[key];
chunk->fill_channel(value, k);
}
return;
}
const Variant *keyptr = NULL;
keyptr = _channel_map.next(keyptr);
while (keyptr) {
Variant key = (*keyptr);
int k = key;
int value = _channel_map[key];
uint8_t *channel = chunk->get_valid_channel(k, 0);
if (!channel)
continue;
int ty = _floor_position - dymin;
for (int y = 0; y < ty; ++y) {
for (int z = 0; z < chunk->get_data_size_z(); ++z) {
for (int x = 0; x < chunk->get_data_size_x(); ++x) {
channel[chunk->get_data_index(x, y, z)] = value;
}
}
}
keyptr = _channel_map.next(keyptr);
}
}
VoxelmanLevelGeneratorFlat::VoxelmanLevelGeneratorFlat() {
_floor_position = 0;
}
VoxelmanLevelGeneratorFlat::~VoxelmanLevelGeneratorFlat() {
_channel_map.clear();
}
void VoxelmanLevelGeneratorFlat::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_floor_position"), &VoxelmanLevelGeneratorFlat::get_floor_position);
ClassDB::bind_method(D_METHOD("set_floor_position", "value"), &VoxelmanLevelGeneratorFlat::set_floor_position);
ADD_PROPERTY(PropertyInfo(Variant::INT, "floor_position"), "set_floor_position", "get_floor_position");
ClassDB::bind_method(D_METHOD("get_channel_map"), &VoxelmanLevelGeneratorFlat::get_channel_map);
ClassDB::bind_method(D_METHOD("set_channel_map", "value"), &VoxelmanLevelGeneratorFlat::set_channel_map);
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "channel_map"), "set_channel_map", "get_channel_map");
ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &VoxelmanLevelGeneratorFlat::_generate_chunk);
}

View File

@ -0,0 +1,53 @@
/*
Copyright (c) 2019-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 VOXELMAN_LEVEL_GENERATOR_FLAT_H
#define VOXELMAN_LEVEL_GENERATOR_FLAT_H
#include "voxelman_level_generator.h"
class VoxelChunk;
class VoxelmanLevelGeneratorFlat : public VoxelmanLevelGenerator {
GDCLASS(VoxelmanLevelGeneratorFlat, VoxelmanLevelGenerator);
public:
int get_floor_position() const;
void set_floor_position(const int floor_height);
Dictionary get_channel_map();
void set_channel_map(const Dictionary &map);
virtual void _generate_chunk(Ref<VoxelChunk> chunk);
VoxelmanLevelGeneratorFlat();
~VoxelmanLevelGeneratorFlat();
protected:
static void _bind_methods();
private:
int _floor_position;
Dictionary _channel_map;
};
#endif

View File

@ -52,6 +52,7 @@ SOFTWARE.
#include "meshers/cubic_mesher/voxel_mesher_cubic.h"
#include "level_generator/voxelman_level_generator.h"
#include "level_generator/voxelman_level_generator_flat.h"
#include "areas/world_area.h"
@ -97,6 +98,7 @@ void register_voxelman_types() {
ClassDB::register_class<VoxelChunkBlocky>();
ClassDB::register_class<VoxelmanLevelGenerator>();
ClassDB::register_class<VoxelmanLevelGeneratorFlat>();
ClassDB::register_class<WorldArea>();