diff --git a/modules/terraman/SCsub b/modules/terraman/SCsub index 1aad6ec0d..d3f1c8d0d 100644 --- a/modules/terraman/SCsub +++ b/modules/terraman/SCsub @@ -45,6 +45,9 @@ sources = [ "world/jobs/terrain_mesher_job_step.cpp", "world/jobs/terrain_light_job.cpp", "world/jobs/terrain_prop_job.cpp", + + "chunk_data_managers/terrain_world_chunk_data_manager.cpp", + "chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.cpp" ] if env["tools"]: diff --git a/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.cpp b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.cpp new file mode 100644 index 000000000..d1a7e1c5a --- /dev/null +++ b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.cpp @@ -0,0 +1,181 @@ +/*************************************************************************/ +/* terrain_world_chunk_data_manager.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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_world_chunk_data_manager.h" + +#include "../world/terrain_chunk.h" +#include "../world/terrain_world.h" + +Ref TerrainWorldChunkDataManager::load_chunk(const Vector2i &p_chunk_position) { + return call("_load_chunk", p_chunk_position); +} +Ref TerrainWorldChunkDataManager::_load_chunk(const Vector2i &p_chunk_position) { + return Ref(); +} + +void TerrainWorldChunkDataManager::load_all_chunks(TerrainWorld *p_world) { + ERR_FAIL_COND(!p_world || !ObjectDB::instance_validate(p_world)); + + Vector chunks = get_available_chunk_list(); + + for (int i = 0; i < chunks.size(); ++i) { + Vector2i chunk_position = chunks[i]; + + if (!p_world->chunk_has(chunk_position.x, chunk_position.y)) { + Ref chunk = load_chunk(chunk_position); + + ERR_CONTINUE(!chunk.is_valid()); + + p_world->chunk_add(chunk, chunk_position.x, chunk_position.y); + } + } +} + +void TerrainWorldChunkDataManager::load_chunks(TerrainWorld *p_world, const Vector &p_chunks) { + ERR_FAIL_COND(!p_world || !ObjectDB::instance_validate(p_world)); + + for (int i = 0; i < p_chunks.size(); ++i) { + Vector2i chunk_position = p_chunks[i]; + + if (!p_world->chunk_has(chunk_position.x, chunk_position.y)) { + Ref chunk = load_chunk(chunk_position); + + // Invalid value got passed in, just skip so scripts don't have to worry about checking validity one by one + // (like a spawn range script) + if (!chunk.is_valid()) { + continue; + } + + p_world->chunk_add(chunk, chunk_position.x, chunk_position.y); + } + } +} + +void TerrainWorldChunkDataManager::load_all_chunks_bind(Node *p_world) { + load_all_chunks(Object::cast_to(p_world)); +} +void TerrainWorldChunkDataManager::load_chunks_bind(Node *p_world, const Vector &p_chunks) { + load_chunks(Object::cast_to(p_world), p_chunks); +} + +Vector TerrainWorldChunkDataManager::get_available_chunk_list() { + return call("_get_available_chunk_list"); +} +Vector TerrainWorldChunkDataManager::_get_available_chunk_list() { + return Vector(); +} + +void TerrainWorldChunkDataManager::delete_chunk_data_at(const Vector2i &p_chunk_position) { + call("_delete_chunk_data_at", p_chunk_position); +} +void TerrainWorldChunkDataManager::_delete_chunk_data_at(const Vector2i &p_chunk_position) { +} + +void TerrainWorldChunkDataManager::delete_chunk_data(const Ref &p_chunk) { + call("_delete_chunk_data", p_chunk); +} +void TerrainWorldChunkDataManager::_delete_chunk_data(const Ref &p_chunk) { +} + +void TerrainWorldChunkDataManager::delete_all_chunk_data() { + call("_delete_all_chunk_data"); +} +void TerrainWorldChunkDataManager::_delete_all_chunk_data() { +} + +// Callbacks +void TerrainWorldChunkDataManager::on_world_chunk_created(const Ref &p_chunk) { + call("_on_world_chunk_created", p_chunk); +} +void TerrainWorldChunkDataManager::_on_world_chunk_created(const Ref &p_chunk) { +} + +void TerrainWorldChunkDataManager::on_world_chunk_removed(const Ref &p_chunk) { + call("_on_world_chunk_removed", p_chunk); +} +void TerrainWorldChunkDataManager::_on_world_chunk_removed(const Ref &p_chunk) { +} + +void TerrainWorldChunkDataManager::on_world_chunk_added(const Ref &p_chunk) { + call("_on_world_chunk_added", p_chunk); +} +void TerrainWorldChunkDataManager::_on_world_chunk_added(const Ref &p_chunk) { +} + +TerrainWorldChunkDataManager::TerrainWorldChunkDataManager() { +} + +TerrainWorldChunkDataManager::~TerrainWorldChunkDataManager() { +} + +void TerrainWorldChunkDataManager::_bind_methods() { + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerrainChunk"), + "_load_chunk", + PropertyInfo(Variant::VECTOR2I, "chunk_position"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::POOL_VECTOR2I_ARRAY, "chunks"), "_get_available_chunk_list")); + + BIND_VMETHOD(MethodInfo("_delete_chunk_data_at", PropertyInfo(Variant::VECTOR2I, "chunk_position"))); + BIND_VMETHOD(MethodInfo("_delete_chunk_data", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerrainChunk"))); + BIND_VMETHOD(MethodInfo("_delete_all_chunk_data")); + + BIND_VMETHOD(MethodInfo("_on_world_chunk_created", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerrainChunk"))); + BIND_VMETHOD(MethodInfo("_on_world_chunk_removed", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerrainChunk"))); + BIND_VMETHOD(MethodInfo("_on_world_chunk_added", PropertyInfo(Variant::OBJECT, "chunk", PROPERTY_HINT_RESOURCE_TYPE, "TerrainChunk"))); + + ClassDB::bind_method(D_METHOD("load_chunk", "chunk_position"), &TerrainWorldChunkDataManager::load_chunk); + ClassDB::bind_method(D_METHOD("_load_chunk", "chunk_position"), &TerrainWorldChunkDataManager::_load_chunk); + + ClassDB::bind_method(D_METHOD("load_all_chunks", "world"), &TerrainWorldChunkDataManager::load_all_chunks_bind); + ClassDB::bind_method(D_METHOD("load_chunks", "world", "chunks"), &TerrainWorldChunkDataManager::load_chunks_bind); + + ClassDB::bind_method(D_METHOD("get_available_chunk_list"), &TerrainWorldChunkDataManager::get_available_chunk_list); + ClassDB::bind_method(D_METHOD("_get_available_chunk_list"), &TerrainWorldChunkDataManager::_get_available_chunk_list); + + // Delete + ClassDB::bind_method(D_METHOD("delete_chunk_data_at", "chunk_position"), &TerrainWorldChunkDataManager::delete_chunk_data_at); + ClassDB::bind_method(D_METHOD("_delete_chunk_data_at", "chunk_position"), &TerrainWorldChunkDataManager::_delete_chunk_data_at); + + ClassDB::bind_method(D_METHOD("delete_chunk_data", "chunk"), &TerrainWorldChunkDataManager::delete_chunk_data); + ClassDB::bind_method(D_METHOD("_delete_chunk_data", "chunk"), &TerrainWorldChunkDataManager::_delete_chunk_data); + + ClassDB::bind_method(D_METHOD("delete_all_chunk_data"), &TerrainWorldChunkDataManager::delete_all_chunk_data); + ClassDB::bind_method(D_METHOD("_delete_all_chunk_data"), &TerrainWorldChunkDataManager::_delete_all_chunk_data); + + // Callbacks + ClassDB::bind_method(D_METHOD("on_world_chunk_created", "chunk"), &TerrainWorldChunkDataManager::on_world_chunk_created); + ClassDB::bind_method(D_METHOD("_on_world_chunk_created", "chunk"), &TerrainWorldChunkDataManager::_on_world_chunk_created); + + ClassDB::bind_method(D_METHOD("on_world_chunk_removed", "chunk"), &TerrainWorldChunkDataManager::on_world_chunk_removed); + ClassDB::bind_method(D_METHOD("_on_world_chunk_removed", "chunk"), &TerrainWorldChunkDataManager::_on_world_chunk_removed); + + ClassDB::bind_method(D_METHOD("on_world_chunk_added", "chunk"), &TerrainWorldChunkDataManager::on_world_chunk_added); + ClassDB::bind_method(D_METHOD("_on_world_chunk_added", "chunk"), &TerrainWorldChunkDataManager::_on_world_chunk_added); +} diff --git a/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.h b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.h new file mode 100644 index 000000000..1d90970d9 --- /dev/null +++ b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager.h @@ -0,0 +1,82 @@ +#ifndef TERRAIN_WORLD_CHUNK_DATA_MANAGER_H +#define TERRAIN_WORLD_CHUNK_DATA_MANAGER_H + +/*************************************************************************/ +/* terrain_world_chunk_data_manager.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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 "core/object/resource.h" + +class TerrainChunk; +class TerrainWorld; + +class TerrainWorldChunkDataManager : public Resource { + GDCLASS(TerrainWorldChunkDataManager, Resource); + +public: + Ref load_chunk(const Vector2i &p_chunk_position); + virtual Ref _load_chunk(const Vector2i &p_chunk_position); + + void load_all_chunks(TerrainWorld *p_world); + void load_chunks(TerrainWorld *p_world, const Vector &p_chunks); + void load_all_chunks_bind(Node *p_world); + void load_chunks_bind(Node *p_world, const Vector &p_chunks); + + Vector get_available_chunk_list(); + virtual Vector _get_available_chunk_list(); + + // Delete + void delete_chunk_data_at(const Vector2i &p_chunk_position); + virtual void _delete_chunk_data_at(const Vector2i &p_chunk_position); + + void delete_chunk_data(const Ref &p_chunk); + virtual void _delete_chunk_data(const Ref &p_chunk); + + void delete_all_chunk_data(); + virtual void _delete_all_chunk_data(); + + // Callbacks + void on_world_chunk_created(const Ref &p_chunk); + virtual void _on_world_chunk_created(const Ref &p_chunk); + + void on_world_chunk_removed(const Ref &p_chunk); + virtual void _on_world_chunk_removed(const Ref &p_chunk); + + void on_world_chunk_added(const Ref &p_chunk); + virtual void _on_world_chunk_added(const Ref &p_chunk); + + TerrainWorldChunkDataManager(); + ~TerrainWorldChunkDataManager(); + +protected: + static void _bind_methods(); +}; + +#endif diff --git a/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.cpp b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.cpp new file mode 100644 index 000000000..c337d10fc --- /dev/null +++ b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.cpp @@ -0,0 +1,54 @@ +/*************************************************************************/ +/* terrain_world_chunk_data_manager_static_folder_resources.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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_world_chunk_data_manager_static_folder_resources.h" + +#include "../world/terrain_chunk.h" + +TerrainWorldChunkDataManagerStaticFolderResources::TerrainWorldChunkDataManagerStaticFolderResources() { +} + +TerrainWorldChunkDataManagerStaticFolderResources::~TerrainWorldChunkDataManagerStaticFolderResources() { +} + +void TerrainWorldChunkDataManagerStaticFolderResources::_bind_methods() { + /* + ClassDB::bind_method(D_METHOD("get_floor_position"), &TerrainWorldChunkDataManagerStaticFolderResources::get_floor_position); + ClassDB::bind_method(D_METHOD("set_floor_position", "value"), &TerrainWorldChunkDataManagerStaticFolderResources::set_floor_position); + ADD_PROPERTY(PropertyInfo(Variant::INT, "floor_position"), "set_floor_position", "get_floor_position"); + + ClassDB::bind_method(D_METHOD("get_channel_map"), &TerrainWorldChunkDataManagerStaticFolderResources::get_channel_map); + ClassDB::bind_method(D_METHOD("set_channel_map", "value"), &TerrainWorldChunkDataManagerStaticFolderResources::set_channel_map); + ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "channel_map"), "set_channel_map", "get_channel_map"); + + ClassDB::bind_method(D_METHOD("_generate_chunk", "chunk"), &TerrainWorldChunkDataManagerStaticFolderResources::_generate_chunk); + */ +} diff --git a/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.h b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.h new file mode 100644 index 000000000..dd41720ba --- /dev/null +++ b/modules/terraman/chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.h @@ -0,0 +1,55 @@ +#ifndef TERRAIN_WORLD_CHUNK_DATA_MANAGER_STATIC_FOLDER_RESOURCES_H +#define TERRAIN_WORLD_CHUNK_DATA_MANAGER_STATIC_FOLDER_RESOURCES_H + +/*************************************************************************/ +/* terrain_world_chunk_data_manager_static_folder_resources.h */ +/*************************************************************************/ +/* This file is part of: */ +/* PANDEMONIUM ENGINE */ +/* https://github.com/Relintai/pandemonium_engine */ +/*************************************************************************/ +/* Copyright (c) 2022-present Péter Magyar. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* */ +/* 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_world_chunk_data_manager.h" + +class TerrainChunk; + +class TerrainWorldChunkDataManagerStaticFolderResources : public TerrainWorldChunkDataManager { + GDCLASS(TerrainWorldChunkDataManagerStaticFolderResources, TerrainWorldChunkDataManager); + +public: + + TerrainWorldChunkDataManagerStaticFolderResources(); + ~TerrainWorldChunkDataManagerStaticFolderResources(); + +protected: + static void _bind_methods(); + +private: + int _floor_position; + Dictionary _channel_map; +}; + +#endif diff --git a/modules/terraman/config.py b/modules/terraman/config.py index 20a13f39f..4f74c3c20 100644 --- a/modules/terraman/config.py +++ b/modules/terraman/config.py @@ -18,6 +18,9 @@ def get_doc_classes(): "TerrainLevelGenerator", "TerrainLevelGeneratorFlat", + "TerrainWorldChunkDataManager", + "TerrainWorldChunkDataManagerStaticFolderResources", + "TerrainSurfaceMerger", "TerrainSurfaceSimple", "TerrainSurface", diff --git a/modules/terraman/doc_classes/TerrainWorldChunkDataManager.xml b/modules/terraman/doc_classes/TerrainWorldChunkDataManager.xml new file mode 100644 index 000000000..99d4bb1be --- /dev/null +++ b/modules/terraman/doc_classes/TerrainWorldChunkDataManager.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/modules/terraman/doc_classes/TerrainWorldChunkDataManagerStaticFolderResources.xml b/modules/terraman/doc_classes/TerrainWorldChunkDataManagerStaticFolderResources.xml new file mode 100644 index 000000000..e7f0166a4 --- /dev/null +++ b/modules/terraman/doc_classes/TerrainWorldChunkDataManagerStaticFolderResources.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/modules/terraman/register_types.cpp b/modules/terraman/register_types.cpp index c9ea55de7..18efa34ef 100644 --- a/modules/terraman/register_types.cpp +++ b/modules/terraman/register_types.cpp @@ -81,6 +81,9 @@ #include "world/jobs/terrain_prop_job.h" #include "world/jobs/terrain_terrain_job.h" +#include "chunk_data_managers/terrain_world_chunk_data_manager.h" +#include "chunk_data_managers/terrain_world_chunk_data_manager_static_folder_resources.h" + void register_terraman_types(ModuleRegistrationLevel p_level) { if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) { ClassDB::register_class(); @@ -122,6 +125,9 @@ void register_terraman_types(ModuleRegistrationLevel p_level) { ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();