X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali-toolkit%2Finternal%2Fcontrols%2Fbubble-effect%2Fbubble-emitter-impl.cpp;h=8b248ce2afd38464d94aa9cc4960a5a7ac9eecd2;hb=af4073fd7a4f946e26110ecd608ef8e748c078aa;hp=af57a7fb3bdbb6aafe4d6a0f1f959f97cd62683e;hpb=223866bce9f3ffe2faf8d1f4dec42bbd9b4e1233;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp index af57a7f..8b248ce 100644 --- a/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp +++ b/dali-toolkit/internal/controls/bubble-effect/bubble-emitter-impl.cpp @@ -32,27 +32,31 @@ namespace { struct Vertex { - float index; - Dali::Vector2 position; - Dali::Vector2 textureCoord; - Vertex() - {} + : index( 0.0f ), position(), textureCoord() + { + } Vertex( float index, const Dali::Vector2& position, const Dali::Vector2& textureCoord ) : index( index ), position( position ), textureCoord( textureCoord ) - {} + { + } + + float index; + Dali::Vector2 position; + Dali::Vector2 textureCoord; }; /** * Return a random value between the given interval. * @param[in] f0 The low bound * @param[in] f1 The up bound + * @param[in] seed The seed to genergate random number * @return A random value between the given interval */ -float RandomRange(float f0, float f1) +float RandomRange(float f0, float f1, unsigned int& seed) { - return f0 + (rand() & 0xfff) * (f1-f0) * (1.0f/4095.0f); + return f0 + (rand_r( &seed ) & 0xfff) * (f1-f0) * (1.0f/4095.0f); } } @@ -76,6 +80,7 @@ BubbleEmitter::BubbleEmitter( const Vector2& movementArea, mDensity( 5 ), mTotalNumOfBubble( maximumNumberOfBubble ), mCurrentBubble( 0 ), + mRandomSeed( 0 ), mRenderTaskRunning(false) { // Calculate how many shaders are required @@ -95,6 +100,8 @@ BubbleEmitter::BubbleEmitter( const Vector2& movementArea, mNumBubblePerActor = mTotalNumOfBubble; mNumActor = 1; } + + mRandomSeed = time( NULL ); } BubbleEmitter::~BubbleEmitter() @@ -128,16 +135,14 @@ void BubbleEmitter::OnInitialize() // Prepare the frame buffer to store the color adjusted background image mEffectImage = FrameBufferImage::New( mMovementArea.width/4.f, mMovementArea.height/4.f, Pixel::RGBA8888, Dali::Image::UNUSED ); - // Generate the samplers and geometry, which is used by all bubbleActors - mSamplerBackground = Sampler::New( mEffectImage, "sBackground" ); - mSamplerBubbleShape = Sampler::New( mShapeImage, "sBubbleShape" ); + // Generate the geometry, which is used by all bubbleActors mMeshGeometry = CreateGeometry( mNumBubblePerActor*mDensity ); Shader bubbleShader = CreateBubbleShader (mNumBubblePerActor ); mMaterial = Material::New( bubbleShader ); - mMaterial.AddSampler( mSamplerBackground ); - mMaterial.AddSampler( mSamplerBubbleShape ); + mMaterial.AddTexture( mEffectImage, "sBackground" ); + mMaterial.AddTexture( mShapeImage, "sBubbleShape" ); mBubbleActors.resize( mNumActor ); @@ -191,7 +196,7 @@ void BubbleEmitter::SetBackground( Image bgImage, const Vector3& hsvDelta ) void BubbleEmitter::SetShapeImage( Image shapeImage ) { - mSamplerBubbleShape.SetImage( shapeImage ); + mMaterial.SetTextureImage( 1, shapeImage ); } void BubbleEmitter::SetBubbleScale( float scale ) @@ -297,7 +302,7 @@ Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch ) for(unsigned int i = 0; i < numOfPatch; i++) { - float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y); + float curSize = RandomRange(mBubbleSizeRange.x, mBubbleSizeRange.y, mRandomSeed); float index = static_cast( i ); vertexData.push_back( Vertex( index, Vector2(0.f,0.f), Vector2(0.f,0.f) ) ); @@ -322,7 +327,7 @@ Geometry BubbleEmitter::CreateGeometry( unsigned int numOfPatch ) vertices.SetData( &vertexData[0] ); Property::Map indexFormat; - indexFormat["indices"] = Property::UNSIGNED_INTEGER; + indexFormat["indices"] = Property::INTEGER; PropertyBuffer indices = PropertyBuffer::New( indexFormat, numIndex ); indices.SetData( &indexData[0] ); @@ -340,7 +345,7 @@ void BubbleEmitter::SetBubbleParameter( BubbleActorPtr bubbleActor, unsigned int int halfRange = displacement.x / 2; // for the y coordinate, always negative, so bubbles always go upwards - Vector2 randomVec(rand()%static_cast(displacement.x) - halfRange, -rand()%static_cast(displacement.y)); + Vector2 randomVec( rand_r( &mRandomSeed ) % static_cast(displacement.x) - halfRange, -rand_r( &mRandomSeed ) % static_cast(displacement.y) ); dir.Normalize(); randomVec.x -= dir.x*halfRange; randomVec.y *= 1.0f - fabsf(dir.x)*0.33f;