Forum Replies Created
-
AuthorPosts
-
Any kind soul here? I converted the monkeyX not Monkey2 but it’s not running.
CONVERSION (MEMORY CRASH)
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108[crayon-5cba84a424ba7955613743 inline="true" ]Namespace Myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Const w:=800, h:=600Class Myapp Extends WindowField canvas:CanvasField icanvas:CanvasField scanvas:CanvasField image:ImageField sourceImage:ImageField targetImage:ImageField size:Int=16 ' try 8 16 32 64Field cx:IntField wx:IntField wy:IntField tilemap:Int[]' 512*512Field s:Int = 4Method New()Super.New("Myapp", w, h, WindowFlags.Resizable)For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNextsourceImage=Image.Load("32x32sheet.png") ' 0,0,0 in Mx ! PixelFormat.RGBA8,TextureFlags.Dynamic)targetImage=New Image(sourceImage.Width,sourceImage.Height) ' ,,,0) 'MAYBE SAME AS BELOWimage=New Image(512,512,PixelFormat.RGBA8,TextureFlags.Dynamic) ' image=New Image(512,512,0,0,0) & Image.SetFlagsMask(Image.Managed)icanvas=New Canvas(image)scanvas=New Canvas(targetImage)' canvas=New Canvas() NOT NEEDED IN MONKEY2 ' image.Texture.Flags &=~ TextureFlags.FilterMipmapEnd' ---------------------------------------------------------------------------------------Method OnRender( canvas:Canvas ) OverrideApp.RequestRender()' canvas.Alpha=1.0scanvas.Clear(Color.Black) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.DrawImage(sourceImage,0,0) ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.Flush() ' INSTEAD OF SHADER (just copies sourceImage to targetImage)' Init canvas & image'canvas.Viewport(0,0,w,h)'canvas.Scissor(0,0,w,h)'canvas.Projection2d(0,w,0,h)canvas.Clear(Color.Black)'icanvas.Viewport(0,0,w,h)'icanvas.Scissor(0,0,w,h)'icanvas.Projection2d(0,w,0,h)icanvas.Clear(Color.Black)' Draw to image' Scroll (by drawing onto itself)icanvas.Clear(Color.Black)icanvas.DrawImage(sourceImage,0,0)icanvas.DrawImage(targetImage,256,256)cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect(64+temp,0,1,64,targetImage,0+temp+cx,0,1,64)Next' Plots something in the tiles (shows how to draw something to an image *after* shader have been applied)For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.Color = Color.Black Else icanvas.Color = Color.WhiteLocal xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.DrawRect(xx*4,yy*4,2*4,2*4)Nexticanvas.Flush() ' Finished drawing' Draw to canvas' Cookiecut 32x32 tiles from a 512x512 tilesheet and draw as tiles of any sizeLocal scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512]Local tilex:= char & 15Local tiley:= char Shr 4canvas.DrawRect(cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32)cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.Flush() ' Finished drawingIf Keyboard.KeyReleased(Key.Escape) Then App.Terminate()End MethodEndFunction Main()New AppInstanceNew MyappApp.Run()End FunctionORIGINAL MONKEYX (works perfectly with all I’ve said, it would be a nice additional Monkey2 banana)
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110[crayon-5cba84a424baf910376289 inline="true" ]#GLFW_WINDOW_WIDTH = 800#GLFW_WINDOW_HEIGHT = 600#GLFW_WINDOW_FULLSCREEN = False#GLFW_WINDOW_RESIZABLE = True#GLFW_WINDOW_RENDER_WHILE_RESIZING = TrueImport mojo2Class MyApp Extends AppField canvas:CanvasField icanvas:CanvasField scanvas:CanvasField image:ImageField sourceImage:ImageField targetImage:ImageField size:Int=16 ' try 8 16 32 64Field cx:IntField wx:IntField wy:IntField tilemap:Int[512*512]Field s:Int = 4Method OnCreate()For Local y:=0 To 511For Local x:=0 To 511tilemap[x + y * 512] = Int(Rnd(127))NextNextsourceImage=Image.Load("32x32sheet.png",0,0,0)targetImage=New Image(sourceImage.Width,sourceImage.Height,,,0)image=New Image(512,512,0,0,0)Image.SetFlagsMask(Image.Managed)icanvas=New Canvas(image)scanvas=New Canvas(targetImage)canvas=New CanvasEndMethod OnUpdate()If KeyHit(KEY_ESCAPE) Then EndAppwx=wx-s*KeyDown(KEY_LEFT)+s*KeyDown(KEY_RIGHT)wy=wy-s*KeyDown(KEY_UP)+s*KeyDown(KEY_DOWN)wx=Max(0,Min(10000,wx)) ' Limit wx to 0 through 10000wy=Max(0,Min(10000,wy)) ' Limit wyx to 0 through 10000EndMethod OnRender()scanvas.Clear ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.DrawImage sourceImage,0,0 ' INSTEAD OF SHADER (just copies sourceImage to targetImage)scanvas.Flush() ' INSTEAD OF SHADER (just copies sourceImage to targetImage)' Init canvas & imageLocal w=DeviceWidthLocal h=DeviceHeightcanvas.SetViewport 0,0,w,hcanvas.SetScissor 0,0,w,hcanvas.SetProjection2d 0,w,0,hcanvas.Clear 0,0,0icanvas.SetViewport 0,0,w,hicanvas.SetScissor 0,0,w,hicanvas.SetProjection2d 0,w,0,hicanvas.Clear 0,0,0' ' Draw to image' Scroll (by drawing onto itself)icanvas.Clear 0,0,0icanvas.DrawImage sourceImage,0,0icanvas.DrawImage targetImage,256,256cx=(cx+2) Mod 512For Local temp:=0 To 127icanvas.DrawRect 064+temp,0,1,64,targetImage,0+temp+cx,0,1,64Next' Plots something in the tiles (shows how to draw something to an image *after* shader have been applied)For Local temp:=1 To 16If Int(Rnd(1)) Then icanvas.SetColor 0,0,0 Else icanvas.SetColor 1,1,1Local xx:= Int(Rnd(7))Local yy:= Int(Rnd(7))icanvas.DrawRect xx*4,yy*4,2*4,2*4Nexticanvas.Flush ' Finished drawing' Draw to canvas' Cookiecut 32x32 tiles from a 512x512 tilesheet and draw as tiles of any sizeLocal scrx:=wx Mod sizeLocal scry:=wy Mod sizeLocal mapx:=wx / sizeLocal mapy:=wy / sizeLocal cnty:= -scryFor Local y:=mapy To mapy+((h/size)+1)Local cntx:=-scrxFor Local x:=mapx To mapx+((w/size)+1)Local char:= tilemap[x + y * 512] ; Local tilex:= char & 15 ; Local tiley:= char Shr 4canvas.DrawRect cntx,cnty,size,size,image,tilex Shl 5,tiley Shl 5,32,32cntx=cntx+sizeNextcnty=cnty+sizeNextcanvas.Flush ' Finished drawingEndEndFunction Main()New MyAppEndAttachments:
I managed to simplify things and maybe I’m able to convert everything now I just need help with the corresponding Monkey2 commands for: (the extra commas and zeros and also Image.SetFlagMask Managed).
[/crayon]Monkey123456[crayon-5cba84a43114e996580108 inline="true" ] sourceImage=Image.Load("´sheet.png",0,0,0)targetImage=New Image(sourceImage.Width,sourceImage.Height,,,0)image=New Image(512,512,0,0,0)Image.SetFlagsMask(Image.Managed)Yes I know that it’s undefined to draw to itself but In MonkeyX you can do thath without slowdowns and that’s what makes me confused.
I use a shader to read sourceimage and process it to targetimage.
After that I plot some stuff onto targetimage which will therefore be unaffected by the shader, and then I use targetimage as the tilesheet to draw parts onto the canvas.But there are self-refference to create a scrolling/rolling effect, and it just works.
I did some tests without any self-reffering and it’s still as slow in Monkey2.Drawing an image that you’ve just draw an image to is expansive in Monkey2.
The slowdown seem to be x4. 4K draws instead of 16K draws. I would accept that If MonkeyX had the same but it doesn’t.This is the best demo I’ve come to manage to produce in Monkey2 as I’m in the process of learning it.
I could provide full MX code if this M2 can’t put some light on the issue. I’m still new to Monkey2 so bear with me.I made a test which uses an untouched image (Barabarian) to blit to the Checkerboard (just another image) and to the main canvas. While doing that it blits some more using the checkerboard as the source and draws onto both itself and the canvas. I would like to throw away the “selfblitting” part and compare, but I think I tried that with similar slow results so that’s not it.
The test can show that the upper combinations will run fine, while the lower combination one will not.
If this fails to explain the problem I can show the full source when Mx is doing it, with shader ontop aswell.
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147[crayon-5cba84a436b11111032194 inline="true" ]Namespace Myapp#Import "<std>"#Import "<mojo>"#Import "<mojo3d>"#Import "assets/"Using std..Using mojo..Const VWIDTH:=1920, VHEIGHT:=1080Class Myapp Extends WindowField Myapp:Stack<sprite>[] = New Stack<sprite>[4]Field images:Image[] = New Image[](Image.Load("asset::32x32sheet.png"),Image.Load("asset::32x32sheet.png"),Image.Load("asset::32x32sheet.png"),Image.Load("asset::32x32sheet.png") )Field image:Image ' Bunny residue, are using only [0] for now.Field icanvas:CanvasMethod New()Super.New("Myapp", VWIDTH, VHEIGHT, WindowFlags.Resizable )image=New Image(512,512,PixelFormat.RGBA8,TextureFlags.Dynamic)image.Texture.Flags &=~ TextureFlags.FilterMipmap'images[0].TextureFlags.Dynamic'images[0].Texture.Flags &=~ TextureFlags.FilterMipmapimage.Handle=New Vec2f(0.5,0.5)icanvas=New Canvas(image)Local tmpimage:=Floor( random.Rnd( 3 ))For Local i:=0 Until Myapp.LengthMyapp[i] = New Stack<sprite>EndEnd' ---------------------------------------------------------------------------------------Method OnRender( canvas:Canvas ) OverrideApp.RequestRender()icanvas.Clear(Color.Black)canvas.Alpha=1.0icanvas.Alpha=0.2For Local x:=0 Until 512/16For Local y:=0 Until 512/16If (x~y)&1icanvas.Color=New Color( Sin( Millisecs()*.01 )*.5+.5,Cos( Millisecs()*.02 )*.5+.5,.5 )Elseicanvas.Color=Color.YellowEndificanvas.DrawRect( Int(x)*16,Int(y)*16,16,16 )NextNextGlobal currentx : Intcurrentx = (currentx+2) Mod 512For Local temp:=0 To 511icanvas.DrawRect(64+temp,0, 1, 64, image, 0+temp+currentx,0,1,64)Nexticanvas.Color=Color.Whiteicanvas.DrawText( "This way up!",icanvas.Viewport.Width/2,0,.5,0)If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()Local count:Inticanvas.Alpha = 1canvas.Alpha = 1For Local s:=Eachin MyappFor Local sprite:=Eachin scanvas.Alpha = 1.0sprite.Update(); sprite.Draw(icanvas);count+=1 ' Draw to checkerboard. Using this instead of tilesheet as source slows things down in Monkey2 but not MonkeyX.canvas.Alpha = 0.2sprite.Update(); sprite.Draw(canvas);count+=1 ' Draw to canvas.NextNexticanvas.Flush()Global rot:=0.0canvas.Alpha = 1.0canvas.DrawImage(image,App.MouseLocation.x,App.MouseLocation.y,rot)icanvas.Alpha = 1canvas.Color = Color.Whitecanvas.DrawRect( 0, 0, VWIDTH, 25 )canvas.Color = Color.Blackcanvas.DrawText("Counting ("+ count +")",0,0);canvas.DrawText(" FPS: " + App.FPS, 300, 0)End MethodMethod OnMouseEvent( event:MouseEvent ) OverrideIf event.Type = EventType.MouseDownLocal _len := 0If event.Button = MouseButton.Left Then _len = 512Local tmpimage:IntFor Local i:=1 Until _len + 1' Test to try to show the differences in sources and destinations of draws, uncomment one' ---------------------------------------------------------------------------------------' No problem wioth performance using barbarian as source to whatever destination' Myapp[ tmpimage ].Add( New sprite(Mouse.X, Mouse.Y, images[0])) ' Draws from barbarian to drawingboard & canvas' Myapp[ tmpimage ].Add( New sprite(Mouse.X, Mouse.Y, images[0])) ' Draws from barabarian to drawingboard & canvas' Slowdown happens when using checkerboard as sourceMyapp[ tmpimage ].Add( New sprite(Mouse.X, Mouse.Y, images[0])) ' Draws from barbarian to checkerboard & canvasMyapp[ tmpimage ].Add( New sprite(Mouse.X, Mouse.Y, image)) ' Draws from checkerboard to checkerboard & canvas (this drops the framrate sigininficatly in Monkey2)EndEndEnd MethodEndClass spriteField x: FloatField y: FloatField xspeed: FloatField yspeed: FloatField texture: ImageGlobal gravity := 0.2Method New( x: Float, y: Float, texture:Image )Self.x = x ; Self.y = y ; Self.texture = texture ; xspeed = random.Rnd(7)EndMethod Update:Void( )yspeed += gravity ; y += yspeed ; x += xspeedIf y >= VHEIGHT Then y = VHEIGHT ; yspeed = -random.Rnd( 25 )If x < 0 Or x > VWIDTH Then xspeed *= -1 ; x = Clamp(x, 0.0, Float(VWIDTH) )EndMethod Draw(canvas:Canvas)canvas.BlendMode = BlendMode.AlphaLocal w:Int = 64Local h:Int = 64Local rx:Int = -(w * 0.5)Local ry:Int = -(h * 0.5)canvas.PushMatrix()canvas.Translate(x,y)canvas.Rotate(Pi/4.0)canvas.DrawRect(rx+w,ry+h,-w,-h,texture,0*32,1*32,w,h)canvas.PopMatrix()EndEndFunction Main()New AppInstanceNew MyappApp.Run()End FunctionAttachments:
It’s such a simple problem but I probably said it wrong.
Say that you want to do this
– You want to draw thousands of images to the canvas, no performance issue.
– You might draw equally many images onto another image, no problem (it even outperforms the canvas, probably due to that images are often smaller, it’s really nice).The problem is the actual combo, and it’s an important combo to have in the toolbox.
Of course this is not about a once-initiated-pre-drawn-image, it’s about the need to do it continuously.
MonkeyX does it and the code above proves it even if it lacks the few lines that does the actual cookie-cutting which is just a bunch of DrawRect really.
Monkey2 on the other hand seem very picky about this?
This is the only gripe I have with Monkey2 now, I really need it to convert totally.
The reason I as is that I really need to draw a texture onto itself efficiently in Monkey2.
Separate experiments went well but throwing everything together made it a snail
Mx did it without resorting to opengl so if M2 differ in its implementation I would need to know how to be able to optimise things back. Are there examples on how to effeciently draw parts of an image onto itself and then draw that in turn onto the canvas? This chain of events are what seem to slow down everything in MX2. Do you need to do Ping pong rendering to do that? I don’t think the source above does it.
The MX source above produce exactly this and it does it well despite being so simple and straightforward. It gives you at least one layer of 64×64 of (shaded) tiles on all Android devices that I´ve tried so far. It’s a good minimum spec. On a PC or Mac you get 16-180 layers(!)
Doing this as efficitly on Monkey2 is the hardest bit when switching to Monkey2 for me.
Indeed don’t give up because of the fact how much time and effort and sacrifices that has gone to into come to this point. Monkey2 already starts to have the quality the masses wants. Just persist and go for those Youtube tutorials, it’s HUGE. Same goes to luxury customer pathways such as steam, and keep up the great communication that is already happening.
I read Mark’s already interested in polishing up things in the next release or so. A professional touch (not as in VisualStudio but as in install-and-create-something-wonderful-right-now) is needed to reach large groups of people.
This and to let people know that it exist and what it’s capable of, and what it can offer them.A few more incredible demos would also be helpful.
P.S. I will show my personal appreciation and backup as soon as I can afford. I really starts to love Monkey2. I can understand if it’s a mess under the hood right now. But let it take time. Everything good takes time.
I include an eloquent version that I used when I want to get the hang of how powerful M2 is.
Monkey2 is bad in fullscreen where Mx handles fullscreen equally good as windowed mode. This might not be a OS issue after all as MX manages to handle it perfectly.
Monkey2 got me 25k in windowed mode, while in fullscreen it becomes ….. 6k
But on older GPU’s this huge difference of fullscreen and windowed modes always seem to diminish.ANDROID numbers
MX seem to be the strongest compiler for my Yoga2 Android for instance (running Lollipop) and a bit weaker on the Samsung Note 4. The weakest being the Note2 and can clearly spot a speed difference between Note2 & Note4.Monkey2 on the other hand shows enormous power on the Samsung Note2, so much that the gap between Note2 and Note4 diminishes to almost nothing. Both gets very strong with M2. The downside is how incredibly weak M2 is with Yoga2. This is an amazingly strong machine and largly outclasses both Notes2&4 when MX is used, the opposite happens with M2 which is surprising.
– Samsung Note2 & Note 4 (suprisingly similiar in power when used togther with MX2) both manages 6K @ 60 fps
– Lenovo Yoga2 (surprisingly weak with MX2) manages 1.6K @ 60 fpsIt’s worth noting that all the equipment are 64-bit except Note2 which is 32-bit, and that Yoga are the only one with an Intel CPU.
Attachments:
November 18, 2017 at 5:46 pm in reply to: Home Run Tri Peaks Solitaire – Out Now on Google Play for Android #11807Looks awesome well done !
I can inform that fullscreen performance in some MacOS revisions are simply TERRIBLE.
Of course that has nothing to do with this example, it’s just a general statement.I’ve had Monkey1 and a semi-fresh MacOS for a long time and enjoyed it very much. I didn’t update on purpose as I knew about the risk of updating and I loved the retro feel to have a working fullscreen equally powerful as windowed apps. Last week I had to update MacOS & Xcode to get Monkey2 a try, and things broke terribly.
Anyways, I digress. The numbers for Monkey2 and freshest MacOS you can get are :
– fullscreen manages 12K while – Windowed manages 25K.
You’ll notice that things gets cut in half, there’s probably a screen-buffer in the way in the system.
To improve the number of draws, don’t forget to change the coordinates of all the draws from Float’s into Int’s.
For me this makes 6K into 25K.
Mind you that I replace the line that draws into canvas.DrawRect and used a larger sprite size of 64×64.
Regardless of drawing method, the scaling factor going from 6K into 25K is remarkable.It’s a really nice editor / IDE one of my favourites so far.
I miss few little things like including smileys and symbols in the remarks of the code as you could with the Monkey1 editor. It’s also sometimes important to be able to play around quickly with colours and fonts.
On the MacOS the font changer actually appears to be a retro file requester you need to find fonts for yourself instead of having the standard dropdown menu with previews? Maybe I’m doing it wrong.
I would like to throw out and mention additional ideas I would love to see :
– To be to be able to see and play all media right in the editor. Included pictures could appear in the source, and sounds could have a play button for instance.
– The search might get a “highlight all found words” mode where you could skip between all using actual keys instead of screen buttons. A more complex variant would be to also create an additional tab that gets filled with all the instances of found words as a list.
– Another idea would be live conversion of whatever the cursor is at, say a number will somehow offer other bases such as hex dec bin to be edited and viewed, and colours could couple RGB with names when actual names exist).
I don’t know if any of these ideas are sensible enough to implement or not but I for one would really enjoy having them.
I think I solved it myself, the x & y needs to be Int instead of Float.
This might work?
canvas.TextureFilteringEnabled = False
-
AuthorPosts