About Monkey 2 › Forums › Monkey 2 Projects › Monkey2 Bunnymark (github)
This topic contains 31 replies, has 12 voices, and was last updated by
Abe _King_
1 year, 3 months ago.
-
AuthorPosts
-
November 3, 2017 at 11:54 pm #11454
Hello! My name’s Abe and I’ve been looking into Monkey2 recently and decided to take a dive and create a quick and simple Bunnymark. Being that I’m new I’m sure there’s plenty of you M2 veterans out there that can improve my code and, that being said, I would very much appreciate that feedback and help!
As of right now, I am getting decent framerates. Decent as in comparison to a couple of other engines I’ve used in the past. Engines ( GM2, Godot, Luxe, HaxeFlixel, HaxePunk, Defold ). The Monkey2 workflow feels just about right to me, I’m still trying to decide if it’s engine I’ll settle with but only time will tell!
Here’s the repository: https://github.com/forgotten-king/Monkey2-BunnyMark
Here’s a short clip: https://streamable.com/cy777 (Gets very blurry towards the lower frame rate )Music by one of my favorite artists, ULI. Track here: https://soundcloud.com/uli_music/1032a
Bunny Assets borrowed from: https://github.com/dmitryhryppa/Frameworks_testAttachments:
November 4, 2017 at 2:04 am #11457Hi Abe, Welcome to the forum.
interesting results!
Have you tried running it in release mode?I get 10,000 at a steady 62 frames a second in release mode.
and 3,000 at a steady 62 frames a second in debug mode.
2013 MacBook Air 1.7Ghz.Personally, I think thats pretty good.
A question: Why are you determining what language/Engine to use based on the speed of the graphics output?
November 4, 2017 at 2:13 am #11458Hi Jesse, thanks for taking the time to try it out :). I would be very happy if you could push your binaries for MAC if possible!
I am nearly certain I was running in release mode, at least I could have sworn :). I’ll check once more to be sure.. Yeah, I have release mode checked and for some reason getting a max of 3.4k! I’ve sent the binary to a friend who has a better setup than me on windows and got around 4.7+ before seeing 48 fps.Your numbers are very good, I would be more than happy to call the engine my own if I could push that much out.
To answer your question, it’s not necessarily the best reason to choose an engine for the graphics output alone, but I do feel substantially more comfortable with an engine that can push out a minimum of 6k on my machine. It just gives me a better feel for what room I’m given to work with. Rooky reasons!
November 4, 2017 at 2:27 am #11459here is the link to the binary:
https://www.dropbox.com/s/24ws94xn2r46dqe/Bunnymark.zip?dl=0I did cheat. I wasn’t going to press the mouse button until I reached the 10.000 bunnies so I changed the arrays size to 10,000 to start with. LOL.
[Edit]
What version of Monkey2 are you using?
November 4, 2017 at 2:31 am #11460On my rig* I can run 10k without it dropping frames.
I also changed the controls to:
[/crayon]Monkey12345678[crayon-5cb9b8b8b7a91855444197 inline="true" ]If event.Button = MouseButton.Left_len = 10Elseif event.Button = MouseButton.Right_len = 1000Elseif event.Button = MouseButton.Middle_len = -100End* 7700K, Geforce 1080, 16GB
November 4, 2017 at 3:29 am #11461Thanks for the feedback, friends! I’ve added in your snipper @therevills. That’s a useful addition!
@jesse, I attempted to see if maybe it was my array resizing that was causing the problems and changed the initial size to higher numbers but I got similar if not the same results prior to that. And thanks for the binary! I’ll probably post that tomorrow
Still can’t seem to get better performance although I am convinced I should have it..
[ Edit ]
Jesse, I’m using the latest itch.io release – believe it was from 2-3 days ago.November 4, 2017 at 7:12 am #11465I’m getting 3k on a 3630QM laptop with GT635M.
Strange thing is desktop or release only slightly affects speed!Do you know there’s a FPS count for you? No need to use millisecs and all the stuffs (and your avg was sticked at 62 because you where using only integers in your division so it was not able to show the real 60) You should always put a float in a division if you want accurate results.
Local avg := 1000/( ( elapsed /frames*1.0) )
canvas.DrawText(” FPS: ” + App.FPS, 300, 0 )
November 4, 2017 at 7:26 am #11466@abakobo Thanks for the input and help/feedback. The App.FPS tip is very helpful :). Regarding the frames needing to be casted to a float – I wasn’t even aware of that! I also figured out by chances that you can cast a variable using something like Float(frames) in this very project (as can be seen used in my clamp on the bunnies X-axis).
I will go ahead and replace my makeshift FPS Avg with the app!
Just a quick reminder for the future: Don’t be shy to send any pull requests to the repository! I’m always happy to see/add to who my contributors are :).
November 4, 2017 at 8:14 am #11468This the results on my scrap-puter (AMD Phenom II x4 955 3.2 Ghz, 4GB, Windows 10 – AMD RADEON HD 5700 (Catalyst 2015… I’m upgrading in this moment to see if it there’s an impact of the performances!)
Changed to FULLSCREEN (in windows.Fullscreen initialization)
Initial array: 3000 bunnies
FPS 58/62 (floating very quick!)
From 3.000 to 3.400 – FPS quite stable (58..62)
At 3500 there’s a ‘drop’ to 54… and starts everything to be unstable, it’s possible to see hiccupsNovember 4, 2017 at 8:56 am #11469on mac (high sierra)
3100 stable at 62fps
3200 drop to 58 fps
3500 55fps
4000 49fpsall windowed.
fullscreen not resized the window correctly, but the same fpsNovember 4, 2017 at 4:46 pm #11472Hello everyone! Thanks for your results :). Glad to see you all trying it out and having some benchmarking fun. I’ve updated some of the code with big thanks to therevills and abakobo!
Now you should be seeing smoother FPS calculations and have a bit more control over your bunnies.
[ Edit ]
We do seem to be getting a fairly good variety of test samples and the results are indeed interesting. Maybe, in the end, I can put together some graphs for the results!November 4, 2017 at 5:35 pm #11473Hmm, this seems very slow to me. I tried it and it only got to 4-5k before the frame rate started to drop which doesn’t seem right. After a bit of experimenting if I changed it to only draw one type of bunny I got up to 200k at 60fps. Surely something must be amiss here under the hood? Or is it to do with drawing different textures? Maybe try with the bunnies packed into a single sprite sheet. Maybe mojo can be optimised here somehow?
November 4, 2017 at 8:31 pm #11475Or is it to do with drawing different textures?
More than likely – changing some rendering ‘state’ (blendmode, shader, material etc – NOT color or matrix) will cause an internal ‘flush’ which will slow things down. Worse case would be something like…
Monkey12345For Local i:=0 Until lotscanvas.DrawImage( image1,x1(),y1() )canvas.DrawImage( image2,x2(),y2() )Next…where image1 and image2 used entirely different textures.
This would not be able to queue ANY draw ops, ie: each: DrawImage would effectively be doing a Flush.
Sorting drawing ops ‘by texture’ (ie: ‘by image’ ) will minimize these problems. Ditto, sorting by blendmode, ie: draw all opaque objects, then all transparent objects.
Using a texture atlas will also help a great deal, as an atlas allows you to draw different images from the same texture.
Perhaps the above test could be modified to include a togglable ‘sort by texture’ mode to show the difference?
November 4, 2017 at 10:06 pm #11476I figured that was the case, but I have experience with a different renderer where it can push out about 90,000 images per second at 60fps for one texture. I was very impressed when this engine could push out 3.4k with 4 different textures and the other renderer could only pump 1000.
So, now, re-testing this whole thing once more, I’ve managed to see a goof up somehow. Turns out using a single texture actually DOES MARGINALLY improve performance. Now I’m very convinced that this engine is more than capable to pump out a very strong game.
Just need to figure out what the support is in Monkey2 for texture-atlases as that can simplify the task quite a bit for non-trivial things as opposed to the trivial sub-imaging for the bunnies. @Mark Sibly, any examples I can look at for such a thing?
I’ll definitely create a dual-test for testing texture grouping and separate. Thanks for the notice guys.
November 4, 2017 at 10:50 pm #11477That’s really interesting, something worth bearing in mind when optimising. Here’s a modified version where each bunny image is put into it’s own separate stack and drawn one after the other. I get over 230k before the fps goes lower than 60. Does have the disadvantage in that one type of bunny (red in this case) gets drawn over the top of the others but that’s where you’d switch to an atlas if that was an issue I guess.
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132Namespace bunnies' Load up the assets#Import "assets/wabbit_alpha.png"#Import "assets/wabbit_alpha2.png"#Import "assets/wabbit_alpha3.png"#Import "assets/wabbit_alpha4.png"' Load up imports#Import "<std>"#Import "<mojo>"Using std..Using mojo..Const VWIDTH:=1024Const VHEIGHT:=768Class Bunnymark Extends WindowField frames: Int = 1Field elapsed: Int = 1Field bunnies:Stack<Bunny>[] = New Stack<Bunny>[4]Field images:Image[] = New Image[](Image.Load("asset::wabbit_alpha.png"),Image.Load("asset::wabbit_alpha2.png"),Image.Load("asset::wabbit_alpha3.png"),Image.Load("asset::wabbit_alpha4.png") )Field lastMilli := Millisecs()Method New()Super.New("Bunnymark", VWIDTH, VHEIGHT, WindowFlags.Resizable )Local tmpimage:=Floor( random.Rnd( 3 ))For Local i:=0 Until bunnies.Lengthbunnies[i] = New Stack<Bunny>EndEndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender() ' Activate this methodIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()Local bunnycount:IntFor Local s:=Eachin bunniesFor Local bunny:=Eachin sbunny.Update()bunny.Draw(canvas)bunnycount+=1NextNext'elapsed += Millisecs() - lastMilli'Local avg := 1000/( ( elapsed /Float(frames)) ) '- not recquired anymore thanks to App.FPScanvas.Color = Color.Whitecanvas.DrawRect( 0, 0, VWIDTH, 25 )canvas.Color = Color.Blackcanvas.DrawText("The Bunnymark ( " + bunnycount + " )",0,0)canvas.DrawText(" FPS: " + App.FPS, 300, 0 ) ' App.FPS suggested by abakobo#rem frames += 1If frames > 100 ' makeshift FPS counter not necessaryframes = 1elapsed = 1EndiflastMilli = Millisecs()#endEnd MethodMethod OnMouseEvent( event:MouseEvent ) OverrideIf event.Type = EventType.MouseDownLocal _len := 0If event.Button = MouseButton.Left_len = 10Elseif event.Button = MouseButton.Right_len = 10000Elseif event.Button = MouseButton.Middle_len = -100End' Extra functionality ( RightButton / Middle ) added by @therevillsLocal tmpimage:IntFor Local i:=1 Until _len + 1tmpimage = Floor( random.Rnd( 3 ))bunnies[ tmpimage ].Add( New Bunny( Mouse.X, Mouse.Y, images[ tmpimage ] ) )EndEndEnd MethodEndClass BunnyField x: FloatField y: FloatField xspeed: FloatField yspeed: FloatField texture: ImageGlobal gravity := 0.5Method New( x: Float, y: Float, texture:Image )Self.x = xSelf.y = ySelf.texture = texturexspeed = random.Rnd( 10 )EndMethod Update:Void( )yspeed += gravityy += yspeedx += xspeedIf y >= VHEIGHTy = VHEIGHTyspeed = -random.Rnd( 35 )EndifIf x < 0 Or x > VWIDTHxspeed *= -1x = Clamp(x, 0.0, Float(VWIDTH) )EndifEndMethod Draw(canvas:Canvas)canvas.DrawImage( texture, x, y )EndEndFunction Main()New AppInstanceNew BunnymarkApp.Run()End Function -
AuthorPosts
You must be logged in to reply to this topic.

