void GridMap::erase_area(int p_area) { ERR_FAIL_COND(!area_map.has(p_area)); Area *a = area_map[p_area]; memdelete(a); area_map.erase(p_area); _recreate_octant_data(); }
void GridMap::set_theme(const Ref<MeshLibrary> &p_theme) { if (!theme.is_null()) theme->unregister_owner(this); theme = p_theme; if (!theme.is_null()) theme->register_owner(this); _recreate_octant_data(); _change_notify("theme"); }
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) return; a->exterior_portal = p_enable; _recreate_octant_data(); }
Error GridMap::create_area(int p_id, const Rect3 &p_bounds) { 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); // 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<int, Area *>::Element *E = area_map.front(); E; E = E->next()) { //this should somehow be faster... 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) { // all good } else { return ERR_INVALID_PARAMETER; } } 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; }
void GridMap::resource_changed(const RES &p_res) { _recreate_octant_data(); }
bool GridMap::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "theme") { set_theme(p_value); } else if (name == "cell_size") { set_cell_size(p_value); } else if (name == "cell_octant_size") { set_octant_size(p_value); } else if (name == "cell_center_x") { set_center_x(p_value); } else if (name == "cell_center_y") { set_center_y(p_value); } else if (name == "cell_center_z") { set_center_z(p_value); } else if (name == "cell_scale") { set_cell_scale(p_value); /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount&1,false); // not even cell_map.clear(); for(int i=0;i<amount/3;i++) { IndexKey ik; ik.key=decode_uint64(&r[i*3]); Cell cell; cell.cell=uint32_t(r[i*+1]); cell_map[ik]=cell; } _recreate_octant_data();*/ } else if (name == "data") { Dictionary d = p_value; if (d.has("cells")) { PoolVector<int> cells = d["cells"]; int amount = cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); for (int i = 0; i < amount / 3; i++) { IndexKey ik; ik.key = decode_uint64((const uint8_t *)&r[i * 3]); Cell cell; cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]); cell_map[ik] = cell; } } _recreate_octant_data(); } else if (name.begins_with("areas/")) { int which = name.get_slicec('/', 1).to_int(); String what = name.get_slicec('/', 2); if (what == "bounds") { ERR_FAIL_COND_V(area_map.has(which), false); create_area(which, p_value); return true; } ERR_FAIL_COND_V(!area_map.has(which), false); if (what == "name") area_set_name(which, p_value); else if (what == "disable_distance") area_set_portal_disable_distance(which, p_value); else if (what == "exterior_portal") area_set_portal_disable_color(which, p_value); else return false; } else return false; return true; }
void GridMap::set_center_z(bool p_enable) { center_z = p_enable; _recreate_octant_data(); }
void GridMap::set_octant_size(int p_size) { octant_size = p_size; _recreate_octant_data(); }
void GridMap::set_cell_size(float p_size) { cell_size = p_size; _recreate_octant_data(); }
bool GridMap::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; if (name == "theme") { set_theme(p_value); } else if (name == "cell_size") { if (p_value.get_type() == Variant::INT || p_value.get_type() == Variant::REAL) { //compatibility float cs = p_value; set_cell_size(Vector3(cs, cs, cs)); } else { set_cell_size(p_value); } } else if (name == "cell_octant_size") { set_octant_size(p_value); } else if (name == "cell_center_x") { set_center_x(p_value); } else if (name == "cell_center_y") { set_center_y(p_value); } else if (name == "cell_center_z") { set_center_z(p_value); } else if (name == "cell_scale") { set_cell_scale(p_value); /* } else if (name=="cells") { PoolVector<int> cells = p_value; int amount=cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount&1,false); // not even cell_map.clear(); for(int i=0;i<amount/3;i++) { IndexKey ik; ik.key=decode_uint64(&r[i*3]); Cell cell; cell.cell=uint32_t(r[i*+1]); cell_map[ik]=cell; } _recreate_octant_data();*/ } else if (name == "data") { Dictionary d = p_value; if (d.has("cells")) { PoolVector<int> cells = d["cells"]; int amount = cells.size(); PoolVector<int>::Read r = cells.read(); ERR_FAIL_COND_V(amount % 3, false); // not even cell_map.clear(); for (int i = 0; i < amount / 3; i++) { IndexKey ik; ik.key = decode_uint64((const uint8_t *)&r[i * 3]); Cell cell; cell.cell = decode_uint32((const uint8_t *)&r[i * 3 + 2]); cell_map[ik] = cell; } } _recreate_octant_data(); } else return false; return true; }
void GridMap::set_cell_size(const Vector3 &p_size) { ERR_FAIL_COND(p_size.x < 0.001 || p_size.y < 0.001 || p_size.z < 0.001); cell_size = p_size; _recreate_octant_data(); }
void GridMap::set_cell_scale(float p_scale) { cell_scale = p_scale; _recreate_octant_data(); }