terraman_2d/world/block_terrain_2d_structure.cpp

110 lines
3.6 KiB
C++
Raw Normal View History

2021-11-22 22:00:45 +01:00
/*
2022-02-22 10:33:06 +01:00
Copyright (c) 2019-2022 Péter Magyar
2021-11-22 22:00:45 +01:00
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.
*/
2022-02-22 11:09:36 +01:00
#include "block_terrain_2d_structure.h"
2021-11-22 22:00:45 +01:00
int BlockTerrain2DStructure::get_channel_type() const {
2021-11-22 22:00:45 +01:00
return _channel_type;
}
void BlockTerrain2DStructure::set_channel_type(const int value) {
2021-11-22 22:00:45 +01:00
_channel_type = value;
}
int BlockTerrain2DStructure::get_channel_isolevel() const {
2021-11-22 22:00:45 +01:00
return _channel_isolevel;
}
void BlockTerrain2DStructure::set_channel_isolevel(const int value) {
2021-11-22 22:00:45 +01:00
_channel_isolevel = value;
}
int BlockTerrain2DStructure::get_voxel_type(int p_x, int p_y, int p_z) const {
2021-11-22 22:00:45 +01:00
DataEntry p;
for (int i = 0; i < _data.size(); ++i) {
p = _data[i];
if (p.x == p_x && p.y == p_y && p.z == p_z) {
return p.data_type;
}
}
return 0;
}
int BlockTerrain2DStructure::get_voxel_isolevel(int p_x, int p_y, int p_z) const {
2021-11-22 22:00:45 +01:00
DataEntry p;
for (int i = 0; i < _data.size(); ++i) {
p = _data[i];
if (p.x == p_x && p.y == p_y && p.z == p_z) {
return p.data_isolevel;
}
}
return 0;
}
void BlockTerrain2DStructure::set_voxel(int p_x, int p_y, int p_z, int p_type, int p_isolevel) {
2021-11-22 22:00:45 +01:00
DataEntry p;
p.x = p_x;
p.y = p_y;
p.z = p_z;
p.data_type = p_type;
p.data_isolevel = p_isolevel;
_data.push_back(p);
}
void BlockTerrain2DStructure::_write_to_chunk(Ref<Terrain2DChunk> chunk) {
//Ref<Terrain2DChunk> c = Object::cast_to<Terrain2DChunk>(chunk);
2021-11-22 22:00:45 +01:00
}
void BlockTerrain2DStructure::clear() {
2021-11-22 22:00:45 +01:00
_data.clear();
}
BlockTerrain2DStructure::BlockTerrain2DStructure() {
2021-11-22 22:00:45 +01:00
_channel_type = 0;
_channel_isolevel = 0;
}
BlockTerrain2DStructure::~BlockTerrain2DStructure() {
2021-11-22 22:00:45 +01:00
_data.clear();
}
void BlockTerrain2DStructure::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_channel_type"), &BlockTerrain2DStructure::get_channel_type);
ClassDB::bind_method(D_METHOD("set_channel_type", "value"), &BlockTerrain2DStructure::set_channel_type);
2021-11-22 22:00:45 +01:00
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_type"), "set_channel_type", "get_channel_type");
ClassDB::bind_method(D_METHOD("get_channel_isolevel"), &BlockTerrain2DStructure::get_channel_isolevel);
ClassDB::bind_method(D_METHOD("set_channel_isolevel", "value"), &BlockTerrain2DStructure::set_channel_isolevel);
2021-11-22 22:00:45 +01:00
ADD_PROPERTY(PropertyInfo(Variant::INT, "channel_isolevel"), "set_channel_isolevel", "get_channel_isolevel");
ClassDB::bind_method(D_METHOD("get_voxel_type", "x", "y", "z"), &BlockTerrain2DStructure::get_voxel_type);
ClassDB::bind_method(D_METHOD("get_voxel_isolevel", "x", "y", "z"), &BlockTerrain2DStructure::get_voxel_isolevel);
2021-11-22 22:00:45 +01:00
ClassDB::bind_method(D_METHOD("set_voxel", "x", "y", "z", "type", "isolevel"), &BlockTerrain2DStructure::set_voxel);
2021-11-22 22:00:45 +01:00
ClassDB::bind_method(D_METHOD("_write_to_chunk", "chunk"), &BlockTerrain2DStructure::_write_to_chunk);
2021-11-22 22:00:45 +01:00
}