mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-22 20:06:49 +01:00
Moved TileMap's Geometry Parser to TileMap's module.
This commit is contained in:
parent
c8d05fe667
commit
b8d9ffec6d
@ -38,7 +38,7 @@
|
|||||||
#include "geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h"
|
#include "geometry_parser_2d/multimeshinstance2d_navigation_geometry_parser_2d.h"
|
||||||
#include "geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h"
|
#include "geometry_parser_2d/polygon2d_navigation_geometry_parser_2d.h"
|
||||||
#include "geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h"
|
#include "geometry_parser_2d/staticbody2d_navigation_geometry_parser_2d.h"
|
||||||
#include "geometry_parser_2d/tilemap_navigation_geometry_parser_2d.h"
|
|
||||||
#ifndef _3D_DISABLED
|
#ifndef _3D_DISABLED
|
||||||
#include "geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h"
|
#include "geometry_parser_3d/meshinstance3d_navigation_geometry_parser_3d.h"
|
||||||
#include "geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h"
|
#include "geometry_parser_3d/multimeshinstance3d_navigation_geometry_parser_3d.h"
|
||||||
@ -51,7 +51,6 @@ void register_navigation_geometry_parsers_types(ModuleRegistrationLevel p_level)
|
|||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MultiMeshInstance2DNavigationGeometryParser2D));
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(MultiMeshInstance2DNavigationGeometryParser2D));
|
||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(Polygon2DNavigationGeometryParser2D));
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(Polygon2DNavigationGeometryParser2D));
|
||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(StaticBody2DNavigationGeometryParser2D));
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(StaticBody2DNavigationGeometryParser2D));
|
||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(TileMap2DNavigationGeometryParser2D));
|
|
||||||
#ifndef _3D_DISABLED
|
#ifndef _3D_DISABLED
|
||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MeshInstance3DNavigationGeometryParser3D));
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MeshInstance3DNavigationGeometryParser3D));
|
||||||
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MultiMeshInstance3DNavigationGeometryParser3D));
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_3d(memnew(MultiMeshInstance3DNavigationGeometryParser3D));
|
||||||
|
@ -3,6 +3,7 @@ Import('env')
|
|||||||
env.add_source_files(env.modules_sources,"register_types.cpp")
|
env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||||
env.add_source_files(env.modules_sources,"tile_map.cpp")
|
env.add_source_files(env.modules_sources,"tile_map.cpp")
|
||||||
env.add_source_files(env.modules_sources,"tile_set.cpp")
|
env.add_source_files(env.modules_sources,"tile_set.cpp")
|
||||||
|
env.add_source_files(env.modules_sources, "geometry_parser/*.cpp")
|
||||||
|
|
||||||
if env["tools"]:
|
if env["tools"]:
|
||||||
env.add_source_files(env.modules_sources, "tile_map_editor_plugin.cpp")
|
env.add_source_files(env.modules_sources, "tile_map_editor_plugin.cpp")
|
||||||
|
@ -0,0 +1,102 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* tilemap_navigation_geometry_parser_2d.cpp */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 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 "tilemap_navigation_geometry_parser_2d.h"
|
||||||
|
|
||||||
|
//#include "scene/2d/tile_map.h"
|
||||||
|
|
||||||
|
#include "modules/tile_map/tile_map.h"
|
||||||
|
#include "modules/tile_map/tile_set.h"
|
||||||
|
#include "scene/resources/navigation_mesh_source_geometry_data_2d.h"
|
||||||
|
#include "scene/resources/navigation_polygon.h"
|
||||||
|
|
||||||
|
#include "modules/modules_enabled.gen.h"
|
||||||
|
|
||||||
|
bool TileMap2DNavigationGeometryParser2D::parses_node(Node *p_node) {
|
||||||
|
return (Object::cast_to<TileMap>(p_node) != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileMap2DNavigationGeometryParser2D::parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry) {
|
||||||
|
TileMap *tilemap = Object::cast_to<TileMap>(p_node);
|
||||||
|
//NavigationPolygon::ParsedGeometryType parsed_geometry_type = p_navigation_polygon->get_parsed_geometry_type();
|
||||||
|
//uint32_t navigation_polygon_collision_mask = p_navigation_polygon->get_collision_mask();
|
||||||
|
|
||||||
|
if (tilemap) {
|
||||||
|
Ref<TileSet> tile_set = tilemap->get_tileset();
|
||||||
|
if (!tile_set.is_valid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Transform2D tilemap_xform = tilemap->get_transform();
|
||||||
|
Array used_cells = tilemap->get_used_cells();
|
||||||
|
|
||||||
|
for (int used_cell_index = 0; used_cell_index < used_cells.size(); used_cell_index++) {
|
||||||
|
Vector2 cell = used_cells[used_cell_index];
|
||||||
|
|
||||||
|
int cell_id = tilemap->get_cell(cell.x, cell.y);
|
||||||
|
|
||||||
|
Transform2D tile_transform;
|
||||||
|
tile_transform.set_origin(tilemap->to_local(cell));
|
||||||
|
|
||||||
|
const Transform2D tile_transform_offset = tilemap_xform * tile_transform;
|
||||||
|
|
||||||
|
Ref<NavigationPolygon> navigation_polygon = tile_set->tile_get_navigation_polygon(cell_id);
|
||||||
|
if (navigation_polygon.is_valid()) {
|
||||||
|
for (int outline_index = 0; outline_index < navigation_polygon->get_outline_count(); outline_index++) {
|
||||||
|
PoolVector<Vector2> traversable_outline = navigation_polygon->get_outline(outline_index);
|
||||||
|
|
||||||
|
Vector<Vector2> traversable_outline_new;
|
||||||
|
traversable_outline_new.resize(traversable_outline.size());
|
||||||
|
|
||||||
|
for (int traversable_outline_index = 0; traversable_outline_index < traversable_outline.size(); traversable_outline_index++) {
|
||||||
|
traversable_outline_new.write[traversable_outline_index] = tile_transform_offset.xform(traversable_outline[traversable_outline_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_source_geometry->_add_traversable_outline(traversable_outline_new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO
|
||||||
|
if (parsed_geometry_type != NavigationPolygon::PARSED_GEOMETRY_MESH_INSTANCES && (tilemap->get_collision_layer() & navigation_polygon_collision_mask)) {
|
||||||
|
for (int collision_polygon_index = 0; collision_polygon_index < tile_set->tile_get_shape_count(cell_id); collision_polygon_index++) {
|
||||||
|
Vector<Vector2> obstruction_outline = tile_set->get_collision_polygon_points(collision_polygon_index);
|
||||||
|
|
||||||
|
for (int obstruction_outline_index = 0; obstruction_outline_index < obstruction_outline.size(); obstruction_outline_index++) {
|
||||||
|
obstruction_outline.write[obstruction_outline_index] = tile_transform_offset.xform(obstruction_outline[obstruction_outline_index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
p_source_geometry->_add_obstruction_outline(obstruction_outline);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/**************************************************************************/
|
||||||
|
/* tilemap_navigation_geometry_parser_2d.h */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* This file is part of: */
|
||||||
|
/* GODOT ENGINE */
|
||||||
|
/* https://godotengine.org */
|
||||||
|
/**************************************************************************/
|
||||||
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||||
|
/* Copyright (c) 2007-2014 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. */
|
||||||
|
/**************************************************************************/
|
||||||
|
|
||||||
|
#ifndef TILEMAP_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||||
|
#define TILEMAP_NAVIGATION_GEOMETRY_PARSER_2D_H
|
||||||
|
|
||||||
|
#include "scene/2d/navigation_geometry_parser_2d.h"
|
||||||
|
|
||||||
|
class TileMap2DNavigationGeometryParser2D : public NavigationGeometryParser2D {
|
||||||
|
public:
|
||||||
|
virtual bool parses_node(Node *p_node);
|
||||||
|
|
||||||
|
virtual void parse_geometry(Node *p_node, Ref<NavigationPolygon> p_navigation_polygon, Ref<NavigationMeshSourceGeometryData2D> p_source_geometry);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TILEMAP_NAVIGATION_GEOMETRY_PARSER_2D_H
|
@ -22,6 +22,9 @@ SOFTWARE.
|
|||||||
|
|
||||||
#include "register_types.h"
|
#include "register_types.h"
|
||||||
|
|
||||||
|
#include "geometry_parser/tilemap_navigation_geometry_parser_2d.h"
|
||||||
|
#include "servers/navigation/navigation_mesh_generator.h"
|
||||||
|
|
||||||
#include "tile_map.h"
|
#include "tile_map.h"
|
||||||
#include "tile_set.h"
|
#include "tile_set.h"
|
||||||
|
|
||||||
@ -34,6 +37,8 @@ void register_tile_map_types(ModuleRegistrationLevel p_level) {
|
|||||||
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
if (p_level == MODULE_REGISTRATION_LEVEL_SCENE) {
|
||||||
ClassDB::register_class<TileMap>();
|
ClassDB::register_class<TileMap>();
|
||||||
ClassDB::register_class<TileSet>();
|
ClassDB::register_class<TileSet>();
|
||||||
|
|
||||||
|
NavigationMeshGenerator::get_singleton()->register_geometry_parser_2d(memnew(TileMap2DNavigationGeometryParser2D));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
Loading…
Reference in New Issue
Block a user