summaryrefslogtreecommitdiff
path: root/modules/gridmap
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gridmap')
-rw-r--r--modules/gridmap/doc_classes/GridMap.xml1
-rw-r--r--modules/gridmap/grid_map.cpp31
-rw-r--r--modules/gridmap/grid_map.h58
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp21
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h38
-rw-r--r--modules/gridmap/register_types.cpp4
-rw-r--r--modules/gridmap/register_types.h4
7 files changed, 61 insertions, 96 deletions
diff --git a/modules/gridmap/doc_classes/GridMap.xml b/modules/gridmap/doc_classes/GridMap.xml
index 4dccb03369..134aadb75e 100644
--- a/modules/gridmap/doc_classes/GridMap.xml
+++ b/modules/gridmap/doc_classes/GridMap.xml
@@ -8,6 +8,7 @@
GridMaps use a [MeshLibrary] which contains a list of tiles. Each tile is a mesh with materials plus optional collision and navigation shapes.
A GridMap contains a collection of cells. Each grid cell refers to a tile in the [MeshLibrary]. All cells in the map have the same dimensions.
Internally, a GridMap is split into a sparse collection of octants for efficient rendering and physics processing. Every octant has the same dimensions and can contain several cells.
+ [b]Note:[/b] GridMap doesn't extend [VisualInstance3D] and therefore can't be hidden or cull masked based on [member VisualInstance3D.layers]. If you make a light not affect the first layer, the whole GridMap won't be lit by the light in question.
</description>
<tutorials>
<link title="Using gridmaps">https://docs.godotengine.org/en/latest/tutorials/3d/using_gridmaps.html</link>
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index 633b209f0f..e7c252dc53 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -189,7 +189,6 @@ void GridMap::set_mesh_library(const Ref<MeshLibrary> &p_mesh_library) {
}
_recreate_octant_data();
- _change_notify("mesh_library");
}
Ref<MeshLibrary> GridMap::get_mesh_library() const {
@@ -286,7 +285,8 @@ void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
//create octant because it does not exist
Octant *g = memnew(Octant);
g->dirty = true;
- g->static_body = PhysicsServer3D::get_singleton()->body_create(PhysicsServer3D::BODY_MODE_STATIC);
+ g->static_body = PhysicsServer3D::get_singleton()->body_create();
+ PhysicsServer3D::get_singleton()->body_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
@@ -491,7 +491,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
Octant::MultimeshInstance mmi;
RID mm = RS::get_singleton()->multimesh_create();
- RS::get_singleton()->multimesh_allocate(mm, E->get().size(), RS::MULTIMESH_TRANSFORM_3D);
+ RS::get_singleton()->multimesh_allocate_data(mm, E->get().size(), RS::MULTIMESH_TRANSFORM_3D);
RS::get_singleton()->multimesh_set_mesh(mm, mesh_library->get_item_mesh(E->key())->get_rid());
int idx = 0;
@@ -700,8 +700,6 @@ void GridMap::_update_visibility() {
return;
}
- _change_notify("visible");
-
for (Map<OctantKey, Octant *>::Element *e = octant_map.front(); e; e = e->next()) {
Octant *octant = e->value();
for (int i = 0; i < octant->multimesh_instances.size(); i++) {
@@ -1046,26 +1044,7 @@ RID GridMap::get_bake_mesh_instance(int p_idx) {
}
GridMap::GridMap() {
- collision_layer = 1;
- collision_mask = 1;
-
- cell_size = Vector3(2, 2, 2);
- octant_size = 8;
- awaiting_update = false;
- _in_tree = false;
- center_x = true;
- center_y = true;
- center_z = true;
-
- clip = false;
- clip_floor = 0;
- clip_axis = Vector3::AXIS_Z;
- clip_above = true;
- cell_scale = 1.0;
-
- navigation = nullptr;
set_notify_transform(true);
- recreating_octants = false;
}
GridMap::~GridMap() {
diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h
index ca7429ea26..e5ec4bb602 100644
--- a/modules/gridmap/grid_map.h
+++ b/modules/gridmap/grid_map.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -53,7 +53,7 @@ class GridMap : public Node3D {
int16_t y;
int16_t z;
};
- uint64_t key;
+ uint64_t key = 0;
_FORCE_INLINE_ bool operator<(const IndexKey &p_key) const {
return key < p_key.key;
@@ -68,7 +68,7 @@ class GridMap : public Node3D {
y = (int16_t)p_vector.y;
z = (int16_t)p_vector.z;
}
- IndexKey() { key = 0; }
+ IndexKey() {}
};
/**
@@ -80,13 +80,7 @@ class GridMap : public Node3D {
unsigned int rot : 5;
unsigned int layer : 8;
};
- uint32_t cell;
-
- Cell() {
- item = 0;
- rot = 0;
- layer = 0;
- }
+ uint32_t cell = 0;
};
/**
@@ -103,7 +97,7 @@ class GridMap : public Node3D {
RID instance;
RID multimesh;
struct Item {
- int index;
+ int index = 0;
Transform transform;
IndexKey key;
};
@@ -116,7 +110,7 @@ class GridMap : public Node3D {
RID collision_debug;
RID collision_debug_instance;
- bool dirty;
+ bool dirty = false;
RID static_body;
Map<IndexKey, NavMesh> navmesh_ids;
};
@@ -129,35 +123,37 @@ class GridMap : public Node3D {
int16_t empty;
};
- uint64_t key;
+ uint64_t key = 0;
_FORCE_INLINE_ bool operator<(const OctantKey &p_key) const {
return key < p_key.key;
}
//OctantKey(const IndexKey& p_k, int p_item) { indexkey=p_k.key; item=p_item; }
- OctantKey() { key = 0; }
+ OctantKey() {}
};
- uint32_t collision_layer;
- uint32_t collision_mask;
+ uint32_t collision_layer = 1;
+ uint32_t collision_mask = 1;
Transform last_transform;
- bool _in_tree;
- Vector3 cell_size;
- int octant_size;
- bool center_x, center_y, center_z;
- float cell_scale;
- Navigation3D *navigation;
+ bool _in_tree = false;
+ Vector3 cell_size = Vector3(2, 2, 2);
+ int octant_size = 8;
+ bool center_x = true;
+ bool center_y = true;
+ bool center_z = true;
+ float cell_scale = 1.0;
+ Navigation3D *navigation = nullptr;
- bool clip;
- bool clip_above;
- int clip_floor;
+ bool clip = false;
+ bool clip_above = true;
+ int clip_floor = 0;
- bool recreating_octants;
+ bool recreating_octants = false;
- Vector3::Axis clip_axis;
+ Vector3::Axis clip_axis = Vector3::AXIS_Z;
Ref<MeshLibrary> mesh_library;
@@ -167,10 +163,10 @@ class GridMap : public Node3D {
void _recreate_octant_data();
struct BakeLight {
- RS::LightType type;
+ RS::LightType type = RS::LightType::LIGHT_DIRECTIONAL;
Vector3 pos;
Vector3 dir;
- float param[RS::LIGHT_PARAM_MAX];
+ float param[RS::LIGHT_PARAM_MAX] = {};
};
_FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const {
@@ -183,7 +179,7 @@ class GridMap : public Node3D {
bool _octant_update(const OctantKey &p_key);
void _octant_clean_up(const OctantKey &p_key);
void _octant_transform(const OctantKey &p_key);
- bool awaiting_update;
+ bool awaiting_update = false;
void _queue_octants_dirty();
void _update_octants_callback();
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index d4fbecd60f..da9cdb9bc5 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -724,7 +724,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
return true;
} else {
selected_palette = -1;
- mesh_library_palette->unselect_all();
+ mesh_library_palette->deselect_all();
update_palette();
_update_cursor_instance();
return true;
@@ -769,7 +769,7 @@ bool GridMapEditor::forward_spatial_input_event(Camera3D *p_camera, const Ref<In
struct _CGMEItemSort {
String name;
- int id;
+ int id = 0;
_FORCE_INLINE_ bool operator<(const _CGMEItemSort &r_it) const { return name < r_it.name; }
};
@@ -1151,7 +1151,6 @@ void GridMapEditor::_bind_methods() {
}
GridMapEditor::GridMapEditor(EditorNode *p_editor) {
- input_action = INPUT_NONE;
editor = p_editor;
undo_redo = p_editor->get_undo_redo();
@@ -1173,7 +1172,7 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
floor->set_min(-32767);
floor->set_max(32767);
floor->set_step(1);
- floor->get_line_edit()->add_theme_constant_override("minimum_spaces", 16);
+ floor->get_line_edit()->add_theme_constant_override("minimum_character_width", 16);
spatial_editor_hb->add_child(floor);
floor->connect("value_changed", callable_mp(this, &GridMapEditor::_floor_changed));
@@ -1234,7 +1233,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0));
settings_vbc->add_margin_child(TTR("Pick Distance:"), settings_pick_distance);
- clip_mode = CLIP_DISABLED;
options->get_popup()->connect("id_pressed", callable_mp(this, &GridMapEditor::_menu_option));
HBoxContainer *hb = memnew(HBoxContainer);
@@ -1275,8 +1273,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
EDITOR_DEF("editors/grid_map/preview_size", 64);
- display_mode = DISPLAY_THUMBNAIL;
-
mesh_library_palette = memnew(ItemList);
add_child(mesh_library_palette);
mesh_library_palette->set_v_size_flags(SIZE_EXPAND_FILL);
@@ -1296,11 +1292,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
edit_floor[1] = -1;
edit_floor[2] = -1;
- cursor_visible = false;
- selected_palette = -1;
- lock_view = false;
- cursor_rot = 0;
-
selection_mesh = RenderingServer::get_singleton()->mesh_create();
paste_mesh = RenderingServer::get_singleton()->mesh_create();
@@ -1418,8 +1409,6 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
}
_set_selection(false);
- updating = false;
- accumulated_floor_delta = 0.0;
indicator_mat.instance();
indicator_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index 69c8d999fd..6c7f0bedf6 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -65,11 +65,11 @@ class GridMapEditor : public VBoxContainer {
};
UndoRedo *undo_redo;
- InputAction input_action;
+ InputAction input_action = INPUT_NONE;
Panel *panel;
MenuButton *options;
SpinBox *floor;
- double accumulated_floor_delta;
+ double accumulated_floor_delta = 0.0;
Button *mode_thumbnail;
Button *mode_list;
LineEdit *search_box;
@@ -82,19 +82,19 @@ class GridMapEditor : public VBoxContainer {
struct SetItem {
Vector3i position;
- int new_value;
- int new_orientation;
- int old_value;
- int old_orientation;
+ int new_value = 0;
+ int new_orientation = 0;
+ int old_value = 0;
+ int old_orientation = 0;
};
List<SetItem> set_items;
GridMap *node = nullptr;
MeshLibrary *last_mesh_library;
- ClipMode clip_mode;
+ ClipMode clip_mode = CLIP_DISABLED;
- bool lock_view;
+ bool lock_view = false;
Transform grid_xform;
Transform edit_grid_xform;
Vector3::Axis edit_axis;
@@ -112,9 +112,9 @@ class GridMapEditor : public VBoxContainer {
RID paste_instance;
struct ClipboardItem {
- int cell_item;
+ int cell_item = 0;
Vector3 grid_offset;
- int orientation;
+ int orientation = 0;
RID instance;
};
@@ -125,14 +125,14 @@ class GridMapEditor : public VBoxContainer {
Ref<StandardMaterial3D> outer_mat;
Ref<StandardMaterial3D> selection_floor_mat;
- bool updating;
+ bool updating = false;
struct Selection {
Vector3 click;
Vector3 current;
Vector3 begin;
Vector3 end;
- bool active;
+ bool active = false;
} selection;
Selection last_selection;
@@ -141,18 +141,18 @@ class GridMapEditor : public VBoxContainer {
Vector3 current;
Vector3 begin;
Vector3 end;
- int orientation;
+ int orientation = 0;
};
PasteIndicator paste_indicator;
- bool cursor_visible;
+ bool cursor_visible = false;
Transform cursor_transform;
Vector3 cursor_origin;
- int display_mode;
- int selected_palette;
- int cursor_rot;
+ int display_mode = DISPLAY_THUMBNAIL;
+ int selected_palette = -1;
+ int cursor_rot = 0;
enum Menu {
MENU_OPTION_NEXT_LEVEL,
diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp
index ab384fa942..5680664213 100644
--- a/modules/gridmap/register_types.cpp
+++ b/modules/gridmap/register_types.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
diff --git a/modules/gridmap/register_types.h b/modules/gridmap/register_types.h
index c0e3c39ca8..b977f4c5da 100644
--- a/modules/gridmap/register_types.h
+++ b/modules/gridmap/register_types.h
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */