From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: A Whole New World (clang-format edition) I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code --- modules/gridmap/grid_map.cpp | 974 +++++++++++++---------------- modules/gridmap/grid_map.h | 88 ++- modules/gridmap/grid_map_editor_plugin.cpp | 958 +++++++++++++--------------- modules/gridmap/grid_map_editor_plugin.h | 36 +- modules/gridmap/register_types.cpp | 4 - 5 files changed, 924 insertions(+), 1136 deletions(-) (limited to 'modules/gridmap') diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp index d4fb174bfe..128592fa29 100644 --- a/modules/gridmap/grid_map.cpp +++ b/modules/gridmap/grid_map.cpp @@ -27,36 +27,36 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "grid_map.h" -#include "servers/visual_server.h" -#include "scene/resources/surface_tool.h" #include "message_queue.h" #include "scene/3d/light.h" +#include "scene/resources/surface_tool.h" +#include "servers/visual_server.h" #include "io/marshalls.h" -#include "scene/scene_string_names.h" #include "os/os.h" #include "scene/resources/mesh_library.h" +#include "scene/scene_string_names.h" -bool GridMap::_set(const StringName& p_name, const Variant& p_value) { +bool GridMap::_set(const StringName &p_name, const Variant &p_value) { - String name=p_name; + String name = p_name; - if (name=="theme") { + if (name == "theme") { set_theme(p_value); - } else if (name=="cell_size") { + } else if (name == "cell_size") { set_cell_size(p_value); - } else if (name=="cell_octant_size") { + } else if (name == "cell_octant_size") { set_octant_size(p_value); - } else if (name=="cell_center_x") { + } else if (name == "cell_center_x") { set_center_x(p_value); - } else if (name=="cell_center_y") { + } else if (name == "cell_center_y") { set_center_y(p_value); - } else if (name=="cell_center_z") { + } else if (name == "cell_center_z") { set_center_z(p_value); - } else if (name=="cell_scale") { + } else if (name == "cell_scale") { set_cell_scale(p_value); -/* } else if (name=="cells") { + /* } else if (name=="cells") { PoolVector cells = p_value; int amount=cells.size(); PoolVector::Read r = cells.read(); @@ -73,146 +73,138 @@ bool GridMap::_set(const StringName& p_name, const Variant& p_value) { } _recreate_octant_data();*/ - } else if (name=="data") { + } else if (name == "data") { Dictionary d = p_value; if (d.has("cells")) { PoolVector cells = d["cells"]; - int amount=cells.size(); + int amount = cells.size(); PoolVector::Read r = cells.read(); - ERR_FAIL_COND_V(amount%3,false); // not even + ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); - for(int i=0;i cells; - cells.resize(cell_map.size()*3); + cells.resize(cell_map.size() * 3); { PoolVector::Write w = cells.write(); - int i=0; - for (Map::Element *E=cell_map.front();E;E=E->next(),i++) { + int i = 0; + for (Map::Element *E = cell_map.front(); E; E = E->next(), i++) { - encode_uint64(E->key().key,(uint8_t*)&w[i*3]); - encode_uint32(E->get().cell,(uint8_t*)&w[i*3+2]); + encode_uint64(E->key().key, (uint8_t *)&w[i * 3]); + encode_uint32(E->get().cell, (uint8_t *)&w[i * 3 + 2]); } } - d["cells"]=cells; - + d["cells"] = cells; - - r_ret= d; + r_ret = d; } else if (name.begins_with("areas/")) { - int which = name.get_slicec('/',1).to_int(); - String what=name.get_slicec('/',2); - if (what=="bounds") - r_ret= area_get_bounds(which); - else if (what=="name") - r_ret= area_get_name(which); - else if (what=="disable_distance") - r_ret= area_get_portal_disable_distance(which); - else if (what=="exterior_portal") - r_ret= area_is_exterior_portal(which); + int which = name.get_slicec('/', 1).to_int(); + String what = name.get_slicec('/', 2); + if (what == "bounds") + r_ret = area_get_bounds(which); + else if (what == "name") + r_ret = area_get_name(which); + else if (what == "disable_distance") + r_ret = area_get_portal_disable_distance(which); + else if (what == "exterior_portal") + r_ret = area_is_exterior_portal(which); else return false; } else return false; return true; - } -void GridMap::_get_property_list( List *p_list) const { +void GridMap::_get_property_list(List *p_list) const { - p_list->push_back( PropertyInfo( Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); - p_list->push_back( PropertyInfo( Variant::NIL, "Cell", PROPERTY_HINT_NONE,"cell_",PROPERTY_USAGE_GROUP)); - p_list->push_back( PropertyInfo( Variant::REAL, "cell_size",PROPERTY_HINT_RANGE,"0.01,16384,0.01") ); - p_list->push_back( PropertyInfo( Variant::INT, "cell_octant_size",PROPERTY_HINT_RANGE,"1,1024,1") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_x") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_y") ); - p_list->push_back( PropertyInfo( Variant::BOOL, "cell_center_z") ); - p_list->push_back( PropertyInfo( Variant::REAL, "cell_scale") ); + p_list->push_back(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "MeshLibrary")); + p_list->push_back(PropertyInfo(Variant::NIL, "Cell", PROPERTY_HINT_NONE, "cell_", PROPERTY_USAGE_GROUP)); + p_list->push_back(PropertyInfo(Variant::REAL, "cell_size", PROPERTY_HINT_RANGE, "0.01,16384,0.01")); + p_list->push_back(PropertyInfo(Variant::INT, "cell_octant_size", PROPERTY_HINT_RANGE, "1,1024,1")); + p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_x")); + p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_y")); + p_list->push_back(PropertyInfo(Variant::BOOL, "cell_center_z")); + p_list->push_back(PropertyInfo(Variant::REAL, "cell_scale")); - p_list->push_back( PropertyInfo( Variant::DICTIONARY, "data", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); + p_list->push_back(PropertyInfo(Variant::DICTIONARY, "data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); - for(const Map::Element *E=area_map.front();E;E=E->next()) { + for (const Map::Element *E = area_map.front(); E; E = E->next()) { - String base="areas/"+itos(E->key())+"/"; - p_list->push_back( PropertyInfo( Variant::RECT3, base+"bounds", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); - p_list->push_back( PropertyInfo( Variant::STRING, base+"name", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); - p_list->push_back( PropertyInfo( Variant::REAL, base+"disable_distance", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); - p_list->push_back( PropertyInfo( Variant::COLOR, base+"disable_color", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); - p_list->push_back( PropertyInfo( Variant::BOOL, base+"exterior_portal", PROPERTY_HINT_NONE,"",PROPERTY_USAGE_STORAGE) ); + String base = "areas/" + itos(E->key()) + "/"; + p_list->push_back(PropertyInfo(Variant::RECT3, base + "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); + p_list->push_back(PropertyInfo(Variant::STRING, base + "name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); + p_list->push_back(PropertyInfo(Variant::REAL, base + "disable_distance", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); + p_list->push_back(PropertyInfo(Variant::COLOR, base + "disable_color", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); + p_list->push_back(PropertyInfo(Variant::BOOL, base + "exterior_portal", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE)); } } - -void GridMap::set_theme(const Ref& p_theme) { +void GridMap::set_theme(const Ref &p_theme) { if (!theme.is_null()) theme->unregister_owner(this); - theme=p_theme; + theme = p_theme; if (!theme.is_null()) theme->register_owner(this); @@ -220,35 +212,34 @@ void GridMap::set_theme(const Ref& p_theme) { _change_notify("theme"); } -Ref GridMap::get_theme() const{ +Ref GridMap::get_theme() const { return theme; } -void GridMap::set_cell_size(float p_size){ +void GridMap::set_cell_size(float p_size) { - cell_size=p_size; + cell_size = p_size; _recreate_octant_data(); - } -float GridMap::get_cell_size() const{ +float GridMap::get_cell_size() const { return cell_size; } -void GridMap::set_octant_size(int p_size){ +void GridMap::set_octant_size(int p_size) { - octant_size=p_size; + octant_size = p_size; _recreate_octant_data(); } -int GridMap::get_octant_size() const{ +int GridMap::get_octant_size() const { return octant_size; } void GridMap::set_center_x(bool p_enable) { - center_x=p_enable; + center_x = p_enable; _recreate_octant_data(); } @@ -258,7 +249,7 @@ bool GridMap::get_center_x() const { void GridMap::set_center_y(bool p_enable) { - center_y=p_enable; + center_y = p_enable; _recreate_octant_data(); } @@ -268,7 +259,7 @@ bool GridMap::get_center_y() const { void GridMap::set_center_z(bool p_enable) { - center_z=p_enable; + center_z = p_enable; _recreate_octant_data(); } @@ -276,56 +267,52 @@ bool GridMap::get_center_z() const { return center_z; } +int GridMap::_find_area(const IndexKey &p_pos) const { -int GridMap::_find_area(const IndexKey& p_pos) const { - - for(const Map::Element *E=area_map.front();E;E=E->next()) { - //this should somehow be faster... - const Area& a=*E->get(); - if ( p_pos.x>=a.from.x && p_pos.x=a.from.y && p_pos.y=a.from.z && p_pos.z::Element *E = area_map.front(); E; E = E->next()) { + //this should somehow be faster... + const Area &a = *E->get(); + if (p_pos.x >= a.from.x && p_pos.x < a.to.x && + p_pos.y >= a.from.y && p_pos.y < a.to.y && + p_pos.z >= a.from.z && p_pos.z < a.to.z) { return E->key(); } } return 0; } -void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ +void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) { - ERR_FAIL_INDEX(ABS(p_x),1<<20); - ERR_FAIL_INDEX(ABS(p_y),1<<20); - ERR_FAIL_INDEX(ABS(p_z),1<<20); + ERR_FAIL_INDEX(ABS(p_x), 1 << 20); + ERR_FAIL_INDEX(ABS(p_y), 1 << 20); + ERR_FAIL_INDEX(ABS(p_z), 1 << 20); IndexKey key; - key.x=p_x; - key.y=p_y; - key.z=p_z; + key.x = p_x; + key.y = p_y; + key.z = p_z; OctantKey ok; - ok.x=p_x/octant_size; - ok.y=p_y/octant_size; - ok.z=p_z/octant_size; + ok.x = p_x / octant_size; + ok.y = p_y / octant_size; + ok.z = p_z / octant_size; ok.area = _find_area(key); - if (cell_map.has(key)) { - int prev_item=cell_map[key].item; + int prev_item = cell_map[key].item; - OctantKey octantkey=ok; + OctantKey octantkey = ok; ERR_FAIL_COND(!octant_map.has(octantkey)); - Octant& g = *octant_map[octantkey]; + Octant &g = *octant_map[octantkey]; ERR_FAIL_COND(!g.items.has(prev_item)); ERR_FAIL_COND(!g.items[prev_item].cells.has(key)); - g.items[prev_item].cells.erase(key); - if (g.items[prev_item].cells.size()==0) { + if (g.items[prev_item].cells.size() == 0) { VS::get_singleton()->free(g.items[prev_item].multimesh_instance); g.items.erase(prev_item); - } if (g.items.empty()) { @@ -339,136 +326,129 @@ void GridMap::set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_rot){ octant_map.erase(octantkey); } else { - - g.dirty=true; + g.dirty = true; } cell_map.erase(key); _queue_dirty_map(); } - if (p_item<0) + if (p_item < 0) return; - OctantKey octantkey=ok; + OctantKey octantkey = ok; //add later if (!octant_map.has(octantkey)) { - - Octant *g = memnew( Octant ); - g->dirty=true; + Octant *g = memnew(Octant); + g->dirty = true; g->static_body = PhysicsServer::get_singleton()->body_create(PhysicsServer::BODY_MODE_STATIC); - PhysicsServer::get_singleton()->body_attach_object_instance_ID(g->static_body,get_instance_ID()); + PhysicsServer::get_singleton()->body_attach_object_instance_ID(g->static_body, get_instance_ID()); if (is_inside_world()) - PhysicsServer::get_singleton()->body_set_space(g->static_body,get_world()->get_space()); + PhysicsServer::get_singleton()->body_set_space(g->static_body, get_world()->get_space()); - SceneTree *st=SceneTree::get_singleton(); + SceneTree *st = SceneTree::get_singleton(); if (st && st->is_debugging_collisions_hint()) { - g->collision_debug=VisualServer::get_singleton()->mesh_create(); - g->collision_debug_instance=VisualServer::get_singleton()->instance_create(); - VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance,g->collision_debug); + g->collision_debug = VisualServer::get_singleton()->mesh_create(); + g->collision_debug_instance = VisualServer::get_singleton()->instance_create(); + VisualServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug); if (is_inside_world()) { - VisualServer::get_singleton()->instance_set_scenario(g->collision_debug_instance,get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(g->collision_debug_instance,get_global_transform()); + VisualServer::get_singleton()->instance_set_scenario(g->collision_debug_instance, get_world()->get_scenario()); + VisualServer::get_singleton()->instance_set_transform(g->collision_debug_instance, get_global_transform()); } - } - octant_map[octantkey]=g; + octant_map[octantkey] = g; } - Octant& g = *octant_map[octantkey]; + Octant &g = *octant_map[octantkey]; if (!g.items.has(p_item)) { Octant::ItemInstances ii; if (theme.is_valid() && theme->has_item(p_item)) { - ii.mesh=theme->get_item_mesh(p_item); - ii.shape=theme->get_item_shape(p_item); - ii.navmesh=theme->get_item_navmesh(p_item); + ii.mesh = theme->get_item_mesh(p_item); + ii.shape = theme->get_item_shape(p_item); + ii.navmesh = theme->get_item_navmesh(p_item); } - ii.multimesh = Ref( memnew( MultiMesh ) ); + ii.multimesh = Ref(memnew(MultiMesh)); ii.multimesh->set_color_format(MultiMesh::COLOR_NONE); ii.multimesh->set_transform_format(MultiMesh::TRANSFORM_3D); ii.multimesh->set_mesh(ii.mesh); ii.multimesh_instance = VS::get_singleton()->instance_create(); - VS::get_singleton()->instance_set_base(ii.multimesh_instance,ii.multimesh->get_rid()); + VS::get_singleton()->instance_set_base(ii.multimesh_instance, ii.multimesh->get_rid()); - g.items[p_item]=ii; + g.items[p_item] = ii; } Octant::ItemInstances &ii = g.items[p_item]; ii.cells.insert(key); - g.dirty=true; + g.dirty = true; _queue_dirty_map(); - cell_map[key]=Cell(); - Cell &c=cell_map[key]; - c.item=p_item; - c.rot=p_rot; - + cell_map[key] = Cell(); + Cell &c = cell_map[key]; + c.item = p_item; + c.rot = p_rot; } -int GridMap::get_cell_item(int p_x,int p_y,int p_z) const{ - - ERR_FAIL_INDEX_V(ABS(p_x),1<<20,INVALID_CELL_ITEM); - ERR_FAIL_INDEX_V(ABS(p_y),1<<20,INVALID_CELL_ITEM); - ERR_FAIL_INDEX_V(ABS(p_z),1<<20,INVALID_CELL_ITEM); +int GridMap::get_cell_item(int p_x, int p_y, int p_z) const { + ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, INVALID_CELL_ITEM); + ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, INVALID_CELL_ITEM); + ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, INVALID_CELL_ITEM); IndexKey key; - key.x=p_x; - key.y=p_y; - key.z=p_z; + key.x = p_x; + key.y = p_y; + key.z = p_z; if (!cell_map.has(key)) return INVALID_CELL_ITEM; return cell_map[key].item; - } -int GridMap::get_cell_item_orientation(int p_x,int p_y,int p_z) const{ +int GridMap::get_cell_item_orientation(int p_x, int p_y, int p_z) const { - ERR_FAIL_INDEX_V(ABS(p_x),1<<20,-1); - ERR_FAIL_INDEX_V(ABS(p_y),1<<20,-1); - ERR_FAIL_INDEX_V(ABS(p_z),1<<20,-1); + ERR_FAIL_INDEX_V(ABS(p_x), 1 << 20, -1); + ERR_FAIL_INDEX_V(ABS(p_y), 1 << 20, -1); + ERR_FAIL_INDEX_V(ABS(p_z), 1 << 20, -1); IndexKey key; - key.x=p_x; - key.y=p_y; - key.z=p_z; + key.x = p_x; + key.y = p_y; + key.z = p_z; if (!cell_map.has(key)) return -1; return cell_map[key].rot; - } -void GridMap::_octant_enter_tree(const OctantKey &p_key){ +void GridMap::_octant_enter_tree(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); - if(navigation){ - Octant&g = *octant_map[p_key]; + if (navigation) { + Octant &g = *octant_map[p_key]; - Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); + Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z)); _octant_clear_navmesh(p_key); - for(Map::Element *E=g.items.front();E;E=E->next()) { - Octant::ItemInstances &ii=E->get(); + for (Map::Element *E = g.items.front(); E; E = E->next()) { + Octant::ItemInstances &ii = E->get(); - for(Set::Element *F=ii.cells.front();F;F=F->next()) { + for (Set::Element *F = ii.cells.front(); F; F = F->next()) { - IndexKey ik=F->get(); - Map::Element *C=cell_map.find(ik); + IndexKey ik = F->get(); + Map::Element *C = cell_map.find(ik); ERR_CONTINUE(!C); - Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); + Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Transform xform; - if (clip && ( (clip_above && cellpos[clip_axis]>clip_floor) || (!clip_above && cellpos[clip_axis] clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) { xform.basis.set_zero(); @@ -477,16 +457,15 @@ void GridMap::_octant_enter_tree(const OctantKey &p_key){ xform.basis.set_orthogonal_index(C->get().rot); } - - xform.set_origin( cellpos*cell_size+ofs); - xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale)); + xform.set_origin(cellpos * cell_size + ofs); + xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); // add the item's navmesh at given xform to GridMap's Navigation ancestor - if(ii.navmesh.is_valid()){ - int nm_id = navigation->navmesh_create(ii.navmesh,xform,this); + if (ii.navmesh.is_valid()) { + int nm_id = navigation->navmesh_create(ii.navmesh, xform, this); Octant::NavMesh nm; - nm.id=nm_id; - nm.xform=xform; - g.navmesh_ids[ik]=nm; + nm.id = nm_id; + nm.xform = xform; + g.navmesh_ids[ik] = nm; } } } @@ -496,56 +475,53 @@ void GridMap::_octant_enter_tree(const OctantKey &p_key){ void GridMap::_octant_enter_world(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform()); - PhysicsServer::get_singleton()->body_set_space(g.static_body,get_world()->get_space()); + Octant &g = *octant_map[p_key]; + PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer::get_singleton()->body_set_space(g.static_body, get_world()->get_space()); //print_line("BODYPOS: "+get_global_transform()); - if (g.collision_debug_instance.is_valid()) { - VS::get_singleton()->instance_set_scenario(g.collision_debug_instance,get_world()->get_scenario()); - VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform()); + VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(g.collision_debug_instance,area_map[p_key.area]->instance); + VS::get_singleton()->instance_set_room(g.collision_debug_instance, area_map[p_key.area]->instance); } } - for(Map::Element *E=g.items.front();E;E=E->next()) { + for (Map::Element *E = g.items.front(); E; E = E->next()) { - VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,get_world()->get_scenario()); - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, get_world()->get_scenario()); + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform()); //print_line("INSTANCEPOS: "+get_global_transform()); if (area_map.has(p_key.area)) { - VS::get_singleton()->instance_set_room(E->get().multimesh_instance,area_map[p_key.area]->instance); + VS::get_singleton()->instance_set_room(E->get().multimesh_instance, area_map[p_key.area]->instance); } } } - void GridMap::_octant_transform(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform()); + Octant &g = *octant_map[p_key]; + PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); if (g.collision_debug_instance.is_valid()) { - VS::get_singleton()->instance_set_transform(g.collision_debug_instance,get_global_transform()); + VS::get_singleton()->instance_set_transform(g.collision_debug_instance, get_global_transform()); } - for(Map::Element *E=g.items.front();E;E=E->next()) { + for (Map::Element *E = g.items.front(); E; E = E->next()) { - VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); + VS::get_singleton()->instance_set_transform(E->get().multimesh_instance, get_global_transform()); //print_line("UPDATEPOS: "+get_global_transform()); } - } -void GridMap::_octant_clear_navmesh(const OctantKey &p_key){ - Octant&g = *octant_map[p_key]; +void GridMap::_octant_clear_navmesh(const OctantKey &p_key) { + Octant &g = *octant_map[p_key]; if (navigation) { - for(Map::Element *E=g.navmesh_ids.front();E;E=E->next()) { + for (Map::Element *E = g.navmesh_ids.front(); E; E = E->next()) { Octant::NavMesh *nvm = &E->get(); - if(nvm && nvm->id){ + if (nvm && nvm->id) { navigation->navmesh_remove(E->get().id); } } @@ -555,7 +531,7 @@ void GridMap::_octant_clear_navmesh(const OctantKey &p_key){ void GridMap::_octant_update(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; + Octant &g = *octant_map[p_key]; if (!g.dirty) return; @@ -576,31 +552,30 @@ void GridMap::_octant_update(const OctantKey &p_key) { * set item's multimesh's instance count to number of cells which have this item * and set said multimesh bounding box to one containing all cells which have this item */ - for(Map::Element *E=g.items.front();E;E=E->next()) { + for (Map::Element *E = g.items.front(); E; E = E->next()) { - Octant::ItemInstances &ii=E->get(); + Octant::ItemInstances &ii = E->get(); ii.multimesh->set_instance_count(ii.cells.size()); Rect3 aabb; - Rect3 mesh_aabb = ii.mesh.is_null()?Rect3():ii.mesh->get_aabb(); - - Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); + Rect3 mesh_aabb = ii.mesh.is_null() ? Rect3() : ii.mesh->get_aabb(); + Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z)); //print_line("OCTANT, CELLS: "+itos(ii.cells.size())); - int idx=0; + int idx = 0; // foreach cell containing this item type - for(Set::Element *F=ii.cells.front();F;F=F->next()) { - IndexKey ik=F->get(); - Map::Element *C=cell_map.find(ik); + for (Set::Element *F = ii.cells.front(); F; F = F->next()) { + IndexKey ik = F->get(); + Map::Element *C = cell_map.find(ik); ERR_CONTINUE(!C); - Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); + Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Transform xform; - if (clip && ( (clip_above && cellpos[clip_axis]>clip_floor) || (!clip_above && cellpos[clip_axis] clip_floor) || (!clip_above && cellpos[clip_axis] < clip_floor))) { xform.basis.set_zero(); @@ -609,19 +584,17 @@ void GridMap::_octant_update(const OctantKey &p_key) { xform.basis.set_orthogonal_index(C->get().rot); } + xform.set_origin(cellpos * cell_size + ofs); + xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); - xform.set_origin( cellpos*cell_size+ofs); - xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale)); - - ii.multimesh->set_instance_transform(idx,xform); + ii.multimesh->set_instance_transform(idx, xform); //ii.multimesh->set_instance_transform(idx,Transform() ); //ii.multimesh->set_instance_color(idx,Color(1,1,1,1)); //print_line("MMINST: "+xform); + if (idx == 0) { - if(idx==0) { - - aabb=xform.xform(mesh_aabb); + aabb = xform.xform(mesh_aabb); } else { aabb.merge_with(xform.xform(mesh_aabb)); @@ -630,22 +603,22 @@ void GridMap::_octant_update(const OctantKey &p_key) { // add the item's shape at given xform to octant's static_body if (ii.shape.is_valid()) { // add the item's shape - PhysicsServer::get_singleton()->body_add_shape(g.static_body,ii.shape->get_rid(),xform); + PhysicsServer::get_singleton()->body_add_shape(g.static_body, ii.shape->get_rid(), xform); if (g.collision_debug.is_valid()) { - ii.shape->add_vertices_to_array(col_debug,xform); + ii.shape->add_vertices_to_array(col_debug, xform); } //print_line("PHIS x: "+xform); } // add the item's navmesh at given xform to GridMap's Navigation ancestor - if(navigation){ - if(ii.navmesh.is_valid()){ - int nm_id = navigation->navmesh_create(ii.navmesh,xform,this); + if (navigation) { + if (ii.navmesh.is_valid()) { + int nm_id = navigation->navmesh_create(ii.navmesh, xform, this); Octant::NavMesh nm; - nm.id=nm_id; - nm.xform=xform; - g.navmesh_ids[ik]=nm; + nm.id = nm_id; + nm.xform = xform; + g.navmesh_ids[ik] = nm; } } @@ -653,95 +626,84 @@ void GridMap::_octant_update(const OctantKey &p_key) { } //ii.multimesh->set_aabb(aabb); - - } if (col_debug.size()) { - Array arr; arr.resize(VS::ARRAY_MAX); - arr[VS::ARRAY_VERTEX]=col_debug; + arr[VS::ARRAY_VERTEX] = col_debug; - VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug,VS::PRIMITIVE_LINES,arr); - SceneTree *st=SceneTree::get_singleton(); + VS::get_singleton()->mesh_add_surface_from_arrays(g.collision_debug, VS::PRIMITIVE_LINES, arr); + SceneTree *st = SceneTree::get_singleton(); if (st) { - VS::get_singleton()->mesh_surface_set_material( g.collision_debug, 0,st->get_debug_collision_material()->get_rid() ); + VS::get_singleton()->mesh_surface_set_material(g.collision_debug, 0, st->get_debug_collision_material()->get_rid()); } } - g.dirty=false; - + g.dirty = false; } - void GridMap::_octant_exit_world(const OctantKey &p_key) { ERR_FAIL_COND(!octant_map.has(p_key)); - Octant&g = *octant_map[p_key]; - PhysicsServer::get_singleton()->body_set_state(g.static_body,PhysicsServer::BODY_STATE_TRANSFORM,get_global_transform()); - PhysicsServer::get_singleton()->body_set_space(g.static_body,RID()); - + Octant &g = *octant_map[p_key]; + PhysicsServer::get_singleton()->body_set_state(g.static_body, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer::get_singleton()->body_set_space(g.static_body, RID()); if (g.collision_debug_instance.is_valid()) { - VS::get_singleton()->instance_set_room(g.collision_debug_instance,RID()); - VS::get_singleton()->instance_set_scenario(g.collision_debug_instance,RID()); + VS::get_singleton()->instance_set_room(g.collision_debug_instance, RID()); + VS::get_singleton()->instance_set_scenario(g.collision_debug_instance, RID()); } - for(Map::Element *E=g.items.front();E;E=E->next()) { + for (Map::Element *E = g.items.front(); E; E = E->next()) { - VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance,RID()); + VS::get_singleton()->instance_set_scenario(E->get().multimesh_instance, RID()); //VS::get_singleton()->instance_set_transform(E->get().multimesh_instance,get_global_transform()); - VS::get_singleton()->instance_set_room(E->get().multimesh_instance,RID()); + VS::get_singleton()->instance_set_room(E->get().multimesh_instance, RID()); } - } - void GridMap::_notification(int p_what) { - - switch(p_what) { + switch (p_what) { case NOTIFICATION_ENTER_WORLD: { _update_area_instances(); - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { //IndexKey ik; //ik.key = E->key().indexkey; _octant_enter_world(E->key()); _octant_update(E->key()); } - awaiting_update=false; - - last_transform=get_global_transform(); + awaiting_update = false; + last_transform = get_global_transform(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { Transform new_xform = get_global_transform(); - if (new_xform==last_transform) + if (new_xform == last_transform) break; //update run - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { _octant_transform(E->key()); } - last_transform=new_xform; + last_transform = new_xform; } break; case NOTIFICATION_EXIT_WORLD: { - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { _octant_exit_world(E->key()); } - //_queue_dirty_map(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS); //_update_dirty_map_callback(); //_update_area_instances(); @@ -749,41 +711,39 @@ void GridMap::_notification(int p_what) { } break; case NOTIFICATION_ENTER_TREE: { - Spatial *c=this; - while(c) { - navigation=c->cast_to(); + Spatial *c = this; + while (c) { + navigation = c->cast_to(); if (navigation) { break; } - c=c->get_parent()->cast_to(); + c = c->get_parent()->cast_to(); } - if(navigation){ - for(Map::Element *E=octant_map.front();E;E=E->next()) { + if (navigation) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { if (navigation) { _octant_enter_tree(E->key()); } } } - _queue_dirty_map(); + _queue_dirty_map(); } break; case NOTIFICATION_EXIT_TREE: { - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { if (navigation) { _octant_clear_navmesh(E->key()); } } - navigation=NULL; + navigation = NULL; } break; } } - - void GridMap::_queue_dirty_map() { if (awaiting_update) @@ -791,34 +751,32 @@ void GridMap::_queue_dirty_map() { if (is_inside_world()) { - MessageQueue::get_singleton()->push_call(this,"_update_dirty_map_callback"); - awaiting_update=true; + MessageQueue::get_singleton()->push_call(this, "_update_dirty_map_callback"); + awaiting_update = true; } } void GridMap::_recreate_octant_data() { - Map cell_copy=cell_map; + Map cell_copy = cell_map; _clear_internal(true); - for (Map::Element *E=cell_copy.front();E;E=E->next()) { + for (Map::Element *E = cell_copy.front(); E; E = E->next()) { - set_cell_item(E->key().x,E->key().y,E->key().z,E->get().item,E->get().rot); + set_cell_item(E->key().x, E->key().y, E->key().z, E->get().item, E->get().rot); } - } void GridMap::_clear_internal(bool p_keep_areas) { - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { if (is_inside_world()) _octant_exit_world(E->key()); - for (Map::Element *F=E->get()->items.front();F;F=F->next()) { + for (Map::Element *F = E->get()->items.front(); F; F = F->next()) { VS::get_singleton()->free(F->get().multimesh_instance); } - if (E->get()->collision_debug.is_valid()) VS::get_singleton()->free(E->get()->collision_debug); if (E->get()->collision_debug_instance.is_valid()) @@ -826,7 +784,6 @@ void GridMap::_clear_internal(bool p_keep_areas) { PhysicsServer::get_singleton()->free(E->get()->static_body); memdelete(E->get()); - } octant_map.clear(); @@ -835,253 +792,231 @@ void GridMap::_clear_internal(bool p_keep_areas) { if (p_keep_areas) return; - for (Map::Element *E=area_map.front();E;E=E->next()) { - + for (Map::Element *E = area_map.front(); E; E = E->next()) { VS::get_singleton()->free(E->get()->base_portal); VS::get_singleton()->free(E->get()->instance); - for(int i=0;iget()->portals.size();i++) { + for (int i = 0; i < E->get()->portals.size(); i++) { VS::get_singleton()->free(E->get()->portals[i].instance); } memdelete(E->get()); } - } void GridMap::clear() { _clear_internal(); - } -void GridMap::resource_changed(const RES& p_res) { +void GridMap::resource_changed(const RES &p_res) { _recreate_octant_data(); } - void GridMap::_update_dirty_map_callback() { if (!awaiting_update) return; - for(Map::Element *E=octant_map.front();E;E=E->next()) { + for (Map::Element *E = octant_map.front(); E; E = E->next()) { _octant_update(E->key()); } - - awaiting_update=false; - + awaiting_update = false; } - void GridMap::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_theme","theme:MeshLibrary"),&GridMap::set_theme); - ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"),&GridMap::get_theme); + ClassDB::bind_method(D_METHOD("set_theme", "theme:MeshLibrary"), &GridMap::set_theme); + ClassDB::bind_method(D_METHOD("get_theme:MeshLibrary"), &GridMap::get_theme); - ClassDB::bind_method(D_METHOD("set_cell_size","size"),&GridMap::set_cell_size); - ClassDB::bind_method(D_METHOD("get_cell_size"),&GridMap::get_cell_size); + ClassDB::bind_method(D_METHOD("set_cell_size", "size"), &GridMap::set_cell_size); + ClassDB::bind_method(D_METHOD("get_cell_size"), &GridMap::get_cell_size); - ClassDB::bind_method(D_METHOD("set_octant_size","size"),&GridMap::set_octant_size); - ClassDB::bind_method(D_METHOD("get_octant_size"),&GridMap::get_octant_size); + ClassDB::bind_method(D_METHOD("set_octant_size", "size"), &GridMap::set_octant_size); + ClassDB::bind_method(D_METHOD("get_octant_size"), &GridMap::get_octant_size); - ClassDB::bind_method(D_METHOD("set_cell_item","x","y","z","item","orientation"),&GridMap::set_cell_item,DEFVAL(0)); - ClassDB::bind_method(D_METHOD("get_cell_item","x","y","z"),&GridMap::get_cell_item); - ClassDB::bind_method(D_METHOD("get_cell_item_orientation","x","y","z"),&GridMap::get_cell_item_orientation); + ClassDB::bind_method(D_METHOD("set_cell_item", "x", "y", "z", "item", "orientation"), &GridMap::set_cell_item, DEFVAL(0)); + ClassDB::bind_method(D_METHOD("get_cell_item", "x", "y", "z"), &GridMap::get_cell_item); + ClassDB::bind_method(D_METHOD("get_cell_item_orientation", "x", "y", "z"), &GridMap::get_cell_item_orientation); //ClassDB::bind_method(D_METHOD("_recreate_octants"),&GridMap::_recreate_octants); - ClassDB::bind_method(D_METHOD("_update_dirty_map_callback"),&GridMap::_update_dirty_map_callback); - ClassDB::bind_method(D_METHOD("resource_changed","resource"),&GridMap::resource_changed); - - ClassDB::bind_method(D_METHOD("set_center_x","enable"),&GridMap::set_center_x); - ClassDB::bind_method(D_METHOD("get_center_x"),&GridMap::get_center_x); - ClassDB::bind_method(D_METHOD("set_center_y","enable"),&GridMap::set_center_y); - ClassDB::bind_method(D_METHOD("get_center_y"),&GridMap::get_center_y); - ClassDB::bind_method(D_METHOD("set_center_z","enable"),&GridMap::set_center_z); - ClassDB::bind_method(D_METHOD("get_center_z"),&GridMap::get_center_z); - - ClassDB::bind_method(D_METHOD("set_clip","enabled","clipabove","floor","axis"),&GridMap::set_clip,DEFVAL(true),DEFVAL(0),DEFVAL(Vector3::AXIS_X)); - - ClassDB::bind_method(D_METHOD("create_area","id","area"),&GridMap::create_area); - ClassDB::bind_method(D_METHOD("area_get_bounds","area","bounds"),&GridMap::area_get_bounds); - ClassDB::bind_method(D_METHOD("area_set_exterior_portal","area","enable"),&GridMap::area_set_exterior_portal); - ClassDB::bind_method(D_METHOD("area_set_name","area","name"),&GridMap::area_set_name); - ClassDB::bind_method(D_METHOD("area_get_name","area"),&GridMap::area_get_name); - ClassDB::bind_method(D_METHOD("area_is_exterior_portal","area"),&GridMap::area_is_exterior_portal); - ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance","area","distance"),&GridMap::area_set_portal_disable_distance); - ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance","area"),&GridMap::area_get_portal_disable_distance); - ClassDB::bind_method(D_METHOD("area_set_portal_disable_color","area","color"),&GridMap::area_set_portal_disable_color); - ClassDB::bind_method(D_METHOD("area_get_portal_disable_color","area"),&GridMap::area_get_portal_disable_color); - ClassDB::bind_method(D_METHOD("erase_area","area"),&GridMap::erase_area); - ClassDB::bind_method(D_METHOD("get_unused_area_id","area"),&GridMap::get_unused_area_id); - - ClassDB::bind_method(D_METHOD("clear"),&GridMap::clear); - - ClassDB::bind_method(D_METHOD("get_meshes"),&GridMap::get_meshes); - - BIND_CONSTANT( INVALID_CELL_ITEM ); - + ClassDB::bind_method(D_METHOD("_update_dirty_map_callback"), &GridMap::_update_dirty_map_callback); + ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &GridMap::resource_changed); + + ClassDB::bind_method(D_METHOD("set_center_x", "enable"), &GridMap::set_center_x); + ClassDB::bind_method(D_METHOD("get_center_x"), &GridMap::get_center_x); + ClassDB::bind_method(D_METHOD("set_center_y", "enable"), &GridMap::set_center_y); + ClassDB::bind_method(D_METHOD("get_center_y"), &GridMap::get_center_y); + ClassDB::bind_method(D_METHOD("set_center_z", "enable"), &GridMap::set_center_z); + ClassDB::bind_method(D_METHOD("get_center_z"), &GridMap::get_center_z); + + ClassDB::bind_method(D_METHOD("set_clip", "enabled", "clipabove", "floor", "axis"), &GridMap::set_clip, DEFVAL(true), DEFVAL(0), DEFVAL(Vector3::AXIS_X)); + + ClassDB::bind_method(D_METHOD("create_area", "id", "area"), &GridMap::create_area); + ClassDB::bind_method(D_METHOD("area_get_bounds", "area", "bounds"), &GridMap::area_get_bounds); + ClassDB::bind_method(D_METHOD("area_set_exterior_portal", "area", "enable"), &GridMap::area_set_exterior_portal); + ClassDB::bind_method(D_METHOD("area_set_name", "area", "name"), &GridMap::area_set_name); + ClassDB::bind_method(D_METHOD("area_get_name", "area"), &GridMap::area_get_name); + ClassDB::bind_method(D_METHOD("area_is_exterior_portal", "area"), &GridMap::area_is_exterior_portal); + ClassDB::bind_method(D_METHOD("area_set_portal_disable_distance", "area", "distance"), &GridMap::area_set_portal_disable_distance); + ClassDB::bind_method(D_METHOD("area_get_portal_disable_distance", "area"), &GridMap::area_get_portal_disable_distance); + ClassDB::bind_method(D_METHOD("area_set_portal_disable_color", "area", "color"), &GridMap::area_set_portal_disable_color); + ClassDB::bind_method(D_METHOD("area_get_portal_disable_color", "area"), &GridMap::area_get_portal_disable_color); + ClassDB::bind_method(D_METHOD("erase_area", "area"), &GridMap::erase_area); + ClassDB::bind_method(D_METHOD("get_unused_area_id", "area"), &GridMap::get_unused_area_id); + + ClassDB::bind_method(D_METHOD("clear"), &GridMap::clear); + + ClassDB::bind_method(D_METHOD("get_meshes"), &GridMap::get_meshes); + + BIND_CONSTANT(INVALID_CELL_ITEM); } void GridMap::set_clip(bool p_enabled, bool p_clip_above, int p_floor, Vector3::Axis p_axis) { if (!p_enabled && !clip) return; - if (clip && p_enabled && clip_floor==p_floor && p_clip_above==clip_above && p_axis==clip_axis) + if (clip && p_enabled && clip_floor == p_floor && p_clip_above == clip_above && p_axis == clip_axis) return; - clip=p_enabled; - clip_floor=p_floor; - clip_axis=p_axis; - clip_above=p_clip_above; + clip = p_enabled; + clip_floor = p_floor; + clip_axis = p_axis; + clip_above = p_clip_above; //make it all update - for(Map::Element *E=octant_map.front();E;E=E->next()) { - - Octant *g=E->get(); - g->dirty=true; + for (Map::Element *E = octant_map.front(); E; E = E->next()) { + Octant *g = E->get(); + g->dirty = true; } - awaiting_update=true; + awaiting_update = true; _update_dirty_map_callback(); } - void GridMap::_update_areas() { //clear the portals - for(Map::Element *E=area_map.front();E;E=E->next()) { + for (Map::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... - Area& a=*E->get(); + Area &a = *E->get(); a.portals.clear(); if (a.instance.is_valid()) { VisualServer::get_singleton()->free(a.instance); - a.instance=RID(); + a.instance = RID(); } } //test all areas against all areas and create portals - this sucks (slow :( ) - for(Map::Element *E=area_map.front();E;E=E->next()) { - Area& a=*E->get(); + for (Map::Element *E = area_map.front(); E; E = E->next()) { + Area &a = *E->get(); if (a.exterior_portal) //that's pretty much all it does... yes it is continue; - Vector3 from_a(a.from.x,a.from.y,a.from.z); - Vector3 to_a(a.to.x,a.to.y,a.to.z); + Vector3 from_a(a.from.x, a.from.y, a.from.z); + Vector3 to_a(a.to.x, a.to.y, a.to.z); - for(Map::Element *F=area_map.front();F;F=F->next()) { + for (Map::Element *F = area_map.front(); F; F = F->next()) { - Area& b=*F->get(); - Vector3 from_b(b.from.x,b.from.y,b.from.z); - Vector3 to_b(b.to.x,b.to.y,b.to.z); + Area &b = *F->get(); + Vector3 from_b(b.from.x, b.from.y, b.from.z); + Vector3 to_b(b.to.x, b.to.y, b.to.z); // initially test intersection and discards - int axis=-1; - float sign=0; - bool valid=true; - Vector3 axmin,axmax; - + int axis = -1; + float sign = 0; + bool valid = true; + Vector3 axmin, axmax; - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { - if (from_a[i]==to_b[i]) { + if (from_a[i] == to_b[i]) { - if (axis!=-1) { - valid=false; + if (axis != -1) { + valid = false; break; } - axis=i; - sign=-1; - } else if (from_b[i]==to_a[i]) { + axis = i; + sign = -1; + } else if (from_b[i] == to_a[i]) { - if (axis!=-1) { - valid=false; + if (axis != -1) { + valid = false; break; } - axis=i; - sign=+1; + axis = i; + sign = +1; } - - if (from_a[i] > to_b[i] || to_a[i] < from_b[i] ) { - valid=false; + if (from_a[i] > to_b[i] || to_a[i] < from_b[i]) { + valid = false; break; } else { - axmin[i]= ( from_a[i] > from_b[i] ) ? from_a[i] :from_b[i]; - axmax[i]= ( to_a[i] < to_b[i] ) ? to_a[i] :to_b[i]; - + axmin[i] = (from_a[i] > from_b[i]) ? from_a[i] : from_b[i]; + axmax[i] = (to_a[i] < to_b[i]) ? to_a[i] : to_b[i]; } - - } - if (axis==-1 || !valid) + if (axis == -1 || !valid) continue; Transform xf; + for (int i = 0; i < 3; i++) { - for(int i=0;i<3;i++) { - - - - int ax=(axis+i)%3; + int ax = (axis + i) % 3; Vector3 axis_vec; - float scale = (i==0)?sign:((axmax[ax]-axmin[ax])*cell_size); - axis_vec[ax]=scale; - xf.basis.set_axis((2+i)%3,axis_vec); - xf.origin[i]=axmin[i]*cell_size; - + float scale = (i == 0) ? sign : ((axmax[ax] - axmin[ax]) * cell_size); + axis_vec[ax] = scale; + xf.basis.set_axis((2 + i) % 3, axis_vec); + xf.origin[i] = axmin[i] * cell_size; } - - Area::Portal portal; - portal.xform=xf; + portal.xform = xf; a.portals.push_back(portal); } } _update_area_instances(); - } void GridMap::_update_area_instances() { Transform base_xform; if (_in_tree) - base_xform=get_global_transform(); + base_xform = get_global_transform(); - for(Map::Element *E=area_map.front();E;E=E->next()) { + for (Map::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... - Area& a=*E->get(); - if (a.instance.is_valid()!=_in_tree) { + Area &a = *E->get(); + if (a.instance.is_valid() != _in_tree) { if (!_in_tree) { - for(int i=0;ifree(p.instance); - p.instance=RID(); + p.instance = RID(); } VisualServer::get_singleton()->free(a.instance); - a.instance=RID(); + a.instance = RID(); } else { //a.instance = VisualServer::get_singleton()->instance_create2(base_room,get_world()->get_scenario()); - for(int i=0;iinstance_create2(a.base_portal,get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_room(p.instance,a.instance); + p.instance = VisualServer::get_singleton()->instance_create2(a.base_portal, get_world()->get_scenario()); + VisualServer::get_singleton()->instance_set_room(p.instance, a.instance); } } } @@ -1089,62 +1024,57 @@ void GridMap::_update_area_instances() { if (a.instance.is_valid()) { Transform xform; - Vector3 from_a(a.from.x,a.from.y,a.from.z); - Vector3 to_a(a.to.x,a.to.y,a.to.z); + Vector3 from_a(a.from.x, a.from.y, a.from.z); + Vector3 to_a(a.to.x, a.to.y, a.to.z); - for(int i=0;i<3;i++) { - xform.origin[i]=from_a[i]*cell_size; + for (int i = 0; i < 3; i++) { + xform.origin[i] = from_a[i] * cell_size; Vector3 s; - s[i]=(to_a[i]-from_a[i])*cell_size; - xform.basis.set_axis(i,s); + s[i] = (to_a[i] - from_a[i]) * cell_size; + xform.basis.set_axis(i, s); } + VisualServer::get_singleton()->instance_set_transform(a.instance, base_xform * xform); - VisualServer::get_singleton()->instance_set_transform(a.instance,base_xform * xform); - - for(int i=0;iinstance_set_transform(p.instance,base_xform * xform); - + VisualServer::get_singleton()->instance_set_transform(p.instance, base_xform * xform); } - } } - } -Error GridMap::create_area(int p_id,const Rect3& p_bounds) { +Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { - ERR_FAIL_COND_V(area_map.has(p_id),ERR_ALREADY_EXISTS); + ERR_FAIL_COND_V(area_map.has(p_id), ERR_ALREADY_EXISTS); ERR_EXPLAIN("ID 0 is taken as global area, start from 1"); - ERR_FAIL_COND_V(p_id==0,ERR_INVALID_PARAMETER); - ERR_FAIL_COND_V(p_bounds.has_no_area(),ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_id == 0, ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(p_bounds.has_no_area(), ERR_INVALID_PARAMETER); // FIRST VALIDATE AREA - IndexKey from,to; - from.x=p_bounds.pos.x; - from.y=p_bounds.pos.y; - from.z=p_bounds.pos.z; - to.x=p_bounds.pos.x+p_bounds.size.x; - to.y=p_bounds.pos.y+p_bounds.size.y; - to.z=p_bounds.pos.z+p_bounds.size.z; - - - for(Map::Element *E=area_map.front();E;E=E->next()) { + IndexKey from, to; + from.x = p_bounds.pos.x; + from.y = p_bounds.pos.y; + from.z = p_bounds.pos.z; + to.x = p_bounds.pos.x + p_bounds.size.x; + to.y = p_bounds.pos.y + p_bounds.size.y; + to.z = p_bounds.pos.z + p_bounds.size.z; + + for (Map::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... - Area& a=*E->get(); + Area &a = *E->get(); //does it interset with anything else? - if ( from.x >= a.to.x || - to.x <= a.from.x || - from.y >= a.to.y || - to.y <= a.from.y || - from.z >= a.to.z || - to.z <= a.from.z ) { + if (from.x >= a.to.x || + to.x <= a.from.x || + from.y >= a.to.y || + to.y <= a.from.y || + from.z >= a.to.z || + to.z <= a.from.z) { // all good } else { @@ -1153,62 +1083,60 @@ Error GridMap::create_area(int p_id,const Rect3& p_bounds) { } } - - Area *area = memnew( Area ); - area->from=from; - area->to=to; - area->portal_disable_distance=0; - area->exterior_portal=false; - area->name="Area "+itos(p_id); - area_map[p_id]=area; + Area *area = memnew(Area); + area->from = from; + area->to = to; + area->portal_disable_distance = 0; + area->exterior_portal = false; + area->name = "Area " + itos(p_id); + area_map[p_id] = area; _recreate_octant_data(); return OK; } Rect3 GridMap::area_get_bounds(int p_area) const { - ERR_FAIL_COND_V(!area_map.has(p_area),Rect3()); + ERR_FAIL_COND_V(!area_map.has(p_area), Rect3()); const Area *a = area_map[p_area]; Rect3 aabb; - aabb.pos=Vector3(a->from.x,a->from.y,a->from.z); - aabb.size=Vector3(a->to.x,a->to.y,a->to.z)-aabb.pos; + aabb.pos = Vector3(a->from.x, a->from.y, a->from.z); + aabb.size = Vector3(a->to.x, a->to.y, a->to.z) - aabb.pos; return aabb; } -void GridMap::area_set_name(int p_area,const String& p_name) { +void GridMap::area_set_name(int p_area, const String &p_name) { ERR_FAIL_COND(!area_map.has(p_area)); Area *a = area_map[p_area]; - a->name=p_name; + a->name = p_name; } String GridMap::area_get_name(int p_area) const { - ERR_FAIL_COND_V(!area_map.has(p_area),""); + ERR_FAIL_COND_V(!area_map.has(p_area), ""); const Area *a = area_map[p_area]; return a->name; } - -void GridMap::area_set_exterior_portal(int p_area,bool p_enable) { +void GridMap::area_set_exterior_portal(int p_area, bool p_enable) { ERR_FAIL_COND(!area_map.has(p_area)); Area *a = area_map[p_area]; - if (a->exterior_portal==p_enable) + if (a->exterior_portal == p_enable) return; - a->exterior_portal=p_enable; + a->exterior_portal = p_enable; _recreate_octant_data(); } bool GridMap::area_is_exterior_portal(int p_area) const { - ERR_FAIL_COND_V(!area_map.has(p_area),false); + ERR_FAIL_COND_V(!area_map.has(p_area), false); const Area *a = area_map[p_area]; return a->exterior_portal; @@ -1219,13 +1147,12 @@ void GridMap::area_set_portal_disable_distance(int p_area, float p_distance) { ERR_FAIL_COND(!area_map.has(p_area)); Area *a = area_map[p_area]; - a->portal_disable_distance=p_distance; - + a->portal_disable_distance = p_distance; } float GridMap::area_get_portal_disable_distance(int p_area) const { - ERR_FAIL_COND_V(!area_map.has(p_area),0); + ERR_FAIL_COND_V(!area_map.has(p_area), 0); const Area *a = area_map[p_area]; return a->portal_disable_distance; @@ -1236,13 +1163,12 @@ void GridMap::area_set_portal_disable_color(int p_area, Color p_color) { ERR_FAIL_COND(!area_map.has(p_area)); Area *a = area_map[p_area]; - a->portal_disable_color=p_color; - + a->portal_disable_color = p_color; } Color GridMap::area_get_portal_disable_color(int p_area) const { - ERR_FAIL_COND_V(!area_map.has(p_area),Color()); + ERR_FAIL_COND_V(!area_map.has(p_area), Color()); const Area *a = area_map[p_area]; return a->portal_disable_color; @@ -1250,34 +1176,29 @@ Color GridMap::area_get_portal_disable_color(int p_area) const { void GridMap::get_area_list(List *p_areas) const { - for(const Map::Element *E=area_map.front();E;E=E->next()) { + for (const Map::Element *E = area_map.front(); E; E = E->next()) { p_areas->push_back(E->key()); } - } - GridMap::Area::Portal::~Portal() { if (instance.is_valid()) VisualServer::get_singleton()->free(instance); } - GridMap::Area::Area() { - base_portal=VisualServer::get_singleton()->portal_create(); - Vector< Point2 > points; - points.push_back( Point2( 0, 1 ) ); - points.push_back( Point2( 1, 1 ) ); - points.push_back( Point2( 1, 0 ) ); - points.push_back( Point2( 0, 0 ) ); - VisualServer::get_singleton()->portal_set_shape(base_portal,points); - + base_portal = VisualServer::get_singleton()->portal_create(); + Vector points; + points.push_back(Point2(0, 1)); + points.push_back(Point2(1, 1)); + points.push_back(Point2(1, 0)); + points.push_back(Point2(0, 0)); + VisualServer::get_singleton()->portal_set_shape(base_portal, points); } - GridMap::Area::~Area() { if (instance.is_valid()) @@ -1289,7 +1210,7 @@ void GridMap::erase_area(int p_area) { ERR_FAIL_COND(!area_map.has(p_area)); - Area* a=area_map[p_area]; + Area *a = area_map[p_area]; memdelete(a); area_map.erase(p_area); _recreate_octant_data(); @@ -1300,92 +1221,79 @@ int GridMap::get_unused_area_id() const { if (area_map.empty()) return 1; else - return area_map.back()->key()+1; + return area_map.back()->key() + 1; } void GridMap::set_cell_scale(float p_scale) { - cell_scale=p_scale; + cell_scale = p_scale; _queue_dirty_map(); } -float GridMap::get_cell_scale() const{ +float GridMap::get_cell_scale() const { return cell_scale; } - - - Array GridMap::get_meshes() { if (theme.is_null()) return Array(); - Vector3 ofs(cell_size*0.5*int(center_x),cell_size*0.5*int(center_y),cell_size*0.5*int(center_z)); + Vector3 ofs(cell_size * 0.5 * int(center_x), cell_size * 0.5 * int(center_y), cell_size * 0.5 * int(center_z)); Array meshes; - for (Map::Element *E=cell_map.front();E;E=E->next()) { - + for (Map::Element *E = cell_map.front(); E; E = E->next()) { int id = E->get().item; if (!theme->has_item(id)) continue; - Ref mesh=theme->get_item_mesh(id); + Ref mesh = theme->get_item_mesh(id); if (mesh.is_null()) continue; - IndexKey ik=E->key(); + IndexKey ik = E->key(); - Vector3 cellpos = Vector3(ik.x,ik.y,ik.z ); + Vector3 cellpos = Vector3(ik.x, ik.y, ik.z); Transform xform; xform.basis.set_orthogonal_index(E->get().rot); - - xform.set_origin( cellpos*cell_size+ofs); - xform.basis.scale(Vector3(cell_scale,cell_scale,cell_scale)); + xform.set_origin(cellpos * cell_size + ofs); + xform.basis.scale(Vector3(cell_scale, cell_scale, cell_scale)); meshes.push_back(xform); meshes.push_back(mesh); - } return meshes; } - - - GridMap::GridMap() { - cell_size=2; - octant_size=4; - 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; + cell_size = 2; + octant_size = 4; + 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 = NULL; set_notify_transform(true); } - GridMap::~GridMap() { if (!theme.is_null()) theme->unregister_owner(this); clear(); - } - diff --git a/modules/gridmap/grid_map.h b/modules/gridmap/grid_map.h index 5d4133383b..2a0c2b9646 100644 --- a/modules/gridmap/grid_map.h +++ b/modules/gridmap/grid_map.h @@ -29,26 +29,23 @@ #ifndef GRID_MAP_H #define GRID_MAP_H - -#include "scene/resources/mesh_library.h" -#include "scene/3d/spatial.h" #include "scene/3d/navigation.h" +#include "scene/3d/spatial.h" +#include "scene/resources/mesh_library.h" #include "scene/resources/multimesh.h" //heh heh, godotsphir!! this shares no code and the design is completely different with previous projects i've done.. //should scale better with hardware that supports instancing - class BakedLightInstance; class GridMap : public Spatial { - - GDCLASS( GridMap, Spatial ); + GDCLASS(GridMap, Spatial); enum { - MAP_DIRTY_TRANSFORMS=1, - MAP_DIRTY_INSTANCES=2, + MAP_DIRTY_TRANSFORMS = 1, + MAP_DIRTY_INSTANCES = 2, }; union IndexKey { @@ -60,12 +57,12 @@ class GridMap : public Spatial { }; uint64_t key; - _FORCE_INLINE_ bool operator<(const IndexKey& p_key) const { + _FORCE_INLINE_ bool operator<(const IndexKey &p_key) const { return key < p_key.key; } - IndexKey() { key=0; } + IndexKey() { key = 0; } }; /** @@ -75,12 +72,16 @@ class GridMap : public Spatial { struct { unsigned int item : 16; - unsigned int rot:5; - unsigned int layer:8; + unsigned int rot : 5; + unsigned int layer : 8; }; uint32_t cell; - Cell() { item=0; rot=0; layer=0; } + Cell() { + item = 0; + rot = 0; + layer = 0; + } }; /** @@ -108,8 +109,8 @@ class GridMap : public Spatial { bool dirty; RID static_body; - Map items; - Map navmesh_ids; + Map items; + Map navmesh_ids; }; union OctantKey { @@ -123,13 +124,13 @@ class GridMap : public Spatial { uint64_t key; - _FORCE_INLINE_ bool operator<(const OctantKey& p_key) const { + _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() { key = 0; } }; Transform last_transform; @@ -137,7 +138,7 @@ class GridMap : public Spatial { bool _in_tree; float cell_size; int octant_size; - bool center_x,center_y,center_z; + bool center_x, center_y, center_z; float cell_scale; Navigation *navigation; @@ -146,7 +147,6 @@ class GridMap : public Spatial { int clip_floor; Vector3::Axis clip_axis; - /** * @brief An Area is something like a room: it has doors, and Octants can choose to belong to it. */ @@ -173,11 +173,9 @@ class GridMap : public Spatial { Ref theme; - Map octant_map; - Map cell_map; - Map area_map; - - + Map octant_map; + Map cell_map; + Map area_map; void _recreate_octant_data(); @@ -189,11 +187,11 @@ class GridMap : public Spatial { float param[VS::LIGHT_PARAM_MAX]; }; - _FORCE_INLINE_ int _find_area(const IndexKey& p_pos) const; + _FORCE_INLINE_ int _find_area(const IndexKey &p_pos) const; _FORCE_INLINE_ Vector3 _octant_get_offset(const OctantKey &p_key) const { - return Vector3(p_key.x,p_key.y,p_key.z)*cell_size*octant_size; + return Vector3(p_key.x, p_key.y, p_key.z) * cell_size * octant_size; } void _octant_enter_world(const OctantKey &p_key); @@ -201,37 +199,33 @@ class GridMap : public Spatial { void _octant_exit_world(const OctantKey &p_key); void _octant_update(const OctantKey &p_key); void _octant_transform(const OctantKey &p_key); - void _octant_clear_navmesh(const GridMap::OctantKey&); + void _octant_clear_navmesh(const GridMap::OctantKey &); bool awaiting_update; void _queue_dirty_map(); void _update_dirty_map_callback(); - void resource_changed(const RES& p_res); - + void resource_changed(const RES &p_res); void _update_areas(); void _update_area_instances(); - void _clear_internal(bool p_keep_areas=false); + void _clear_internal(bool p_keep_areas = false); protected: - - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List *p_list) const; + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; void _notification(int p_what); static void _bind_methods(); - public: - enum { - INVALID_CELL_ITEM=-1 + INVALID_CELL_ITEM = -1 }; - void set_theme(const Ref& p_theme); + void set_theme(const Ref &p_theme); Ref get_theme() const; void set_cell_size(float p_size); @@ -240,7 +234,6 @@ public: void set_octant_size(int p_size); int get_octant_size() const; - void set_center_x(bool p_enable); bool get_center_x() const; void set_center_y(bool p_enable); @@ -248,16 +241,16 @@ public: void set_center_z(bool p_enable); bool get_center_z() const; - void set_cell_item(int p_x,int p_y,int p_z, int p_item,int p_orientation=0); - int get_cell_item(int p_x,int p_y,int p_z) const; - int get_cell_item_orientation(int p_x,int p_y,int p_z) const; + void set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_orientation = 0); + int get_cell_item(int p_x, int p_y, int p_z) const; + int get_cell_item_orientation(int p_x, int p_y, int p_z) const; - void set_clip(bool p_enabled, bool p_clip_above=true, int p_floor=0, Vector3::Axis p_axis=Vector3::AXIS_X); + void set_clip(bool p_enabled, bool p_clip_above = true, int p_floor = 0, Vector3::Axis p_axis = Vector3::AXIS_X); - Error create_area(int p_id,const Rect3& p_area); + Error create_area(int p_id, const Rect3 &p_area); Rect3 area_get_bounds(int p_area) const; - void area_set_exterior_portal(int p_area,bool p_enable); - void area_set_name(int p_area,const String& p_name); + void area_set_exterior_portal(int p_area, bool p_enable); + void area_set_name(int p_area, const String &p_name); String area_get_name(int p_area) const; bool area_is_exterior_portal(int p_area) const; void area_set_portal_disable_distance(int p_area, float p_distance); @@ -271,11 +264,8 @@ public: void set_cell_scale(float p_scale); float get_cell_scale() const; - - Array get_meshes(); - void clear(); GridMap(); diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp index a5d2f84c68..a6a3a03503 100644 --- a/modules/gridmap/grid_map_editor_plugin.cpp +++ b/modules/gridmap/grid_map_editor_plugin.cpp @@ -27,59 +27,53 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "grid_map_editor_plugin.h" +#include "editor/editor_settings.h" #include "editor/plugins/spatial_editor_plugin.h" #include "scene/3d/camera.h" -#include "editor/editor_settings.h" -#include "os/keyboard.h" #include "geometry.h" +#include "os/keyboard.h" void GridMapEditor::_node_removed(Node *p_node) { - if(p_node==node) { - node=NULL; + if (p_node == node) { + node = NULL; hide(); theme_pallete->hide(); } - } - void GridMapEditor::_configure() { - if(!node) + if (!node) return; update_grid(); - } -void GridMapEditor::_menu_option(int p_option) { +void GridMapEditor::_menu_option(int p_option) { - - switch(p_option) { + switch (p_option) { case MENU_OPTION_CONFIGURE: { - } break; case MENU_OPTION_LOCK_VIEW: { - int index=options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW); - lock_view=!options->get_popup()->is_item_checked(index); + int index = options->get_popup()->get_item_index(MENU_OPTION_LOCK_VIEW); + lock_view = !options->get_popup()->is_item_checked(index); - options->get_popup()->set_item_checked(index,lock_view); + options->get_popup()->set_item_checked(index, lock_view); } break; case MENU_OPTION_CLIP_DISABLED: case MENU_OPTION_CLIP_ABOVE: case MENU_OPTION_CLIP_BELOW: { - clip_mode=ClipMode(p_option-MENU_OPTION_CLIP_DISABLED); - for(int i=0;i<3;i++) { - - int index=options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED+i); - options->get_popup()->set_item_checked(index,i==clip_mode); + clip_mode = ClipMode(p_option - MENU_OPTION_CLIP_DISABLED); + for (int i = 0; i < 3; i++) { + int index = options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED + i); + options->get_popup()->set_item_checked(index, i == clip_mode); } _update_clip(); @@ -88,102 +82,100 @@ void GridMapEditor::_menu_option(int p_option) { case MENU_OPTION_Y_AXIS: case MENU_OPTION_Z_AXIS: { - int new_axis = p_option-MENU_OPTION_X_AXIS; - for(int i=0;i<3;i++) { - int idx=options->get_popup()->get_item_index(MENU_OPTION_X_AXIS+i); - options->get_popup()->set_item_checked(idx,i==new_axis); + int new_axis = p_option - MENU_OPTION_X_AXIS; + for (int i = 0; i < 3; i++) { + int idx = options->get_popup()->get_item_index(MENU_OPTION_X_AXIS + i); + options->get_popup()->set_item_checked(idx, i == new_axis); } - edit_axis=Vector3::Axis(new_axis); + edit_axis = Vector3::Axis(new_axis); update_grid(); _update_clip(); } break; case MENU_OPTION_CURSOR_ROTATE_Y: { Basis r; - if (input_action==INPUT_DUPLICATE) { + if (input_action == INPUT_DUPLICATE) { r.set_orthogonal_index(selection.duplicate_rot); - r.rotate(Vector3(0,1,0),-Math_PI/2.0); - selection.duplicate_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0); + selection.duplicate_rot = r.get_orthogonal_index(); _update_duplicate_indicator(); break; } r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(0,1,0),-Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 1, 0), -Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_X: { Basis r; - if (input_action==INPUT_DUPLICATE) { + if (input_action == INPUT_DUPLICATE) { r.set_orthogonal_index(selection.duplicate_rot); - r.rotate(Vector3(1,0,0),-Math_PI/2.0); - selection.duplicate_rot=r.get_orthogonal_index(); + r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0); + selection.duplicate_rot = r.get_orthogonal_index(); _update_duplicate_indicator(); break; } r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(1,0,0),-Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(1, 0, 0), -Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_ROTATE_Z: { Basis r; - if (input_action==INPUT_DUPLICATE) { + if (input_action == INPUT_DUPLICATE) { r.set_orthogonal_index(selection.duplicate_rot); - r.rotate(Vector3(0,0,1),-Math_PI/2.0); - selection.duplicate_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0); + selection.duplicate_rot = r.get_orthogonal_index(); _update_duplicate_indicator(); break; } r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(0,0,1),-Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 0, 1), -Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Y: { Basis r; r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(0,1,0),Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 1, 0), Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_X: { Basis r; r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(1,0,0),Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(1, 0, 0), Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_BACK_ROTATE_Z: { Basis r; r.set_orthogonal_index(cursor_rot); - r.rotate(Vector3(0,0,1),Math_PI/2.0); - cursor_rot=r.get_orthogonal_index(); + r.rotate(Vector3(0, 0, 1), Math_PI / 2.0); + cursor_rot = r.get_orthogonal_index(); _update_cursor_transform(); } break; case MENU_OPTION_CURSOR_CLEAR_ROTATION: { - if (input_action==INPUT_DUPLICATE) { - + if (input_action == INPUT_DUPLICATE) { - selection.duplicate_rot=0; + selection.duplicate_rot = 0; _update_duplicate_indicator(); break; } - cursor_rot=0; + cursor_rot = 0; _update_cursor_transform(); } break; - case MENU_OPTION_DUPLICATE_SELECTS: { int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS); - options->get_popup()->set_item_checked( idx, !options->get_popup()->is_item_checked( idx ) ); + options->get_popup()->set_item_checked(idx, !options->get_popup()->is_item_checked(idx)); } break; case MENU_OPTION_SELECTION_MAKE_AREA: case MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR: { @@ -191,37 +183,34 @@ void GridMapEditor::_menu_option(int p_option) { if (!selection.active) break; int area = node->get_unused_area_id(); - Error err = node->create_area(area,Rect3(selection.begin,selection.end-selection.begin+Vector3(1,1,1))); - if (err!=OK) { - - + Error err = node->create_area(area, Rect3(selection.begin, selection.end - selection.begin + Vector3(1, 1, 1))); + if (err != OK) { } - if (p_option==MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) { + if (p_option == MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR) { - node->area_set_exterior_portal(area,true); + node->area_set_exterior_portal(area, true); } _update_areas_display(); update_areas(); - } break; case MENU_OPTION_REMOVE_AREA: { - if (selected_area<1) + if (selected_area < 1) return; node->erase_area(selected_area); _update_areas_display(); update_areas(); } break; case MENU_OPTION_SELECTION_DUPLICATE: - if (!(selection.active && input_action==INPUT_NONE)) + if (!(selection.active && input_action == INPUT_NONE)) return; - if (last_mouseover==Vector3(-1,-1,-1)) //nono mouseovering anythin + if (last_mouseover == Vector3(-1, -1, -1)) //nono mouseovering anythin break; - input_action=INPUT_DUPLICATE; - selection.click=last_mouseover; - selection.current=last_mouseover; - selection.duplicate_rot=0; + input_action = INPUT_DUPLICATE; + selection.click = last_mouseover; + selection.current = last_mouseover; + selection.duplicate_rot = 0; _update_duplicate_indicator(); break; case MENU_OPTION_SELECTION_CLEAR: { @@ -230,28 +219,24 @@ void GridMapEditor::_menu_option(int p_option) { _delete_selection(); - } break; case MENU_OPTION_GRIDMAP_SETTINGS: { settings_dialog->popup_centered(settings_vbc->get_combined_minimum_size() + Size2(50, 50)); } break; - } } void GridMapEditor::_update_cursor_transform() { - cursor_transform=Transform(); - cursor_transform.origin=cursor_origin; + cursor_transform = Transform(); + cursor_transform.origin = cursor_origin; cursor_transform.basis.set_orthogonal_index(cursor_rot); cursor_transform = node->get_transform() * cursor_transform; - if (cursor_instance.is_valid()) { - VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform); - VisualServer::get_singleton()->instance_set_visible(cursor_instance,cursor_visible); + VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); + VisualServer::get_singleton()->instance_set_visible(cursor_instance, cursor_visible); } - } void GridMapEditor::_update_selection_transform() { @@ -260,93 +245,87 @@ void GridMapEditor::_update_selection_transform() { Transform xf; xf.basis.set_zero(); - VisualServer::get_singleton()->instance_set_transform(selection_instance,xf); + VisualServer::get_singleton()->instance_set_transform(selection_instance, xf); return; } Transform xf; - xf.scale(Vector3(1,1,1)*(Vector3(1,1,1)+(selection.end-selection.begin))*node->get_cell_size()); - xf.origin=selection.begin*node->get_cell_size(); - - VisualServer::get_singleton()->instance_set_transform(selection_instance,node->get_global_transform() * xf); + xf.scale(Vector3(1, 1, 1) * (Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size()); + xf.origin = selection.begin * node->get_cell_size(); + VisualServer::get_singleton()->instance_set_transform(selection_instance, node->get_global_transform() * xf); } void GridMapEditor::_validate_selection() { if (!selection.active) return; - selection.begin=selection.click; - selection.end=selection.current; - - if (selection.begin.x>selection.end.x) - SWAP(selection.begin.x,selection.end.x); - if (selection.begin.y>selection.end.y) - SWAP(selection.begin.y,selection.end.y); - if (selection.begin.z>selection.end.z) - SWAP(selection.begin.z,selection.end.z); + selection.begin = selection.click; + selection.end = selection.current; + if (selection.begin.x > selection.end.x) + SWAP(selection.begin.x, selection.end.x); + if (selection.begin.y > selection.end.y) + SWAP(selection.begin.y, selection.end.y); + if (selection.begin.z > selection.end.z) + SWAP(selection.begin.z, selection.end.z); _update_selection_transform(); } -bool GridMapEditor::do_input_action(Camera* p_camera,const Point2& p_point,bool p_click) { +bool GridMapEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) { if (!spatial_editor) return false; - - if (selected_pallete<0 && input_action!=INPUT_COPY && input_action!=INPUT_SELECT && input_action!=INPUT_DUPLICATE) + if (selected_pallete < 0 && input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE) return false; Ref theme = node->get_theme(); if (theme.is_null()) return false; - if (input_action!=INPUT_COPY && input_action!=INPUT_SELECT && input_action!=INPUT_DUPLICATE && !theme->has_item(selected_pallete)) + if (input_action != INPUT_COPY && input_action != INPUT_SELECT && input_action != INPUT_DUPLICATE && !theme->has_item(selected_pallete)) return false; Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(p_point); Vector3 normal = camera->project_ray_normal(p_point); Transform local_xform = node->get_global_transform().affine_inverse(); - Vector planes=camera->get_frustum(); - from=local_xform.xform(from); - normal=local_xform.basis.xform(normal).normalized(); - + Vector planes = camera->get_frustum(); + from = local_xform.xform(from); + normal = local_xform.basis.xform(normal).normalized(); Plane p; - p.normal[edit_axis]=1.0; - p.d=edit_floor[edit_axis]*node->get_cell_size(); + p.normal[edit_axis] = 1.0; + p.d = edit_floor[edit_axis] * node->get_cell_size(); Vector3 inters; if (!p.intersects_segment(from, from + normal * settings_pick_distance->get_value(), &inters)) return false; - //make sure the intersection is inside the frustum planes, to avoid //painting on invisible regions - for(int i=0;iget_cell_size(),node->get_cell_size(),node->get_cell_size()}; + float cell_size[3] = { node->get_cell_size(), node->get_cell_size(), node->get_cell_size() }; - last_mouseover=Vector3(-1,-1,-1); + last_mouseover = Vector3(-1, -1, -1); - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { - if (i==edit_axis) - cell[i]=edit_floor[i]; + if (i == edit_axis) + cell[i] = edit_floor[i]; else { - cell[i]=inters[i]/node->get_cell_size(); - if (inters[i]<0) - cell[i]-=1; //compensate negative - grid_ofs[i]=cell[i]*cell_size[i]; + cell[i] = inters[i] / node->get_cell_size(); + if (inters[i] < 0) + cell[i] -= 1; //compensate negative + grid_ofs[i] = cell[i] * cell_size[i]; } /*if (cell[i]<0 || cell[i]>=grid_size[i]) { @@ -357,68 +336,65 @@ bool GridMapEditor::do_input_action(Camera* p_camera,const Point2& p_point,bool }*/ } - last_mouseover=Vector3(cell[0],cell[1],cell[2]); - VS::get_singleton()->instance_set_transform(grid_instance[edit_axis],Transform(Basis(),grid_ofs)); - + last_mouseover = Vector3(cell[0], cell[1], cell[2]); + VS::get_singleton()->instance_set_transform(grid_instance[edit_axis], Transform(Basis(), grid_ofs)); if (cursor_instance.is_valid()) { - cursor_origin=(Vector3(cell[0],cell[1],cell[2])+Vector3(0.5*node->get_center_x(),0.5*node->get_center_y(),0.5*node->get_center_z()))*node->get_cell_size(); - cursor_visible=true; + cursor_origin = (Vector3(cell[0], cell[1], cell[2]) + Vector3(0.5 * node->get_center_x(), 0.5 * node->get_center_y(), 0.5 * node->get_center_z())) * node->get_cell_size(); + cursor_visible = true; _update_cursor_transform(); - } - if (input_action==INPUT_DUPLICATE) { + if (input_action == INPUT_DUPLICATE) { - selection.current=Vector3(cell[0],cell[1],cell[2]); + selection.current = Vector3(cell[0], cell[1], cell[2]); _update_duplicate_indicator(); - } else if (input_action==INPUT_SELECT) { + } else if (input_action == INPUT_SELECT) { - selection.current=Vector3(cell[0],cell[1],cell[2]); + selection.current = Vector3(cell[0], cell[1], cell[2]); if (p_click) - selection.click=selection.current; - selection.active=true; + selection.click = selection.current; + selection.active = true; _validate_selection(); return true; - } else if (input_action==INPUT_COPY) { + } else if (input_action == INPUT_COPY) { - int item=node->get_cell_item(cell[0],cell[1],cell[2]); - if (item>=0) { - selected_pallete=item; + int item = node->get_cell_item(cell[0], cell[1], cell[2]); + if (item >= 0) { + selected_pallete = item; theme_pallete->set_current(item); update_pallete(); _update_cursor_instance(); } return true; - } if (input_action==INPUT_PAINT) { + } + if (input_action == INPUT_PAINT) { SetItem si; - si.pos=Vector3(cell[0],cell[1],cell[2]); - si.new_value=selected_pallete; - si.new_orientation=cursor_rot; - si.old_value=node->get_cell_item(cell[0],cell[1],cell[2]); - si.old_orientation=node->get_cell_item_orientation(cell[0],cell[1],cell[2]); + si.pos = Vector3(cell[0], cell[1], cell[2]); + si.new_value = selected_pallete; + si.new_orientation = cursor_rot; + si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]); + si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]); set_items.push_back(si); - node->set_cell_item(cell[0],cell[1],cell[2],selected_pallete,cursor_rot); + node->set_cell_item(cell[0], cell[1], cell[2], selected_pallete, cursor_rot); return true; - } else if (input_action==INPUT_ERASE) { + } else if (input_action == INPUT_ERASE) { SetItem si; - si.pos=Vector3(cell[0],cell[1],cell[2]); - si.new_value=-1; - si.new_orientation=0; - si.old_value=node->get_cell_item(cell[0],cell[1],cell[2]); - si.old_orientation=node->get_cell_item_orientation(cell[0],cell[1],cell[2]); + si.pos = Vector3(cell[0], cell[1], cell[2]); + si.new_value = -1; + si.new_orientation = 0; + si.old_value = node->get_cell_item(cell[0], cell[1], cell[2]); + si.old_orientation = node->get_cell_item_orientation(cell[0], cell[1], cell[2]); set_items.push_back(si); - node->set_cell_item(cell[0],cell[1],cell[2],-1); + node->set_cell_item(cell[0], cell[1], cell[2], -1); return true; } - return false; - } void GridMapEditor::_delete_selection() { @@ -427,269 +403,253 @@ void GridMapEditor::_delete_selection() { return; undo_redo->create_action("GridMap Delete Selection"); - for(int i=selection.begin.x;i<=selection.end.x;i++) { + for (int i = selection.begin.x; i <= selection.end.x; i++) { - for(int j=selection.begin.y;j<=selection.end.y;j++) { + for (int j = selection.begin.y; j <= selection.end.y; j++) { - for(int k=selection.begin.z;k<=selection.end.z;k++) { + for (int k = selection.begin.z; k <= selection.end.z; k++) { - undo_redo->add_do_method(node,"set_cell_item",i,j,k,GridMap::INVALID_CELL_ITEM); - undo_redo->add_undo_method(node,"set_cell_item",i,j,k,node->get_cell_item(i,j,k),node->get_cell_item_orientation(i,j,k)); + undo_redo->add_do_method(node, "set_cell_item", i, j, k, GridMap::INVALID_CELL_ITEM); + undo_redo->add_undo_method(node, "set_cell_item", i, j, k, node->get_cell_item(i, j, k), node->get_cell_item_orientation(i, j, k)); } - } } undo_redo->commit_action(); - selection.active=false; + selection.active = false; _validate_selection(); - } void GridMapEditor::_update_duplicate_indicator() { - if (!selection.active || input_action!=INPUT_DUPLICATE) { + if (!selection.active || input_action != INPUT_DUPLICATE) { Transform xf; xf.basis.set_zero(); - VisualServer::get_singleton()->instance_set_transform(duplicate_instance,xf); + VisualServer::get_singleton()->instance_set_transform(duplicate_instance, xf); return; } Transform xf; - xf.scale(Vector3(1,1,1)*(Vector3(1,1,1)+(selection.end-selection.begin))*node->get_cell_size()); - xf.origin=(selection.begin+(selection.current-selection.click))*node->get_cell_size(); + xf.scale(Vector3(1, 1, 1) * (Vector3(1, 1, 1) + (selection.end - selection.begin)) * node->get_cell_size()); + xf.origin = (selection.begin + (selection.current - selection.click)) * node->get_cell_size(); Basis rot; rot.set_orthogonal_index(selection.duplicate_rot); xf.basis = rot * xf.basis; - VisualServer::get_singleton()->instance_set_transform(duplicate_instance,node->get_global_transform() * xf); - - + VisualServer::get_singleton()->instance_set_transform(duplicate_instance, node->get_global_transform() * xf); } -struct __Item { Vector3 pos; int rot; int item ; }; +struct __Item { + Vector3 pos; + int rot; + int item; +}; void GridMapEditor::_duplicate_paste() { if (!selection.active) return; int idx = options->get_popup()->get_item_index(MENU_OPTION_DUPLICATE_SELECTS); - bool reselect = options->get_popup()->is_item_checked( idx ); + bool reselect = options->get_popup()->is_item_checked(idx); - - - List< __Item > items; + List<__Item> items; Basis rot; rot.set_orthogonal_index(selection.duplicate_rot); - for(int i=selection.begin.x;i<=selection.end.x;i++) { + for (int i = selection.begin.x; i <= selection.end.x; i++) { - for(int j=selection.begin.y;j<=selection.end.y;j++) { + for (int j = selection.begin.y; j <= selection.end.y; j++) { - for(int k=selection.begin.z;k<=selection.end.z;k++) { + for (int k = selection.begin.z; k <= selection.end.z; k++) { - int itm = node->get_cell_item(i,j,k); - if (itm==GridMap::INVALID_CELL_ITEM) + int itm = node->get_cell_item(i, j, k); + if (itm == GridMap::INVALID_CELL_ITEM) continue; - int orientation = node->get_cell_item_orientation(i,j,k); + int orientation = node->get_cell_item_orientation(i, j, k); __Item item; - Vector3 rel=Vector3(i,j,k)-selection.begin; + Vector3 rel = Vector3(i, j, k) - selection.begin; rel = rot.xform(rel); Basis orm; orm.set_orthogonal_index(orientation); orm = rot * orm; - item.pos=selection.begin+rel; - item.item=itm; - item.rot=orm.get_orthogonal_index(); + item.pos = selection.begin + rel; + item.item = itm; + item.rot = orm.get_orthogonal_index(); items.push_back(item); } - } } - Vector3 ofs=selection.current-selection.click; + Vector3 ofs = selection.current - selection.click; if (items.size()) { undo_redo->create_action("GridMap Duplicate Selection"); - for(List< __Item >::Element *E=items.front();E;E=E->next()) { - __Item &it=E->get(); - Vector3 pos = it.pos+ofs; - - undo_redo->add_do_method(node,"set_cell_item",pos.x,pos.y,pos.z,it.item,it.rot); - undo_redo->add_undo_method(node,"set_cell_item",pos.x,pos.y,pos.z,node->get_cell_item(pos.x,pos.y,pos.z),node->get_cell_item_orientation(pos.x,pos.y,pos.z)); + for (List<__Item>::Element *E = items.front(); E; E = E->next()) { + __Item &it = E->get(); + Vector3 pos = it.pos + ofs; + undo_redo->add_do_method(node, "set_cell_item", pos.x, pos.y, pos.z, it.item, it.rot); + undo_redo->add_undo_method(node, "set_cell_item", pos.x, pos.y, pos.z, node->get_cell_item(pos.x, pos.y, pos.z), node->get_cell_item_orientation(pos.x, pos.y, pos.z)); } undo_redo->commit_action(); } - if (reselect) { - selection.begin+=ofs; - selection.end+=ofs; - selection.click=selection.begin; - selection.current=selection.end; + selection.begin += ofs; + selection.end += ofs; + selection.click = selection.begin; + selection.current = selection.end; _validate_selection(); } - } -bool GridMapEditor::forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { +bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { if (!node) { return false; } - if (edit_mode->get_selected()==0) { // regular click + if (edit_mode->get_selected() == 0) { // regular click switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - if (p_event.mouse_button.button_index==BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { + if (p_event.mouse_button.button_index == BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { if (p_event.mouse_button.pressed) - floor->set_value( floor->get_value() +1); + floor->set_value(floor->get_value() + 1); return true; //eaten - } else if (p_event.mouse_button.button_index==BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { + } else if (p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) { if (p_event.mouse_button.pressed) - floor->set_value( floor->get_value() -1); + floor->set_value(floor->get_value() - 1); return true; } if (p_event.mouse_button.pressed) { - if (p_event.mouse_button.button_index==BUTTON_LEFT) { + if (p_event.mouse_button.button_index == BUTTON_LEFT) { - if (input_action==INPUT_DUPLICATE) { + if (input_action == INPUT_DUPLICATE) { //paste _duplicate_paste(); - input_action=INPUT_NONE; + input_action = INPUT_NONE; _update_duplicate_indicator(); } else if (p_event.mouse_button.mod.shift) { - input_action=INPUT_SELECT; + input_action = INPUT_SELECT; } else if (p_event.mouse_button.mod.command) - input_action=INPUT_COPY; + input_action = INPUT_COPY; else { - input_action=INPUT_PAINT; + input_action = INPUT_PAINT; set_items.clear(); } - } else if (p_event.mouse_button.button_index==BUTTON_RIGHT) - if (input_action==INPUT_DUPLICATE) { + } else if (p_event.mouse_button.button_index == BUTTON_RIGHT) + if (input_action == INPUT_DUPLICATE) { - input_action=INPUT_NONE; + input_action = INPUT_NONE; _update_duplicate_indicator(); } else { - input_action=INPUT_ERASE; + input_action = INPUT_ERASE; set_items.clear(); } else return false; - return do_input_action(p_camera,Point2(p_event.mouse_button.x,p_event.mouse_button.y),true); + return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true); } else { - if ( - (p_event.mouse_button.button_index==BUTTON_RIGHT && input_action==INPUT_ERASE) || - (p_event.mouse_button.button_index==BUTTON_LEFT && input_action==INPUT_PAINT) ) { + (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) || + (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) { if (set_items.size()) { undo_redo->create_action("GridMap Paint"); - for(List::Element *E=set_items.front();E;E=E->next()) { + for (List::Element *E = set_items.front(); E; E = E->next()) { - const SetItem &si=E->get(); - undo_redo->add_do_method(node,"set_cell_item",si.pos.x,si.pos.y,si.pos.z,si.new_value,si.new_orientation); + const SetItem &si = E->get(); + undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation); } - for(List::Element *E=set_items.back();E;E=E->prev()) { + for (List::Element *E = set_items.back(); E; E = E->prev()) { - const SetItem &si=E->get(); - undo_redo->add_undo_method(node,"set_cell_item",si.pos.x,si.pos.y,si.pos.z,si.old_value,si.old_orientation); + const SetItem &si = E->get(); + undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation); } - undo_redo->commit_action(); } set_items.clear(); - input_action=INPUT_NONE; + input_action = INPUT_NONE; return true; - } - - - if (p_event.mouse_button.button_index==BUTTON_LEFT && input_action!=INPUT_NONE) { + if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) { set_items.clear(); - input_action=INPUT_NONE; + input_action = INPUT_NONE; return true; } - if (p_event.mouse_button.button_index==BUTTON_RIGHT && (input_action==INPUT_ERASE || input_action==INPUT_DUPLICATE)) { - input_action=INPUT_NONE; + if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) { + input_action = INPUT_NONE; return true; } } } break; case InputEvent::MOUSE_MOTION: { - return do_input_action(p_camera,Point2(p_event.mouse_motion.x,p_event.mouse_motion.y),false); + return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false); } break; } - } else if (edit_mode->get_selected()==1) { + } else if (edit_mode->get_selected() == 1) { //area mode, select an area switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { - if (p_event.mouse_button.button_index==BUTTON_LEFT && p_event.mouse_button.pressed) { + if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) { - Point2 point = Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); Camera *camera = p_camera; Vector3 from = camera->project_ray_origin(point); Vector3 normal = camera->project_ray_normal(point); Transform local_xform = node->get_global_transform().affine_inverse(); - from=local_xform.xform(from); - normal=local_xform.basis.xform(normal).normalized(); + from = local_xform.xform(from); + normal = local_xform.basis.xform(normal).normalized(); List areas; node->get_area_list(&areas); - float min_d=1e10; - int min_area=-1; + float min_d = 1e10; + int min_area = -1; - - for(List::Element *E=areas.front();E;E=E->next()) { + for (List::Element *E = areas.front(); E; E = E->next()) { int area = E->get(); Rect3 aabb = node->area_get_bounds(area); - aabb.pos*=node->get_cell_size(); - aabb.size*=node->get_cell_size(); - + aabb.pos *= node->get_cell_size(); + aabb.size *= node->get_cell_size(); - Vector3 rclip,rnormal; - if (!aabb.intersects_segment(from,from+normal*10000,&rclip,&rnormal)) + Vector3 rclip, rnormal; + if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal)) continue; float d = normal.dot(rclip); - if (dset_pressed(true); } - display_mode=p_mode; + display_mode = p_mode; update_pallete(); } -void GridMapEditor::update_pallete() { +void GridMapEditor::update_pallete() { int selected = theme_pallete->get_current(); theme_pallete->clear(); if (display_mode == DISPLAY_THUMBNAIL) { theme_pallete->set_max_columns(0); theme_pallete->set_icon_mode(ItemList::ICON_MODE_TOP); - } else if (display_mode == DISPLAY_LIST){ + } else if (display_mode == DISPLAY_LIST) { theme_pallete->set_max_columns(1); theme_pallete->set_icon_mode(ItemList::ICON_MODE_LEFT); } - float min_size = EDITOR_DEF("editors/grid_map/preview_size",64); + float min_size = EDITOR_DEF("editors/grid_map/preview_size", 64); theme_pallete->set_fixed_icon_size(Size2(min_size, min_size)); - theme_pallete->set_fixed_column_width(min_size*3/2); + theme_pallete->set_fixed_column_width(min_size * 3 / 2); theme_pallete->set_max_text_lines(2); Ref theme = node->get_theme(); if (theme.is_null()) { - last_theme=NULL; + last_theme = NULL; return; } @@ -747,65 +706,63 @@ void GridMapEditor::update_pallete() { ids = theme->get_item_list(); List<_CGMEItemSort> il; - for(int i=0;iget_item_name(ids[i]); + is.id = ids[i]; + is.name = theme->get_item_name(ids[i]); il.push_back(is); } il.sort(); int item = 0; - for(List<_CGMEItemSort>::Element *E=il.front();E;E=E->next()) { + for (List<_CGMEItemSort>::Element *E = il.front(); E; E = E->next()) { int id = E->get().id; theme_pallete->add_item(""); - String name=theme->get_item_name(id); + String name = theme->get_item_name(id); Ref preview = theme->get_item_preview(id); if (!preview.is_null()) { theme_pallete->set_item_icon(item, preview); theme_pallete->set_item_tooltip(item, name); } - if (name!="") { - theme_pallete->set_item_text(item,name); + if (name != "") { + theme_pallete->set_item_text(item, name); } theme_pallete->set_item_metadata(item, id); item++; } - if (selected!=-1) { + if (selected != -1) { theme_pallete->select(selected); } - last_theme=theme.operator->(); + last_theme = theme.operator->(); } - void GridMapEditor::_area_renamed() { - TreeItem * it = area_list->get_selected(); + TreeItem *it = area_list->get_selected(); int area = it->get_metadata(0); - if (area<1) + if (area < 1) return; - node->area_set_name(area,it->get_text(0)); + node->area_set_name(area, it->get_text(0)); } - void GridMapEditor::_area_selected() { - TreeItem * it = area_list->get_selected(); + TreeItem *it = area_list->get_selected(); int area = it->get_metadata(0); - if (area<1) + if (area < 1) return; - selected_area=area; + selected_area = area; } -void GridMapEditor::update_areas() { +void GridMapEditor::update_areas() { area_list->clear(); @@ -814,246 +771,221 @@ void GridMapEditor::update_areas() { TreeItem *root = area_list->create_item(NULL); area_list->set_hide_root(true); - TreeItem *selected=NULL; - + TreeItem *selected = NULL; - for (List::Element *E=areas.front();E;E=E->next()) { + for (List::Element *E = areas.front(); E; E = E->next()) { int area = E->get(); TreeItem *ti = area_list->create_item(root); - String name=node->area_get_name(area); + String name = node->area_get_name(area); - ti->set_metadata(0,area); - ti->set_text(0,name); - ti->set_editable(0,true); - if (area==selected_area) - selected=ti; + ti->set_metadata(0, area); + ti->set_text(0, name); + ti->set_editable(0, true); + if (area == selected_area) + selected = ti; } - if (selected) selected->select(0); - } void GridMapEditor::edit(GridMap *p_gridmap) { - node=p_gridmap; + node = p_gridmap; VS *vs = VS::get_singleton(); - last_mouseover=Vector3(-1,-1,-1); - input_action=INPUT_NONE; - selection.active=false; + last_mouseover = Vector3(-1, -1, -1); + input_action = INPUT_NONE; + selection.active = false; _update_selection_transform(); _update_duplicate_indicator(); - spatial_editor = editor->get_editor_plugin_screen()->cast_to(); + spatial_editor = editor->get_editor_plugin_screen()->cast_to(); if (!node) { set_process(false); - for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_set_visible(grid_instance[i],false); - + for (int i = 0; i < 3; i++) { + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], false); } - VisualServer::get_singleton()->instance_set_visible(cursor_instance,false); + VisualServer::get_singleton()->instance_set_visible(cursor_instance, false); _clear_areas(); return; } - update_pallete(); update_areas(); set_process(true); Vector3 edited_floor = p_gridmap->get_meta("_editor_floor_"); - clip_mode=p_gridmap->has_meta("_editor_clip_")?ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()):CLIP_DISABLED; - - - - for(int i=0;i<3;i++) { - if (vs->mesh_get_surface_count(grid[i])>0) - vs->mesh_remove_surface(grid[i],0); - edit_floor[i]=edited_floor[i]; + clip_mode = p_gridmap->has_meta("_editor_clip_") ? ClipMode(p_gridmap->get_meta("_editor_clip_").operator int()) : CLIP_DISABLED; + for (int i = 0; i < 3; i++) { + if (vs->mesh_get_surface_count(grid[i]) > 0) + vs->mesh_remove_surface(grid[i], 0); + edit_floor[i] = edited_floor[i]; } { //update grids indicator_mat.instance(); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR,true); - indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR,true); - indicator_mat->set_albedo(Color(0.8,0.5,0.1)); - + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true); + indicator_mat->set_flag(FixedSpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); + indicator_mat->set_albedo(Color(0.8, 0.5, 0.1)); Vector grid_points[3]; Vector grid_colors[3]; - float cell_size[3]={p_gridmap->get_cell_size(),p_gridmap->get_cell_size(),p_gridmap->get_cell_size()}; + float cell_size[3] = { p_gridmap->get_cell_size(), p_gridmap->get_cell_size(), p_gridmap->get_cell_size() }; - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { Vector3 axis; - axis[i]=1; + axis[i] = 1; Vector3 axis_n1; - axis_n1[(i+1)%3]=cell_size[(i+1)%3]; + axis_n1[(i + 1) % 3] = cell_size[(i + 1) % 3]; Vector3 axis_n2; - axis_n2[(i+2)%3]=cell_size[(i+2)%3]; + axis_n2[(i + 2) % 3] = cell_size[(i + 2) % 3]; - for(int j=-GRID_CURSOR_SIZE;j<=GRID_CURSOR_SIZE;j++) { + for (int j = -GRID_CURSOR_SIZE; j <= GRID_CURSOR_SIZE; j++) { - for(int k=-GRID_CURSOR_SIZE;k<=GRID_CURSOR_SIZE;k++) { + for (int k = -GRID_CURSOR_SIZE; k <= GRID_CURSOR_SIZE; k++) { - Vector3 p = axis_n1*j + axis_n2 *k; - float trans = Math::pow(MAX(0,1.0-(Vector2(j,k).length()/GRID_CURSOR_SIZE)),2); + Vector3 p = axis_n1 * j + axis_n2 * k; + float trans = Math::pow(MAX(0, 1.0 - (Vector2(j, k).length() / GRID_CURSOR_SIZE)), 2); - Vector3 pj = axis_n1*(j+1) + axis_n2 *k; - float transj = Math::pow(MAX(0,1.0-(Vector2(j+1,k).length()/GRID_CURSOR_SIZE)),2); + Vector3 pj = axis_n1 * (j + 1) + axis_n2 * k; + float transj = Math::pow(MAX(0, 1.0 - (Vector2(j + 1, k).length() / GRID_CURSOR_SIZE)), 2); - Vector3 pk = axis_n1*j + axis_n2 *(k+1); - float transk = Math::pow(MAX(0,1.0-(Vector2(j,k+1).length()/GRID_CURSOR_SIZE)),2); + Vector3 pk = axis_n1 * j + axis_n2 * (k + 1); + float transk = Math::pow(MAX(0, 1.0 - (Vector2(j, k + 1).length() / GRID_CURSOR_SIZE)), 2); grid_points[i].push_back(p); grid_points[i].push_back(pk); - grid_colors[i].push_back(Color(1,1,1,trans)); - grid_colors[i].push_back(Color(1,1,1,transk)); + grid_colors[i].push_back(Color(1, 1, 1, trans)); + grid_colors[i].push_back(Color(1, 1, 1, transk)); grid_points[i].push_back(p); grid_points[i].push_back(pj); - grid_colors[i].push_back(Color(1,1,1,trans)); - grid_colors[i].push_back(Color(1,1,1,transj)); + grid_colors[i].push_back(Color(1, 1, 1, trans)); + grid_colors[i].push_back(Color(1, 1, 1, transj)); } - } Array d; d.resize(VS::ARRAY_MAX); - d[VS::ARRAY_VERTEX]=grid_points[i]; - d[VS::ARRAY_COLOR]=grid_colors[i]; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i],VisualServer::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(grid[i],0,indicator_mat->get_rid()); - - + d[VS::ARRAY_VERTEX] = grid_points[i]; + d[VS::ARRAY_COLOR] = grid_colors[i]; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(grid[i], VisualServer::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(grid[i], 0, indicator_mat->get_rid()); } - } update_grid(); _update_clip(); _update_areas_display(); - - } void GridMapEditor::_update_clip() { - - node->set_meta("_editor_clip_",clip_mode); - if (clip_mode==CLIP_DISABLED) + node->set_meta("_editor_clip_", clip_mode); + if (clip_mode == CLIP_DISABLED) node->set_clip(false); else - node->set_clip(true,clip_mode==CLIP_ABOVE,edit_floor[edit_axis],edit_axis); + node->set_clip(true, clip_mode == CLIP_ABOVE, edit_floor[edit_axis], edit_axis); } - void GridMapEditor::update_grid() { - grid_xform.origin.x-=1; //force update in hackish way.. what do i care + grid_xform.origin.x -= 1; //force update in hackish way.. what do i care //VS *vs = VS::get_singleton(); - grid_ofs[edit_axis]=edit_floor[edit_axis]*node->get_cell_size(); - - edit_grid_xform.origin=grid_ofs; - edit_grid_xform.basis=Basis(); + grid_ofs[edit_axis] = edit_floor[edit_axis] * node->get_cell_size(); + edit_grid_xform.origin = grid_ofs; + edit_grid_xform.basis = Basis(); - for(int i=0;i<3;i++) { - VisualServer::get_singleton()->instance_set_visible(grid_instance[i],i==edit_axis); - + for (int i = 0; i < 3; i++) { + VisualServer::get_singleton()->instance_set_visible(grid_instance[i], i == edit_axis); } - updating=true; + updating = true; floor->set_value(edit_floor[edit_axis]); - updating=false; - + updating = false; } - - void GridMapEditor::_notification(int p_what) { - if (p_what==NOTIFICATION_ENTER_TREE) { + if (p_what == NOTIFICATION_ENTER_TREE) { - theme_pallete->connect("item_selected", this,"_item_selected_cbk"); - edit_mode->connect("item_selected", this,"_edit_mode_changed"); - area_list->connect("item_edited", this,"_area_renamed"); - area_list->connect("item_selected", this,"_area_selected"); - for(int i=0;i<3;i++) { + theme_pallete->connect("item_selected", this, "_item_selected_cbk"); + edit_mode->connect("item_selected", this, "_edit_mode_changed"); + area_list->connect("item_edited", this, "_area_renamed"); + area_list->connect("item_selected", this, "_area_selected"); + for (int i = 0; i < 3; i++) { - grid[i]=VS::get_singleton()->mesh_create(); - grid_instance[i]=VS::get_singleton()->instance_create2(grid[i],get_tree()->get_root()->get_world()->get_scenario()); + grid[i] = VS::get_singleton()->mesh_create(); + grid_instance[i] = VS::get_singleton()->instance_create2(grid[i], get_tree()->get_root()->get_world()->get_scenario()); } - selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh,get_tree()->get_root()->get_world()->get_scenario()); - duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh,get_tree()->get_root()->get_world()->get_scenario()); + selection_instance = VisualServer::get_singleton()->instance_create2(selection_mesh, get_tree()->get_root()->get_world()->get_scenario()); + duplicate_instance = VisualServer::get_singleton()->instance_create2(duplicate_mesh, get_tree()->get_root()->get_world()->get_scenario()); _update_selection_transform(); _update_duplicate_indicator(); - } else if (p_what==NOTIFICATION_EXIT_TREE) { + } else if (p_what == NOTIFICATION_EXIT_TREE) { - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { VS::get_singleton()->free(grid_instance[i]); VS::get_singleton()->free(grid[i]); - grid_instance[i]=RID(); - grid[i]=RID(); + grid_instance[i] = RID(); + grid[i] = RID(); } VisualServer::get_singleton()->free(selection_instance); VisualServer::get_singleton()->free(duplicate_instance); - selection_instance=RID(); - duplicate_instance=RID(); + selection_instance = RID(); + duplicate_instance = RID(); - } else if (p_what==NOTIFICATION_PROCESS) { + } else if (p_what == NOTIFICATION_PROCESS) { Transform xf = node->get_global_transform(); - if (xf!=grid_xform) { - for(int i=0;i<3;i++) { - + if (xf != grid_xform) { + for (int i = 0; i < 3; i++) { - VS::get_singleton()->instance_set_transform(grid_instance[i],xf * edit_grid_xform); + VS::get_singleton()->instance_set_transform(grid_instance[i], xf * edit_grid_xform); } - grid_xform=xf; + grid_xform = xf; } Ref cgmt = node->get_theme(); - if (cgmt.operator->()!=last_theme) + if (cgmt.operator->() != last_theme) update_pallete(); if (lock_view) { - EditorNode*editor = get_tree()->get_root()->get_child(0)->cast_to(); + EditorNode *editor = get_tree()->get_root()->get_child(0)->cast_to(); Plane p; - p.normal[edit_axis]=1.0; - p.d=edit_floor[edit_axis]*node->get_cell_size(); + p.normal[edit_axis] = 1.0; + p.d = edit_floor[edit_axis] * node->get_cell_size(); p = node->get_transform().xform(p); // plane to snap SpatialEditorPlugin *sep = editor->get_editor_plugin_screen()->cast_to(); if (sep) sep->snap_cursor_to_plane(p); - //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); - + //editor->get_editor_plugin_screen()->call("snap_cursor_to_plane",p); } } - } void GridMapEditor::_update_cursor_instance() { @@ -1063,32 +995,30 @@ void GridMapEditor::_update_cursor_instance() { if (cursor_instance.is_valid()) VisualServer::get_singleton()->free(cursor_instance); - cursor_instance=RID(); + cursor_instance = RID(); - if (selected_pallete>=0) { + if (selected_pallete >= 0) { if (node && !node->get_theme().is_null()) { Ref mesh = node->get_theme()->get_item_mesh(selected_pallete); if (!mesh.is_null() && mesh->get_rid().is_valid()) { - cursor_instance=VisualServer::get_singleton()->instance_create2(mesh->get_rid(),get_tree()->get_root()->get_world()->get_scenario()); - VisualServer::get_singleton()->instance_set_transform(cursor_instance,cursor_transform); + cursor_instance = VisualServer::get_singleton()->instance_create2(mesh->get_rid(), get_tree()->get_root()->get_world()->get_scenario()); + VisualServer::get_singleton()->instance_set_transform(cursor_instance, cursor_transform); } } } - } void GridMapEditor::_item_selected_cbk(int idx) { - selected_pallete=theme_pallete->get_item_metadata(idx); + selected_pallete = theme_pallete->get_item_metadata(idx); _update_cursor_instance(); - } void GridMapEditor::_clear_areas() { - for(int i=0;ifree(areas[i].instance); VisualServer::get_singleton()->free(areas[i].mesh); @@ -1154,7 +1084,7 @@ void GridMapEditor::_update_areas_display() { void GridMapEditor::_edit_mode_changed(int p_what) { - if (p_what==0) { + if (p_what == 0) { theme_pallete->show(); area_list->hide(); @@ -1162,89 +1092,82 @@ void GridMapEditor::_edit_mode_changed(int p_what) { theme_pallete->hide(); area_list->show(); - } } void GridMapEditor::_floor_changed(float p_value) { - if (updating) return; - edit_floor[edit_axis]=p_value; - node->set_meta("_editor_floor_",Vector3(edit_floor[0],edit_floor[1],edit_floor[2])); + edit_floor[edit_axis] = p_value; + node->set_meta("_editor_floor_", Vector3(edit_floor[0], edit_floor[1], edit_floor[2])); update_grid(); _update_clip(); - } void GridMapEditor::_bind_methods() { - ClassDB::bind_method("_menu_option",&GridMapEditor::_menu_option); - ClassDB::bind_method("_configure",&GridMapEditor::_configure); - ClassDB::bind_method("_item_selected_cbk",&GridMapEditor::_item_selected_cbk); - ClassDB::bind_method("_edit_mode_changed",&GridMapEditor::_edit_mode_changed); - ClassDB::bind_method("_area_renamed",&GridMapEditor::_area_renamed); - ClassDB::bind_method("_area_selected",&GridMapEditor::_area_selected); - ClassDB::bind_method("_floor_changed",&GridMapEditor::_floor_changed); + ClassDB::bind_method("_menu_option", &GridMapEditor::_menu_option); + ClassDB::bind_method("_configure", &GridMapEditor::_configure); + ClassDB::bind_method("_item_selected_cbk", &GridMapEditor::_item_selected_cbk); + ClassDB::bind_method("_edit_mode_changed", &GridMapEditor::_edit_mode_changed); + ClassDB::bind_method("_area_renamed", &GridMapEditor::_area_renamed); + ClassDB::bind_method("_area_selected", &GridMapEditor::_area_selected); + ClassDB::bind_method("_floor_changed", &GridMapEditor::_floor_changed); - ClassDB::bind_method(D_METHOD("_set_display_mode","mode"), &GridMapEditor::_set_display_mode); + ClassDB::bind_method(D_METHOD("_set_display_mode", "mode"), &GridMapEditor::_set_display_mode); } - - GridMapEditor::GridMapEditor(EditorNode *p_editor) { + input_action = INPUT_NONE; + editor = p_editor; + undo_redo = p_editor->get_undo_redo(); - input_action=INPUT_NONE; - editor=p_editor; - undo_redo=p_editor->get_undo_redo(); - - int mw = EDITOR_DEF("editors/grid_map/palette_min_width",230); - Control *ec = memnew( Control); - ec->set_custom_minimum_size(Size2(mw,0)); + int mw = EDITOR_DEF("editors/grid_map/palette_min_width", 230); + Control *ec = memnew(Control); + ec->set_custom_minimum_size(Size2(mw, 0)); add_child(ec); - - spatial_editor_hb = memnew( HBoxContainer ); + spatial_editor_hb = memnew(HBoxContainer); SpatialEditor::get_singleton()->add_control_to_menu_panel(spatial_editor_hb); - options = memnew( MenuButton ); + options = memnew(MenuButton); spatial_editor_hb->add_child(options); spatial_editor_hb->hide(); options->set_text("Grid"); - options->get_popup()->add_check_item("Snap View",MENU_OPTION_LOCK_VIEW); + options->get_popup()->add_check_item("Snap View", MENU_OPTION_LOCK_VIEW); options->get_popup()->add_separator(); - options->get_popup()->add_item("Prev Level ("+keycode_get_string(KEY_MASK_CMD)+"Down Wheel)",MENU_OPTION_PREV_LEVEL); - options->get_popup()->add_item("Next Level ("+keycode_get_string(KEY_MASK_CMD)+"Up Wheel)",MENU_OPTION_NEXT_LEVEL); + options->get_popup()->add_item("Prev Level (" + keycode_get_string(KEY_MASK_CMD) + "Down Wheel)", MENU_OPTION_PREV_LEVEL); + options->get_popup()->add_item("Next Level (" + keycode_get_string(KEY_MASK_CMD) + "Up Wheel)", MENU_OPTION_NEXT_LEVEL); options->get_popup()->add_separator(); - options->get_popup()->add_check_item("Clip Disabled",MENU_OPTION_CLIP_DISABLED); - options->get_popup()->set_item_checked( options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true ); - options->get_popup()->add_check_item("Clip Above",MENU_OPTION_CLIP_ABOVE); - options->get_popup()->add_check_item("Clip Below",MENU_OPTION_CLIP_BELOW); + options->get_popup()->add_check_item("Clip Disabled", MENU_OPTION_CLIP_DISABLED); + options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_CLIP_DISABLED), true); + options->get_popup()->add_check_item("Clip Above", MENU_OPTION_CLIP_ABOVE); + options->get_popup()->add_check_item("Clip Below", MENU_OPTION_CLIP_BELOW); options->get_popup()->add_separator(); - options->get_popup()->add_check_item("Edit X Axis",MENU_OPTION_X_AXIS,KEY_Z); - options->get_popup()->add_check_item("Edit Y Axis",MENU_OPTION_Y_AXIS,KEY_X); - options->get_popup()->add_check_item("Edit Z Axis",MENU_OPTION_Z_AXIS,KEY_C); - options->get_popup()->set_item_checked( options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true ); + options->get_popup()->add_check_item("Edit X Axis", MENU_OPTION_X_AXIS, KEY_Z); + options->get_popup()->add_check_item("Edit Y Axis", MENU_OPTION_Y_AXIS, KEY_X); + options->get_popup()->add_check_item("Edit Z Axis", MENU_OPTION_Z_AXIS, KEY_C); + options->get_popup()->set_item_checked(options->get_popup()->get_item_index(MENU_OPTION_Y_AXIS), true); options->get_popup()->add_separator(); - options->get_popup()->add_item("Cursor Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_A); - options->get_popup()->add_item("Cursor Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_S); - options->get_popup()->add_item("Cursor Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_D); - options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_BACK_ROTATE_X,KEY_MASK_SHIFT+KEY_A); - options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_BACK_ROTATE_Y,KEY_MASK_SHIFT+KEY_S); - options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_BACK_ROTATE_Z,KEY_MASK_SHIFT+KEY_D); - options->get_popup()->add_item("Cursor Clear Rotation",MENU_OPTION_CURSOR_CLEAR_ROTATION,KEY_W); + options->get_popup()->add_item("Cursor Rotate X", MENU_OPTION_CURSOR_ROTATE_X, KEY_A); + options->get_popup()->add_item("Cursor Rotate Y", MENU_OPTION_CURSOR_ROTATE_Y, KEY_S); + options->get_popup()->add_item("Cursor Rotate Z", MENU_OPTION_CURSOR_ROTATE_Z, KEY_D); + options->get_popup()->add_item("Cursor Back Rotate X", MENU_OPTION_CURSOR_BACK_ROTATE_X, KEY_MASK_SHIFT + KEY_A); + options->get_popup()->add_item("Cursor Back Rotate Y", MENU_OPTION_CURSOR_BACK_ROTATE_Y, KEY_MASK_SHIFT + KEY_S); + options->get_popup()->add_item("Cursor Back Rotate Z", MENU_OPTION_CURSOR_BACK_ROTATE_Z, KEY_MASK_SHIFT + KEY_D); + options->get_popup()->add_item("Cursor Clear Rotation", MENU_OPTION_CURSOR_CLEAR_ROTATION, KEY_W); options->get_popup()->add_separator(); - options->get_popup()->add_check_item("Duplicate Selects",MENU_OPTION_DUPLICATE_SELECTS); + options->get_popup()->add_check_item("Duplicate Selects", MENU_OPTION_DUPLICATE_SELECTS); options->get_popup()->add_separator(); - options->get_popup()->add_item("Create Area",MENU_OPTION_SELECTION_MAKE_AREA,KEY_CONTROL+KEY_C); - options->get_popup()->add_item("Create Exterior Connector",MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR); - options->get_popup()->add_item("Erase Area",MENU_OPTION_REMOVE_AREA); + options->get_popup()->add_item("Create Area", MENU_OPTION_SELECTION_MAKE_AREA, KEY_CONTROL + KEY_C); + options->get_popup()->add_item("Create Exterior Connector", MENU_OPTION_SELECTION_MAKE_EXTERIOR_CONNECTOR); + options->get_popup()->add_item("Erase Area", MENU_OPTION_REMOVE_AREA); options->get_popup()->add_separator(); - options->get_popup()->add_item("Selection -> Duplicate",MENU_OPTION_SELECTION_DUPLICATE,KEY_MASK_SHIFT+KEY_INSERT); - options->get_popup()->add_item("Selection -> Clear",MENU_OPTION_SELECTION_CLEAR,KEY_MASK_SHIFT+KEY_DELETE); + options->get_popup()->add_item("Selection -> Duplicate", MENU_OPTION_SELECTION_DUPLICATE, KEY_MASK_SHIFT + KEY_INSERT); + options->get_popup()->add_item("Selection -> Clear", MENU_OPTION_SELECTION_CLEAR, KEY_MASK_SHIFT + KEY_DELETE); //options->get_popup()->add_separator(); //options->get_popup()->add_item("Configure",MENU_OPTION_CONFIGURE); @@ -1265,46 +1188,46 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { settings_pick_distance->set_value(EDITOR_DEF("editors/grid_map/pick_distance", 5000.0)); settings_vbc->add_margin_child("Pick Distance:", settings_pick_distance); - clip_mode=CLIP_DISABLED; - options->get_popup()->connect("id_pressed", this,"_menu_option"); + clip_mode = CLIP_DISABLED; + options->get_popup()->connect("id_pressed", this, "_menu_option"); - HBoxContainer *hb = memnew( HBoxContainer ); + HBoxContainer *hb = memnew(HBoxContainer); add_child(hb); hb->set_h_size_flags(SIZE_EXPAND_FILL); edit_mode = memnew(OptionButton); edit_mode->set_area_as_parent_rect(); - edit_mode->set_anchor_and_margin(MARGIN_BOTTOM,ANCHOR_BEGIN,24); - edit_mode->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,14); + edit_mode->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_BEGIN, 24); + edit_mode->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 14); edit_mode->add_item("Tiles"); edit_mode->add_item("Areas"); hb->add_child(edit_mode); edit_mode->set_h_size_flags(SIZE_EXPAND_FILL); - mode_thumbnail = memnew( ToolButton ); + mode_thumbnail = memnew(ToolButton); mode_thumbnail->set_toggle_mode(true); mode_thumbnail->set_pressed(true); - mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail","EditorIcons")); + mode_thumbnail->set_icon(p_editor->get_gui_base()->get_icon("FileThumbnail", "EditorIcons")); hb->add_child(mode_thumbnail); mode_thumbnail->connect("pressed", this, "_set_display_mode", varray(DISPLAY_THUMBNAIL)); - mode_list = memnew( ToolButton ); + mode_list = memnew(ToolButton); mode_list->set_toggle_mode(true); mode_list->set_pressed(false); mode_list->set_icon(p_editor->get_gui_base()->get_icon("FileList", "EditorIcons")); hb->add_child(mode_list); mode_list->connect("pressed", this, "_set_display_mode", varray(DISPLAY_LIST)); - EDITOR_DEF("editors/grid_map/preview_size",64); + EDITOR_DEF("editors/grid_map/preview_size", 64); display_mode = DISPLAY_THUMBNAIL; - selected_area=-1; + selected_area = -1; - theme_pallete = memnew( ItemList ); + theme_pallete = memnew(ItemList); add_child(theme_pallete); theme_pallete->set_v_size_flags(SIZE_EXPAND_FILL); - area_list = memnew( Tree ); + area_list = memnew(Tree); add_child(area_list); area_list->set_v_size_flags(SIZE_EXPAND_FILL); area_list->hide(); @@ -1314,26 +1237,25 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { fl->set_text(" Floor: "); spatial_editor_hb->add_child(fl); - floor = memnew( SpinBox ); + floor = memnew(SpinBox); floor->set_min(-32767); floor->set_max(32767); floor->set_step(1); - floor->get_line_edit()->add_constant_override("minimum_spaces",16); + floor->get_line_edit()->add_constant_override("minimum_spaces", 16); spatial_editor_hb->add_child(floor); - floor->connect("value_changed",this,"_floor_changed"); - + floor->connect("value_changed", this, "_floor_changed"); - edit_axis=Vector3::AXIS_Y; - edit_floor[0]=-1; - edit_floor[1]=-1; - edit_floor[2]=-1; + edit_axis = Vector3::AXIS_Y; + edit_floor[0] = -1; + edit_floor[1] = -1; + edit_floor[2] = -1; - cursor_visible=false; - selected_pallete=-1; - lock_view=false; - cursor_rot=0; - last_mouseover=Vector3(-1,-1,-1); + cursor_visible = false; + selected_pallete = -1; + lock_view = false; + cursor_rot = 0; + last_mouseover = Vector3(-1, -1, -1); selection_mesh = VisualServer::get_singleton()->mesh_create(); duplicate_mesh = VisualServer::get_singleton()->mesh_create(); @@ -1341,45 +1263,43 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { { //selection mesh create - PoolVector lines; PoolVector triangles; - for (int i=0;i<6;i++) { - + for (int i = 0; i < 6; i++) { Vector3 face_points[4]; - for (int j=0;j<4;j++) { + for (int j = 0; j < 4; j++) { float v[3]; - v[0]=1.0; - v[1]=1-2*((j>>1)&1); - v[2]=v[1]*(1-2*(j&1)); + v[0] = 1.0; + v[1] = 1 - 2 * ((j >> 1) & 1); + v[2] = v[1] * (1 - 2 * (j & 1)); - for (int k=0;k<3;k++) { + for (int k = 0; k < 3; k++) { - if (i<3) - face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1); + if (i < 3) + face_points[j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); else - face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1); + face_points[3 - j][(i + k) % 3] = v[k] * (i >= 3 ? -1 : 1); } } - triangles.push_back(face_points[0]*0.5+Vector3(0.5,0.5,0.5)); - triangles.push_back(face_points[1]*0.5+Vector3(0.5,0.5,0.5)); - triangles.push_back(face_points[2]*0.5+Vector3(0.5,0.5,0.5)); + triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5)); + triangles.push_back(face_points[1] * 0.5 + Vector3(0.5, 0.5, 0.5)); + triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5)); - triangles.push_back(face_points[2]*0.5+Vector3(0.5,0.5,0.5)); - triangles.push_back(face_points[3]*0.5+Vector3(0.5,0.5,0.5)); - triangles.push_back(face_points[0]*0.5+Vector3(0.5,0.5,0.5)); + triangles.push_back(face_points[2] * 0.5 + Vector3(0.5, 0.5, 0.5)); + triangles.push_back(face_points[3] * 0.5 + Vector3(0.5, 0.5, 0.5)); + triangles.push_back(face_points[0] * 0.5 + Vector3(0.5, 0.5, 0.5)); } - for(int i=0;i<12;i++) { + for (int i = 0; i < 12; i++) { - Rect3 base(Vector3(0,0,0),Vector3(1,1,1)); - Vector3 a,b; - base.get_edge(i,a,b); + Rect3 base(Vector3(0, 0, 0), Vector3(1, 1, 1)); + Vector3 a, b; + base.get_edge(i, a, b); lines.push_back(a); lines.push_back(b); } @@ -1388,49 +1308,42 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) { d.resize(VS::ARRAY_MAX); inner_mat.instance(); - inner_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); - inner_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); - inner_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); - inner_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); + inner_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.3)); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); + inner_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); + inner_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); - - d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,0,inner_mat->get_rid()); + d[VS::ARRAY_VERTEX] = triangles; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_TRIANGLES, d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 0, inner_mat->get_rid()); outer_mat.instance(); - outer_mat->set_albedo(Color(0.7,0.7,1.0,0.3)); - outer_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP,true); - outer_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED,true); + outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.3)); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_ONTOP, true); + outer_mat->set_flag(FixedSpatialMaterial::FLAG_UNSHADED, true); outer_mat->set_line_width(3.0); - outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT,true); - - - d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh,1,outer_mat->get_rid()); + outer_mat->set_feature(FixedSpatialMaterial::FEATURE_TRANSPARENT, true); - d[VS::ARRAY_VERTEX]=triangles; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_TRIANGLES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,0,inner_mat->get_rid()); + d[VS::ARRAY_VERTEX] = lines; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(selection_mesh, 1, outer_mat->get_rid()); - d[VS::ARRAY_VERTEX]=lines; - VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh,VS::PRIMITIVE_LINES,d); - VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh,1,outer_mat->get_rid()); + d[VS::ARRAY_VERTEX] = triangles; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh, VS::PRIMITIVE_TRIANGLES, d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh, 0, inner_mat->get_rid()); + d[VS::ARRAY_VERTEX] = lines; + VisualServer::get_singleton()->mesh_add_surface_from_arrays(duplicate_mesh, VS::PRIMITIVE_LINES, d); + VisualServer::get_singleton()->mesh_surface_set_material(duplicate_mesh, 1, outer_mat->get_rid()); } - selection.active=false; - updating=false; - + selection.active = false; + updating = false; } - - - GridMapEditor::~GridMapEditor() { - for(int i=0;i<3;i++) { + for (int i = 0; i < 3; i++) { if (grid[i].is_valid()) VisualServer::get_singleton()->free(grid[i]); @@ -1440,12 +1353,10 @@ GridMapEditor::~GridMapEditor() { VisualServer::get_singleton()->free(cursor_instance); } - VisualServer::get_singleton()->free(selection_mesh); if (selection_instance.is_valid()) VisualServer::get_singleton()->free(selection_instance); - VisualServer::get_singleton()->free(duplicate_mesh); if (duplicate_instance.is_valid()) VisualServer::get_singleton()->free(duplicate_instance); @@ -1455,8 +1366,7 @@ GridMapEditor::~GridMapEditor() { void GridMapEditorPlugin::edit(Object *p_object) { - - gridmap_editor->edit(p_object?p_object->cast_to():NULL); + gridmap_editor->edit(p_object ? p_object->cast_to() : NULL); } bool GridMapEditorPlugin::handles(Object *p_object) const { @@ -1477,26 +1387,18 @@ void GridMapEditorPlugin::make_visible(bool p_visible) { gridmap_editor->edit(NULL); gridmap_editor->set_process(false); } - } - GridMapEditorPlugin::GridMapEditorPlugin(EditorNode *p_node) { - editor=p_node; - gridmap_editor = memnew( GridMapEditor(editor) ); + editor = p_node; + gridmap_editor = memnew(GridMapEditor(editor)); SpatialEditor::get_singleton()->get_palette_split()->add_child(gridmap_editor); - SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor,0); + SpatialEditor::get_singleton()->get_palette_split()->move_child(gridmap_editor, 0); gridmap_editor->hide(); - - - } - -GridMapEditorPlugin::~GridMapEditorPlugin() -{ +GridMapEditorPlugin::~GridMapEditorPlugin() { } - diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h index 07ac34cd4e..27a063ee41 100644 --- a/modules/gridmap/grid_map_editor_plugin.h +++ b/modules/gridmap/grid_map_editor_plugin.h @@ -29,10 +29,10 @@ #ifndef GRID_MAP_EDITOR_PLUGIN_H #define GRID_MAP_EDITOR_PLUGIN_H -#include "editor/editor_plugin.h" #include "editor/editor_node.h" -#include "grid_map.h" +#include "editor/editor_plugin.h" #include "editor/pane_drag.h" +#include "grid_map.h" /** @author Juan Linietsky */ @@ -40,11 +40,11 @@ class SpatialEditorPlugin; class GridMapEditor : public VBoxContainer { - GDCLASS(GridMapEditor, VBoxContainer ); + GDCLASS(GridMapEditor, VBoxContainer); enum { - GRID_CURSOR_SIZE=50 + GRID_CURSOR_SIZE = 50 }; enum InputAction { @@ -65,14 +65,14 @@ class GridMapEditor : public VBoxContainer { }; enum DisplayMode { - DISPLAY_THUMBNAIL, - DISPLAY_LIST + DISPLAY_THUMBNAIL, + DISPLAY_LIST }; UndoRedo *undo_redo; InputAction input_action; Panel *panel; - MenuButton * options; + MenuButton *options; SpinBox *floor; OptionButton *edit_mode; ToolButton *mode_thumbnail; @@ -94,7 +94,7 @@ class GridMapEditor : public VBoxContainer { List set_items; GridMap *node; - MeshLibrary* last_theme; + MeshLibrary *last_theme; ClipMode clip_mode; bool lock_view; @@ -118,10 +118,8 @@ class GridMapEditor : public VBoxContainer { bool updating; - struct Selection { - Vector3 click; Vector3 current; Vector3 begin; @@ -141,7 +139,6 @@ class GridMapEditor : public VBoxContainer { int selected_area; int cursor_rot; - enum Menu { MENU_OPTION_CONFIGURE, @@ -173,7 +170,6 @@ class GridMapEditor : public VBoxContainer { SpatialEditorPlugin *spatial_editor; - struct AreaDisplay { RID mesh; @@ -212,20 +208,18 @@ class GridMapEditor : public VBoxContainer { void update_areas(); EditorNode *editor; - bool do_input_action(Camera* p_camera,const Point2& p_point,bool p_click); + bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click); -friend class GridMapEditorPlugin; + friend class GridMapEditorPlugin; Panel *theme_panel; protected: void _notification(int p_what); void _node_removed(Node *p_node); static void _bind_methods(); -public: - - bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event); - +public: + bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event); void edit(GridMap *p_gridmap); GridMapEditor() {} @@ -235,14 +229,13 @@ public: class GridMapEditorPlugin : public EditorPlugin { - GDCLASS( GridMapEditorPlugin, EditorPlugin ); + GDCLASS(GridMapEditorPlugin, EditorPlugin); GridMapEditor *gridmap_editor; EditorNode *editor; public: - - virtual bool forward_spatial_input_event(Camera* p_camera,const InputEvent& p_event) { return gridmap_editor->forward_spatial_input_event(p_camera,p_event); } + virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); } virtual String get_name() const { return "GridMap"; } bool has_main_screen() const { return false; } virtual void edit(Object *p_node); @@ -251,7 +244,6 @@ public: GridMapEditorPlugin(EditorNode *p_node); ~GridMapEditorPlugin(); - }; #endif // CUBE_GRID_MAP_EDITOR_PLUGIN_H diff --git a/modules/gridmap/register_types.cpp b/modules/gridmap/register_types.cpp index 9cd70a0f9b..4035caea78 100644 --- a/modules/gridmap/register_types.cpp +++ b/modules/gridmap/register_types.cpp @@ -43,9 +43,5 @@ void register_gridmap_types() { #endif } - - void unregister_gridmap_types() { - - } -- cgit v1.2.3