Forum Replies Created
-
AuthorPosts
-
OriginalVersion = 20ms
OriginalVersion = 20000μs
AbakoboVersion = 18ms
AbakoboVersion = 18022μsMmm! Direct pointer usage was not a great gain (but still a gain ? or just cache work? ;). It was the key to speed in a Julia set fractal generator..
Not using Canvas operation was the major key for shure!Note that Image and Pixmap (extends Ressource) are not GCed so you you have to .Discard() them before replacing/loosing them or you’ll leak memory. But as the are not GCed Mark won’t tell it’s not safe to point to them!?I have to install these to get it to work on linux Mint
Monkey1234sudo 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-devI would start to try with someting like that (not tested) (might create problems with lighnting and image shaders..?):
Monkey12345678910111213141516171819For 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 pptr[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] = 0EndEndEndNextBut I would also try to work with pixmaps until the last moment and as few canvas work as possible (using PastePixmap at the end can be usefull sometimes). I think it is generally faster but i’m not shure about that (and what about lighnint and shaders integrity). Not faster for drawing plain bitmaps/inmages to the target render/mojocanvas I guess…
If you can, try to use an array of Pixmaps instead of array of Images and then use pointer to read/write directly in the memory (like in the example) without using methods (even functions ?) when you are in an intensive loop spot. Reading/Writing pix per pix can be intense.
There’s also a shader approach as an option (more technical but might use GPU’s parallel computing ability, with pure mx2 you have no (parallel)multi-threading).Welcome!
about the physics engine, chipmunk is included in mx2. And there is a tutorial for it! :https://github.com/peterigz/Monkey2Tutorials
I started to work on Box2D and should continue (and finish it) this end of December.
https://github.com/abakobo/Box2DI finaly decided to go with std::copy so I keep the memory allocated by mx2 and don’t have to worry about GC/memory stuffs.
It’s passing a fixed size char_t array and then transforms it to string when back to mx2. It the way I felt the safest (with my knowledge;)the aim was to deal with the error message..
cpp side
Monkey12345678910111213141516171819202122b2World* b2dJsonReadFromFile_ext (const char* filename, char* charErrMsg, int charsize, b2World* existingWorld) {std::string errMsg;b2dJson json;b2World* returnWorld = json.readFromFile(filename, errMsg, existingWorld );if (charsize>8) { // the char array must have a certain size..if (errMsg.size()<charsize-2){std::copy(errMsg.begin(), errMsg.end(), charErrMsg);}else {std::string errMsgBis;errMsgBis = errMsg.substr (0,charsize-3);std::copy(errMsgBis.begin(), errMsgBis.end(), charErrMsg);charErrMsg[errMsgBis.size()] = '\0'; // terminating the cstring}}return returnWorld;}mx2 side
Monkey123456789101112131415161718192021ExternFunction b2dJsonReadFromFile_ext:b2World(filename:CString , errorMsg:char_t Ptr , charsize:Int , existingWorld:b2World = Null)PublicFunction b2dJsonReadFromFile:b2World(filename:String , existingWorld:b2World = Null)Local maxChrSize:Int=321Local buf:=New char_t[maxChrSize]Local retWorld:=b2dJsonReadFromFile_ext(filename , buf.Data , maxChrSize , existingWorld )#If __DEBUG__'print the error message if in debug modePrint String.FromCString( buf.Data )#EndifReturn retWorldEndthere’s the std::string.c_str() method that returns a char array, i’ll go with thar cpp side..
Maybe using a backslash before your char will skip is markdown code.
Can’t reproduce the artifacts I had at a time. All working good now! (not using alpha)
I’ve had problems saving the pixmap to png too. I think it uses some png compression by default thus artifacts. It’s probably just a flag under the hood though.
Gandalf of Sophisticated Basic Compiler Design.
I found a new name that would fit fine with google search!
MOINOBA (MOnkey Is NOt BAsic) (erm just joking …)
and passing by reference could be useful in some designs!
Monkey12345678910111213141516171819202122232425262728Namespace myapp#Import "<std>"Using std..Function Main()Local f:Int(Int Ptr)f=fun1f+=fun2Local j:Intj=5Print f(Varptr j)EndFunction fun1:Int(i:Int Ptr)Print "fun1: "+i[0]i[0]=i[0]*2Return i[0]EndFunction fun2:Int(i:Int Ptr)Print "fun2: "+i[0]i[0]=i[0]*3Return i[0]EndHere’s is some (more) discovery of undocumented behaviour..
Is it expected behaviour?
Monkey1234567891011121314151617181920212223242526Namespace myapp#Import "<std>"Using std..Function Main()Local f:Int(Int)' f=fun1+fun2 'returns error "Types must be primitive" at semantingf=fun1' f=f+fun2 'returns error "Types must be primitive" at semantingf+=fun2Print f(5) ' will run both funcs and get the return of the last oneEndFunction fun1:Int(i:Int)Print "fun1: "+iReturn i*2EndFunction fun2:Int(i:Int)Print "fun2: "+iReturn i*3EndNot sure what is your problem here but you can have a lot CR or LF or CRLF in a single string.
Do you mean the string does not contain any ~n(LF #10) or ~r(CR #13) any more? i.e. when you print it, the line return are not there anymore? Do you mean “into Monkey I get ALL then lines in one line“?
When I load a string with LoadString I then have to split it in lines to process it with some line per line logic.
Monkey1234567891011Local bigString:=LoadString("mytext.txt",true) 'true to convert eol to LF onlyIf bigString<>NullFor Local line:=Eachin bigString.Split("~n")NextEndiforlines:=bigString.Split("~n") ' this create an array with all the lines without the LF ate the endIt’s not really weird. It’s first class functions. If you forget the brackets you’ll pass the function itself not it’s result. But it’s true it’s a bit surprising the first time.
I’m not sure to understand what you’re looking for but may be pixmaps are what you need!? It helped me to boost some processes sometimes.
with the PastePixmap for example. And you can modify pixmaps pixels using direct pointer access too (for plot by plot faster drawing. There’s is also discussions about shaders in the help forums too.
Monkey12image.Texture.PastePixmap( pixmap,0,0 )canvas.DrawImage( image,0,0 ) -
AuthorPosts