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

	switch(p_what) {
	
		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
			//_set_process(false);
			clear_caches();
		} break;
		case NOTIFICATION_READY: {

			if (!get_tree()->is_editor_hint() && animation_set.has(autoplay)) {
				play(autoplay);
			}
		} break;
		case NOTIFICATION_PROCESS: {
			if (animation_process_mode==ANIMATION_PROCESS_FIXED)
				break;

			if (processing)
				_animation_process( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {
		
			if (animation_process_mode==ANIMATION_PROCESS_IDLE)
				break;

			if (processing)
				_animation_process( get_fixed_process_delta_time() );
		} break;
		case NOTIFICATION_EXIT_TREE: {
		
			//stop_all();
			clear_caches();
		} break;
	}
}
Exemplo n.º 2
0
void AnimationTree::_notification(int p_what) {

	if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_mode == ANIMATION_PROCESS_PHYSICS) {
		_process_graph(get_physics_process_delta_time());
	}

	if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_mode == ANIMATION_PROCESS_IDLE) {
		_process_graph(get_process_delta_time());
	}

	if (p_what == NOTIFICATION_EXIT_TREE) {
		_clear_caches();
		if (last_animation_player) {

			Object *old_player = ObjectDB::get_instance(last_animation_player);
			if (old_player) {
				old_player->disconnect("caches_cleared", this, "_clear_caches");
			}
		}
	}
}
Exemplo n.º 3
0
void Tween::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
		} break;
		case NOTIFICATION_READY: {

		} break;
		case NOTIFICATION_PROCESS: {
			if (tween_process_mode==TWEEN_PROCESS_FIXED)
				break;

			if (processing)
				_tween_process( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (tween_process_mode==TWEEN_PROCESS_IDLE)
				break;

			if (processing)
				_tween_process( get_fixed_process_delta_time() );
		} break;
		case NOTIFICATION_EXIT_TREE: {

			stop_all();
		} break;
	}
}
Exemplo n.º 4
0
void AnimationTreePlayer::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			if (!processing) {
				//make sure that a previous process state was not saved
				//only process if "processing" is set
				set_fixed_process(false);
				set_process(false);
			}
		} break;
		case NOTIFICATION_READY: {
			dirty_caches=true;
			if (master!=NodePath()) {
				_update_sources();
			}
		} break;
		case NOTIFICATION_PROCESS: {
			if (animation_process_mode==ANIMATION_PROCESS_FIXED)
				break;

			if (processing)
				_process_animation( get_process_delta_time() );
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (animation_process_mode==ANIMATION_PROCESS_IDLE)
				break;

			if (processing)
				_process_animation(get_fixed_process_delta_time());
		} break;
	}

}
Exemplo n.º 5
0
void EditorFileDialog::_notification(int p_what) {

	if (p_what==NOTIFICATION_ENTER_TREE) {

		mode_thumbnails->set_icon(get_icon("FileThumbnail","EditorIcons"));
		mode_list->set_icon(get_icon("FileList","EditorIcons"));
		dir_prev->set_icon(get_icon("ArrowLeft","EditorIcons"));
		dir_next->set_icon(get_icon("ArrowRight","EditorIcons"));
		dir_up->set_icon(get_icon("ArrowUp","EditorIcons"));
		favorite->set_icon(get_icon("Favorites","EditorIcons"));

		fav_up->set_icon(get_icon("MoveUp","EditorIcons"));
		fav_down->set_icon(get_icon("MoveDown","EditorIcons"));
		fav_rm->set_icon(get_icon("RemoveSmall","EditorIcons"));

	}
	if (p_what==NOTIFICATION_PROCESS) {

		if (preview_waiting) {
			preview_wheel_timeout-=get_process_delta_time();
			if (preview_wheel_timeout<=0) {
				preview_wheel_index++;
				if (preview_wheel_index>=8)
					preview_wheel_index=0;
				Ref<Texture> frame = get_icon("WaitPreview"+itos(preview_wheel_index+1),"EditorIcons");
				preview->set_texture(frame);
				preview_wheel_timeout=0.1;
			}
		}
	}

	if (p_what==NOTIFICATION_DRAW) {

		//RID ci = get_canvas_item();
		//get_stylebox("panel","PopupMenu")->draw(ci,Rect2(Point2(),get_size()));
	}
}
void ExportTemplateManager::_notification(int p_what) {

	if (p_what == NOTIFICATION_PROCESS) {

		update_countdown -= get_process_delta_time();

		if (update_countdown > 0) {
			return;
		}
		update_countdown = 0.5;
		String status;
		bool errored = false;

		switch (download_templates->get_http_client_status()) {
			case HTTPClient::STATUS_DISCONNECTED:
				status = TTR("Disconnected");
				errored = true;
				break;
			case HTTPClient::STATUS_RESOLVING: status = TTR("Resolving"); break;
			case HTTPClient::STATUS_CANT_RESOLVE:
				status = TTR("Can't Resolve");
				errored = true;
				break;
			case HTTPClient::STATUS_CONNECTING: status = TTR("Connecting..."); break;
			case HTTPClient::STATUS_CANT_CONNECT:
				status = TTR("Can't Connect");
				errored = true;
				break;
			case HTTPClient::STATUS_CONNECTED: status = TTR("Connected"); break;
			case HTTPClient::STATUS_REQUESTING: status = TTR("Requesting..."); break;
			case HTTPClient::STATUS_BODY:
				status = TTR("Downloading");
				if (download_templates->get_body_size() > 0) {
					status += " " + String::humanize_size(download_templates->get_downloaded_bytes()) + "/" + String::humanize_size(download_templates->get_body_size());
					template_download_progress->set_max(download_templates->get_body_size());
					template_download_progress->set_value(download_templates->get_downloaded_bytes());
				} else {
					status += " " + String::humanize_size(download_templates->get_downloaded_bytes());
				}
				break;
			case HTTPClient::STATUS_CONNECTION_ERROR:
				status = TTR("Connection Error");
				errored = true;
				break;
			case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR:
				status = TTR("SSL Handshake Error");
				errored = true;
				break;
		}

		template_list_state->set_text(status);
		if (errored) {
			set_process(false);
			;
		}
	}

	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
		if (!is_visible_in_tree()) {
			set_process(false);
		}
	}
}
void BakedLightEditor::_notification(int p_option) {


	if (p_option==NOTIFICATION_ENTER_TREE) {

		button_bake->set_icon(get_icon("Bake","EditorIcons"));
		button_reset->set_icon(get_icon("Reload","EditorIcons"));
		button_make_lightmaps->set_icon(get_icon("LightMap","EditorIcons"));
	}

	if (p_option==NOTIFICATION_PROCESS) {

		if (baker->is_baking() && !baker->is_paused()) {

			update_timeout-=get_process_delta_time();
			if (update_timeout<0) {

				if (baker->get_baked_light()!=node->get_baked_light()) {
					_end_baking();
					return;
				}

				uint64_t t = OS::get_singleton()->get_ticks_msec();

#ifdef DEBUG_CUBES
				double norm =  baker->get_normalization();
				float max_lum=0;

				{
					DVector<Color>::Write cw=colors.write();
					BakedLightBaker::Octant *octants=baker->octant_pool.ptr();
					BakedLightBaker::Octant *oct = &octants[baker->leaf_list];
					int vert_idx=0;

					while(oct) {



						Color colors[8];
						for(int i=0;i<8;i++) {

							colors[i].r=oct->light_accum[i][0]/norm;
							colors[i].g=oct->light_accum[i][1]/norm;
							colors[i].b=oct->light_accum[i][2]/norm;

							float lum = colors[i].get_v();
							//if (lum<0.05)
							//	color.a=0;
							if (lum>max_lum)
								max_lum=lum;

						}
						static const int vert2cub[36]={7,3,1,1,5,7,7,6,2,2,3,7,7,5,4,4,6,7,2,6,4,4,0,2,4,5,1,1,0,4,1,3,2,2,0,1};
						for (int i=0;i<36;i++) {


							cw[vert_idx++]=colors[vert2cub[i]];
						}

						if (oct->next_leaf)
							oct=&octants[oct->next_leaf];
						else
							oct=NULL;

					}
				}
				print_line("MSCOL: "+itos(OS::get_singleton()->get_ticks_msec()-t));
				t = OS::get_singleton()->get_ticks_msec();

				Array a;
				a.resize(Mesh::ARRAY_MAX);
				a[Mesh::ARRAY_VERTEX]=vertices;
				a[Mesh::ARRAY_COLOR]=colors;
				while(mesh->get_surface_count())
					mesh->surface_remove(0);
				mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,a);
				mesh->surface_set_material(0,material);
#endif
				ERR_FAIL_COND(node->get_baked_light().is_null());

				baker->update_octree_images(octree_texture,light_texture);
				baker->update_octree_sampler(octree_sampler);
			//	print_line("sampler size: "+itos(octree_sampler.size()*4));

#if 1
//debug
				Image img(baker->baked_octree_texture_w,baker->baked_octree_texture_h,0,Image::FORMAT_RGBA,octree_texture);
				Ref<ImageTexture> it = memnew( ImageTexture );
				it->create_from_image(img);
				ResourceSaver::save("baked_octree.png",it);


#endif


				uint64_t rays_snap = baker->get_rays_thrown();
				int rays_sec = (rays_snap-last_rays_time)*1.0-(update_timeout);
				last_rays_time=rays_snap;

				bake_info->set_text("rays/s: "+itos(rays_sec));
				update_timeout=1;
				print_line("MSUPDATE: "+itos(OS::get_singleton()->get_ticks_msec()-t));
				t=OS::get_singleton()->get_ticks_msec();
				node->get_baked_light()->set_octree(octree_texture);
				node->get_baked_light()->set_light(light_texture);
				node->get_baked_light()->set_sampler_octree(octree_sampler);
				node->get_baked_light()->set_edited(true);

				print_line("MSSET: "+itos(OS::get_singleton()->get_ticks_msec()-t));



			}
		}
	}
}
Exemplo n.º 8
0
void AnimatedSprite::_notification(int p_what) {

	switch (p_what) {
		case NOTIFICATION_INTERNAL_PROCESS: {

			if (frames.is_null())
				return;
			if (!frames->has_animation(animation))
				return;
			if (frame < 0)
				return;

			float speed = frames->get_animation_speed(animation) * speed_scale;
			if (speed == 0)
				return; //do nothing

			float remaining = get_process_delta_time();

			while (remaining) {

				if (timeout <= 0) {

					timeout = _get_frame_duration();

					int fc = frames->get_frame_count(animation);
					if (frame >= fc - 1) {
						if (frames->get_animation_loop(animation)) {
							frame = 0;
							emit_signal(SceneStringNames::get_singleton()->animation_finished);
						} else {
							frame = fc - 1;
							if (!is_over) {
								is_over = true;
								emit_signal(SceneStringNames::get_singleton()->animation_finished);
							}
						}
					} else {
						frame++;
					}

					update();
					_change_notify("frame");
					emit_signal(SceneStringNames::get_singleton()->frame_changed);
				}

				float to_process = MIN(timeout, remaining);
				remaining -= to_process;
				timeout -= to_process;
			}
		} break;

		case NOTIFICATION_DRAW: {

			if (frames.is_null())
				return;
			if (frame < 0)
				return;
			if (!frames->has_animation(animation))
				return;

			Ref<Texture> texture = frames->get_frame(animation, frame);
			if (texture.is_null())
				return;

			Ref<Texture> normal = frames->get_normal_frame(animation, frame);

			RID ci = get_canvas_item();

			Size2i s;
			s = texture->get_size();
			Point2 ofs = offset;
			if (centered)
				ofs -= s / 2;

			if (Engine::get_singleton()->get_use_pixel_snap()) {
				ofs = ofs.floor();
			}
			Rect2 dst_rect(ofs, s);

			if (hflip)
				dst_rect.size.x = -dst_rect.size.x;
			if (vflip)
				dst_rect.size.y = -dst_rect.size.y;

			texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal);

		} break;
	}
}
Exemplo n.º 9
0
void ScriptEditorDebugger::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_ENTER_TREE: {

			inspector->edit(variables);

			step->set_icon( get_icon("DebugStep","EditorIcons"));
			next->set_icon( get_icon("DebugNext","EditorIcons"));
			back->set_icon( get_icon("Back","EditorIcons"));
			forward->set_icon( get_icon("Forward","EditorIcons"));
			dobreak->set_icon( get_icon("Pause","EditorIcons"));
			docontinue->set_icon( get_icon("DebugContinue","EditorIcons"));
			//scene_tree_refresh->set_icon( get_icon("Reload","EditorIcons"));
			le_set->connect("pressed",this,"_live_edit_set");
			le_clear->connect("pressed",this,"_live_edit_clear");
			error_list->connect("item_selected",this,"_error_selected");
			error_stack->connect("item_selected",this,"_error_stack_selected");
			vmem_refresh->set_icon( get_icon("Reload","EditorIcons"));

		} break;
		case NOTIFICATION_PROCESS: {

			if (connection.is_valid()) {
				inspect_scene_tree_timeout-=get_process_delta_time();
				if (inspect_scene_tree_timeout<0) {
					inspect_scene_tree_timeout=EditorSettings::get_singleton()->get("debugger/scene_tree_refresh_interval");
					if (inspect_scene_tree->is_visible()) {
						_scene_tree_request();

						if (inspected_object_id!=0) {
							//take the chance and re-inspect selected object
							Array msg;
							msg.push_back("inspect_object");
							msg.push_back(inspected_object_id);
							ppeer->put_var(msg);
						}
					}
				}

				inspect_edited_object_timeout-=get_process_delta_time();
				if (inspect_edited_object_timeout<0) {
					inspect_edited_object_timeout=EditorSettings::get_singleton()->get("debugger/remote_inspect_refresh_interval");
					if (inspect_scene_tree->is_visible() && inspected_object_id) {
						//take the chance and re-inspect selected object
						Array msg;
						msg.push_back("inspect_object");
						msg.push_back(inspected_object_id);
						ppeer->put_var(msg);
					}
				}
			}

			if (error_count!=last_error_count) {

				if (error_count==0) {
					error_split->set_name(TTR("Errors"));
					debugger_button->set_text(TTR("Debugger"));
					debugger_button->set_icon(Ref<Texture>());
					tabs->set_tab_icon(error_split->get_index(),Ref<Texture>());
				} else {
					error_split->set_name(TTR("Errors")+" ("+itos(error_count)+")");
					debugger_button->set_text(TTR("Debugger")+" ("+itos(error_count)+")");
					debugger_button->set_icon(get_icon("Error","EditorIcons"));
					tabs->set_tab_icon(error_split->get_index(),get_icon("Error","EditorIcons"));
				}
				last_error_count=error_count;
			}

			if (connection.is_null()) {

				if (server->is_connection_available()) {

					connection = server->take_connection();
					if (connection.is_null())
						break;

					EditorNode::get_log()->add_message("** Debug Process Started **");
					log_forced_visible=false;

					ppeer->set_stream_peer(connection);

					//EditorNode::get_singleton()->make_bottom_panel_item_visible(this);
					//emit_signal("show_debugger",true);

					dobreak->set_disabled(false);
					tabs->set_current_tab(0);

					reason->set_text(TTR("Child Process Connected"));
					reason->set_tooltip(TTR("Child Process Connected"));
					profiler->clear();

					inspect_scene_tree->clear();
					le_set->set_disabled(true);
					le_clear->set_disabled(false);
					error_list->clear();
					error_stack->clear();
					error_count=0;
					profiler_signature.clear();
					//live_edit_root->set_text("/root");

					EditorNode::get_singleton()->get_pause_button()->set_pressed(false);
					EditorNode::get_singleton()->get_pause_button()->set_disabled(false);

					update_live_edit_root();
					if (profiler->is_profiling()) {
						_profiler_activate(true);
					}


				} else {

					break;
				}
			};

			if (!connection->is_connected()) {
				stop();
				editor->notify_child_process_exited(); //somehow, exited
				break;
			};

			if (ppeer->get_available_packet_count() <= 0) {
				break;
			};

			while(ppeer->get_available_packet_count() > 0) {

				if (pending_in_queue) {

					int todo = MIN( ppeer->get_available_packet_count(), pending_in_queue );

					for(int i=0;i<todo;i++) {

						Variant cmd;
						Error ret = ppeer->get_var(cmd);
						if (ret!=OK) {
							stop();
							ERR_FAIL_COND(ret!=OK);
						}

						message.push_back(cmd);
						pending_in_queue--;
					}


					if (pending_in_queue==0) {
						_parse_message(message_type,message);
						message.clear();

					}


				} else {

					if (ppeer->get_available_packet_count()>=2) {


						Variant cmd;
						Error ret = ppeer->get_var(cmd);
						if (ret!=OK) {
							stop();
							ERR_FAIL_COND(ret!=OK);
						}
						if (cmd.get_type()!=Variant::STRING) {
							stop();
							ERR_FAIL_COND(cmd.get_type()!=Variant::STRING);
						}

						message_type=cmd;
						//print_line("GOT: "+message_type);

						ret = ppeer->get_var(cmd);
						if (ret!=OK) {
							stop();
							ERR_FAIL_COND(ret!=OK);
						}
						if (cmd.get_type()!=Variant::INT) {
							stop();
							ERR_FAIL_COND(cmd.get_type()!=Variant::INT);
						}

						pending_in_queue=cmd;

						if (pending_in_queue==0) {
							_parse_message(message_type,Array());
							message.clear();
						}

					} else {


						break;
					}

				}
			}



		} break;
	}

}
Exemplo n.º 10
0
void EditorAudioBus::_notification(int p_what) {

	if (p_what == NOTIFICATION_READY) {

		for (int i = 0; i < CHANNELS_MAX; i++) {
			channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
			channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
			channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
			channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
			channel[i].prev_active = true;
		}
		scale->set_texture(get_icon("BusVuDb", "EditorIcons"));

		disabled_vu = get_icon("BusVuFrozen", "EditorIcons");

		Color solo_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#ffe337" : "#ffeb70");
		Color mute_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#ff2929" : "#ff7070");
		Color bypass_color = Color::html(EditorSettings::get_singleton()->is_dark_theme() ? "#22ccff" : "#70deff");

		solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
		solo->add_color_override("icon_color_pressed", solo_color);
		mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
		mute->add_color_override("icon_color_pressed", mute_color);
		bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));
		bypass->add_color_override("icon_color_pressed", bypass_color);

		bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));

		update_bus();
		set_process(true);
	}

	if (p_what == NOTIFICATION_DRAW) {

		if (has_focus()) {
			draw_style_box(get_stylebox("focus", "Button"), Rect2(Vector2(), get_size()));
		} else if (is_master) {
			draw_style_box(get_stylebox("disabled", "Button"), Rect2(Vector2(), get_size()));
		}
	}

	if (p_what == NOTIFICATION_PROCESS) {

		if (cc != AudioServer::get_singleton()->get_bus_channels(get_index())) {
			cc = AudioServer::get_singleton()->get_bus_channels(get_index());
			_update_visible_channels();
		}

		for (int i = 0; i < cc; i++) {
			float real_peak[2] = { -100, -100 };
			bool activity_found = false;

			if (AudioServer::get_singleton()->is_bus_channel_active(get_index(), i)) {
				activity_found = true;
				real_peak[0] = MAX(real_peak[0], AudioServer::get_singleton()->get_bus_peak_volume_left_db(get_index(), i));
				real_peak[1] = MAX(real_peak[1], AudioServer::get_singleton()->get_bus_peak_volume_right_db(get_index(), i));
			}

			if (real_peak[0] > channel[i].peak_l) {
				channel[i].peak_l = real_peak[0];
			} else {
				channel[i].peak_l -= get_process_delta_time() * 60.0;
			}

			if (real_peak[1] > channel[i].peak_r) {
				channel[i].peak_r = real_peak[1];
			} else {
				channel[i].peak_r -= get_process_delta_time() * 60.0;
			}

			channel[i].vu_l->set_value(channel[i].peak_l);
			channel[i].vu_r->set_value(channel[i].peak_r);

			if (activity_found != channel[i].prev_active) {
				if (activity_found) {
					channel[i].vu_l->set_over_texture(Ref<Texture>());
					channel[i].vu_r->set_over_texture(Ref<Texture>());
				} else {
					channel[i].vu_l->set_over_texture(disabled_vu);
					channel[i].vu_r->set_over_texture(disabled_vu);
				}

				channel[i].prev_active = activity_found;
			}
		}
	}

	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {

		for (int i = 0; i < CHANNELS_MAX; i++) {
			channel[i].peak_l = -100;
			channel[i].peak_r = -100;
			channel[i].prev_active = true;
		}

		set_process(is_visible_in_tree());
	}

	if (p_what == NOTIFICATION_THEME_CHANGED) {

		for (int i = 0; i < CHANNELS_MAX; i++) {
			channel[i].vu_l->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
			channel[i].vu_l->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
			channel[i].vu_r->set_under_texture(get_icon("BusVuEmpty", "EditorIcons"));
			channel[i].vu_r->set_progress_texture(get_icon("BusVuFull", "EditorIcons"));
			channel[i].prev_active = true;
		}
		scale->set_texture(get_icon("BusVuDb", "EditorIcons"));

		disabled_vu = get_icon("BusVuFrozen", "EditorIcons");

		solo->set_icon(get_icon("AudioBusSolo", "EditorIcons"));
		mute->set_icon(get_icon("AudioBusMute", "EditorIcons"));
		bypass->set_icon(get_icon("AudioBusBypass", "EditorIcons"));

		bus_options->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons"));
	}
}
Exemplo n.º 11
0
void AnimatedSprite::_notification(int p_what) {

	switch(p_what) {
		case NOTIFICATION_PROCESS: {

			if (frames.is_null())
				return;
			if (!frames->has_animation(animation))
				return;
			if (frame<0)
				return;

			float speed = frames->get_animation_speed(animation) * play_rate;
			if (speed==0)
				return; //do nothing

			float remaining = get_process_delta_time();

			while(remaining) {

				if (timeout<=0) {

					int fc = frames->get_frame_count(animation);
					if (frame>=fc-1) {
						if (frames->get_animation_loop(animation)) {
							frame=0;
						} else {
							frame=fc-1;
							// early exit so we don't do anything for non-looping ended animations, may want to
							// broadcast once more "frame" notify, pending
							break;
						}
					} else {
						frame++;
					}
					// to avoid timeout being reset for non-looping animations so queries can be use timeout value
					timeout = 1.0 / speed;
					update();
					_change_notify("frame");
				}

				float to_process = MIN(timeout,remaining);
				remaining-=to_process;
				timeout-=to_process;
			}
		} break;

		case NOTIFICATION_DRAW: {

			if (frames.is_null()) {
				print_line("no draw no faemos");
				return;
			}

			if (frame<0) {
				print_line("no draw frame <0");
				return;
			}

			if (!frames->has_animation(animation)) {
				print_line("no draw no anim: "+String(animation));
				return;
			}



			Ref<Texture> texture = frames->get_frame(animation,frame);
			if (texture.is_null()) {
				print_line("no draw texture is null");
				return;
			}

			//print_line("DECIDED TO DRAW");

			RID ci = get_canvas_item();

			/*
			texture->draw(ci,Point2());
			break;
			*/

			Size2i s;
			s = texture->get_size();
			Point2 ofs=offset;

			adjust_offset(ofs, s);

			if (OS::get_singleton()->get_use_pixel_snap()) {
				ofs=ofs.floor();
			}
			Rect2 dst_rect(ofs,s);

			if (hflip)
				dst_rect.size.x=-dst_rect.size.x;
			if (vflip)
				dst_rect.size.y=-dst_rect.size.y;

			//texture->draw_rect(ci,dst_rect,false,modulate);
			texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()),modulate);
//			VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);

		} break;
	}

}
Exemplo n.º 12
0
void AnimatedSprite::_notification(int p_what) {

	switch (p_what) {
		case NOTIFICATION_INTERNAL_PROCESS: {

			if (frames.is_null())
				return;
			if (!frames->has_animation(animation))
				return;
			if (frame < 0)
				return;

			float speed = frames->get_animation_speed(animation);
			if (speed == 0)
				return; //do nothing

			float remaining = get_process_delta_time();

			while (remaining) {

				if (timeout <= 0) {

					timeout = 1.0 / speed;

					int fc = frames->get_frame_count(animation);
					if (frame >= fc - 1) {
						if (frames->get_animation_loop(animation)) {
							frame = 0;
						} else {
							frame = fc - 1;
						}
					} else {
						frame++;
						if (frame == fc - 1) {
							emit_signal(SceneStringNames::get_singleton()->animation_finished);
						}
					}

					update();
					_change_notify("frame");
					emit_signal(SceneStringNames::get_singleton()->frame_changed);
				}

				float to_process = MIN(timeout, remaining);
				remaining -= to_process;
				timeout -= to_process;
			}
		} break;

		case NOTIFICATION_DRAW: {

			if (frames.is_null()) {
				print_line("no draw no faemos");
				return;
			}

			if (frame < 0) {
				print_line("no draw frame <0");
				return;
			}

			if (!frames->has_animation(animation)) {
				print_line("no draw no anim: " + String(animation));
				return;
			}

			Ref<Texture> texture = frames->get_frame(animation, frame);
			if (texture.is_null()) {
				print_line("no draw texture is null");
				return;
			}

			Ref<Texture> normal = frames->get_normal_frame(animation, frame);

			//print_line("DECIDED TO DRAW");

			RID ci = get_canvas_item();

			/*
			texture->draw(ci,Point2());
			break;
			*/

			Size2i s;
			s = texture->get_size();
			Point2 ofs = offset;
			if (centered)
				ofs -= s / 2;

			if (Engine::get_singleton()->get_use_pixel_snap()) {
				ofs = ofs.floor();
			}
			Rect2 dst_rect(ofs, s);

			if (hflip)
				dst_rect.size.x = -dst_rect.size.x;
			if (vflip)
				dst_rect.size.y = -dst_rect.size.y;

			//texture->draw_rect(ci,dst_rect,false,modulate);
			texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal);
			//VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);

		} break;
	}
}
Exemplo n.º 13
0
void Node::_notification(int p_notification) {
	
	switch(p_notification) {

		case NOTIFICATION_PROCESS: {

			if (get_script_instance()) {

				Variant time=get_process_delta_time();
				const Variant*ptr[1]={&time};
				Variant::CallError err;
				get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_process,ptr,1);
			}
		} break;
		case NOTIFICATION_FIXED_PROCESS: {

			if (get_script_instance()) {

				Variant time=get_fixed_process_delta_time();
				const Variant*ptr[1]={&time};
				Variant::CallError err;
				get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_fixed_process,ptr,1);
			}

		} break;
		case NOTIFICATION_ENTER_TREE: {

			if (data.pause_mode==PAUSE_MODE_INHERIT) {

				if (data.parent)
					data.pause_owner=data.parent->data.pause_owner;
				else
					data.pause_owner=NULL;
			} else {
				data.pause_owner=this;
			}

			if (data.input)
				add_to_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_input)
				add_to_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_key_input)
				add_to_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID()));

			get_tree()->node_count++;

		} break;
		case NOTIFICATION_EXIT_TREE: {

			get_tree()->node_count--;
			if (data.input)
				remove_from_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_input)
				remove_from_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID()));
			if (data.unhandled_key_input)
				remove_from_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID()));

		} break;
		case NOTIFICATION_READY: {

			if (get_script_instance()) {

				Variant::CallError err;
				get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0);
			}
			//emit_signal(SceneStringNames::get_singleton()->enter_tree);

		} break;
		case NOTIFICATION_POSTINITIALIZE: {
			data.in_constructor=false;
		} break;
		case NOTIFICATION_PREDELETE: {

			set_owner(NULL);
			
			while ( data.owned.size() ) {
			
				data.owned.front()->get()->set_owner(NULL);	
			}

			if (data.parent) {
				
				data.parent->remove_child(this);
			}

			// kill children as cleanly as possible
			while( data.children.size() ) {
				
				Node *child = data.children[0];		
				remove_child(child);
				memdelete( child );
			}

		} break;
	}
}
Exemplo n.º 14
0
void Particles2D::_notification(int p_what) {

	switch(p_what) {

		case NOTIFICATION_PROCESS: {

			_process_particles( get_process_delta_time() );
		} break;

		case NOTIFICATION_ENTER_TREE: {

			float ppt=preprocess;
			while(ppt>0) {
				_process_particles(0.1);
				ppt-=0.1;
			}
		} break;
		case NOTIFICATION_DRAW: {


			if (particles.size()==0 || lifetime==0)
				return;

			RID ci=get_canvas_item();
			Size2 size(1,1);
			Point2 center;
			int total_frames=1;

			if (!texture.is_null()) {
				size=texture->get_size();
				size.x/=h_frames;
				size.y/=v_frames;
				total_frames=h_frames*v_frames;
			}


			float time_pos=(time/lifetime);

			Particle *pdata=&particles[0];
			int particle_count=particles.size();

			RID texrid;

			if (texture.is_valid())
				texrid = texture->get_rid();

			Matrix32 invxform;
			if (!local_space)
				invxform=get_global_transform().affine_inverse();

			int start_particle = (int)(time * (float)particle_count / lifetime);
			
			for (int id=0;id<particle_count;++id) {
				int i = start_particle + id;
				if (i >= particle_count) {
					i -= particle_count;
				}

				Particle &p=pdata[i];
				if (!p.active)
					continue;

				float ptime = ((float)i / particle_count)*explosiveness;

				if (ptime<time_pos)
					ptime=time_pos-ptime;
				else
					ptime=(1.0-ptime)+time_pos;

				uint32_t rand_seed=p.seed*(i+1);

				Color color;

				if(color_ramp.is_valid())
				{
					color = color_ramp->get_color_at_offset(ptime);
				} else
				{
					color = default_color;
				}


				{
					float huerand=_rand_from_seed(&rand_seed);
					float huerot = param[PARAM_HUE_VARIATION] + randomness[PARAM_HUE_VARIATION] * huerand;

					if (Math::abs(huerot) > CMP_EPSILON) {

						float h=color.get_h();
						float s=color.get_s();
						float v=color.get_v();
						float a=color.a;
						//float preh=h;
						h+=huerot;
						h=Math::abs(Math::fposmod(h,1.0));
						//print_line("rand: "+rtos(randomness[PARAM_HUE_VARIATION])+" rand: "+rtos(huerand));
						//print_line(itos(i)+":hue: "+rtos(preh)+" + "+rtos(huerot)+" = "+rtos(h));
						color.set_hsv(h,s,v);
						color.a=a;
					}
				}

				float initial_size = param[PARAM_INITIAL_SIZE]+param[PARAM_INITIAL_SIZE]*_rand_from_seed(&rand_seed)*randomness[PARAM_FINAL_SIZE];
				float final_size = param[PARAM_FINAL_SIZE]+param[PARAM_FINAL_SIZE]*_rand_from_seed(&rand_seed)*randomness[PARAM_FINAL_SIZE];

				float size_mult=initial_size*(1.0-ptime) + final_size*ptime;

				//Size2 rectsize=size * size_mult;
				//rectsize=rectsize.floor();

				//Rect2 r = Rect2(Vecto,rectsize);

				Matrix32 xform;

				if (p.rot) {

					xform.set_rotation(p.rot);
					xform.translate(-size*size_mult/2.0);
					xform.elements[2]+=p.pos;
				} else {
					xform.elements[2]=-size*size_mult/2.0;
					xform.elements[2]+=p.pos;
				}

				if (!local_space) {
					xform = invxform * xform;
				}


				xform.scale_basis(Size2(size_mult,size_mult));


				VisualServer::get_singleton()->canvas_item_add_set_transform(ci,xform);


				if (texrid.is_valid()) {

					Rect2 src_rect;
					src_rect.size=size;

					if (total_frames>1) {
						int frame = Math::fast_ftoi(Math::floor(p.frame*total_frames)) % total_frames;
						src_rect.pos.x = size.x * (frame%h_frames);
						src_rect.pos.y = size.y * (frame/h_frames);
					}


					texture->draw_rect_region(ci,Rect2(Point2(),size),src_rect,color);
					//VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color);
				} else {
					VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2(),size),color);

				}

			}


		} break;

	}

}
void AnimationNodeStateMachineEditor::_notification(int p_what) {

	if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
		error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
		error_label->add_color_override("font_color", get_color("error_color", "Editor"));
		panel->add_style_override("panel", get_stylebox("bg", "Tree"));
		goto_parent->set_icon(get_icon("MoveUp", "EditorIcons"));

		tool_select->set_icon(get_icon("ToolSelect", "EditorIcons"));
		tool_create->set_icon(get_icon("ToolAddNode", "EditorIcons"));
		tool_connect->set_icon(get_icon("ToolConnect", "EditorIcons"));

		transition_mode->clear();
		transition_mode->add_icon_item(get_icon("TransitionImmediate", "EditorIcons"), TTR("Immediate"));
		transition_mode->add_icon_item(get_icon("TransitionSync", "EditorIcons"), TTR("Sync"));
		transition_mode->add_icon_item(get_icon("TransitionEnd", "EditorIcons"), TTR("At End"));

		//force filter on those, so they deform better
		get_icon("TransitionImmediateBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);
		get_icon("TransitionEndBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);
		get_icon("TransitionSyncBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);
		get_icon("TransitionImmediateAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);
		get_icon("TransitionEndAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);
		get_icon("TransitionSyncAutoBig", "EditorIcons")->set_flags(Texture::FLAG_FILTER);

		tool_erase->set_icon(get_icon("Remove", "EditorIcons"));
		tool_autoplay->set_icon(get_icon("AutoPlay", "EditorIcons"));
		tool_end->set_icon(get_icon("AutoEnd", "EditorIcons"));

		play_mode->clear();
		play_mode->add_icon_item(get_icon("PlayTravel", "EditorIcons"), TTR("Travel"));
		play_mode->add_icon_item(get_icon("Play", "EditorIcons"), TTR("Immediate"));
	}

	if (p_what == NOTIFICATION_PROCESS) {

		String error;

		if (error_time > 0) {
			error = error_text;
			error_time -= get_process_delta_time();
		} else if (!state_machine->get_tree()) {
			error = TTR("StateMachine does not belong to an AnimationTree node.");
		} else if (!state_machine->get_tree()->is_active()) {
			error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
		} else if (state_machine->get_tree()->is_state_invalid()) {
			error = state_machine->get_tree()->get_invalid_state_reason();
		} else if (state_machine->get_parent().is_valid() && state_machine->get_parent()->is_class("AnimationNodeStateMachine")) {
			if (state_machine->get_start_node() == StringName() || state_machine->get_end_node() == StringName()) {
				error = TTR("Start and end nodes are needed for a sub-transition.");
			}
		}

		if (error != error_label->get_text()) {
			error_label->set_text(error);
			if (error != String()) {
				error_panel->show();
			} else {
				error_panel->hide();
			}
		}

		for (int i = 0; i < transition_lines.size(); i++) {
			int tidx = -1;
			for (int j = 0; j < state_machine->get_transition_count(); j++) {
				if (transition_lines[i].from_node == state_machine->get_transition_from(j) && transition_lines[i].to_node == state_machine->get_transition_to(j)) {
					tidx = j;
					break;
				}
			}

			if (tidx == -1) { //missing transition, should redraw
				state_machine_draw->update();
				break;
			}

			if (transition_lines[i].disabled != state_machine->get_transition(tidx)->is_disabled()) {
				state_machine_draw->update();
				break;
			}

			if (transition_lines[i].auto_advance != state_machine->get_transition(tidx)->has_auto_advance()) {
				state_machine_draw->update();
				break;
			}

			if (transition_lines[i].mode != state_machine->get_transition(tidx)->get_switch_mode()) {
				state_machine_draw->update();
				break;
			}
		}

		bool same_travel_path = true;
		Vector<StringName> tp = state_machine->get_travel_path();

		{

			if (last_travel_path.size() != tp.size()) {
				same_travel_path = false;
			} else {
				for (int i = 0; i < last_travel_path.size(); i++) {
					if (last_travel_path[i] != tp[i]) {
						same_travel_path = false;
						break;
					}
				}
			}
		}

		//update if travel state changed
		if (!same_travel_path || last_active != state_machine->is_playing() || last_current_node != state_machine->get_current_node() || last_blend_from_node != state_machine->get_blend_from_node()) {

			state_machine_draw->update();
			last_travel_path = tp;
			last_current_node = state_machine->get_current_node();
			last_active = state_machine->is_playing();
			last_blend_from_node = state_machine->get_blend_from_node();
			state_machine_play_pos->update();
		}

		if (last_play_pos != state_machine->get_current_play_pos()) {

			last_play_pos = state_machine->get_current_play_pos();
			state_machine_play_pos->update();
		}
	}

	if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
		over_node = StringName();
	}
}