April 2018 Monthly-ish update!

Hey ho mighty Patreon supporters and assorted lesser beings,

OK, monkey2 version 2018.04 is out! Again, this pre-built release is for patreon supporters only but you can pretty easily build it yourself from source. As always, if you’ve donated to the monkey2 cause via the itch.io page (or otherwise), feel free to contact me for a copy of 2018.04 if you want. I hope to solve this little wrinkle with ‘buying’ monkey2 later. The itch.io page is here: https://blitzresearch.itch.io/monkey2-private

I’ve made some good progress on the reflection/serialization side of things to the point where you can now ‘view’ serialized scenes in ted2go! I’ve added some demo ‘.mojo3d’ files to the release in the root monkey2 directory – just double click on them to open in a new tab. The actual file format involved is really just json so you can also go in and tweak scene files quite easily.

This is all still very much WIP but it does most of what I wanted it to do already. The actual ‘schema’ of the json stuff is yet to be finalized too so perhaps best not to get too carried away with generating scenes just yet.

To actually create a scene file in a mojo3d app is pretty easy, you just need to do 3 things:

* Enable reflection for mojo3d. This is done by adding a ‘#Reflect mojo3d’ somewhere at the top of an app source file, eg: just after your #Imports.

* Enabled ‘editing’ for your scene. To do this, you will need to create a new Scene instance and pass ‘true’ to the constructor, eg: _scene=New Scene( True ). You need to do this before creating any entities, materials, textures etc.

* Save you scene somewhere via the Scene.Save method, eg: _scene.Save( “myscene.mojo3d” ).

You should end up with a scene file you can open in ted2go. Have a look at the source code for the included scene files eg: modules/mojo3d/tests/shapes-scene.monkey2 for an example.

Note that the system only handles mojo3d stuff, and even then not everything. I’ve mainly concentrated on getting cameras, lights, models (procedural models created via Model.CreateBox etc) and the physics components going. Not hierarchy support yet, and anything that involves ‘Load’ (only Model.Load and PbrMaterial.Load have been implemented so far) is likely to be very flaky as I only got that going for the first time yesterday! I would like to eventually get this stuff working at a broader scope than for just mojo3d scenes, but for the near future at least this stuff will remain a mojo3d-only feature.

But loading does work (so far), and turned out to be easier than I thought (for once). The main problem with objects created via Model.Load etc is that it may involve indirectly creating a bunch of dependent objects like textures, materials, child entities etc. I was initially dreading having to deal with this and had some pretty convoluted solutions floating around in my brain until it occurred to me that these really should be managed (ie: added to the internal ‘jsonify me’ list) in the same way objects created with New are managed. However, they don’t need a serialized constructor as they are implicitly constructed by the loader, and their initial state shouldn’t be captured until *after* the loader completes (as opposed to after New completes). So assuming that the user doesn’t mess with loaded objects, they have no constructor and will have no ‘delta state’ (ie: the difference between an object’s initial state and its current state) so can be skipped entirely by the jsonifier and wont appear in the scene file at all. On the other hand, if the user *does* mess with a loaded object, it still has no constructor but will have some delta state to be jsonified so will end up appearing in the scene file. This is really what the weird ducks-scene.mojo3d demo is all about. It loads a duck model (and, implicitly, a material) via Model.Load, copies it a bunch of times and messes with each copy’s material’s metalness/roughness a bit. Even if you were to modified the duck model, the scene file would still work!

I have also added TypeInfo.Name support even for unreflected types so you can now go ‘Print Typeof<Image>’ and get ‘mojo.graphics.Image’ even with reflection off. Reflection is still a beast overhead wise, although fortunately it only hurts build times the first time you build (it used to be the first 2 builds on gcc targets but that’s hopefully been fixed now thanks to newly discovered -MMD command line option!). I can think of quite a few optimizations to make here too now, such as optionally only reflecting decls with metadata which would work fine for the mojo3d scene system. In general, I really, really, recommend using the microsoft visual C/C compilers with monkey2 for better compile times and smaller executables, especially when dealing with relection!

Last but definitely not least I have *finally* added GetPixel and GetPixelARGB methods to Image and Canvas classes. In the case of images, these currently make use of the ‘managed pixmap hack’ that people have been using in the past (and that I was completely unaware of!) but hides the nasty details and can eventually be optimized for desktop gl which, unlike gles, actually allows you to read texels from textures – woohoo. Getting pixels from a canvas is very slow but is just something you’ve gotta do sometimes, eg: for a paint program color picker so that’s in there too.

Have fun!

***** Monkey2 v2018.04 Mx2cc v1.1.12 ted2go v2.10 *****

Added GetPixel and GetPixelARGB to both Image and Canvas classes – canvas versions are as slow as hell, eg: 3 secs for 16×16! Image versions still relies on the ‘managed pixmap hack’, but I recommend you use these instead as I can optimize them per target over time.

Fixed makedocs links to enums.

Tweaked mx2cc’s gcc dependancy checking so it happens while compiling (just like msvc’s) so there should now only be 1 ‘slow build’ under mingw instead of 2. Sometimes it’s just a matter of knowing that a certain command line option even exists!

Updated my anroid dev system to: Android Studio 3.1 ; Android SDK Tools 26.1.1 ; NDK 16.1.4479499 ; Android SDK 27 (Oreo 8.1) so you should do the same if you haven’t yet.

Removed the ComponentType param overloads from NumComponents and GetComponent in Entity. Use NumComponents<T> and GetComponent<T> instead. Duh. Also added GetComponents<T>:T[]().

Added Variant.GetArrayLength, Variant.GetArrayElement, Variant.SetArrayElement and TypeInfo.NewArray. These make it possible to serialize arrays.

MAJOR overhaul of the mx2cc ‘dependancies’ logic – may potentially cause the dreaded ‘forward reference to incomplete type’ c++ build error but should be considerably more efficient (ie: #include fewer headers for faster(ish) builds). I also think I actually understand how it works this time around so it should be easier to find problems with this stuff in future.

Experimental mojo3d scene loading and saving added. Only very minimal support right now, eg: physics components are not yet supported and no texture or model loading support.

See mojo3d/tests/loadscene.monkey2 for a demo. This should also create a test-scene.mojo3d file in your monkey2 dir which you can double click to open in latest ted2go (the version included in the monkey2 repos).

To save a scene, you need to enabled mojo3d reflection by adding this to your file:

#Reflect mojo3d

You also need to enable ‘editing’ mode in your code with something like _scene.Editing=True before creating scene contents. Once you’ve created your scene, save it using the Scene.Save( path:String ) method. Ditto you can load a scene using the Scene.Load:Scene( path:String ) function.

Typeinfo.Name now always returns proper typename even if reflection info disabled and even for generic types. Typeinfo.Name used to return a ‘unknown@12345678’ style string.

String.ToUpper, String.ToLower and String.Capitalize now use java equivalents internally on android ‘coz NDK doesn’t support locales.

Updated MX2_MSVC_TOOLS_DIR in env_windows.txt for latest Visual Studio Community Edition 2017 update (15.6.2).

Added AngelFont and ImageFont support. Font.Load tries to guess correct font type via file extension but you can use ImageFont.Load and AngelFont.Load directly if you want. Changed monochrome font texture format to I8.

Fixed PATH growing when updating modules in ted2go.


Liked it? Take a second to support Monkey 2 on Patreon!

Leave a Reply