From ea62e02c6a8f71264b522e2d6725136b94416878 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 1 Mar 2022 23:43:07 +0100 Subject: [PATCH] Added a new Isometric world/chunk/mesher. It's a copy of the simple ones right now. --- SCsub | 8 +- config.py | 10 +- .../isometric/terrain_2d_mesher_isometric.cpp | 351 ++++++++++++++++++ .../isometric/terrain_2d_mesher_isometric.h | 55 +++ register_types.cpp | 13 +- .../isometric/terrain_2d_chunk_isometric.cpp | 39 ++ world/isometric/terrain_2d_chunk_isometric.h | 41 ++ .../isometric/terrain_2d_world_isometric.cpp | 72 ++++ world/isometric/terrain_2d_world_isometric.h | 41 ++ 9 files changed, 622 insertions(+), 8 deletions(-) create mode 100644 meshers/isometric/terrain_2d_mesher_isometric.cpp create mode 100644 meshers/isometric/terrain_2d_mesher_isometric.h create mode 100644 world/isometric/terrain_2d_chunk_isometric.cpp create mode 100644 world/isometric/terrain_2d_chunk_isometric.h create mode 100644 world/isometric/terrain_2d_world_isometric.cpp create mode 100644 world/isometric/terrain_2d_world_isometric.h diff --git a/SCsub b/SCsub index 13e4cf3..428058c 100644 --- a/SCsub +++ b/SCsub @@ -38,6 +38,7 @@ sources = [ "meshers/terrain_2d_mesher.cpp", + "meshers/isometric/terrain_2d_mesher_isometric.cpp", "meshers/simple/terrain_2d_mesher_simple.cpp", "meshers/default/terrain_2d_mesher_default.cpp", @@ -47,11 +48,14 @@ sources = [ "world/block_terrain_2d_structure.cpp", "world/terrain_2d_environment_data.cpp", + "world/default/terrain_2d_world_default.cpp", + "world/default/terrain_2d_chunk_default.cpp", + "world/simple/terrain_2d_chunk_simple.cpp", "world/simple/terrain_2d_world_simple.cpp", - "world/default/terrain_2d_world_default.cpp", - "world/default/terrain_2d_chunk_default.cpp", + "world/isometric/terrain_2d_chunk_isometric.cpp", + "world/isometric/terrain_2d_world_isometric.cpp", "level_generator/terrain_2d_level_generator.cpp", "level_generator/terrain_2d_level_generator_flat.cpp", diff --git a/config.py b/config.py index 9d49fe2..6343e76 100644 --- a/config.py +++ b/config.py @@ -45,9 +45,13 @@ def get_doc_classes(): "BlockTerrain2DStructure", "Terrain2DWorld", - "Terrain2DMesherBlocky", - "Terrain2DWorldBlocky", - "Terrain2DChunkBlocky", + "Terrain2DMesherSimple", + "Terrain2DWorldSimple", + "Terrain2DChunkSimple", + + "Terrain2DMesherIsometric", + "Terrain2DWorldIsometric", + "Terrain2DChunkIsometric", "Terrain2DWorldMarchingCubes", "Terrain2DChunkMarchingCubes", diff --git a/meshers/isometric/terrain_2d_mesher_isometric.cpp b/meshers/isometric/terrain_2d_mesher_isometric.cpp new file mode 100644 index 0000000..d460b17 --- /dev/null +++ b/meshers/isometric/terrain_2d_mesher_isometric.cpp @@ -0,0 +1,351 @@ +/* +Copyright (c) 2019-2022 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 "terrain_2d_mesher_isometric.h" + +#include "core/math/math_funcs.h" + +#include "../../library/terrain_2d_material_cache.h" + +void Terrain2DMesherIsometric::_add_chunk(Ref p_chunk) { + Ref chunk = p_chunk; + + ERR_FAIL_COND(!chunk.is_valid()); + ERR_FAIL_COND(chunk->get_margin_end() < 1); + ERR_FAIL_COND(chunk->get_margin_start() < 1); + + add_chunk_normal(chunk); +} + +void Terrain2DMesherIsometric::add_chunk_normal(Ref chunk) { + //if ((get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_GENERATE_AO) != 0) + // if (!chunk->get_channel(Terrain2DChunkDefault::DEFAULT_CHANNEL_AO)) + // chunk->generate_ao(); + + uint8_t *channel_type = chunk->channel_get(_channel_index_type); + + if (!channel_type) + return; + + uint8_t *channel_flags = chunk->channel_get(Terrain2DChunkDefault::DEFAULT_CHANNEL_FLAGS); + + if (!channel_flags) + return; + + int x_size = chunk->get_size_x(); + int y_size = chunk->get_size_y(); + int cell_size_x = get_cell_size_x(); + int cell_size_y = get_cell_size_y(); + + Transform2D mesh_transform_terrain = chunk->mesh_transform_terrain_get(); + Transform2D mesh_transform_wall_north = chunk->mesh_transform_wall_north_get(); + Transform2D mesh_transform_wall_south = chunk->mesh_transform_wall_south_get(); + Transform2D mesh_transform_wall_east = chunk->mesh_transform_wall_east_get(); + Transform2D mesh_transform_wall_west = chunk->mesh_transform_wall_west_get(); + + uint8_t *channel_color_r = NULL; + uint8_t *channel_color_g = NULL; + uint8_t *channel_color_b = NULL; + uint8_t *channel_ao = NULL; + uint8_t *channel_rao = NULL; + + Color base_light(_base_light_value, _base_light_value, _base_light_value); + Color light[4]{ Color(1, 1, 1), Color(1, 1, 1), Color(1, 1, 1), Color(1, 1, 1) }; + + bool use_lighting = (get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0; + bool use_ao = (get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_AO) != 0; + bool use_rao = (get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_RAO) != 0; + + if (use_lighting) { + channel_color_r = chunk->channel_get_valid(Terrain2DChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_R); + channel_color_g = chunk->channel_get_valid(Terrain2DChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_G); + channel_color_b = chunk->channel_get_valid(Terrain2DChunkDefault::DEFAULT_CHANNEL_LIGHT_COLOR_B); + + if (use_ao) + channel_ao = chunk->channel_get_valid(Terrain2DChunkDefault::DEFAULT_CHANNEL_AO); + + if (use_rao) + channel_rao = chunk->channel_get_valid(Terrain2DChunkDefault::DEFAULT_CHANNEL_RANDOM_AO); + } + + Ref mcache; + + if (chunk->material_cache_key_has()) { + mcache = _library->material_cache_get(chunk->material_cache_key_get()); + } + + int texture_scale = get_texture_scale(); + + int margin_start = chunk->get_margin_start(); + //z_size + margin_start is fine, x, and z are in data space. + for (int y = margin_start; y < y_size + margin_start; ++y) { + for (int x = margin_start; x < x_size + margin_start; ++x) { + int indexes[4] = { + chunk->get_data_index(x, y), + chunk->get_data_index(x + 1, y), + chunk->get_data_index(x, y + 1), + chunk->get_data_index(x + 1, y + 1) + }; + + uint8_t type = channel_type[indexes[0]]; + + if (type == 0) + continue; + + Ref surface; + + if (!mcache.is_valid()) { + surface = _library->terra_surface_get(type - 1); + } else { + surface = mcache->surface_id_get(type - 1); + } + + if (!surface.is_valid()) + continue; + + int flags = channel_flags[indexes[0]]; + + if (use_lighting) { + for (int i = 0; i < 4; ++i) { + int indx = indexes[i]; + + light[i] = Color(channel_color_r[indx] / 255.0, + channel_color_g[indx] / 255.0, + channel_color_b[indx] / 255.0); + + float ao = 0; + + if (use_ao) + ao = channel_ao[indx] / 255.0; + + if (use_rao) { + float rao = channel_rao[indx] / 255.0; + ao += rao; + } + + light[i] += base_light; + + if (ao > 0) + light[i] -= Color(ao, ao, ao) * _ao_strength; + + light[i].r = CLAMP(light[i].r, 0, 1.0); + light[i].g = CLAMP(light[i].g, 0, 1.0); + light[i].b = CLAMP(light[i].b, 0, 1.0); + } + } + + Vector2 uvs[] = { + Vector2(0, 0), + Vector2(1, 0), + Vector2(0, 1), + Vector2(1, 1) + }; + + if (texture_scale > 1) { + for (int i = 0; i < 4; ++i) { + uvs[i] = surface->transform_uv_scaled(uvs[i], x % texture_scale, y % texture_scale, texture_scale); + } + } else { + for (int i = 0; i < 4; ++i) { + uvs[i] = surface->transform_uv(uvs[i]); + } + } + + Vector2 verts_normal[] = { + Vector2(0, 0), + Vector2(cell_size_x, 0), + Vector2(0, cell_size_y), + Vector2(cell_size_x, cell_size_y) + }; + + // Note that +y is down! + Vector2 verts_wall[] = { + Vector2(0, -cell_size_y), + Vector2(cell_size_x, -cell_size_y), + Vector2(0, 0), + Vector2(cell_size_x, 0) + }; + + bool render_normal = true; + + int vc = get_vertex_count(); + + bool hole = (flags & Terrain2DChunkDefault::FLAG_CHANNEL_WALL_HOLE) != 0; + + if ((flags & Terrain2DChunkDefault::FLAG_CHANNEL_WALL_NORTH) != 0) { + render_normal = false; + + Vector2 vert_start_offset = mesh_transform_terrain.xform(Vector2(x * cell_size_x, y * cell_size_y)); + + for (int i = 0; i < 4; ++i) { + if (use_lighting) { + add_color(light[i]); + } else { + add_color(Color(1, 1, 1, 1)); + } + + add_uv(uvs[i]); + + if (hole) { + add_vertex(mesh_transform_wall_north.xform(verts_normal[i]) + vert_start_offset); + } else { + add_vertex(mesh_transform_wall_north.xform(verts_wall[i]) + vert_start_offset); + } + } + + add_indices(vc + 0); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 3); + + vc += 4; + } + + if ((flags & Terrain2DChunkDefault::FLAG_CHANNEL_WALL_WEST) != 0) { + render_normal = false; + + Vector2 vert_start_offset = mesh_transform_terrain.xform(Vector2(x * cell_size_x, (y + 1) * cell_size_y)); + + for (int i = 0; i < 4; ++i) { + if (use_lighting) { + add_color(light[i]); + } else { + add_color(Color(1, 1, 1, 1)); + } + + add_uv(uvs[i]); + + if (hole) { + add_vertex(mesh_transform_wall_west.xform(verts_normal[i]) + vert_start_offset); + } else { + add_vertex(mesh_transform_wall_west.xform(verts_wall[i]) + vert_start_offset); + } + } + + add_indices(vc + 0); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 3); + + vc += 4; + } + + if ((flags & Terrain2DChunkDefault::FLAG_CHANNEL_WALL_SOUTH) != 0) { + render_normal = false; + + Vector2 vert_start_offset = mesh_transform_terrain.xform(Vector2(x * cell_size_x, (y + 1) * cell_size_y)); + + for (int i = 0; i < 4; ++i) { + if (use_lighting) { + add_color(light[i]); + } else { + add_color(Color(1, 1, 1, 1)); + } + + add_uv(uvs[i]); + + if (hole) { + add_vertex(mesh_transform_wall_south.xform(verts_normal[i]) + vert_start_offset); + } else { + add_vertex(mesh_transform_wall_south.xform(verts_wall[i]) + vert_start_offset); + } + } + + add_indices(vc + 0); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 3); + + vc += 4; + } + + if ((flags & Terrain2DChunkDefault::FLAG_CHANNEL_WALL_EAST) != 0) { + render_normal = false; + + Vector2 vert_start_offset = mesh_transform_terrain.xform(Vector2((x + 1) * cell_size_x, (y + 1) * cell_size_y)); + + for (int i = 0; i < 4; ++i) { + if (use_lighting) { + add_color(light[i]); + } else { + add_color(Color(1, 1, 1, 1)); + } + + add_uv(uvs[i]); + + if (hole) { + add_vertex(mesh_transform_wall_east.xform(verts_normal[i]) + vert_start_offset); + } else { + add_vertex(mesh_transform_wall_east.xform(verts_wall[i]) + vert_start_offset); + } + } + + add_indices(vc + 0); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 3); + + vc += 4; + } + + if (render_normal) { + Vector2 vert_start_offset = mesh_transform_terrain.xform(Vector2(x * cell_size_x, y * cell_size_y)); + + for (int i = 0; i < 4; ++i) { + if (use_lighting) { + add_color(light[i]); + } else { + add_color(Color(1, 1, 1, 1)); + } + + add_uv(uvs[i]); + add_vertex(mesh_transform_terrain.xform(verts_normal[i]) + vert_start_offset); + } + + add_indices(vc + 0); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 1); + add_indices(vc + 2); + add_indices(vc + 3); + } + } + } +} + +Terrain2DMesherIsometric::Terrain2DMesherIsometric() { +} + +Terrain2DMesherIsometric::~Terrain2DMesherIsometric() { +} + +void Terrain2DMesherIsometric::_bind_methods() { + ClassDB::bind_method(D_METHOD("_add_chunk", "buffer"), &Terrain2DMesherIsometric::_add_chunk); +} diff --git a/meshers/isometric/terrain_2d_mesher_isometric.h b/meshers/isometric/terrain_2d_mesher_isometric.h new file mode 100644 index 0000000..2df3151 --- /dev/null +++ b/meshers/isometric/terrain_2d_mesher_isometric.h @@ -0,0 +1,55 @@ +/* +Copyright (c) 2019-2022 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 TERRAIN_2D_MESHER_ISOMETRIC_H +#define TERRAIN_2D_MESHER_ISOMETRIC_H + +#include "core/version.h" + +#if VERSION_MAJOR > 3 +#include "core/math/color.h" +#else +#include "core/color.h" +#endif + +#include "core/math/vector2.h" +#include "core/math/vector3.h" + +#include "../default/terrain_2d_mesher_default.h" +#include "../../world/default/terrain_2d_chunk_default.h" + +class Terrain2DMesherIsometric : public Terrain2DMesherDefault { + GDCLASS(Terrain2DMesherIsometric, Terrain2DMesherDefault); + +public: + void _add_chunk(Ref p_chunk); + + void add_chunk_normal(Ref chunk); + + Terrain2DMesherIsometric(); + ~Terrain2DMesherIsometric(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/register_types.cpp b/register_types.cpp index 90925b5..c5e85ce 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -25,15 +25,15 @@ SOFTWARE. #include "library/terrain_2d_surface.h" #include "library/terrain_2d_surface_simple.h" -#include "library/terrain_2d_material_cache.h" #include "library/terrain_2d_library.h" #include "library/terrain_2d_library_simple.h" +#include "library/terrain_2d_material_cache.h" #ifdef TEXTURE_PACKER_PRESENT -#include "library/terrain_2d_surface_merger.h" #include "library/terrain_2d_library_merger.h" #include "library/terrain_2d_library_merger_pcm.h" #include "library/terrain_2d_material_cache_pcm.h" +#include "library/terrain_2d_surface_merger.h" #endif #include "data/terrain_2d_light.h" @@ -56,10 +56,13 @@ SOFTWARE. #include "world/terrain_2d_world_editor.h" #include "meshers/simple/terrain_2d_mesher_simple.h" - #include "world/simple/terrain_2d_chunk_simple.h" #include "world/simple/terrain_2d_world_simple.h" +#include "meshers/isometric/terrain_2d_mesher_isometric.h" +#include "world/isometric/terrain_2d_chunk_isometric.h" +#include "world/isometric/terrain_2d_world_isometric.h" + #include "nodes/terrain_2d_light_node.h" #include "world/jobs/terrain_2d_job.h" @@ -102,6 +105,10 @@ void register_terraman_2d_types() { ClassDB::register_class(); ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); diff --git a/world/isometric/terrain_2d_chunk_isometric.cpp b/world/isometric/terrain_2d_chunk_isometric.cpp new file mode 100644 index 0000000..fa4e817 --- /dev/null +++ b/world/isometric/terrain_2d_chunk_isometric.cpp @@ -0,0 +1,39 @@ +/* +Copyright (c) 2019-2022 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 "terrain_2d_chunk_isometric.h" + +#include "../../defines.h" + +Terrain2DChunkIsometric::Terrain2DChunkIsometric() { +} + +Terrain2DChunkIsometric::~Terrain2DChunkIsometric() { +} + +void Terrain2DChunkIsometric::_setup_channels() { + channel_set_count(MAX_DEFAULT_CHANNELS); +} + +void Terrain2DChunkIsometric::_bind_methods() { + ADD_PROPERTYI(PropertyInfo(Variant::POOL_BYTE_ARRAY, "data_channel"), "channel_set_compressed", "channel_get_compressed", 0); +} diff --git a/world/isometric/terrain_2d_chunk_isometric.h b/world/isometric/terrain_2d_chunk_isometric.h new file mode 100644 index 0000000..4f05ccc --- /dev/null +++ b/world/isometric/terrain_2d_chunk_isometric.h @@ -0,0 +1,41 @@ +/* +Copyright (c) 2019-2022 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 TERRAIN_2D_CHUNK_ISOMETRIC_H +#define TERRAIN_2D_CHUNK_ISOMETRIC_H + +#include "../default/terrain_2d_chunk_default.h" + +class Terrain2DChunkIsometric : public Terrain2DChunkDefault { + GDCLASS(Terrain2DChunkIsometric, Terrain2DChunkDefault); + +public: + Terrain2DChunkIsometric(); + ~Terrain2DChunkIsometric(); + +protected: + virtual void _setup_channels(); + + static void _bind_methods(); +}; + +#endif diff --git a/world/isometric/terrain_2d_world_isometric.cpp b/world/isometric/terrain_2d_world_isometric.cpp new file mode 100644 index 0000000..3e86913 --- /dev/null +++ b/world/isometric/terrain_2d_world_isometric.cpp @@ -0,0 +1,72 @@ +/* +Copyright (c) 2019-2022 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 "terrain_2d_world_isometric.h" + +#include "terrain_2d_chunk_isometric.h" + +#include "../../meshers/isometric/terrain_2d_mesher_isometric.h" +#include "../jobs/terrain_2d_light_job.h" +#include "../jobs/terrain_2d_prop_job.h" +#include "../jobs/terrain_2d_terrain_job.h" + +Ref Terrain2DWorldIsometric::_create_chunk(int x, int y, Ref chunk) { + if (!chunk.is_valid()) { + chunk = Ref(memnew(Terrain2DChunkIsometric)); + } + + if (chunk->job_get_count() == 0) { + Ref tj; + tj.instance(); + + Ref lj; + lj.instance(); + + tj->set_mesher(Ref(memnew(Terrain2DMesherIsometric()))); + + Ref liquid_mesher; + liquid_mesher.instance(); + liquid_mesher->set_channel_index_type(Terrain2DChunkDefault::DEFAULT_CHANNEL_LIQUID_TYPE); + tj->set_liquid_mesher(liquid_mesher); + + Ref pj; + pj.instance(); + pj->set_prop_mesher(Ref(memnew(Terrain2DMesherIsometric))); + + chunk->job_add(lj); + chunk->job_add(tj); + chunk->job_add(pj); + } + + return Terrain2DWorld::_create_chunk(x, y, chunk); +} + +Terrain2DWorldIsometric::Terrain2DWorldIsometric() { + set_data_margin_start(1); + set_data_margin_end(1); +} + +Terrain2DWorldIsometric ::~Terrain2DWorldIsometric() { +} + +void Terrain2DWorldIsometric::_bind_methods() { +} \ No newline at end of file diff --git a/world/isometric/terrain_2d_world_isometric.h b/world/isometric/terrain_2d_world_isometric.h new file mode 100644 index 0000000..dd6cf37 --- /dev/null +++ b/world/isometric/terrain_2d_world_isometric.h @@ -0,0 +1,41 @@ +/* +Copyright (c) 2019-2022 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 TERRAIN_2D_WORLD_ISOMETRIC_H +#define TERRAIN_2D_WORLD_ISOMETRIC_H + +#include "../default/terrain_2d_world_default.h" + +class Terrain2DWorldIsometric : public Terrain2DWorldDefault { + GDCLASS(Terrain2DWorldIsometric, Terrain2DWorldDefault); + +public: + Terrain2DWorldIsometric(); + ~Terrain2DWorldIsometric(); + +protected: + Ref _create_chunk(int x, int y, Ref p_chunk); + + static void _bind_methods(); +}; + +#endif