Forum Replies Created
-
AuthorPosts
-
No problem, I was also very interested in how well my code worked as so far it’s only had a 50% success rate!
Up to 75% now so I feel a bit better…
In this case I have this in my App class: App.SdlEventFilter = MySdlEventFilter , and then
This is weird because the latest code doesn’t use events at all!
Well, nearly, I still grab jevent->which for debugging, so jevent better never be NULL.
So some things to try: Remove ALL code from event handlers in joystick.monkey2. Check if other apps crash when joysticks are added/removed – maybe it’s an SDL event thing. Comment out stuff until it works. Stick some print statements around SDL calls – there shouldn’t be many of them left. You could also build a debug version and use gdb to debug it, but you’d have to tweak env_windows.txt a bit…Let me know if you want to try this.
I think the approach I’m using is good – in fact, latest SDL 2.0.7 adds a function that will make it even easier.
You could actually try latest SDL if you want, there are quite a few changes to joystick so they may have fixed something. Grab SDL 2.0.7 source from here: https://www.libsdl.org/download-2.0.php and copy the ‘include’ and ‘src’ dirs into the current sdl2/SDL dir, overwriting existing dirs (backup or whatever first!). Then, copy all the SDL_config_blah.h files from current include dir (ie: from your backup) to the new 2.0.7 include dir. Tried this yesterday and it seemed to work fine on windows, joystick and ted2go worked anyway. Much more testing to do before I can ‘officially’ upgrade sdl2 though.
After around 100 plug-unplug of two different gamepads I had no crash…
Thanks for super comprehensive test! I’ve also had SDL fail to register plugins a few times, but it never seems to cause any problems. Still, perhaps indicative of something bad going on in SDL, as I still get the ‘ping’ when it’s plugged in…but SDL misses it.
Tried with a XBox360 pad and a Pandora gamepad no crashes to report
Thanks!
(note to self: don’t edit posts by going back->edit->submit!)
It should be very easy to build from source on llnux – as long as you have also installed the myriad of dev-lib dependancies required on Linux. And you’ll need these for building monkey2 apps as well as monkey2 itself, so hosting a prebuilt version on Linux is of very little value.
On Windows and Macos this stuff is easy – all required dependancies are built-in to the c++ compilers used by monkey2.
However, on Linux installing g++ is just the start, you’ll also need to install things like the dev libs for x, opengl, and a ton of other obscure stuff depedending on what actual version of linux you’re using.
I would love to make monkey2 easier to use on Linux, but making it ‘apt-gettable’ or something would be a huge undertaking for me, given my limited knowledge of the relevant linux stuff, and I just can’t justify the time/effort/pain involved as the audience for Linux seems to be tiny to non-existant?
The nice thing is that once you do have it running on Linux, it’s pretty sweet (but I would say that)!
No idea – perhaps try asking on the chipmunk forums?
https://chipmunk-physics.net/forum/viewforum.php?f=1
Just using like the function above. Couldn’t think of a better way to check for “Any Key” being pressed.
You don’t need to pass rawkeys to KeyDown, you can just pass a plain ‘virtual’ key, eg: ‘Key.A’ or ‘Key.Z’ etc.
But to pass an int ‘key’ to KeyDown you’ll need to convert it to a ‘Key’ type first – in fact, this is probably all your use of ScanCodeToRawKey is really achieving here – In this case, it doesn’t really matter whether you pass virtual keys or rawkeys or banana keys to KeyDown, since you’re just throwing every possible value at it!
To convert an int to a key, you can ‘Cast<Key>( n )’ it – example below. But as people have noted there are other ways to do this too.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New( title:String="Simple mojo app",width:Int=640,height:Int=480,flags:WindowFlags=Null )Super.New( title,width,height,flags )EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )For Local i:=0 Until 512Local key:=Cast<Key>( i )If Keyboard.KeyDown( key ) Print "KeyDown:"+Keyboard.KeyName( key )EndEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndI did have a look into this andit’s doable but a bit complicated to make ‘nice’.
Just to clarify though, are you only wanting to apply a shader to a bunch of shapes? This is easier…
ScanCodeToRawKey is an internal function – it has been @hidden from docs, and should therefore be considered ‘use art your own risk’.
I’ve had to make it public in the past as monkey2 lacked an ‘Internal’ directive, ie: decls are visible to other module members only. But that has recently been added to monkey so I have made several methods/functions Internal.
What are you actually using it for?
Hmm, can’t find an Image.Window, do you perhaps mean Pixmap.Window?
It might have been more consistent if I’d used Image.Window, but the idea was for New Image( image,rect…) etc. to create a ‘window’ into an atlas that shares the same ‘material’ (ie: texture) as the atlas, thus minimizing renderstate changes.
But I messed up here, and each image created with New Image( image,rect… ) actually ended up with a new ‘material’ too, which caused a renderstate change for each DrawImage. Pretty easily fixed, although there’a a minor chance it may affect some existing code out there – will deal with that if/when it happens.
Yay, decided to do my own bunnymark based on ethernaut’s and found a pretty major issue in mojo!
You’re supposed to be able to use images as atlases in mojo, and New Image( image,x,y,w,h ) is supposed to ‘grab’ a frame from an atlas.
This works BUT currently also creates a new material for the frame instead of just sharing the same material as the atlas – so my version was initially slower than ethernaut’s by a large margin! Fixing this so that all images created from other images ‘share’ the same material gives a considerable speed up – was getting about 50K images @60hz with ethernaut’s version, now get about 180K with mine!
Will push this change to the repos soon.
My bunnymark (works but will be slow with current mx2):
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144Namespace bunnies#Import "assets/wabbit_alpha.png"#Import "<std>"#Import "<mojo>"Using std..Using mojo..Const initialCount := 10000Function Main()New AppInstanceNew BunnymarkApp.Run()End Function'******************************************************************************************************Class Bunnymark Extends WindowGlobal atlas:ImageGlobal frames:=New Image[4]Field bunnies := New Stack<Bunny>Method New()Super.New("Bunnymark", 1024, 768, WindowFlags.Resizable )atlas=Image.Load( "asset::wabbit_alpha.png" )For Local j:=0 Until 2For Local i:=0 Until 2frames[ j*2+i ]=New Image( atlas,i*32,i*64,32,64 )NextNextFor Local n := 0 Until initialCountbunnies.Push( New Bunny( 512, 384,frames[ Rnd(4) ] ) )NextEndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()If Keyboard.KeyReleased(Key.Escape) Then App.Terminate()canvas.Color = Color.Whitecanvas.DrawRect( 0, 0, App.ActiveWindow.Width , 25 )For Local bunny:=Eachin bunniesbunny.Update( canvas )Nextcanvas.Color = Color.Blackcanvas.DrawText("The Bunnymark ( " + bunnies.Length + " )",10,5)canvas.DrawText(" FPS: " + App.FPS, 250, 5 )canvas.DrawText(" Left mouse = +10, middle = +100, right = +1000 (hold alt key to remove) ", 450, 5 )EndMethod OnMouseEvent( event:MouseEvent ) OverrideIf event.Type = EventType.MouseDownLocal _len := 0If event.Button = MouseButton.Left_len = 10Elseif event.Button = MouseButton.Middle_len = 100Elseif event.Button = MouseButton.Right_len = 1000EndIf Keyboard.KeyDown( Key.LeftAlt ) Or Keyboard.KeyDown( Key.RightAlt )For Local n := 1 To _lenIf bunnies.Length Then bunnies.Pop()NextElseFor Local n := 1 To _lenbunnies.Push( New Bunny( Mouse.X, Mouse.Y,frames[ Rnd(4) ] ) )NextEndEndEndEnd'******************************************************************************************************Class BunnyGlobal gravity := 0.1Global border := 32.0Field x: FloatField y: FloatField xspeed: FloatField yspeed: FloatField maxBounce:= 5.0Field image:ImageMethod New( x:Float,y:Float,image:Image )Self.x = xSelf.y = yxspeed = Rnd( -10, 10 )Self.image=imageEndMethod Update:Void( canvas:Canvas )yspeed += gravityy += yspeedx += xspeedIf y < border*2y = border*2yspeed *= -1yspeed = Clamp( yspeed, 0.0, Float( maxBounce ) )EndIf y > App.ActiveWindow.Height - bordery = App.ActiveWindow.Height - borderyspeed = -random.Rnd( maxBounce * 3 )EndIf( x < border ) Or ( x > App.ActiveWindow.Width - border )xspeed *= -1x = Clamp( x, border, Float(App.ActiveWindow.Width - border ) )Endcanvas.DrawImage( image,x,y )EndEndI have never had any reports of a ‘true’ positive so I’m 99.999% sure you’re OK.
Should be possible, I will look into it.
But how does user ‘know’ they are using an extension and it’s safe to skip ‘?.’?
If there’s a possiblility an object could be Null, coder should always use ?. or check for null IMO, regardless of whether member is an extension or not. Extensions should behave as much like ‘normal’ methods as possible.
Making a special case for extensions just complicates the language more. My current thinking anyway…
Self can be null inside of extension.
I never really considered this, not sure if I like it or not!
[edit] Don’t think I do like it, esp now there’s ‘?.’ – please don’t depend on it in future.
Yes, this issue has been in there for ages and I should probably get round to doing something about it one of these days, just not quite sure what exactly!
-
AuthorPosts