Exemplo n.º 1
0
void GridMap::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_ENTER_WORLD: {

			Spatial *c = this;
			while (c) {
				navigation = Object::cast_to<Navigation>(c);
				if (navigation) {
					break;
				}

				c = Object::cast_to<Spatial>(c->get_parent());
			}

			last_transform = get_global_transform();

			for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
				_octant_enter_world(E->key());
			}

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			Transform new_xform = get_global_transform();
			if (new_xform == last_transform)
				break;
			//update run
			for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
				_octant_transform(E->key());
			}

			last_transform = new_xform;

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
				_octant_exit_world(E->key());
			}

			navigation = NULL;

			//_queue_octants_dirty(MAP_DIRTY_INSTANCES|MAP_DIRTY_TRANSFORMS);
			//_update_octants_callback();
			//_update_area_instances();

		} break;
		case NOTIFICATION_VISIBILITY_CHANGED: {
			_update_visibility();
		} break;
	}
}
Exemplo n.º 2
0
void GridMap::_clear_internal() {

	for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
		if (is_inside_world())
			_octant_exit_world(E->key());

		_octant_clean_up(E->key());
		memdelete(E->get());
	}

	octant_map.clear();
	cell_map.clear();
}
Exemplo n.º 3
0
void GridMap::_clear_internal(bool p_keep_areas) {

	for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
		if (is_inside_world())
			_octant_exit_world(E->key());

		for (Map<int, Octant::ItemInstances>::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())
			VS::get_singleton()->free(E->get()->collision_debug_instance);

		PhysicsServer::get_singleton()->free(E->get()->static_body);
		memdelete(E->get());
	}

	octant_map.clear();
	cell_map.clear();

	if (p_keep_areas)
		return;

	for (Map<int, Area *>::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; i < E->get()->portals.size(); i++) {
			VS::get_singleton()->free(E->get()->portals[i].instance);
		}

		memdelete(E->get());
	}
}
Exemplo n.º 4
0
void GridMap::_notification(int p_what) {

	switch (p_what) {

		case NOTIFICATION_ENTER_WORLD: {

			_update_area_instances();

			for (Map<OctantKey, Octant *>::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();

		} break;
		case NOTIFICATION_TRANSFORM_CHANGED: {

			Transform new_xform = get_global_transform();
			if (new_xform == last_transform)
				break;
			//update run
			for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
				_octant_transform(E->key());
			}

			last_transform = new_xform;

		} break;
		case NOTIFICATION_EXIT_WORLD: {

			for (Map<OctantKey, Octant *>::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();

		} break;
		case NOTIFICATION_ENTER_TREE: {

			Spatial *c = this;
			while (c) {
				navigation = c->cast_to<Navigation>();
				if (navigation) {
					break;
				}

				c = c->get_parent()->cast_to<Spatial>();
			}

			if (navigation) {
				for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
					if (navigation) {
						_octant_enter_tree(E->key());
					}
				}
			}

			_queue_dirty_map();
		} break;
		case NOTIFICATION_EXIT_TREE: {
			for (Map<OctantKey, Octant *>::Element *E = octant_map.front(); E; E = E->next()) {
				if (navigation) {
					_octant_clear_navmesh(E->key());
				}
			}

			navigation = NULL;

		} break;
	}
}