Forum Replies Created
-
AuthorPosts
-
This is as far I as go with it, now I need to figure out the datatype conversions. Whoever can continue it, will help a lot.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#Import "<windows.h>"#Import "<libuser32.a>"ExternFunction MessageBoxA:Int(hWnd:Int, lpText:CString, lpCaption:CString, uType:Int)Function GetDesktopWindow:Int Ptr()Function GetForegroundWindow:Int Ptr()Function GetWindowRect:Bool(hWnd:Int Ptr, rect:Rect Ptr)PublicStruct Rect ' StructLayout(LayoutKind.Sequential)Field Left:IntField Top:IntField Right:IntField Bottom:IntMethod To:String()Return "Rect (" + Left + ", " + Top + ", " + Right + ", " + Bottom + ")"EndEndFunction CaptureWindow(handle:Int Ptr) ' should return BitmapLocal rect := New RectGetWindowRect(handle, Varptr rect)'http://www.pinvoke.net/search.aspx?search=GetWindowRect&namespace=[All]'Print(rect)' var bounds = new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);' var result = new Bitmap(bounds.Width, bounds.Height);' using (var graphics = Graphics.FromImage(result))' {' graphics.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size);' }' return result;EndFunction CaptureDesktop()CaptureWindow(GetDesktopWindow())EndFunction CaptureActiveWindow()CaptureWindow(GetForegroundWindow())EndFunction Main:Void()' Tests'MessageBoxA(Null, "Test", "Test", 0)'Print(Cast<Int>(GetDesktopWindow())) ' OK'Print(Cast<Int>(GetForegroundWindow())) ' OKCaptureDesktop()EndHi Aaron we had a talk about Classes VS Structs here.
http://monkey2.monkey-x.com/forums/topic/struct-goofiness/#post-7734In C the concept of reference/value is about how you want to pass your structs into mutator functions. If you pass a struct by value it is made into a copy, but if you pass it by reference it means that you pass the address of the struct – not the actual struct.
In object oriented programming languages it’s something else, it means that objects are something like virtual datatypes which have meaning inside the language runtime, but not 100% direct meaning to the operating system overall. For example in C if you declare an integer it means 4 bytes of memory, but in an object oriented language it means an object that is an integer datatype.
In Monkey i found that if you want to mutate structs you need to do something like this:
Monkey1234567891011121314151617#Import "<mojo>"Using mojo..Struct TypeStructField Test:StringEndFunction ChangeTypeStruct(t:TypeStruct Ptr, message:String)t->Test = messageEndFunction Main()New AppInstanceLocal t := New TypeStructChangeTypeStruct(Varptr t, "Hello")Print(t.Test)EndFor the record monkey2 has a Vector2 class, unless you want to increase your experience and writing it yourself.
Also I found today that with the powers of reflection you can literally change the objects at runtime. See reflectiontest.monkey2 example.
Most common case is to load images is as PNGs, like you load the graphic in Krita and delete the background, alternatively there would be a case that you create the image in memory from scratch. You load the source image, and then read each pixel by pixel – depending on what masked pixels you want to make transparent, you simply won’t draw it. It seems possibly a good idea that it would work, and it would be reusable.
From Mark’s blog…
http://monkey2.monkey-x.com/
“However, unlike real threads, fibers don’t run ‘in parallel’.”I had tried also some stuff with fibers a while ago and I found that their usage is quite limited, but it’s very specific. From what I found in practical terms, fibers are more useful in event oriented applications (like Ted2Go) where you don’t want your application run in a 60fps loop but neither you want intense loops to freeze your user interface. For example if you have an intense loop, you can throw it in a thread, to let your main app – the gui mostly – be responsive.
Generally if your game runs at 60fps you won’t have any problems to use fibers, unless you want to do even more intense calculations (like lightmapping).
You need macros for processor logic or for generating code?
Hi, the code seems very simple but it is very minified, seems hard to examine. Perhaps I could use a lua IDE and start to rename the variables a bit just to clear things out. However it is impressive.
I had also an idea about squeezing it in Ted2Go, perhaps in the summer I will go for it.
Perhaps there could be a chance that they accept this syntax.
https://help.github.com/articles/creating-and-highlighting-code-blocks/
I did a measurement to see for real, time is in millisecs.
Monkey123456789Created: 1000000 items.Starting Test ATime Elapsed: 160Starting Test BTime Elapsed: 64Starting Test CTime Elapsed: 158Starting Test DTime Elapsed: 157Some back story behind this test.
In real circumstances someone would go for the option A which is the most obvious and well understood concept. So this means that it’s end of story.____ All of the other ways are most close to the concept of internal DSLs (I learnt about it these days) it’s about how you can utilize these techniques to create a very smooth API. ____ Option B converts your list to array, Option D proves how Monkey can use the To operator effectively to convert from List to List<B>. However option C is my favorite because it provides this smooth API transition, this way you can bypass internal class contents and let the object present itself according to how it is called (To operator in action).
Regarding the benchmarks
One striking thing to note in these benchmarks is that I never expected that array iteration (B) would be this fast. I had a subconscious fear for this due to this array conversion, (from the point I have a list ready to use – I see no reason to convert it to a list and iterate it) – however as it seems there is some compiler logic that make this happen. As far as I see this conversion happens only once, then the compiler will have to jump straight into array blocks. On the other hand option (A) as it involves objects and pointers, makes accessing the memory much more complicated.In the world of C structs technically are a collection of variables, where this is the only way that the data of the program can be modeled.
However in other object oriented languages, usage of structs has been limited to some very specific purposes. You have to be totally responsible why you need to use structs. Perhaps you might need, compatibility with native C libraries, or having some binary memory alignment, or have some “structs” with very precise lifescope.
Elevating the features of structs is a trap that high level programming languages make. Perhaps other programming languages as C# want to make life easier and provide some useful features. But in the end it only makes things complicated, because makes design choices ambiguous.
In practical terms, it’s not about gaining any benefits in speed or efficiency. One user in this forum created some benchmarks to see the difference in speed between classes and structs and the difference is less than 30% (structs are faster).
I had created a few weeks a test on this, however this is very unpolished and not tested. In the future once I come up with better ideas and a nice API for this I will post the results. For example autofit, change from portrait to landscape, dynamically, zooming, etc…
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class VirtualWindowPrivateField xCenter:Int, yCenter:IntField xOrigin:Int, yOrigin:IntField originalWidth:Int, originalHeight:IntField virtualWidth:Int, virtualHeight:IntPublicProperty Width:Int()Return virtualWidthEndProperty Height:Int()Return virtualHeightEndMethod New(originalWidth:Int, originalHeight:Int, virtualWidth:Int, virtualHeight:Int)Self.originalWidth = originalWidthSelf.originalHeight = originalHeightSelf.virtualWidth = virtualWidthSelf.virtualHeight = virtualHeightxCenter = originalWidth / 2yCenter = originalHeight / 2xOrigin = xCenter - (virtualWidth / 2)yOrigin = yCenter - (virtualHeight / 2)EndMethod DrawFunction(canvas:Canvas, func:Void(canvas:Canvas))' canvas.Translate(-xOrigin, -yOrigin)canvas.PushMatrix()canvas.Translate(xOrigin, yOrigin)canvas.Color = New Color(0.3, 0.3, 0.3)canvas.DrawRect(0, 0, virtualWidth, virtualHeight)func(canvas)canvas.PopMatrix()EndMethod CoordsToVirtual:Vec2i(realX:Int, realY:Int)Return New Vec2i(realX - xOrigin, realY - yOrigin)EndMethod CoordsToReal:Vec2i(virtX:Int, virtY:Int)Return New Vec2i(virtX + xOrigin, virtY + yOrigin)EndEndClass MyApp Extends WindowField viwin:VirtualWindowMethod New(title:String, width:Int, height:Int)Super.New(title, width, height)viwin = New VirtualWindow(width, height, 480, 720)EndMethod OnRender(canvas:Canvas) Override' Get Some CoordinatesLocal coords := viwin.CoordsToVirtual(Mouse.X, Mouse.Y)' := Mouse.X, ypos := Mouse.YIf coords.X < 0 Then coords.X = 0If coords.X > viwin.Width Then coords.X = viwin.WidthIf coords.Y < 0 Then coords.Y = 0If coords.Y > viwin.Height Then coords.Y = viwin.HeightApp.RequestRender()' Draw Things Inside The Virtual Spaceviwin.DrawFunction(canvas, Lambda(c:Canvas)canvas.Color = Color.Whitecanvas.DrawText("Real Coords: " + viwin.CoordsToReal(coords.X, coords.Y), 0, 0)canvas.DrawText("Virt Coords: " + coords, 0, 20 )canvas.Color = New Color(0.8, 0.1, 0.2)canvas.DrawCircle(coords.X, coords.Y, 10)End)canvas.Flush()EndEndFunction Main()New AppInstanceNew MyApp("Monkey2 Virtual Window", 1280, 720)App.Run()EndMy inspiration comes mostly from the 3D rendering and not from exactly from “virtual drawing”. In essence this might go for something like a “camera” approach. The essence is to consider that your game takes place in a “virtual space” and not on actual screen pixels (either real pixels or virtual pixels). For example lets say that you want to render the environment for basketball game, you might put instead of a pixel resolution the actual dimensions of the arena. This is a clever way to abstract your thinking from screen pixels.
See here: http://stackoverflow.com/questions/9000485/how-to-compile-a-directx-11-app-in-mingw
Hi, welcome to the community, when I started learning Monkey2 was only about anything related to syntax, I could transfer my skills from C# easily, however the only thing that I found trouble was the syntax. Many information can be found in the previous MonkeyX, the languages share lots of similarities.
https://www.monkey-x.com/docs/html/Home.html -
AuthorPosts