Commit a05f094117781e7c3d061547a11f440d0fb6f147
1 parent
400b7a12
Optimized benchmark animation (Reduce event thread overhead)
Since we were create new animations every PropertyNotify, and at that time, we iterate whole balls. If event thread time delayed (~= the ball is very much) event callback stacked a lot, and then break the app. To avoid it, we make the number of animations relative with ball + change the animation only if we need, not always. It will reduce the event thread overhead. Change-Id: Ic6da267e827d012c9e68c7d64594596f3617233a Signed-off-by: Eunki, Hong <eunkiki.hong@samsung.com>
Showing
1 changed file
with
120 additions
and
99 deletions
examples/benchmark-2dphysics/benchmark-2d-physics-controller.cpp
| @@ -108,22 +108,103 @@ public: | @@ -108,22 +108,103 @@ public: | ||
| 108 | case BenchmarkType::ANIMATION: | 108 | case BenchmarkType::ANIMATION: |
| 109 | default: | 109 | default: |
| 110 | { | 110 | { |
| 111 | + DALI_LOG_ERROR("CreateAnimationSimulation\n"); | ||
| 111 | CreateAnimationSimulation(); | 112 | CreateAnimationSimulation(); |
| 112 | break; | 113 | break; |
| 113 | } | 114 | } |
| 114 | case BenchmarkType::PHYSICS_2D: | 115 | case BenchmarkType::PHYSICS_2D: |
| 115 | { | 116 | { |
| 117 | + DALI_LOG_ERROR("CreatePhysicsSimulation\n"); | ||
| 116 | CreatePhysicsSimulation(); | 118 | CreatePhysicsSimulation(); |
| 117 | break; | 119 | break; |
| 118 | } | 120 | } |
| 119 | } | 121 | } |
| 120 | } | 122 | } |
| 121 | 123 | ||
| 124 | + bool AnimationSimFinished() | ||
| 125 | + { | ||
| 126 | + switch(mType) | ||
| 127 | + { | ||
| 128 | + case BenchmarkType::ANIMATION: | ||
| 129 | + default: | ||
| 130 | + { | ||
| 131 | + UnparentAndReset(mAnimationSimRootActor); | ||
| 132 | + for(auto&& animation : mBallAnimations) | ||
| 133 | + { | ||
| 134 | + animation.Stop(); | ||
| 135 | + animation.Clear(); | ||
| 136 | + } | ||
| 137 | + mBallAnimations.clear(); | ||
| 138 | + | ||
| 139 | + mType = BenchmarkType::PHYSICS_2D; | ||
| 140 | + | ||
| 141 | + CreateSimulation(); | ||
| 142 | + return true; | ||
| 143 | + } | ||
| 144 | + case BenchmarkType::PHYSICS_2D: | ||
| 145 | + { | ||
| 146 | + mApplication.Quit(); | ||
| 147 | + break; | ||
| 148 | + } | ||
| 149 | + } | ||
| 150 | + return false; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + void OnTerminate(Application& application) | ||
| 154 | + { | ||
| 155 | + UnparentAndReset(mAnimationSimRootActor); | ||
| 156 | + UnparentAndReset(mPhysicsRoot); | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + void OnWindowResize(Window window, Window::WindowSize newSize) | ||
| 160 | + { | ||
| 161 | + switch(mType) | ||
| 162 | + { | ||
| 163 | + case BenchmarkType::ANIMATION: | ||
| 164 | + default: | ||
| 165 | + { | ||
| 166 | + // TODO : Implement here if you want. | ||
| 167 | + break; | ||
| 168 | + } | ||
| 169 | + case BenchmarkType::PHYSICS_2D: | ||
| 170 | + { | ||
| 171 | + if(mPhysicsAdaptor) | ||
| 172 | + { | ||
| 173 | + auto scopedAccessor = mPhysicsAdaptor.GetPhysicsAccessor(); | ||
| 174 | + cpSpace* space = scopedAccessor->GetNative().Get<cpSpace*>(); | ||
| 175 | + | ||
| 176 | + CreateBounds(space, newSize); | ||
| 177 | + } | ||
| 178 | + break; | ||
| 179 | + } | ||
| 180 | + } | ||
| 181 | + } | ||
| 182 | + | ||
| 183 | + bool OnTouched(Dali::Actor actor, const Dali::TouchEvent& touch) | ||
| 184 | + { | ||
| 185 | + mApplication.Quit(); | ||
| 186 | + return false; | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + void OnKeyEv(const Dali::KeyEvent& event) | ||
| 190 | + { | ||
| 191 | + if(event.GetState() == KeyEvent::DOWN) | ||
| 192 | + { | ||
| 193 | + if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) | ||
| 194 | + { | ||
| 195 | + mApplication.Quit(); | ||
| 196 | + } | ||
| 197 | + } | ||
| 198 | + } | ||
| 199 | + | ||
| 200 | + // BenchmarkType::ANIMATION | ||
| 201 | + | ||
| 122 | void CreateAnimationSimulation() | 202 | void CreateAnimationSimulation() |
| 123 | { | 203 | { |
| 124 | Window::WindowSize windowSize = mWindow.GetSize(); | 204 | Window::WindowSize windowSize = mWindow.GetSize(); |
| 125 | mBallActors.resize(mBallNumber); | 205 | mBallActors.resize(mBallNumber); |
| 126 | mBallVelocity.resize(mBallNumber); | 206 | mBallVelocity.resize(mBallNumber); |
| 207 | + mBallAnimations.resize(mBallNumber); | ||
| 127 | 208 | ||
| 128 | mAnimationSimRootActor = Layer::New(); | 209 | mAnimationSimRootActor = Layer::New(); |
| 129 | mAnimationSimRootActor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); | 210 | mAnimationSimRootActor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS); |
| @@ -172,49 +253,22 @@ public: | @@ -172,49 +253,22 @@ public: | ||
| 172 | 253 | ||
| 173 | PropertyNotification bottomNotify = mBallActors[i].AddPropertyNotification(Actor::Property::POSITION_Y, GreaterThanCondition(height - margin)); | 254 | PropertyNotification bottomNotify = mBallActors[i].AddPropertyNotification(Actor::Property::POSITION_Y, GreaterThanCondition(height - margin)); |
| 174 | bottomNotify.NotifySignal().Connect(this, &Physics2dBenchmarkController::OnHitBottomWall); | 255 | bottomNotify.NotifySignal().Connect(this, &Physics2dBenchmarkController::OnHitBottomWall); |
| 256 | + | ||
| 257 | + ContinueAnimation(i); | ||
| 175 | } | 258 | } |
| 176 | 259 | ||
| 177 | title.RaiseToTop(); | 260 | title.RaiseToTop(); |
| 178 | - ContinueAnimation(); | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - bool AnimationSimFinished() | ||
| 182 | - { | ||
| 183 | - switch(mType) | ||
| 184 | - { | ||
| 185 | - case BenchmarkType::ANIMATION: | ||
| 186 | - default: | ||
| 187 | - { | ||
| 188 | - UnparentAndReset(mAnimationSimRootActor); | ||
| 189 | - mBallAnimation.Stop(); | ||
| 190 | - mBallAnimation.Clear(); | ||
| 191 | - | ||
| 192 | - mType = BenchmarkType::PHYSICS_2D; | ||
| 193 | - | ||
| 194 | - CreateSimulation(); | ||
| 195 | - return true; | ||
| 196 | - } | ||
| 197 | - case BenchmarkType::PHYSICS_2D: | ||
| 198 | - { | ||
| 199 | - mApplication.Quit(); | ||
| 200 | - break; | ||
| 201 | - } | ||
| 202 | - } | ||
| 203 | - return false; | ||
| 204 | } | 261 | } |
| 205 | 262 | ||
| 206 | - void ContinueAnimation() | 263 | + void ContinueAnimation(int index) |
| 207 | { | 264 | { |
| 208 | - if(mBallAnimation) | 265 | + if(mBallAnimations[index]) |
| 209 | { | 266 | { |
| 210 | - mBallAnimation.Clear(); | 267 | + mBallAnimations[index].Clear(); |
| 211 | } | 268 | } |
| 212 | - mBallAnimation = Animation::New(MAX_ANIMATION_DURATION); | ||
| 213 | - for(int i = 0; i < mBallNumber; ++i) | ||
| 214 | - { | ||
| 215 | - mBallAnimation.AnimateBy(Property(mBallActors[i], Actor::Property::POSITION), mBallVelocity[i] * MAX_ANIMATION_DURATION); | ||
| 216 | - } | ||
| 217 | - mBallAnimation.Play(); | 269 | + mBallAnimations[index] = Animation::New(MAX_ANIMATION_DURATION); |
| 270 | + mBallAnimations[index].AnimateBy(Property(mBallActors[index], Actor::Property::POSITION), mBallVelocity[index] * MAX_ANIMATION_DURATION); | ||
| 271 | + mBallAnimations[index].Play(); | ||
| 218 | } | 272 | } |
| 219 | 273 | ||
| 220 | void OnHitLeftWall(PropertyNotification& source) | 274 | void OnHitLeftWall(PropertyNotification& source) |
| @@ -222,9 +276,12 @@ public: | @@ -222,9 +276,12 @@ public: | ||
| 222 | auto actor = Actor::DownCast(source.GetTarget()); | 276 | auto actor = Actor::DownCast(source.GetTarget()); |
| 223 | if(actor) | 277 | if(actor) |
| 224 | { | 278 | { |
| 225 | - int index = actor["index"]; | ||
| 226 | - mBallVelocity[index].x = fabsf(mBallVelocity[index].x); | ||
| 227 | - ContinueAnimation(); | 279 | + int index = actor["index"]; |
| 280 | + if(mBallVelocity[index].x < 0.0f) | ||
| 281 | + { | ||
| 282 | + mBallVelocity[index].x = fabsf(mBallVelocity[index].x); | ||
| 283 | + ContinueAnimation(index); | ||
| 284 | + } | ||
| 228 | } | 285 | } |
| 229 | } | 286 | } |
| 230 | 287 | ||
| @@ -233,9 +290,12 @@ public: | @@ -233,9 +290,12 @@ public: | ||
| 233 | auto actor = Actor::DownCast(source.GetTarget()); | 290 | auto actor = Actor::DownCast(source.GetTarget()); |
| 234 | if(actor) | 291 | if(actor) |
| 235 | { | 292 | { |
| 236 | - int index = actor["index"]; | ||
| 237 | - mBallVelocity[index].x = -fabsf(mBallVelocity[index].x); | ||
| 238 | - ContinueAnimation(); | 293 | + int index = actor["index"]; |
| 294 | + if(mBallVelocity[index].x > 0.0f) | ||
| 295 | + { | ||
| 296 | + mBallVelocity[index].x = -fabsf(mBallVelocity[index].x); | ||
| 297 | + ContinueAnimation(index); | ||
| 298 | + } | ||
| 239 | } | 299 | } |
| 240 | } | 300 | } |
| 241 | 301 | ||
| @@ -244,9 +304,12 @@ public: | @@ -244,9 +304,12 @@ public: | ||
| 244 | auto actor = Actor::DownCast(source.GetTarget()); | 304 | auto actor = Actor::DownCast(source.GetTarget()); |
| 245 | if(actor) | 305 | if(actor) |
| 246 | { | 306 | { |
| 247 | - int index = actor["index"]; | ||
| 248 | - mBallVelocity[index].y = -fabsf(mBallVelocity[index].y); | ||
| 249 | - ContinueAnimation(); | 307 | + int index = actor["index"]; |
| 308 | + if(mBallVelocity[index].y > 0.0f) | ||
| 309 | + { | ||
| 310 | + mBallVelocity[index].y = -fabsf(mBallVelocity[index].y); | ||
| 311 | + ContinueAnimation(index); | ||
| 312 | + } | ||
| 250 | } | 313 | } |
| 251 | } | 314 | } |
| 252 | 315 | ||
| @@ -255,12 +318,17 @@ public: | @@ -255,12 +318,17 @@ public: | ||
| 255 | auto actor = Actor::DownCast(source.GetTarget()); | 318 | auto actor = Actor::DownCast(source.GetTarget()); |
| 256 | if(actor) | 319 | if(actor) |
| 257 | { | 320 | { |
| 258 | - int index = actor["index"]; | ||
| 259 | - mBallVelocity[index].y = fabsf(mBallVelocity[index].y); | ||
| 260 | - ContinueAnimation(); | 321 | + int index = actor["index"]; |
| 322 | + if(mBallVelocity[index].y < 0.0f) | ||
| 323 | + { | ||
| 324 | + mBallVelocity[index].y = fabsf(mBallVelocity[index].y); | ||
| 325 | + ContinueAnimation(index); | ||
| 326 | + } | ||
| 261 | } | 327 | } |
| 262 | } | 328 | } |
| 263 | 329 | ||
| 330 | + // BenchmarkType::PHYSICS_2D | ||
| 331 | + | ||
| 264 | void CreatePhysicsSimulation() | 332 | void CreatePhysicsSimulation() |
| 265 | { | 333 | { |
| 266 | Window::WindowSize windowSize = mWindow.GetSize(); | 334 | Window::WindowSize windowSize = mWindow.GetSize(); |
| @@ -370,53 +438,6 @@ public: | @@ -370,53 +438,6 @@ public: | ||
| 370 | return shape; | 438 | return shape; |
| 371 | } | 439 | } |
| 372 | 440 | ||
| 373 | - void OnTerminate(Application& application) | ||
| 374 | - { | ||
| 375 | - UnparentAndReset(mAnimationSimRootActor); | ||
| 376 | - UnparentAndReset(mPhysicsRoot); | ||
| 377 | - } | ||
| 378 | - | ||
| 379 | - void OnWindowResize(Window window, Window::WindowSize newSize) | ||
| 380 | - { | ||
| 381 | - switch(mType) | ||
| 382 | - { | ||
| 383 | - case BenchmarkType::ANIMATION: | ||
| 384 | - default: | ||
| 385 | - { | ||
| 386 | - // TODO : Implement here if you want. | ||
| 387 | - break; | ||
| 388 | - } | ||
| 389 | - case BenchmarkType::PHYSICS_2D: | ||
| 390 | - { | ||
| 391 | - if(mPhysicsAdaptor) | ||
| 392 | - { | ||
| 393 | - auto scopedAccessor = mPhysicsAdaptor.GetPhysicsAccessor(); | ||
| 394 | - cpSpace* space = scopedAccessor->GetNative().Get<cpSpace*>(); | ||
| 395 | - | ||
| 396 | - CreateBounds(space, newSize); | ||
| 397 | - } | ||
| 398 | - break; | ||
| 399 | - } | ||
| 400 | - } | ||
| 401 | - } | ||
| 402 | - | ||
| 403 | - bool OnTouched(Dali::Actor actor, const Dali::TouchEvent& touch) | ||
| 404 | - { | ||
| 405 | - mApplication.Quit(); | ||
| 406 | - return false; | ||
| 407 | - } | ||
| 408 | - | ||
| 409 | - void OnKeyEv(const Dali::KeyEvent& event) | ||
| 410 | - { | ||
| 411 | - if(event.GetState() == KeyEvent::DOWN) | ||
| 412 | - { | ||
| 413 | - if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK)) | ||
| 414 | - { | ||
| 415 | - mApplication.Quit(); | ||
| 416 | - } | ||
| 417 | - } | ||
| 418 | - } | ||
| 419 | - | ||
| 420 | private: | 441 | private: |
| 421 | Application& mApplication; | 442 | Application& mApplication; |
| 422 | Window mWindow; | 443 | Window mWindow; |
| @@ -434,11 +455,11 @@ private: | @@ -434,11 +455,11 @@ private: | ||
| 434 | cpShape* mTopBound{nullptr}; | 455 | cpShape* mTopBound{nullptr}; |
| 435 | cpShape* mBottomBound{nullptr}; | 456 | cpShape* mBottomBound{nullptr}; |
| 436 | 457 | ||
| 437 | - std::vector<Actor> mBallActors; | ||
| 438 | - std::vector<Vector3> mBallVelocity; | ||
| 439 | - int mBallNumber; | ||
| 440 | - Animation mBallAnimation; | ||
| 441 | - Timer mTimer; | 458 | + std::vector<Actor> mBallActors; |
| 459 | + std::vector<Vector3> mBallVelocity; | ||
| 460 | + std::vector<Animation> mBallAnimations; | ||
| 461 | + int mBallNumber; | ||
| 462 | + Timer mTimer; | ||
| 442 | }; | 463 | }; |
| 443 | 464 | ||
| 444 | int DALI_EXPORT_API main(int argc, char** argv) | 465 | int DALI_EXPORT_API main(int argc, char** argv) |