summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-02-27 14:03:44 +0100
committerGitHub <noreply@github.com>2017-02-27 14:03:44 +0100
commit5f31b3ce58a8480d651dd431c498e857cdd9a496 (patch)
tree360e1596f53fbd57c0f18af79f77b7bbeaae7976
parent34a0aa6900880235f2ca78a7631f30cd3e3ecb2c (diff)
parent5d094602b864d6195b4b45de4a26a242b22e4dd1 (diff)
Merge pull request #7897 from RandomShaper/particles2d-process-mode
Add process mode option to Particles2D
-rw-r--r--scene/2d/particles_2d.cpp28
-rw-r--r--scene/2d/particles_2d.h11
2 files changed, 37 insertions, 2 deletions
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 055bec2ca9..88682c7278 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -454,7 +454,7 @@ void Particles2D::_process_particles(float p_delta) {
if (!emitting && active_count==0) {
emit_signal(SceneStringNames::get_singleton()->emission_finished);
set_process(false);
-
+ set_fixed_process(false);
}
update();
@@ -472,6 +472,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;
@@ -697,7 +702,8 @@ 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;
@@ -709,6 +715,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);
@@ -1013,6 +1032,9 @@ void Particles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_emitting","active"),&Particles2D::set_emitting);
ClassDB::bind_method(D_METHOD("is_emitting"),&Particles2D::is_emitting);
+ ClassDB::bind_method(D_METHOD("set_process_mode","mode"),&Particles2D::set_process_mode);
+ ClassDB::bind_method(D_METHOD("get_process_mode"),&Particles2D::get_process_mode);
+
ClassDB::bind_method(D_METHOD("set_amount","amount"),&Particles2D::set_amount);
ClassDB::bind_method(D_METHOD("get_amount"),&Particles2D::get_amount);
@@ -1093,6 +1115,7 @@ void Particles2D::_bind_methods() {
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/preprocess",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),"set_pre_process_time","get_pre_process_time") ;
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/emit_timeout",PROPERTY_HINT_RANGE,"0,3600,0.1"),"set_emit_timeout","get_emit_timeout") ;
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/emitting"),"set_emitting","is_emitting") ;
+ ADD_PROPERTY(PropertyInfo(Variant::INT,"config/process_mode",PROPERTY_HINT_ENUM, "Fixed,Idle"),"set_process_mode","get_process_mode");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/offset"),"set_emissor_offset","get_emissor_offset");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/half_extents"),"set_emission_half_extents","get_emission_half_extents");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/local_space"),"set_use_local_space","is_using_local_space");
@@ -1175,6 +1198,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;
diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h
index 4a2d57d6b9..a12683f376 100644
--- a/scene/2d/particles_2d.h
+++ b/scene/2d/particles_2d.h
@@ -111,6 +111,11 @@ public:
MAX_COLOR_PHASES=4
};
+ enum ProcessMode {
+ PROCESS_FIXED,
+ PROCESS_IDLE,
+ };
+
private:
float param[PARAM_MAX];
@@ -153,6 +158,8 @@ private:
Vector2 extents;
PoolVector<Vector2> emission_points;
+ ProcessMode process_mode;
+
float time;
int active_count;
@@ -177,6 +184,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;
@@ -253,6 +263,7 @@ public:
Particles2D();
};
+VARIANT_ENUM_CAST( Particles2D::ProcessMode );
VARIANT_ENUM_CAST( Particles2D::Parameter );
#endif // PARTICLES_FRAME_H