Example #1
0
void ARVROrigin::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE: {
			set_process_internal(true);
		}; break;
		case NOTIFICATION_EXIT_TREE: {
			set_process_internal(false);
		}; break;
		case NOTIFICATION_INTERNAL_PROCESS: {
			// get our ARVRServer
			ARVRServer *arvr_server = ARVRServer::get_singleton();
			ERR_FAIL_NULL(arvr_server);

			// set our world origin to our node transform
			arvr_server->set_world_origin(get_global_transform());

			// check if we have a primary interface
			Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
			if (arvr_interface.is_valid() && tracked_camera != NULL) {
				// get our positioning transform for our headset
				Transform t = arvr_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, Transform());

				// now apply this to our camera
				tracked_camera->set_transform(t);
			};
		}; break;
		default:
			break;
	};
};
void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p_res, Object *p_receiver, const StringName &p_receiver_func, const Variant &p_userdata) {

	ERR_FAIL_NULL(p_receiver);
	ERR_FAIL_COND(!p_res.is_valid());

	preview_mutex->lock();

	String path_id = "ID:" + itos(p_res->get_instance_id());

	if (cache.has(path_id) && cache[path_id].last_hash == p_res->hash_edited_version()) {

		cache[path_id].order = order++;
		p_receiver->call_deferred(p_receiver_func, path_id, cache[path_id].preview, p_userdata);
		preview_mutex->unlock();
		return;
	}

	cache.erase(path_id); //erase if exists, since it will be regen

	//print_line("send to thread "+p_path);
	QueueItem item;
	item.function = p_receiver_func;
	item.id = p_receiver->get_instance_id();
	item.resource = p_res;
	item.path = path_id;
	item.userdata = p_userdata;

	queue.push_back(item);
	preview_mutex->unlock();
	preview_sem->post();
}
Example #3
0
void Object::disconnect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) {

	ERR_FAIL_NULL(p_to_object);
	Signal *s = signal_map.getptr(p_signal);
	if (!s) {
		ERR_EXPLAIN("Nonexistent signal: "+p_signal);
		ERR_FAIL_COND(!s);
	}
	if (s->lock>0) {
		ERR_EXPLAIN("Attempt to disconnect signal '"+p_signal+"' while emitting (locks: "+itos(s->lock)+")");
		ERR_FAIL_COND(s->lock>0);
	}

	Signal::Target target(p_to_object->get_instance_ID(),p_to_method);

	if (!s->slot_map.has(target)) {
		ERR_EXPLAIN("Disconnecting nonexistent signal '"+p_signal+"', slot: "+itos(target._id)+":"+target.method);
		ERR_FAIL();
	}

	p_to_object->connections.erase(s->slot_map[target].cE);
	s->slot_map.erase(target);

	if (s->slot_map.empty() && ObjectTypeDB::has_signal(get_type_name(),p_signal )) {
		//not user signal, delete
		signal_map.erase(p_signal);
	}
}
Example #4
0
void Node::move_child(Node *p_child,int p_pos) {	
	
	ERR_FAIL_NULL(p_child);
	ERR_EXPLAIN("Invalid new child position: "+itos(p_pos));
	ERR_FAIL_INDEX( p_pos, data.children.size()+1 );
	ERR_EXPLAIN("child is not a child of this node.");
	ERR_FAIL_COND(p_child->data.parent!=this);
	ERR_FAIL_COND(data.blocked>0);
	
	data.children.remove( p_child->data.pos );
	data.children.insert( p_pos, p_child );

	if (data.tree) {
		data.tree->tree_changed();
	}

	data.blocked++;
	//new pos first
	for (int i=0;i<data.children.size();i++) {
		
		data.children[i]->data.pos=i;
	}
	// notification second
	move_child_notify(p_child);
	for (int i=0;i<data.children.size();i++) {
		data.children[i]->notification( NOTIFICATION_MOVED_IN_PARENT );

	}

	data.blocked--;

}
Example #5
0
void Camera2D::set_custom_viewport(Node *p_viewport) {
	ERR_FAIL_NULL(p_viewport);
	if (is_inside_tree()) {
		remove_from_group(group_name);
		remove_from_group(canvas_group_name);
	}

	custom_viewport = Object::cast_to<Viewport>(p_viewport);

	if (custom_viewport) {
		custom_viewport_id = custom_viewport->get_instance_id();
	} else {
		custom_viewport_id = 0;
	}

	if (is_inside_tree()) {

		if (custom_viewport)
			viewport = custom_viewport;
		else
			viewport = get_viewport();

		RID vp = viewport->get_viewport_rid();
		group_name = "__cameras_" + itos(vp.get_id());
		canvas_group_name = "__cameras_c" + itos(canvas.get_id());
		add_to_group(group_name);
		add_to_group(canvas_group_name);
	}
}
Example #6
0
void ARVROrigin::set_world_scale(float p_world_scale) {
	// get our ARVRServer
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	arvr_server->set_world_scale(p_world_scale);
};
Example #7
0
void RayCast::add_exception(const Object* p_object){

	ERR_FAIL_NULL(p_object);
	CollisionObject *co=((Object*)p_object)->cast_to<CollisionObject>();
	if (!co)
		return;
	add_exception_rid(co->get_rid());
}
Example #8
0
void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) {

	ERR_FAIL_NULL(p_node);
	ERR_FAIL_INDEX(p_bone, bones.size());

	uint32_t id = p_node->get_instance_id();
	bones.write[p_bone].nodes_bound.erase(id);
}
Example #9
0
void RayCast2D::remove_exception(const Object* p_object){

	ERR_FAIL_NULL(p_object);
	CollisionObject2D *co=((Object*)p_object)->cast_to<CollisionObject2D>();
	if (!co)
		return;
	remove_exception_rid(co->get_rid());
}
Example #10
0
void Range::share(Range *p_range) {

	ERR_FAIL_NULL(p_range);

	p_range->_ref_shared(shared);
	p_range->_changed_notify();
	p_range->_value_changed_notify();
}
Example #11
0
void RayCast2D::add_exception(const Object *p_object) {

	ERR_FAIL_NULL(p_object);
	const CollisionObject2D *co = Object::cast_to<CollisionObject2D>(p_object);
	if (!co)
		return;
	add_exception_rid(co->get_rid());
}
void BTCompositeNode::add_child_node(BTNode& child, Vector<BehaviorTree::Node*>& node_hierarchy) {
	BTNode* p_parent = get_parent() ? get_parent()->cast_to<BTNode>() : NULL;
	ERR_EXPLAIN("Parent node is not a BTNode.");
	ERR_FAIL_NULL(p_parent);
	if (p_parent) {
		node_hierarchy.push_back(get_behavior_node());
		p_parent->add_child_node(child, node_hierarchy);
	}
}
Example #13
0
void PopupPanel::set_child_rect(Control *p_child) {
	ERR_FAIL_NULL(p_child);

	Ref<StyleBox> p = get_stylebox("panel");
	p_child->set_area_as_parent_rect();
	for (int i = 0; i < 4; i++) {
		p_child->set_margin(Margin(i), p->get_margin(Margin(i)));
	}
}
Example #14
0
void SoftBody::remove_collision_exception_with(Node *p_node) {
	ERR_FAIL_NULL(p_node);
	CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node);
	if (!collision_object) {
		ERR_EXPLAIN("Collision exception only works between two CollisionObject");
	}
	ERR_FAIL_COND(!collision_object);
	PhysicsServer::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid());
}
Example #15
0
void Node::remove_and_delete_child(Node *p_child) {

	ERR_FAIL_NULL( p_child );
	ERR_FAIL_COND( p_child->get_parent()!=this );

	remove_child(p_child);
	memdelete(p_child);

}
void GDAPI godot_arvr_set_controller_axis(godot_int p_controller_id, godot_int p_axis, godot_real p_value, godot_bool p_can_be_negative) {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	InputDefault *input = (InputDefault *)Input::get_singleton();
	ERR_FAIL_NULL(input);

	ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
	if (tracker != NULL) {
		int joyid = tracker->get_joy_id();
		if (joyid != -1) {
			InputDefault::JoyAxis jx;
			jx.min = p_can_be_negative ? -1 : 0;
			jx.value = p_value;
			input->joy_axis(joyid, p_axis, jx);
		}
	}
}
Example #17
0
void PhysicsBody::remove_collision_exception_with(Node* p_node) {

	ERR_FAIL_NULL(p_node);
	PhysicsBody *physics_body = p_node->cast_to<PhysicsBody>();
	if (!physics_body) {
		ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
	}
	ERR_FAIL_COND(!physics_body);
	PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
}
Example #18
0
void VisualServerRaster::request_frame_drawn_callback(Object *p_where, const StringName &p_method, const Variant &p_userdata) {

	ERR_FAIL_NULL(p_where);
	FrameDrawnCallbacks fdc;
	fdc.object = p_where->get_instance_id();
	fdc.method = p_method;
	fdc.param = p_userdata;

	frame_drawn_callbacks.push_back(fdc);
}
Example #19
0
void ARVRController::set_rumble(real_t p_rumble) {
	// get our ARVRServer
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
	if (tracker != NULL) {
		tracker->set_rumble(p_rumble);
	};
};
Example #20
0
void Array::sort_custom(Object *p_obj,const StringName& p_function){

	ERR_FAIL_NULL(p_obj);

	SortArray<Variant,_ArrayVariantSortCustom> avs;
	avs.compare.obj=p_obj;
	avs.compare.func=p_function;
	avs.sort(_p->array.ptr(),_p->array.size());

}
Example #21
0
void Node::set_editable_instance(Node* p_node,bool p_editable) {

	ERR_FAIL_NULL(p_node);
	ERR_FAIL_COND(!is_a_parent_of(p_node));
	NodePath p = get_path_to(p_node);
	if (!p_editable)
		data.editable_instances.erase(p);
	else
		data.editable_instances[p]=true;

}
Example #22
0
void ARVRInterface::set_is_primary(bool p_is_primary) {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	if (p_is_primary) {
		ERR_FAIL_COND(!is_initialized());

		arvr_server->set_primary_interface(this);
	} else {
		arvr_server->clear_primary_interface_if(this);
	};
};
void GDAPI godot_arvr_remove_controller(godot_int p_controller_id) {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	InputDefault *input = (InputDefault *)Input::get_singleton();
	ERR_FAIL_NULL(input);

	ARVRPositionalTracker *remove_tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
	if (remove_tracker != NULL) {
		// unset our joystick if applicable
		int joyid = remove_tracker->get_joy_id();
		if (joyid != -1) {
			input->joy_connection_changed(joyid, false, "", "");
			remove_tracker->set_joy_id(-1);
		}

		// remove our tracker from our server
		arvr_server->remove_tracker(remove_tracker);
		memdelete(remove_tracker);
	}
}
void ARVRPositionalTracker::set_type(ARVRServer::TrackerType p_type) {
	if (type != p_type) {
		type = p_type;
		hand = ARVRPositionalTracker::TRACKER_HAND_UNKNOWN;

		ARVRServer *arvr_server = ARVRServer::get_singleton();
		ERR_FAIL_NULL(arvr_server);

		// get a tracker id for our type
		// note if this is a controller this will be 3 or higher but we may change it later.
		tracker_id = arvr_server->get_free_tracker_id_for_type(p_type);
	};
};
Example #25
0
void ARVRController::_notification(int p_what) {
	switch (p_what) {
		case NOTIFICATION_ENTER_TREE: {
			set_process_internal(true);
		}; break;
		case NOTIFICATION_EXIT_TREE: {
			set_process_internal(false);
		}; break;
		case NOTIFICATION_INTERNAL_PROCESS: {
			// get our ARVRServer
			ARVRServer *arvr_server = ARVRServer::get_singleton();
			ERR_FAIL_NULL(arvr_server);

			// find the tracker for our controller
			ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id);
			if (tracker == NULL) {
				// this controller is currently turned off
				is_active = false;
				button_states = 0;
			} else {
				is_active = true;
				set_transform(tracker->get_transform(true));

				int joy_id = tracker->get_joy_id();
				if (joy_id >= 0) {
					int mask = 1;
					// check button states
					for (int i = 0; i < 16; i++) {
						bool was_pressed = (button_states & mask) == mask;
						bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i);

						if (!was_pressed && is_pressed) {
							emit_signal("button_pressed", i);
							button_states += mask;
						} else if (was_pressed && !is_pressed) {
							emit_signal("button_release", i);
							button_states -= mask;
						};

						mask = mask << 1;
					};

				} else {
					button_states = 0;
				};
			};
		}; break;
		default:
			break;
	};
};
void GDAPI godot_arvr_set_controller_transform(godot_int p_controller_id, godot_transform *p_transform, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL(arvr_server);

	ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, p_controller_id);
	if (tracker != NULL) {
		Transform *transform = (Transform *)p_transform;
		if (p_tracks_orientation) {
			tracker->set_orientation(transform->basis);
		}
		if (p_tracks_position) {
			tracker->set_rw_position(transform->origin);
		}
	}
}
Example #27
0
void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) {

	ERR_FAIL_NULL(p_node);
	ERR_FAIL_INDEX(p_bone, bones.size());

	uint32_t id = p_node->get_instance_id();

	for (const List<uint32_t>::Element *E = bones[p_bone].nodes_bound.front(); E; E = E->next()) {

		if (E->get() == id)
			return; // already here
	}

	bones.write[p_bone].nodes_bound.push_back(id);
}
Example #28
0
void EditorSelection::remove_node(Node *p_node) {

	ERR_FAIL_NULL(p_node);

	if (!selection.has(p_node))
		return;

	changed = true;
	nl_changed = true;
	Object *meta = selection[p_node];
	if (meta)
		memdelete(meta);
	selection.erase(p_node);
	p_node->disconnect("tree_exiting", this, "_node_removed");
	//emit_signal("selection_changed");
}
Example #29
0
void Node::add_child(Node *p_child) {

	ERR_FAIL_NULL(p_child);
	/* Fail if node has a parent */
	ERR_EXPLAIN("Can't add child "+p_child->get_name()+" to itself.")
	ERR_FAIL_COND( p_child==this ); // adding to itself!
	ERR_EXPLAIN("Can't add child, already has a parent");
	ERR_FAIL_COND( p_child->data.parent );
	ERR_EXPLAIN("Can't add child while a notification is happening");
	ERR_FAIL_COND( data.blocked > 0 );
		
	/* Validate name */
	_validate_child_name(p_child);

	_add_child_nocheck(p_child,p_child->data.name);
	
}
Example #30
0
void ARVRServer::remove_tracker(ARVRPositionalTracker *p_tracker) {
	ERR_FAIL_NULL(p_tracker);

	int idx = -1;
	for (int i = 0; i < trackers.size(); i++) {

		if (trackers[i] == p_tracker) {

			idx = i;
			break;
		};
	};

	ERR_FAIL_COND(idx == -1);

	emit_signal("tracker_removed", p_tracker->get_name(), p_tracker->get_type(), p_tracker->get_tracker_id());
	trackers.remove(idx);
};