Forum Replies Created
-
AuthorPosts
-
More convenient syntax for this will proabably happen, eg: $20000000L
Is it due to parser limitations? or is it a kind of visual helper? I’d personnaly rather like to be able to use any kind of literals up to Max_Unsigned_64bit without special syntax for bigger ones.
A 64bit enum type would be great too for bitmasking too!
I’d be glad to participate but finishing the box2d module is my priority for this begging of 2018..
Good Jam!
If you reach to computer limit, it’s normal that adding inputs, thus listeners calling their callback functions, will slow down the computer somehow. On my computer the code runs at 31 FPS so it’s crawling anyway!
Again you are using a lot of canvases. this is bad practice…
And you don’t need to Flush the main canvas at the end of OnRender, it’s done automatically. Canvas.Flush() is a greedy call, avoid it too..oh man! the generated image is very psychedelic! I had to jump on alt+F4!
about your code:
you are using two canvases, canvases slows down you computer, you’d probably will have better perfs with transform matrixes and a single canvas.And yes there’s a OnUpdate() event but also OnKeyEvent() and OnMouseEvent(). OnUpdate is not documented though!(will post issue). You can have a look at spacechimps banana to see an example of an app using both OnUpdate() and OnKeyEvent()
let’s say you’ve unzipped your monkey-develop from github to the Desktop (which is in the home folder).
on freshly installed Mint, I got build working typing the following, there may be some new libs to install now but it worked at the time :
Monkey1234567891011sudo apt-get update && sudo apt-get upgradesudo apt-get install g++-multilib libglu1-mesa-dev libopenal-dev libxi-dev libxrandr-dev libxinerama-dev libxcursor-dev libxxf86vm-dev libx11-dev libgl1-mesa-dev libpulse-devcd Desktopsudo chmod +x -R ./monkey2-developcd monkey2-develop/scripts./rebuildall2go.shIt looks like the 64bit thing is for apps using some native code. Pure Java is not concerned. I think mx1 outputs Java only.
I’ve been working on the module a bit.
Now wrapped (partially) the b2djson lib from iforce2d (The R.U.B.E. importer). Still have to implement images import.
Unfortunately it uses another json lib than mx2’s but it’s not that large. And I did not want to dig into cpp to use the mx2 json module.
The loader is compatible with the mx2 asset construct thus compatible with Android (tested).On the pure box2d side, I have to work on Callbacks, collisions and wrapping b2d’s generic functions to have the api fully wrapped. Buoyancy is on the list too.
Should be continuing in January, Christmas events are taking more time that expected, as usual..
Mmm testing it gives duplicate Main()… could be reserved to modules! will check and try to find the docs where a read this..
EDIT: yep it’s for modules only so it can be a bit of work just for a simple init…
But it’s great design!
can not be indexed
the []= operator can be user defined (it’s used in json, map,…)
To initialize your classes you’ll have to do some of the work in a Function. But note that monkey can have several mains! You can import a .monkey2 file like init.monkey2 and in that file make all you initializations in “function main”. The main of init.monkey2 will run before the main.monkey2’s main. I think it’s the cleanest way to init you program. Or you could just have a InitGlobals() function called in main so you main remain clean..
I’ve asked several times Playniax to created a repo but it looks like he’s not really into Git…
You can ask in the Pyro2 topic in the projects section. http://monkeycoder.co.nz/forums/topic/pyro-pyro-editor-for-monkey2-progress-report/I think the Pyro2 license allows you to create a repo but it’d be much better to fork the original of course.
here’s a sample code to test signed integers
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142Namespace myapp#Import "<std>"Using std..Function Main()Print "signed Byte test"Local l:ULong=Pow(2,7)-1Local b:Byte=lPrint bb+=1Print bPrint "signed Short test"l=Pow(2,15)-1Local s:Short=lPrint ss+=1Print sPrint "signed Int test"l=Pow(2,31)-1Local i:Int=lPrint ii+=1Print iPrint "signed Long test"'l=Pow(2,63)-1 this doesn't work probably due to Pow using Double thus caping somehowl=9223372036854775807 'note that there is a bug with ted2 and you can not enter larger litterals so for larger values you'll have to use StringToUlongLocal sl:Long=lPrint slsl+=1Print slEndI think the max is always the same wether it uses one or two complement or magnitude..
You could import limit.h and get the values from there? But C++ Int is not always 32 bit?
Unsigned is easy because they are represented the same on all machines:
UByte(8bits) Max = (2^8)-1 = 255
UShort(16bits) Max = (2^16)-1 = 65535
UInt(32bits) Max = (2^32)-1 = 4294967295
Ulong(64bits) Max = (2^64)-1 = 18446744073709551615For signed it is usually one bit less but can be sometimes padded.
if not padded (if padded remove one more bit?)
Byte(8bits) Max = (2^7)-1 = 127
Short(16bits) Max = (2^15)-1 = 32767
Int(32bits) Max = (2^31)-1 = 2147483647
Long(64bits) Max = (2^63)-1 = 9223372036854775807some little tests would be enough to fix your different signed maxs
Hmmm, I thought I read Mark had changed the GC…
Oops my bad, was not aware of that! Might be unsafe to play with pointers then. Using a very local pointer should do the trick though.
I wrote a SVG parser, that makes everything into shapes, path segmets, lines etc. Then I triangulate that, and then DrawPrimitives()
Sounds great! Do plan to share this at a time?
Some small pimping..
now debug:
Monkey12345678910111213141516171819OriginalVersion = 67OriginalVersion = 67176AbakoboVersion = 65AbakoboVersion = 65788impixiVersion = 4impixiVersion = 3503NewVersion = 2NewVersion = 2501Tileset3 = 2Tileset3 = 2002Tileset4 = 1Tileset4 = 501Total microsecs for 100 loops :orig: 6746617abak: 6623185impi: 356210tileset2: 236657tileset3: 189626tileset4: 64550Release:
Monkey12345678910111213141516171819OriginalVersion = 28OriginalVersion = 27316AbakoboVersion = 29AbakoboVersion = 29003impixiVersion = 1impixiVersion = 1004NewVersion = 0NewVersion = 500Tileset3 = 1Tileset3 = 500Tileset4 = 0Tileset4 = 0Total microsecs after 100 loops:orig: 2945291abak: 2924291impi: 101610tileset2: 76025tileset3: 45032tileset4: 26521For the “new” Tileset class I loaded a Padded png (545*18)
Tileset2 is the original “NewVersion”
Tileset3 is just moving color declaration outise of the loop. sometimes it has no/bad effect depending on how the loop is looped (100 times a list of each one or a list of 100 times each one)
Tileset4 uses Pointer to read into memory (sometimes returns 0 microsec (or 500 or 501!?) not shure it work ok but looks like.Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416Namespace myapp#Import "<std>"#Import "<mojo>"#Import "assets/"Using std..Using mojo..Const Size:=New Vec2i( 320,200 )Class MyWindow Extends WindowField tileSet:Image[]Field tileSetMask:Int[,,]Field tileSetClass:TileSetField tileSetClass2:TileSet2Field tileSetClass3:TileSet3Field tileSetClass4:TileSet4Method New()Super.New( "My Window",1024,768,WindowFlags.Resizable )Window.ClearColor = Color.BlackLayout="letterbox"tileSet = LoadSpriteSheet("tileset.png", 32, 16, 16)tileSetMask = New Int[32, 16, 16]Local s := Millisecs()Local n := Microsecs()Local averageFloor:=100Local orig: LongLocal abak: LongLocal impi: LongLocal new1: LongLocal new2: LongLocal new3: LongFor Local averageCount:=1 To averageFloors = Millisecs()n = Microsecs()OriginalVersion()orig+=Microsecs()-nPrint "OriginalVersion = " +(Millisecs()-s)Print "OriginalVersion = " +(Microsecs()-n)s = Millisecs()n = Microsecs()AbakoboVersion()abak+=Microsecs()-nPrint "AbakoboVersion = " +(Millisecs()-s)Print "AbakoboVersion = " +(Microsecs()-n)s = Millisecs()n = Microsecs()tileSetClass = New TileSet("asset::tileset.png", 16, 16)impi+=Microsecs()-nPrint "impixiVersion = " +(Millisecs()-s)Print "impixiVersion = " +(Microsecs()-n)s = Millisecs()n = Microsecs()tileSetClass2 = New TileSet2("tilesetpad.png", 32, 16, 16)new1+=Microsecs()-nPrint "NewVersion = " +(Millisecs()-s)Print "NewVersion = " +(Microsecs()-n)s = Millisecs()n = Microsecs()tileSetClass3 = New TileSet3("tilesetpad.png", 32, 16, 16)new2+=Microsecs()-nPrint "Tileset3 = " +(Millisecs()-s)Print "Tileset3 = " +(Microsecs()-n)s = Millisecs()n = Microsecs()tileSetClass4 = New TileSet4("tilesetpad.png", 32, 16, 16)new3+=Microsecs()-nPrint "Tileset4 = " +(Millisecs()-s)Print "Tileset4 = " +(Microsecs()-n)Print averageCount+" percent done."Print averageCount+" percent done."Print averageCount+" percent done."Print averageCount+" percent done."Print averageCount+" percent done."NextPrint "orig: "+origPrint "abak: "+abakPrint "impi: "+impiPrint "tileset2: "+new1Print "tileset3: "+new2Print "tileset4: "+new3EndMethod OnRender( canvas:Canvas ) Overridecanvas.TextureFilteringEnabled = FalseApp.RequestRender()canvas.DrawImage(tileSetClass.imgAtlas, 0, 0)canvas.DrawImage(tileSetClass.imgAtlasMask, tileSetClass.imgAtlas.Width, 0)Local drawTileIndex:Int = 29For Local y := 0 To 16 - 1For Local x := 0 To 16 - 1If drawTileIndex > - 1If tileSetClass2.tileSetMask[drawTileIndex, x, y] > 0canvas.Color = Color.Orangecanvas.DrawRect(x + 150 , y + 150, 1, 1)canvas.Color = Color.WhiteEndEndEndEndEndMethod OnMeasure:Vec2i() OverrideReturn SizeEndMethod AbakoboVersion()For Local i:Int = 0 Until tileSet.LengthLocal tmpCanvas := New Canvas(tileSet[i])Local px := tmpCanvas.CopyPixmap(tmpCanvas.Viewport)Local pixPtr:UInt Ptr 'to declare only once so i's not created each time in the loop (more usefull with structs (like Color) or classes or arrays intanciation...'RGBA8(per channel) is the default pixel format but can be different. 4*8=32bit long thus UIntFor Local y := 0 To px.Height - 1pixPtr=Cast<UInt Ptr>( px.PixelPtr( 0,y ) )For Local x := 0 To px.Width - 1If pixPtr[x]&$FF000000>0 'Bitwise opertor to check if there is some alpha (8 leftside bits of RGBA32(read ABGR! Endianess?) thus &$FF000000 to clear the BGR 24 bits. (is there a problem with the pixel format documentation? or is it reading small from big?)tileSetMask[i, x, y] = 1ElsetileSetMask[i, x, y] = 0EndEndEndNextEndMethod OriginalVersion()For Local i:Int = 0 Until tileSet.LengthLocal tmpCanvas := New Canvas(tileSet[i])Local px := tmpCanvas.CopyPixmap(tmpCanvas.Viewport)For Local y := 0 To px.Height - 1For Local x := 0 To px.Width - 1Local color:Color = px.GetPixel(x, y)If color.A > 0tileSetMask[i, x, y] = 1ElsetileSetMask[i, x, y] = 0EndEndEndNextEndEndClass TileSetPublicMethod New(url:String, tileWidth:Int, tileHeight:Int)Local pmAtlas := Pixmap.Load(url, PixelFormat.Unknown)If Not pmAtlas Then RuntimeError("Could not load spritesheet: " + url)Local tileCount := (pmAtlas.Width / tileWidth) * (pmAtlas.Height / tileHeight)Local pmAtlasMask := New Pixmap(pmAtlas.Width, pmAtlas.Height, PixelFormat.I8)Local pmAtlasDataPtr:UByte Ptr = pmAtlas.Data + Cast<UByte>(pmAtlas.Depth - 1)Local pmAtlasMaskDataPtr:UByte Ptr = pmAtlasMask.Data + Cast<UByte>(pmAtlasMask.Depth - 1)Local pidx:ULong = 0While pidx < (pmAtlas.Width * pmAtlas.Height)If pmAtlasDataPtr[0] > 0pmAtlasMaskDataPtr[0] = 255ElsepmAtlasMaskDataPtr[0] = 0EndifpmAtlasDataPtr += Cast<UByte>(pmAtlas.Depth)pmAtlasMaskDataPtr += Cast<UByte>(pmAtlasMask.Depth)pidx += 1WendimgAtlas = Image.Load(url)imgAtlasMask = New Image(pmAtlasMask)pmAtlas.Discard()EndField imgAtlas:ImageField imgAtlasMask:ImageEndClass TileSet2Field tileSetMask:Int[,,]Field tileSet:Image[]Method New(path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, preScale:Float = 1.0, padding:Int = 0, border:Int = 0, prefix:String = "asset::", format:PixelFormat = PixelFormat.Unknown)Local pixmap := Pixmap.Load(prefix + path, format )Assert( pixmap, " ~n ~nGameGraphics: Pixmap " + path + " not found.~n ~n" )tileSetMask = New Int[numFrames, cellWidth, cellHeight]Local imgs := New Image[ numFrames ]Local atlasImg := New Image( pixmap )Local paddedWidth := cellWidth + ( padding * 2 )Local paddedHeight := cellHeight + ( padding * 2 )Local columns:Int = ( atlasImg.Width - border - border ) / paddedWidthFor Local i := 0 Until numFramesLocal col := i Mod columnsLocal x := ( col * paddedWidth ) + padding + borderLocal y := ( ( i / columns ) * paddedHeight ) + padding + borderimgs[i] = New Image( atlasImg, New Recti( x , y, x + cellWidth, y + cellHeight ) )imgs[i].Scale = New Vec2f( preScale, preScale )For Local k := 0 To cellHeight - 1For Local j := 0 To cellWidth - 1Local color:Color = pixmap.GetPixel(x + j, y + k)'Print "i = " + i + " j = " + j + " k = " + kIf color.A > 0tileSetMask[i, j, k] = 1ElsetileSetMask[i, j, k] = 0EndEndEndNextatlasImg = NulltileSet = imgsEndEndClass TileSet3Field tileSetMask:Int[,,]Field tileSet:Image[]Method New(path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, preScale:Float = 1.0, padding:Int = 0, border:Int = 0, prefix:String = "asset::", format:PixelFormat = PixelFormat.Unknown)Local pixmap := Pixmap.Load(prefix + path, format )Assert( pixmap, " ~n ~nGameGraphics: Pixmap " + path + " not found.~n ~n" )If pixmap.Format<>PixelFormat.RGBA8Print "wrong pixel format need RGBA8"ElsetileSetMask = New Int[numFrames, cellWidth, cellHeight]Local imgs := New Image[ numFrames ]Local atlasImg := New Image( pixmap )Local paddedWidth := cellWidth + ( padding * 2 )Local paddedHeight := cellHeight + ( padding * 2 )Local columns:Int = ( atlasImg.Width - border - border ) / paddedWidthFor Local i := 0 Until numFramesLocal col := i Mod columnsLocal x := ( col * paddedWidth ) + padding + borderLocal y := ( ( i / columns ) * paddedHeight ) + padding + borderimgs[i] = New Image( atlasImg, New Recti( x , y, x + cellWidth, y + cellHeight ) )imgs[i].Scale = New Vec2f( preScale, preScale )Local color:ColorFor Local k := 0 To cellHeight - 1For Local j := 0 To cellWidth - 1color = pixmap.GetPixel(x + j, y + k)'Print "i = " + i + " j = " + j + " k = " + kIf color.A > 0tileSetMask[i, j, k] = 1ElsetileSetMask[i, j, k] = 0EndEndEndNextatlasImg = NulltileSet = imgsEndEndEndClass TileSet4Field tileSetMask:Int[,,]Field tileSet:Image[]Method New(path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, preScale:Float = 1.0, padding:Int = 0, border:Int = 0, prefix:String = "asset::", format:PixelFormat = PixelFormat.Unknown)Local pixmap := Pixmap.Load(prefix + path, format )Assert( pixmap, " ~n ~nGameGraphics: Pixmap " + path + " not found.~n ~n" )If pixmap.Format<>PixelFormat.RGBA8Print "wrong pixel format need RGBA8"ElsetileSetMask = New Int[numFrames, cellWidth, cellHeight]Local imgs := New Image[ numFrames ]Local atlasImg := New Image( pixmap )Local paddedWidth := cellWidth + ( padding * 2 )Local paddedHeight := cellHeight + ( padding * 2 )Local columns:Int = ( atlasImg.Width - border - border ) / paddedWidthFor Local i := 0 Until numFramesLocal col := i Mod columnsLocal x := ( col * paddedWidth ) + padding + borderLocal y := ( ( i / columns ) * paddedHeight ) + padding + borderimgs[i] = New Image( atlasImg, New Recti( x , y, x + cellWidth, y + cellHeight ) )imgs[i].Scale = New Vec2f( preScale, preScale )'Local color:ColorLocal pixPtr:UInt PtrFor Local k := 0 To cellHeight - 1pixPtr=Cast<UInt Ptr>( pixmap.PixelPtr( x,y+k ) )For Local j := 0 To cellWidth - 1'color = pixmap.GetPixel(x + j, y + k)'Print "i = " + i + " j = " + j + " k = " + kIf pixPtr[j]&$FF000000>0tileSetMask[i, j, k] = 1ElsetileSetMask[i, j, k] = 0EndEndEnd#remLocal pixPtr:UInt Ptr 'to declare only once so i's not created each time in the loop (more usefull with structs (like Color) or classes or arrays intanciation...'RGBA8(per channel) is the default pixel format but can be different. 4*8=32bit long thus UIntFor Local y := 0 To px.Height - 1pixPtr=Cast<UInt Ptr>( px.PixelPtr( 0,y ) )For Local x := 0 To px.Width - 1If pixPtr[x]&$FF000000>0 'Bitwise opertor to check if there is some alpha (8 leftside bits of RGBA32(read ABGR! Endianess?) thus &$FF000000 to clear the BGR 24 bits. (is there a problem with the pixel format documentation? or is it reading small from big?)tileSetMask[i, x, y] = 1ElsetileSetMask[i, x, y] = 0EndEnd#EndNextatlasImg = NulltileSet = imgsEndEndEndFunction LoadSpriteSheet:Image[] (path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, preScale:Float = 1.0, padding:Int = 0, border:Int = 0, prefix:String = "asset::")Local atlasTexture := Texture.Load(prefix + path, Null )Assert( atlasTexture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )Local imgs := New Image[ numFrames ]Local atlasImg := New Image( atlasTexture )Local paddedWidth := cellWidth + ( padding * 2 )Local paddedHeight := cellHeight + ( padding * 2 )Local columns:Int = ( atlasImg.Width - border - border ) / paddedWidthFor Local i := 0 Until numFramesLocal col := i Mod columnsLocal x := ( col * paddedWidth ) + padding + borderLocal y := ( ( i / columns ) * paddedHeight ) + padding + borderimgs[i] = New Image( atlasImg, New Recti( x , y, x + cellWidth, y + cellHeight ) )imgs[i].Scale = New Vec2f( preScale, preScale )NextatlasImg = NullReturn imgsEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndAttachments:
-
AuthorPosts