示例#1
0
文件: node.cpp 项目: NosicLin/godot
bool Node::is_a_parent_of(const Node *p_node) const {

	ERR_FAIL_NULL_V(p_node,false);
	Node *p=p_node->data.parent;
	while(p) {
		
		if (p==this)
			return true;
		p=p->data.parent;
	}
	
	return false;
}
godot_int GDAPI godot_arvr_add_controller(char *p_device_name, godot_int p_hand, godot_bool p_tracks_orientation, godot_bool p_tracks_position) {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, 0);

	InputDefault *input = (InputDefault *)Input::get_singleton();
	ERR_FAIL_NULL_V(input, 0);

	ARVRPositionalTracker *new_tracker = memnew(ARVRPositionalTracker);
	new_tracker->set_name(p_device_name);
	new_tracker->set_type(ARVRServer::TRACKER_CONTROLLER);
	if (p_hand == 1) {
		new_tracker->set_hand(ARVRPositionalTracker::TRACKER_LEFT_HAND);
	} else if (p_hand == 2) {
		new_tracker->set_hand(ARVRPositionalTracker::TRACKER_RIGHT_HAND);
	}

	// also register as joystick...
	int joyid = input->get_unused_joy_id();
	if (joyid != -1) {
		new_tracker->set_joy_id(joyid);
		input->joy_connection_changed(joyid, true, p_device_name, "");
	}

	if (p_tracks_orientation) {
		Basis orientation;
		new_tracker->set_orientation(orientation);
	}
	if (p_tracks_position) {
		Vector3 position;
		new_tracker->set_position(position);
	}

	// add our tracker to our server and remember its pointer
	arvr_server->add_tracker(new_tracker);

	// note, this ID is only unique within controllers!
	return new_tracker->get_tracker_id();
}
示例#3
0
MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) {

#ifdef DEBUG_ENABLED
	ERR_FAIL_NULL_V(p_attr_class, NULL);
#endif

	if (!attrs_fetched)
		fetch_attributes();

	if (!attributes)
		return NULL;

	return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr());
}
示例#4
0
Vector<Plane> ARVRCamera::get_frustum() const {
	// get our ARVRServer
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, Vector<Plane>());

	Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
	ERR_FAIL_COND_V(arvr_interface.is_null(), Vector<Plane>());

	ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>());

	Size2 viewport_size = get_viewport()->get_visible_rect().size;
	CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
	return cm.get_projection_planes(get_camera_transform());
};
示例#5
0
bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) {

#ifdef DEBUG_ENABLED
	ERR_FAIL_NULL_V(p_attr_class, false);
#endif

	if (!attrs_fetched)
		fetch_attributes();

	if (!attributes)
		return false;

	return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr());
}
示例#6
0
Error GDMono::_load_scripts_domain() {

	ERR_FAIL_COND_V(scripts_domain != NULL, ERR_BUG);

	print_verbose("Mono: Loading scripts domain...");

	scripts_domain = GDMonoUtils::create_domain("GodotEngine.ScriptsDomain");

	ERR_EXPLAIN("Mono: Could not create scripts app domain");
	ERR_FAIL_NULL_V(scripts_domain, ERR_CANT_CREATE);

	mono_domain_set(scripts_domain, true);

	return OK;
}
示例#7
0
Error GDMonoAssembly::wrapper_for_image(MonoImage *p_image) {

	ERR_FAIL_COND_V(loaded, ERR_FILE_ALREADY_IN_USE);

	assembly = mono_image_get_assembly(p_image);
	ERR_FAIL_NULL_V(assembly, FAILED);

	image = p_image;

	mono_image_addref(image);

	loaded = true;

	return OK;
}
示例#8
0
文件: gd_mono.cpp 项目: torugok/godot
Error GDMono::_load_tools_domain() {

	ERR_FAIL_COND_V(tools_domain != NULL, ERR_BUG);

	if (OS::get_singleton()->is_stdout_verbose()) {
		OS::get_singleton()->print("Mono: Loading tools domain...\n");
	}

	tools_domain = GDMonoUtils::create_domain("GodotEngine.ToolsDomain");

	ERR_EXPLAIN("Mono: Could not create tools app domain");
	ERR_FAIL_NULL_V(tools_domain, ERR_CANT_CREATE);

	return OK;
}
示例#9
0
GDMonoMethod *GDMonoClass::get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count) {

	ERR_FAIL_NULL_V(p_raw_method, NULL);

	MethodKey key = MethodKey(p_name, p_params_count);

	GDMonoMethod **match = methods.getptr(key);

	if (match)
		return *match;

	GDMonoMethod *method = memnew(GDMonoMethod(p_name, p_raw_method));
	methods.set(key, method);

	return method;
}
示例#10
0
文件: gd_mono.cpp 项目: torugok/godot
Error GDMono::_load_scripts_domain() {

	ERR_FAIL_COND_V(scripts_domain != NULL, ERR_BUG);

	if (OS::get_singleton()->is_stdout_verbose()) {
		OS::get_singleton()->print("Mono: Loading scripts domain...\n");
	}

	scripts_domain = GDMonoUtils::create_domain("GodotEngine.ScriptsDomain");

	ERR_EXPLAIN("Mono: Could not create scripts app domain");
	ERR_FAIL_NULL_V(scripts_domain, ERR_CANT_CREATE);

	mono_domain_set(scripts_domain, true);

	return OK;
}
示例#11
0
文件: gd_mono.cpp 项目: torugok/godot
Error GDMono::_unload_scripts_domain() {

	ERR_FAIL_NULL_V(scripts_domain, ERR_BUG);

	if (OS::get_singleton()->is_stdout_verbose()) {
		OS::get_singleton()->print("Mono: Unloading scripts domain...\n");
	}

	_GodotSharp::get_singleton()->_dispose_callback();

	if (mono_domain_get() != root_domain)
		mono_domain_set(root_domain, true);

	mono_gc_collect(mono_gc_max_generation());

	finalizing_scripts_domain = true;
	mono_domain_finalize(scripts_domain, 2000);
	finalizing_scripts_domain = false;

	mono_gc_collect(mono_gc_max_generation());

	_domain_assemblies_cleanup(mono_domain_get_id(scripts_domain));

	api_assembly = NULL;
	project_assembly = NULL;
#ifdef TOOLS_ENABLED
	editor_api_assembly = NULL;
#endif

	MonoDomain *domain = scripts_domain;
	scripts_domain = NULL;

	_GodotSharp::get_singleton()->_dispose_callback();

	MonoObject *ex = NULL;
	mono_domain_try_unload(domain, &ex);

	if (ex) {
		ERR_PRINT("Exception thrown when unloading scripts domain:");
		mono_print_unhandled_exception(ex);
		return FAILED;
	}

	return OK;
}
示例#12
0
Error GDMono::_unload_scripts_domain() {

	ERR_FAIL_NULL_V(scripts_domain, ERR_BUG);

	print_verbose("Mono: Unloading scripts domain...");

	_GodotSharp::get_singleton()->_dispose_callback();

	if (mono_domain_get() != root_domain)
		mono_domain_set(root_domain, true);

	mono_gc_collect(mono_gc_max_generation());

	mono_domain_finalize(scripts_domain, 2000);

	mono_gc_collect(mono_gc_max_generation());

	_domain_assemblies_cleanup(mono_domain_get_id(scripts_domain));

	core_api_assembly = NULL;
	project_assembly = NULL;
#ifdef TOOLS_ENABLED
	editor_api_assembly = NULL;
#endif

	core_api_assembly_out_of_sync = false;
	editor_api_assembly_out_of_sync = false;

	MonoDomain *domain = scripts_domain;
	scripts_domain = NULL;

	_GodotSharp::get_singleton()->_dispose_callback();

	MonoException *exc = NULL;
	mono_domain_try_unload(domain, (MonoObject **)&exc);

	if (exc) {
		ERR_PRINT("Exception thrown when unloading scripts domain");
		GDMonoUtils::debug_unhandled_exception(exc);
		return FAILED;
	}

	return OK;
}
示例#13
0
文件: object.cpp 项目: AMG194/godot
bool Object::is_connected(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) const {

	ERR_FAIL_NULL_V(p_to_object,false);
	const Signal *s = signal_map.getptr(p_signal);
	if (!s) {
		bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
		if (signal_is_valid)
			return false;
		ERR_EXPLAIN("Nonexistent signal: "+p_signal);
		ERR_FAIL_COND_V(!s,false);
	}

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

	return s->slot_map.has(target);
	//const Map<Signal::Target,Signal::Slot>::Element *E = s->slot_map.find(target);
	//return (E!=NULL);

}
示例#14
0
Error DotNetSolution::save() {
	bool dir_exists = DirAccess::exists(path);
	ERR_EXPLAIN("The directory does not exist.");
	ERR_FAIL_COND_V(!dir_exists, ERR_FILE_NOT_FOUND);

	String projs_decl;
	String sln_platform_cfg;
	String proj_platform_cfg;

	for (Map<String, ProjectInfo>::Element *E = projects.front(); E; E = E->next()) {
		const String &name = E->key();
		const ProjectInfo &proj_info = E->value();

		bool is_front = E == projects.front();

		if (!is_front)
			projs_decl += "\n";

		projs_decl += sformat(PROJECT_DECLARATION, name, proj_info.relpath.replace("/", "\\"), proj_info.guid);

		for (int i = 0; i < proj_info.configs.size(); i++) {
			const String &config = proj_info.configs[i];

			if (i != 0 || !is_front) {
				sln_platform_cfg += "\n";
				proj_platform_cfg += "\n";
			}

			sln_platform_cfg += sformat(SOLUTION_PLATFORMS_CONFIG, config);
			proj_platform_cfg += sformat(PROJECT_PLATFORMS_CONFIG, proj_info.guid, config);
		}
	}

	String content = sformat(SOLUTION_TEMPLATE, projs_decl, sln_platform_cfg, proj_platform_cfg);

	FileAccess *file = FileAccess::open(path_join(path, name + ".sln"), FileAccess::WRITE);
	ERR_FAIL_NULL_V(file, ERR_FILE_CANT_WRITE);
	file->store_string(content);
	file->close();
	memdelete(file);

	return OK;
}
示例#15
0
MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringName &p_native, Object *p_object) {
	String object_type = p_object->get_class_name();

	if (object_type[0] == '_')
		object_type = object_type.substr(1, object_type.length());

	if (!ClassDB::is_parent_class(object_type, p_native)) {
		ERR_EXPLAIN("Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'");
		ERR_FAIL_V(NULL);
	}

	MonoObject *mono_object = mono_object_new(SCRIPTS_DOMAIN, p_class->get_mono_ptr());
	ERR_FAIL_NULL_V(mono_object, NULL);

	CACHED_FIELD(GodotObject, ptr)->set_value_raw(mono_object, p_object);

	// Construct
	GDMonoUtils::runtime_object_init(mono_object);

	return mono_object;
}
示例#16
0
Error Object::connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds,uint32_t p_flags) {

	ERR_FAIL_NULL_V(p_to_object,ERR_INVALID_PARAMETER);

	Signal *s = signal_map.getptr(p_signal);
	if (!s) {
		bool signal_is_valid = ObjectTypeDB::has_signal(get_type_name(),p_signal);
		//check in script
		if (!signal_is_valid && !script.is_null() && Ref<Script>(script)->has_script_signal(p_signal))
			signal_is_valid=true;

		if (!signal_is_valid) {
			ERR_EXPLAIN("In Object of type '"+String(get_type())+"': Attempt to connect nonexistent signal '"+p_signal+"' to method '"+p_to_object->get_type()+"."+p_to_method+"'");
			ERR_FAIL_COND_V(!signal_is_valid,ERR_INVALID_PARAMETER);
		}
		signal_map[p_signal]=Signal();
		s=&signal_map[p_signal];
	}

	Signal::Target target(p_to_object->get_instance_ID(),p_to_method);
	if (s->slot_map.has(target)) {
		ERR_EXPLAIN("Signal '"+p_signal+"'' already connected to given method '"+p_to_method+"' in that object.");
		ERR_FAIL_COND_V(s->slot_map.has(target),ERR_INVALID_PARAMETER);
	}

	Signal::Slot slot;

	Connection conn;
	conn.source=this;
	conn.target=p_to_object;
	conn.method=p_to_method;
	conn.signal=p_signal;
	conn.flags=p_flags;
	conn.binds=p_binds;
	slot.conn=conn;
	slot.cE=p_to_object->connections.push_back(conn);
	s->slot_map[target]=slot;

	return OK;
}
示例#17
0
Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const {
	// get our ARVRServer
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, Vector3());

	Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface();
	ERR_FAIL_COND_V(arvr_interface.is_null(), Vector3());

	if (!is_inside_tree()) {
		ERR_EXPLAIN("Camera is not inside scene.");
		ERR_FAIL_COND_V(!is_inside_tree(), Vector3());
	};

	Size2 viewport_size = get_viewport()->get_camera_rect_size();
	Vector2 cpos = get_viewport()->get_camera_coords(p_pos);
	Vector3 ray;

	CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar());
	float screen_w, screen_h;
	cm.get_viewport_size(screen_w, screen_h);
	ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_w, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_h, -get_znear()).normalized();

	return ray;
};
示例#18
0
bool MobileVRInterface::initialize() {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, false);

	if (!initialized) {
		// reset our sensor data and orientation
		mag_count = 0;
		has_gyro = false;
		sensor_first = true;
		mag_next_min = Vector3(10000, 10000, 10000);
		mag_next_max = Vector3(-10000, -10000, -10000);
		mag_current_min = Vector3(0, 0, 0);
		mag_current_max = Vector3(0, 0, 0);

		// build our shader
		if (lens_shader == NULL) {
			///@TODO need to switch between GLES2 and GLES3 version, Reduz suggested moving this into our drivers and making this a core shader
			// create a shader
			lens_shader = new LensDistortedShaderGLES3();

			// create our shader stuff
			lens_shader->init();

			glGenBuffers(1, &half_screen_quad);
			glBindBuffer(GL_ARRAY_BUFFER, half_screen_quad);
			{
				/* clang-format off */
				const float qv[16] = {
					0, -1,
					-1, -1,
					0, 1,
					-1, 1,
					1, 1,
					1, 1,
					1, -1,
					1, -1,
				};
				/* clang-format on */

				glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 16, qv, GL_STATIC_DRAW);
			}

			glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind

			glGenVertexArrays(1, &half_screen_array);
			glBindVertexArray(half_screen_array);
			glBindBuffer(GL_ARRAY_BUFFER, half_screen_quad);
			glVertexAttribPointer(VS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, 0);
			glEnableVertexAttribArray(0);
			glVertexAttribPointer(VS::ARRAY_TEX_UV, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 4, ((uint8_t *)NULL) + 8);
			glEnableVertexAttribArray(4);
			glBindVertexArray(0);
			glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
		}

		// reset our orientation
		orientation = Basis();

		// make this our primary interface
		arvr_server->set_primary_interface(this);

		last_ticks = OS::get_singleton()->get_ticks_usec();

		initialized = true;
	};

	return true;
};
godot_real GDAPI godot_arvr_get_worldscale() {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, 1.0);

	return arvr_server->get_world_scale();
}
示例#20
0
Error SceneState::pack(Node *p_scene) {
	ERR_FAIL_NULL_V( p_scene, ERR_INVALID_PARAMETER );


	clear();

	Node *scene = p_scene;

	Map<StringName,int> name_map;
	HashMap<Variant,int,VariantHasher> variant_map;
	Map<Node*,int> node_map;
	Map<Node*,int> nodepath_map;

	//if using scene inheritance, pack the scene it inherits from
	if (scene->get_scene_inherited_state().is_valid()) {
		String path = scene->get_scene_inherited_state()->get_path();
		Ref<PackedScene> instance = ResourceLoader::load(path);
		if (instance.is_valid()) {

			base_scene_idx=_vm_get_variant(instance,variant_map);
		}
	}
	//instanced, only direct sub-scnes are supported of course


	Error err = _parse_node(scene,scene,-1,name_map,variant_map,node_map,nodepath_map);
	if (err) {
		clear();
		ERR_FAIL_V(err);
	}

	err = _parse_connections(scene,scene,name_map,variant_map,node_map,nodepath_map);
	if (err) {
		clear();
		ERR_FAIL_V(err);
	}

	names.resize(name_map.size());

	for(Map<StringName,int>::Element *E=name_map.front();E;E=E->next()) {

		names[E->get()]=E->key();
	}

	variants.resize(variant_map.size());
	const Variant *K=NULL;
	while((K=variant_map.next(K))) {

		int idx = variant_map[*K];
		variants[idx]=*K;
	}

	node_paths.resize(nodepath_map.size());
	for(Map<Node*,int>::Element *E=nodepath_map.front();E;E=E->next()) {

		node_paths[E->get()]=scene->get_path_to(E->key());
	}


	return OK;
}
示例#21
0
bool ARVRInterface::is_primary() {
	ARVRServer *arvr_server = ARVRServer::get_singleton();
	ERR_FAIL_NULL_V(arvr_server, false);

	return arvr_server->get_primary_interface() == this;
};
示例#22
0
文件: node.cpp 项目: GovanifY/godot
bool Node::is_greater_than(const Node *p_node) const {

	ERR_FAIL_NULL_V(p_node,false);
	ERR_FAIL_COND_V( !data.inside_tree, false );
	ERR_FAIL_COND_V( !p_node->data.inside_tree, false );
	
	ERR_FAIL_COND_V( data.depth<0, false);
	ERR_FAIL_COND_V( p_node->data.depth<0, false);
#ifdef NO_ALLOCA
	
	Vector<int> this_stack;
	Vector<int> that_stack;
	this_stack.resize(data.depth);
	that_stack.resize(p_node->data.depth);

#else
	
	int *this_stack=(int*)alloca(sizeof(int)*data.depth);
	int *that_stack=(int*)alloca(sizeof(int)*p_node->data.depth);
	
#endif
	
	const Node *n = this;
	
	int idx=data.depth-1;
	while(n) {
		ERR_FAIL_INDEX_V(idx, data.depth,false);
		this_stack[idx--]=n->data.pos;
		n=n->data.parent;
	}
	ERR_FAIL_COND_V(idx!=-1,false);
	n = p_node;
	idx=p_node->data.depth-1;
	while(n) {
		ERR_FAIL_INDEX_V(idx, p_node->data.depth,false);
		that_stack[idx--]=n->data.pos;
		
		n=n->data.parent;
	}
	ERR_FAIL_COND_V(idx!=-1,false);
	idx=0;
	
	bool res;
	while(true) {
	
		// using -2 since out-of-tree or nonroot nodes have -1
		int this_idx = (idx >= data.depth)? -2 : this_stack[idx];
		int that_idx = (idx >= p_node->data.depth)? -2 : that_stack[idx];

		if (this_idx > that_idx) {
			res=true;
			break;
		} else if (this_idx < that_idx) {
			res=false;
			break;
		} else if (this_idx == -2 ) {
			res=false; // equal
			break;
		}
		idx++;
	}
		
	return res;
}