Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Improve performnace with Mesh? — Gideros Forum

Improve performnace with Mesh?

hnimhnim Member
edited October 2012 in General questions
i saw this video
11000 textured quad (rectangle shape/sprite ? ) were update at frame-rate ~30. So i wonder if we can make same thing with Gideros. If yes, maybe we will have a simple batch? :D

Comments

  • NascodeNascode Guru
    Accepted Answer
    Ah, dont let @atilim look at this video! He wont take a rest until Gideros surpassed that vid :D
    have fun with our games~
    http://www.nightspade.com
    +1 -1 (+1 / -0 )Share on Facebook
  • he must see this. he must see this. =))
  • Gotta love Codea :)
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • bad luck. i do some try, but it's too slow, slower than using bitmap :(
  • That surprises me - I would have thought a single mesh to be more efficient than rendering lot's of separate bitmaps, fancy sharing your code so we can see if we can identify the bottlenecks?
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • i made a simple example
    in bitmaptest, i add 11000 bitmap (8x8px), each frame i change their position to a random point. I got fps 59 on Desktop player
    in meshtest, i set vertex to create 11000 rect, each frame i setVertex to new position. I got fps 40 on Desktop player.
  • atilimatilim Maintainer
    edited October 2012
    @hnim I think your bottleneck is Lua and not the drawing.

    I've done a simple test. Here is my code:
    local function add(t, ...)
    	local n = select("#", ...)	
    	for i=1,n do
    		t[#t+1] = select(i, ...)
    	end
    end
     
    application:setBackgroundColor(0x306090)
     
    local vertices = {}
    local indices = {}
    local velocities = {}
     
    local nrect = 0
     
    for i = -400, 400, 5 do
    	for j = -400, 400, 5 do
    		local x = i / 275
    		local y = -j / 275
     
    		-- implicit heart function is from <a href="http://mathworld.wolfram.com/HeartCurve.html" rel="nofollow">http://mathworld.wolfram.com/HeartCurve.html</a>
    		local a = x * x + y * y - 1
    		local f = a * a * a - x * x * y * y * y
     
    		if f < 0 then
    			local n = #vertices/2
     
    			-- add 4 corners
    			add(vertices, i,     j)
    			add(vertices, i + 4, j)
    			add(vertices, i + 4, j + 4)
    			add(vertices, i,     j + 4)
     
    			-- add 2 triangles to indices
    			add(indices, n + 1, n + 2, n + 3)
    			add(indices, n + 1, n + 3, n + 4)
     
    			-- and velocities
    			add(velocities, x + math.random(-100,100)/200, -y + math.random(-100,100)/200)
     
    			nrect = nrect + 1
    		end
    	end
    end
     
    print("# of rects = "..nrect)
     
    local mesh = Mesh.new()
     
    mesh:setVertexArray(vertices)
    mesh:setIndexArray(indices)
    mesh:setPosition(768/2, 1024/2)
     
    stage:addChild(mesh)
     
    local function onEnterFrame()
    	for i = 1,#vertices,8 do
    		local ind = (i - 1) / 4 + 1
    		local vx = velocities[ind]
    		local vy = velocities[ind+1]
     
    		vertices[i+0] = vertices[i+0] + vx
    		vertices[i+1] = vertices[i+1] + vy
    		vertices[i+2] = vertices[i+2] + vx
    		vertices[i+3] = vertices[i+3] + vy
    		vertices[i+4] = vertices[i+4] + vx
    		vertices[i+5] = vertices[i+5] + vy
    		vertices[i+6] = vertices[i+6] + vx
    		vertices[i+7] = vertices[i+7] + vy
    	end
     
    	mesh:setVertexArray(vertices)
    end
     
    stage:addEventListener(Event.ENTER_FRAME, onEnterFrame)
    This code creates and explodes 11073 rects and runs at ~15 fps on iPad 3.

    * If I comment out the explosion calculation code, it runs at 60fps.
    * If I explode 1000 random rects at each frame, it runs at 60fps.
    * Without explosion calculation code, it's possible to display 5 * 11073 = 55365 rects at 60 fps.

    Conclusion: if you try to move >10000 rects, Lua can be really a bottleneck.
    Guess: If the explosion calculation code is developed in C/C++ as a plugin, it may be possible to explode ~50000 rects at 60fps.

  • hnimhnim Member
    edited October 2012
    @atitlim: that's really Lua problem. I simple convert your code to object model, frame rate drops significant (from ~60 to 45 on Desktop Player).

    i attached my test project here if someone can take a look.
    zip
    zip
    BatchTest.zip
    3K
Sign In or Register to comment.