mirror of
https://github.com/godotengine/godot.git
synced 2025-01-06 02:00:57 +00:00
Add process mode option to Particles2D
This commit is contained in:
parent
d5c2a6b76b
commit
7e90b98db2
@ -452,7 +452,7 @@ void Particles2D::_process_particles(float p_delta) {
|
||||
time=Math::fmod( time+frame_time, lifetime );
|
||||
if (!emitting && active_count==0) {
|
||||
set_process(false);
|
||||
|
||||
set_fixed_process(false);
|
||||
}
|
||||
|
||||
update();
|
||||
@ -470,6 +470,11 @@ void Particles2D::_notification(int p_what) {
|
||||
_process_particles( get_process_delta_time() );
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_FIXED_PROCESS: {
|
||||
|
||||
_process_particles( get_fixed_process_delta_time() );
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_ENTER_TREE: {
|
||||
|
||||
float ppt=preprocess;
|
||||
@ -691,9 +696,10 @@ void Particles2D::set_emitting(bool p_emitting) {
|
||||
|
||||
if (active_count==0)
|
||||
time=0;
|
||||
set_process(true);
|
||||
set_process(process_mode==PROCESS_IDLE);
|
||||
set_fixed_process(process_mode==PROCESS_FIXED);
|
||||
time_to_live = emit_timeout;
|
||||
};
|
||||
}
|
||||
emitting=p_emitting;
|
||||
_change_notify("config/emitting");
|
||||
}
|
||||
@ -703,6 +709,19 @@ bool Particles2D::is_emitting() const {
|
||||
return emitting;
|
||||
}
|
||||
|
||||
void Particles2D::set_process_mode(ProcessMode p_mode) {
|
||||
|
||||
process_mode=p_mode;
|
||||
const bool should_process=emitting || active_count!=0;
|
||||
set_process(should_process && process_mode==PROCESS_IDLE);
|
||||
set_fixed_process(should_process && process_mode==PROCESS_FIXED);
|
||||
}
|
||||
|
||||
Particles2D::ProcessMode Particles2D::get_process_mode() const {
|
||||
|
||||
return process_mode;
|
||||
}
|
||||
|
||||
void Particles2D::set_amount(int p_amount) {
|
||||
|
||||
ERR_FAIL_INDEX(p_amount,1024+1);
|
||||
@ -1016,6 +1035,9 @@ void Particles2D::_bind_methods() {
|
||||
ObjectTypeDB::bind_method(_MD("set_emitting","active"),&Particles2D::set_emitting);
|
||||
ObjectTypeDB::bind_method(_MD("is_emitting"),&Particles2D::is_emitting);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_process_mode","mode"),&Particles2D::set_process_mode);
|
||||
ObjectTypeDB::bind_method(_MD("get_process_mode"),&Particles2D::get_process_mode);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("set_amount","amount"),&Particles2D::set_amount);
|
||||
ObjectTypeDB::bind_method(_MD("get_amount"),&Particles2D::get_amount);
|
||||
|
||||
@ -1094,6 +1116,7 @@ void Particles2D::_bind_methods() {
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/preprocess",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),_SCS("set_pre_process_time"),_SCS("get_pre_process_time") );
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/emit_timeout",PROPERTY_HINT_RANGE,"0,3600,0.1"),_SCS("set_emit_timeout"),_SCS("get_emit_timeout") );
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/emitting"),_SCS("set_emitting"),_SCS("is_emitting") );
|
||||
ADD_PROPERTY(PropertyInfo( Variant::INT, "config/process_mode",PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_process_mode"), _SCS("get_process_mode") );
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/offset"),_SCS("set_emissor_offset"),_SCS("get_emissor_offset"));
|
||||
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/half_extents"),_SCS("set_emission_half_extents"),_SCS("get_emission_half_extents"));
|
||||
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/local_space"),_SCS("set_use_local_space"),_SCS("is_using_local_space"));
|
||||
@ -1176,6 +1199,7 @@ Particles2D::Particles2D() {
|
||||
particles.resize(32);
|
||||
active_count=-1;
|
||||
set_emitting(true);
|
||||
process_mode=PROCESS_IDLE;
|
||||
local_space=true;
|
||||
preprocess=0;
|
||||
time_scale=1.0;
|
||||
|
@ -111,6 +111,11 @@ public:
|
||||
MAX_COLOR_PHASES=4
|
||||
};
|
||||
|
||||
enum ProcessMode {
|
||||
PROCESS_FIXED,
|
||||
PROCESS_IDLE,
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
float param[PARAM_MAX];
|
||||
@ -154,6 +159,8 @@ private:
|
||||
Vector2 extents;
|
||||
DVector<Vector2> emission_points;
|
||||
|
||||
ProcessMode process_mode;
|
||||
|
||||
float time;
|
||||
int active_count;
|
||||
|
||||
@ -179,6 +186,9 @@ public:
|
||||
void set_emitting(bool p_emitting);
|
||||
bool is_emitting() const;
|
||||
|
||||
void set_process_mode(ProcessMode p_mode);
|
||||
ProcessMode get_process_mode() const;
|
||||
|
||||
void set_amount(int p_amount);
|
||||
int get_amount() const;
|
||||
|
||||
@ -255,6 +265,7 @@ public:
|
||||
Particles2D();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST( Particles2D::ProcessMode );
|
||||
VARIANT_ENUM_CAST( Particles2D::Parameter );
|
||||
|
||||
#endif // PARTICLES_FRAME_H
|
||||
|
Loading…
Reference in New Issue
Block a user