MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / set_cell_item

Method set_cell_item

modules/gridmap/grid_map.cpp:358–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358void GridMap::set_cell_item(const Vector3i &p_position, int p_item, int p_rot) {
359 if (baked_meshes.size() && !recreating_octants) {
360 //if you set a cell item, baked meshes go good bye
361 clear_baked_meshes();
362 _recreate_octant_data();
363 }
364
365 ERR_FAIL_INDEX(Math::abs(p_position.x), 1 << 20);
366 ERR_FAIL_INDEX(Math::abs(p_position.y), 1 << 20);
367 ERR_FAIL_INDEX(Math::abs(p_position.z), 1 << 20);
368
369 IndexKey key;
370 key.x = p_position.x;
371 key.y = p_position.y;
372 key.z = p_position.z;
373
374 const OctantKey ok = get_octant_key_from_cell_coords(p_position);
375
376 if (p_item < 0) {
377 //erase
378 if (cell_map.has(key)) {
379 OctantKey octantkey = ok;
380
381 ERR_FAIL_COND(!octant_map.has(octantkey));
382 Octant &g = *octant_map[octantkey];
383 g.cells.erase(key);
384 g.dirty = true;
385 cell_map.erase(key);
386 _queue_octants_dirty();
387 }
388 return;
389 }
390
391 OctantKey octantkey = ok;
392
393 if (!octant_map.has(octantkey)) {
394 //create octant because it does not exist
395 Octant *g = memnew(Octant);
396 g->dirty = true;
397#ifndef PHYSICS_3D_DISABLED
398 g->static_body = PhysicsServer3D::get_singleton()->body_create();
399 PhysicsServer3D::get_singleton()->body_set_mode(g->static_body, PhysicsServer3D::BODY_MODE_STATIC);
400 PhysicsServer3D::get_singleton()->body_attach_object_instance_id(g->static_body, get_instance_id());
401 PhysicsServer3D::get_singleton()->body_set_collision_layer(g->static_body, collision_layer);
402 PhysicsServer3D::get_singleton()->body_set_collision_mask(g->static_body, collision_mask);
403 PhysicsServer3D::get_singleton()->body_set_collision_priority(g->static_body, collision_priority);
404 if (physics_material.is_valid()) {
405 PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_FRICTION, physics_material->computed_friction());
406 PhysicsServer3D::get_singleton()->body_set_param(g->static_body, PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material->computed_bounce());
407 }
408#endif // PHYSICS_3D_DISABLED
409 SceneTree *st = SceneTree::get_singleton();
410
411 if (st && st->is_debugging_collisions_hint()) {
412 g->collision_debug = RenderingServer::get_singleton()->mesh_create();
413 g->collision_debug_instance = RenderingServer::get_singleton()->instance_create();
414 RenderingServer::get_singleton()->instance_set_base(g->collision_debug_instance, g->collision_debug);
415 }

Callers 2

_menu_optionMethod · 0.80
do_input_actionMethod · 0.80

Calls 15

computed_frictionMethod · 0.80
computed_bounceMethod · 0.80
instance_set_baseMethod · 0.80
sizeMethod · 0.65
absFunction · 0.50
hasMethod · 0.45
eraseMethod · 0.45
body_createMethod · 0.45
body_set_modeMethod · 0.45

Tested by

no test coverage detected