MonkeyMax - The Return

Monkey Targets Forums/User Targets/MonkeyMax - The Return

Karja(Posted 2012) [#1]
I had a look at the excellent work on the MonkeyMax target that's been done in Diddy, and decided to see how hard it would be to get it running again. Some blood, sweat and tears later, and here's a patched version that's compatible with Monkey v0.54c:

http://www.karjasoft.com/temp/MonkeyMax_v0.54c.zip

Note: this is a work in progress! To install this, simple copy the files into a Monkey Pro directory. Note again: this will overwrite a couple of files! Most notably, it patches trans and mojo, and your config.winnt.txt, etc. So keep backups, and do some manual patching if needed.

Some simple samples are available under bananas.

What works:
* Normal monkey as well as mojo and diddy can be used
* Loading text and graphics
* Compiling everything that I've used in my own game, including interfaces, graphics, etc etc

What doesn't work:
* Sound and input - I'm just using placeholders
* Advanced rendering - scaling, alpha, rotation etc isn't working yet
* Most likely, reflection!
* Lots of stuff that I'll run into when I start fixing the obvious things

Comments:
* BlitzMax doesn't have interfaces, so an interface is just an abstract class for now. It compiles at least...
* Most of the necessary modifications remaining are probably just in the native mojo parts, but some Trans work is probably needed
* This is a work in progress! And I'll leave it for a while now - this was a proof of concept for me, and I'll look into it more later

If you do mess around with this, let me know how it works and what else is needed! Samah, therevills, if this is useful for Diddy, feel free to use and update as you see fit.


Why0Why(Posted 2012) [#2]
This is great! I bought Monkey and Jungle and after playing with it, I decided to go back to Max for now as my main target is PC/Mac and I don't feel Monkey is there yet for these platforms. I do foresee getting to the point where I am using Monkey again when it has matured some, but this might move me back more quickly.


therevills(Posted 2012) [#3]
Cool! Now this is what Open Source coding is about!

Reflection "should" work, as Monkey just adds more code around the existing files to act like reflection at runtime...

Quick Q: How did you get around this issue: http://www.monkeycoder.co.nz/Community/post.php?topic=1647&post=15463 As it looks like you have just changed mojo to accept BlitzMax as a target?


Karja(Posted 2012) [#4]
Haha... I actually had to do a nasty hack to get around it. I renamed bbMain to bbMain2 during translation, and added a custom bbMain that calls bbMain2 as well as Setup if it's a mojo app. It's at the end of bmaxtranslate.


therevills(Posted 2012) [#5]
Ah crafty! :)

Also beware of the issue with case sensitivity: http://www.monkeycoder.co.nz/Community/post.php?topic=1573&post=14615

I'm pretty sure Trans could be changed to deal with this somehow...

With your interface change, I was think about doing to same (using Abstract) but it still doesnt really work if you want to extend and implement at the same time, but as you say at least it compiles ;)

I'm pretty busy with my current project, but if you need help let me know :)


Karja(Posted 2012) [#6]
Ah yes - I already ran into one issue with case sensitivity when it concerned global variables and functions. But I modified trans to have a "fg_" prefix for functions and just "g_" for variables. For the case above I guess it could be solved by, for example, assigning a steadily increasing number to each variable. X -> l_x_1, x -> l_x_2, etc. Or something similar.

I really should work on my project instead of messing around with this, so I'll see how much time I put into it at the moment... I'm confident that it can be done now at least! :)


therevills(Posted 2012) [#7]
I'm confident that it can be done now at least! :)


Yeah me too, thats why I started it but I get bored of things after the inital challenge is done ;)

I've just commited your changes to the Diddy's repository :)


Karja(Posted 2012) [#8]
Coolness! I SHOULD work on the game instead, but I like this kind of tinkering... We'll see if I do some more work on it after all in the near future. :)


Why0Why(Posted 2012) [#9]
These types of projects are why I have loved the Blitz community for years. Looking at how robust Max is now, there is a module for almost everything. Monkey is headed in that direction and I am sure in a year or so will be well down that road.


Karja(Posted 2012) [#10]
Okay, a small addition that ought to make things a bit more usable with Diddy and Angelfont:

mojo.bmax.bmx:
	Method SetMatrix:Int(ix:float,iy:float,jx:float,jy:float,tx:float,ty:float)
		Local sx:Float = Sqr( (ix*ix) + (jx*jx) )
		Local sy:Float = Sqr( (iy*iy) + (jy*jy) )
		Local rot:Float = Atan2( jx, ix )
		SetTransform( rot, sx, sy )
		SetOrigin( tx, ty )
		Return 0
	EndMethod


Now Diddy's drawing with rotation/scaling seems to work as expected. This also makes font rendering work. I guess I couldn't keep my paws off this...


therevills(Posted 2012) [#11]
I guess I couldn't keep my paws off this...

LOL!


Karja(Posted 2012) [#12]
Alright then, time for an update! Here are some additional files to make things a bit more stable. (These are just the files that differ compared "v0.54c.zip" above. It'll be easier to add them to Diddy that way.)

http://www.karjasoft.com/temp/MonkeyMax_v0.54c_2.zip

My game is almost completely working in BlitzMax now! Stuff that works include:
- Mouse and keyboard input
- Loading graphics/text
- Drawing alpha/scaled bitmaps
- Angelfont
- Diddy, what I use from it (IComparable interfaces, tweens, graphics, etc)
- Pretty much everything I have in my game, except...

What's not working:
- Rotation. I just extract the scale and the translation from the matrix right now - messing with the rotation was too bothersome at the moment.
- Sound
- Config and environment variables for the BlitzMax target - I'll add some for the screen size and such later

But it's -working-! I can actually play my game on BlitzMax now.


therevills(Posted 2012) [#13]
I havent actually havent tested your new stuff yet...

I thought blending worked okay before (its been awhile since I used this):

Function BlitzMaxSetBlend(blend:Int)
	SetBlend(blend)
EndFunction


Isnt this enough, as ALPHABLEND is just an int defined as zero in Monkey and .... Ahhh I've just checked BlitzMax's consts for blends:

'modes for SetBlend
Const MASKBLEND=1
Const SOLIDBLEND=2
Const ALPHABLEND=3
Const LIGHTBLEND=4
Const SHADEBLEND=5

And Monkey's
Const AlphaBlend=0
Const LightenBlend=1 'deprecated
Const AdditiveBlend=1

Good catch!


Karja(Posted 2012) [#14]
Yeah, I got some strange results at first - and it didn't help that there were a bug in the casting to float as well, that had to be fixed before the correct values were even passed into the SetAlpha function. But it's all working fine now!

Most of the work was probably in the bmxtranslator file. There were many little issues with castings, binary operations, slices and so on. A single line changed there was the difference between my game locking up completely, and running smooth as a baby's bottom.


therevills(Posted 2012) [#15]
Just had a quick play.

The exit screen in Diddy uses:
Error ""

To terminate the app, but it crashes in BlitzMax.

Also Mouse Hits doesnt seem to work...

I'm off to bed now, but good job finishing off MonkeyMax so far :)


Karja(Posted 2012) [#16]
Bah, who cares - it works for me! ;) Nah, just kidding. Strange. I also use 'Error ""' but my app exited cleanly... And I just use MouseDown myself, and keep internal states; haven't tried MouseHit yet, unfortunately.

Well, there's still stuff to do then!


Why0Why(Posted 2012) [#17]
This may drive me back over to Monkey from Max! Especially reading the numbers for New Star Soccer and how the Flash version may have pushed purchases to other platforms.


therevills(Posted 2012) [#18]
Strange. I also use 'Error ""' but my app exited cleanly... And I just use MouseDown myself, and keep internal states; haven't tried MouseHit yet, unfortunately.


That's cool, I only did a quick test. I'll have a look today since I was nearly falling asleep at the keyboard last night (long week at work).

Edit1:
Ah with 'Error ""', it "crashes" when you compile in debug mode, which is correct for BlitzMax it just looks strange as it just says: "Unhandled Exception" and hangs the game (Monk cannot stop it)... if you run it in release mode, its fine.

Edit2:
I've changed error in lang.bmx to this:
Function error( err:String )
	If err = "" Then
		End
	Else
		RuntimeError err;
	EndIf
EndFunction

So it exits cleaner in debug mode.

With MouseHit, I think its a Diddy issue - I tested with the "pure" mojo example and it works fine...

Edit3:
The MouseHit issue is due to the non case-sensitive code in BlitzMax, the framework of Diddy has a variable called mouseHit:Int, which is messing it up and the InputCache stuff is messing it up too...


therevills(Posted 2012) [#19]
Damn you Karja!! You've got me interested in this again!!! :P

Just added some sound commands to MonkeyMax...

Must get back to my current project!!!!


therevills(Posted 2012) [#20]
Samah thinks we should be able to do interfaces this way:

Monkey:
Interface Foo
	Method Bar:Void()
End

Class SomeClass Implements Foo
	Method Bar:Void()
		Print "hello world"
	End
End

Function Main()
	Local sc:SomeClass = New SomeClass
	Local f:Foo = sc
	f.Bar()
End

Blitz:
Type Foo Abstract
	Global implementations:TList = New TList
	Method Bar() Abstract
EndType

Type SomeClass
	Method Bar()
		Print "hello world"
	EndMethod
EndType

Foo.implementations.AddLast(TTypeId.ForName("SomeClass"))

Local sc:SomeClass = New SomeClass
Local f:Object = sc
If Foo.implementations.Contains(TTypeId.ForObject(sc)) Then
	SomeClass(f).Bar()
EndIf

It looks good, but I've got no idea how to add this to Trans... O_o


therevills(Posted 2012) [#21]
Just going thru the Monkey examples and most of them work!! O_O

Along the way I have added more stub methods (eg SetKeyboardEnabled)

These are the ones which currently have major issues:

* Richard_Betson\mirror_fx_transform
- the right hand lines are in the wrong place

* hitoro\autofitdemo and hitoro\simpledemo
- looks wrong

* hitoro\rockout
- plays okay until you change the VR

* hitoro\rotationsickness
- the green background moves incorrectly


* mak\audiotest
- crashes
The code doesnt take in any extra targets when added an else it worked, apart from the music and looping sounds

* mak\bouncyaliens
- fails compilation - array resizing (Unable to convert from 'Object Array' to 'bb_bouncyaliens_Sprite_Array')


* mak\firepaint
- TouchDown doesnt translate to MouseDown
Fixed

* mak\mojotest
- the vertical lines arnt right

* mak\reflectiontest
- Duplicate identifier


* mak\unicodetest
- "Joing" not found D'oh! LOL
Fixed


* warpy\bezier
- Exits straight away
Fixed


* warpy\horsey
- Crash
BlitzMax doesnt load mp3s - added RuntimeError to help debug this

* warpy\monkeypuzzle
- the mouse isnt in the middle of the monkey head

* warpy\pegs
- Crash Fixed the crash, but still doesnt display correctly

* warpy\transform and warpy\transform_mouse
-Transformations not quite right...

So overall, its nearly there...

Main issues are:

* Sound
* Matrix Transformations
* Arrays
* Duplicate Identifiers

And of course Interfaces...


Karja(Posted 2012) [#22]
Wow, so cool! Haha... I love the fact that my meddling has not only messed up my own project, but others' too. ;) No, but seriously - this is really close to being quite useful now. It compiles fast, it runs in a stable way on Windows and Mac - the BlitzMax target is going to be awesome.

I won't have time to do anything for a couple of days (friends coming over, promised my better half to go shopping tomorrow, etc), but some spontaneous thoughts about the interfaces:

'----- No problem for this part ---
Type Foo Abstract
	Global implementations:TList = New TList
	Method Bar() Abstract
EndType

'----- Easy as pie, no issues here ---
Type SomeClass
	Method Bar()
		Print "hello world"
	EndMethod
EndType

'----- Again, this can be done - but since this will be lower than the
' calls to bbMain and so on, this won't be called early enough. So it needs 
' to be inserted further up...or we can simply move the TRANSCODE block
' further up in the template. That should work ---
Foo.implementations.AddLast(TTypeId.ForName("SomeClass"))

Local sc:SomeClass = New SomeClass
Local f:Object = sc
'----- This is where the tricky part is. To do this we have to keep extra
' info in bmxtranslate, that has to be checked against each method call... ------
If Foo.implementations.Contains(TTypeId.ForObject(sc)) Then
	SomeClass(f).Bar()
EndIf


So... Basically, when an interface is noted in EmitFuncDecl, info about it has to be stored in a global list, and each method call in TransFunc (I think) has to check against that list... Wouldn't it be more efficient to just add an extra call each time we know that an object belongs to an interface? I.e., that the actual BMax code would be:

Type Foo Abstract
	Method Bar() Abstract
EndType

Type SomeClass
	Method Bar()
		Print "hello world"
	EndMethod
EndType

Local sc:SomeClass = New SomeClass
Local f:Object = sc
SomeClass(f).Bar()


Since we could check whether or not f belongs to an interface at compile time rather at runtime.


therevills(Posted 2012) [#23]
I love the fact that my meddling has not only messed up my own project, but others' too. ;)

LOL!

It compiles fast, it runs in a stable way on Windows and Mac - the BlitzMax target is going to be awesome.

Yeah, I agree. When I first tested this I was pretty impressed with the speed.

spontaneous thoughts about the interfaces

Sounds good... I think we should leave interfaces alone for now and get the other stuff working correctly, as its going to be hardest issue to deal with...

In other news I was bored this morning and came up with a MonkeyMax logo:



(Using the SVG logo from here: http://www.blitzbasic.com/Community/posts.php?topic=88846 )


slenkar(Posted 2012) [#24]
matrix transforms are easy if you use this opengldriver I made
http://www.blitzbasic.com/codearcs/codearcs.php?code=2612

just use the opengl command that sets the matrix


therevills(Posted 2012) [#25]
matrix transforms are easy if you use this opengldriver I made

Thanks Slenkar, but again I want to be able to use DirectX and not limit the BlitzMax target.


marksibly(Posted 2012) [#26]
Hi,

Interfaces are tricky...

I don't think the above approaches will work, because they assume that the translator knows the real type of the interface object in order to perform the downcast, eg: how would this be translated?

Function DoSomething( f:Foo )
  f.Bar()
End


Without resorting to reflection, the only way I can think of doing interfaces efficiently would be to get the translator to generate 'thunk' classes that forward interface method calls to 'real' object calls, eg:



This is kinda complicated though: The translator would need to generate a whole new class for each combination of class/implemented interface; TransCastExpr() would need to generate _ToBlah() cast calls when casting to interfaces; Downcasting to interfaces gets tricky - a _ToBlah() method for *every* interface could perhaps be added to a root object? Not pretty, but should work and would be fast.


marksibly(Posted 2012) [#27]
Hi,

Another approach...

Incredibly lazy, but you could just add *all* interface methods to an internal root object, eg:



The compiler's already type checked everything, so you should never get 'Internal Error' (yeah, right!).

You'd have to check for duplicates when adding interface methods to the 'root' object; you'd still need to use _toBlah() in TransCastExpr when casting to interfaces; there may be 'munging' issues, ie: you may have to set the 'overrides' field of FuncDecls that implement interface methods; but it should work OK and is probably the easiest way to do it I can think of.

I fact, I'll have a tinker with this myself and see if I can come up with something quick 'n' nasty - no promises though!


therevills(Posted 2012) [#28]
Interesting Mark...

With the "lazy" way, how would it handle a class which is extended and implements at the same time?

Interface Foo
	Method Bar:Void()
End

Class Test
	Method TestMethod()
		Print "Testing..."
	End
End

Class SomeClass Extends Test Implements Foo
	Method Bar:Void()
		Print "hello world"
	End
End

Function Main()
	Local sc:SomeClass = New SomeClass
	Local f:Foo = sc
	f.Bar()
End


I fact, I'll have a tinker with this myself and see if I can come up with something quick 'n' nasty - no promises though!

That would be fantastic if you could, as I think it is beyond me.

Whilst you are looking Mark, could you see why bouncyaliens doesnt work please?


marksibly(Posted 2012) [#29]
Hi,

Ok, not pretty but this sort of works.

You'll also need to add this line to the end of the InsertDecl method in decl.monkey in the trans module (line 420 here):

		If decl.IsSemanted() semanted.AddLast decl


I can't actually run very much (firepaint gives an array index error; mojotest can't find drawpoint; keyboardtest can't find setkeyboardenabled) but this does at least successfully run ifacetest and ifacetest2 (if you comment out the import mojo in facetest2).

Hope it's useful...




therevills(Posted 2012) [#30]
Cool! I'll have a look tonight - thanks Mark!

(firepaint gives an array index error; mojotest can't find drawpoint; keyboardtest can't find setkeyboardenabled)


I've fixed these issues already, if you grab the zip file from here you should have more success: http://diddy.googlecode.com/files/monkeymax_r365.zip


therevills(Posted 2012) [#31]
Hey Mark, just been testing and it looks good - but some of the Diddy examples now don't compile, the error is this:
Compile Error
Missing return statement.

I tested with Tile/testTile.monkey and Particle/testParticle.monkey.

Also the IDE puts the cursor right at the bottom of the file.
TRANS monkey compiler V1.30
Parsing...
Semanting...

Process Complete

Any ideas?

I think its the new line in decl.monkey:
	Method InsertDecl( decl:Decl )
		If decl.scope InternalErr
		
		Local ident$=decl.ident
		If Not ident Return
		
		decl.scope=Self
		decls.AddLast decl
		
		Local decls:StringMap<Object>
		Local tdecl:=declsMap.Get( ident )
		
		If FuncDecl( decl )
			Local funcs:=FuncDeclList( tdecl )
			If funcs Or Not tdecl
				If Not funcs
					funcs=New FuncDeclList
					declsMap.Insert ident,funcs
				Endif
				funcs.AddLast FuncDecl( decl )
			Else
				Err "Duplicate identifier '"+ident+"'."
			Endif
		Else If Not tdecl
			declsMap.Insert ident,decl
		Else
			Err "Duplicate identifier '"+ident+"'."
		Endif

		If decl.IsSemanted() semanted.AddLast decl ' <---- Added for MonkeyMax
	End

When I comment it out and rebuild trans, the above examples compile but don't work.


Heres a simple example of the error:
Strict

Import mojo

Function Main:Int()
	New Game()
	Return 0
End

Class Game Extends App
	Field circleShape:Shape = New Circle()
	
	Method OnCreate:Int()
		SetUpdateRate 60
		Return 0
	End
	
	Method OnUpdate:Int()
		Return 0
	End
	
	Method OnRender:Int()
		Cls
		DrawText "TEST", 100, 100
		circleShape.Draw()
		Return 0
	End
End

Interface Shape
	Method Draw:Void()
End

Class Circle Implements Shape
	Method Draw:Void()
		DrawOval 200, 200, 50, 50
	End
End



Karja(Posted 2012) [#32]
@therevills:
I just downloaded monkeymax_r365 and applied it to a Monkey Pro dir on a separate computer, added the line in decl.monkey, and made a new trans executable with it.

Every example I'm testing with is working as expected - including the test you posted. Could you try again with a clean environment and see if it works there?


therevills(Posted 2012) [#33]
@Karja - did you also apply the KludgeInterfaces change to the bmx translator?

Just tried a total clean install:

1. Downloaded 54c and copy monkeymax_r365 on top of monkey and ran the above sample - No problem
2. Changed decl.monkey and compiled trans and ran the sample - No problem
3. Added KludgeInterfaces change and recompiled trans and ran the same - Error!
4. Removed decl.monkey change, recompiled trans and tried again - the code compiles but it is missing functions for BlitzMax to compile it successfully (Identifier 'm_Draw' not found)


Karja(Posted 2012) [#34]
Haha, didn't get that far. I was just trying the line change first. But now I have, and I've noted some things:

Inside EmitBlock in bmxtranslator:
		If func And Not r
		
			Print( "...Dealing with " + func )

			If ENV_CONFIG<>"release" EmitLeave
			
			If Not VoidType( func.retType )
				If func.IsCtor()
					Emit "return self;"
				Else
					If func.ModuleScope().IsStrict()
						_errInfo=func.errInfo
'						Err "Missing return statement."
						Print "Missing return statement."
					Endif
					Emit "return "+TransValue( func.retType,"" )+";"
				Endif
			Endif
		Endif


If you change the Err to a Print, your test code compiles and works. Also, the printout I added shows that there's a problem when "...Dealing with Method _Object._ToShape:_Object()". Which seems to be this generated BlitzMax code:

Type _Object 
	Method  _ToShape:_Object()
		return _Object(null);
	EndMethod
	Method  m_Draw()
	EndMethod
EndType


...But I didn't have time to look further right now.


therevills(Posted 2012) [#35]
Ah its a "Strict" issue with the KludgeInterfaces...

If you run this code:


Its fine, but as soon as you uncomment the commented lines you get the "Missing return statement" error. If you then remove "Strict" it works fine.


marksibly(Posted 2012) [#36]
Hi,

This hopefully fixes strict mode...




therevills(Posted 2012) [#37]
Looks good - Thanks again Mark!

With that change in decl.monkey, is it "safe" for the other targets?


marksibly(Posted 2012) [#38]
Hi,

> With that change in decl.monkey, is it "safe" for the other targets?

Should be...


therevills(Posted 2012) [#39]
Should be...

Famous last works! ;)

So back to the other current issues with MonkeyMax:

* Sound
* Matrix Transformations
* Arrays
* Duplicate Identifiers
* Interfaces

I've updated the zip file for MonkeyMax on the GoogleCode site (MonkeyMax_r370.zip).


Karja(Posted 2012) [#40]
Regarding the matrix transformations, I'm thinking that there are a couple of different ways to do this:

1) Since we know the order in which rotation, scaling and translation is performed, we can reverse these operations from the matrix we get in SetMatrix. However, SetMatrix is called many times. Ineffective to do ATan operations and such things each time.

2) Use a BlitzMax OpenGL module that allows setting the matrix directly. But we want to use DX as well.

3) Mess around with Max2D to set the matrix directly. I don't like this option - we don't want to change the target, and I don't think we have public access to all necessary methods and fields.

4) Modify the GraphicsDevice in mojo to add a couple of methods:

Class GraphicsDevice="gxtkGraphics"

	Method Mode()
	Method Width()
	Method Height()
	
	Method LoadSurface:Surface( path$ )
	
	Method Cls( r#,g#,b# )
	Method SetAlpha( alpha# )
	Method SetColor( r#,g#,b# )
	Method SetMatrix( ix#,iy#,jx#,jy#,tx#,ty# )
	Method SetScissor( x,y,width,height )
	Method SetBlend( blend )

	Method SetTransform( tx#, ty# )
	Method SetScale( sx#, sy# )
	Method SetRotation( a# )
	
	Method DrawPoint( x#,y# )
	Method DrawRect( x#,y#,w#,h# )
	Method DrawLine( x1#,y1#,x2#,y2# )
	Method DrawOval( x#,y#,w#,h# )
	Method DrawPoly( verts#[] )
	Method DrawSurface( surface:Surface,x#,y# )
	Method DrawSurface2( surface:Surface,x#,y#,srcx,srcy,srcw,srch )
End

Function Translate( x#,y# )
	Transform 1,0,0,1,x,y
	context.device.SetTranslate( x, y )
End Function

Function Scale( x#,y# )
	Transform x,0,0,y,0,0
	context.device.SetScale( x, y )
End Function

Function Rotate( angle# )
	Transform Cos(angle),-Sin(angle),Sin(angle),Cos(angle),0,0
	context.device.SetRotation( angle )
End Function


The downside is that all mojo targets need to be modified to have dummy implementations of these methods. Also, SetMatrix is called directly sometimes, so we still need to check out for a call to set an identity matrix, and reset everything then.

Any thoughts? I see 1 or 4 as the real options. 1 is most non-intrusive but a bit inefficient. I like that method even though I'll need to read up on matrix math for it. :P


therevills(Posted 2012) [#41]
Number 1 is our only real option... we have nearly got it, only a few of the demos mess up.

Yeah Atan is slow, could we use a lookup table to increase the speed?


therevills(Posted 2012) [#42]
Samah's back from Japan and he has fixed the matrix stuff by messing around with it for 30 mins or so :)

http://code.google.com/p/diddy/source/detail?r=373

* Sounds (to finish)
* Matrix Transformations
* Arrays (to fix resize_object_array)
* Duplicate Identifiers (todo... any ideas??)
* Interfaces


therevills(Posted 2012) [#43]
Again Samah suggested a way to find with Duplicate Identifiers...

We now append "_1" in front of any uppercase letters, this makes the output code a bit more messy but it works ;)

http://code.google.com/p/diddy/source/detail?r=374

* Sounds (to finish)
* Matrix Transformations
* Arrays (to fix resize_object_array)
* Duplicate Identifiers
* Interfaces

The list is getting smaller :)


therevills(Posted 2012) [#44]
After banging my head against the keyboard I've thought of a way to fix the Array resize object issue... BlitzMax can use Slicing to resize arrays!!! Pretty simple why didnt I think of it earlier!

So now its only really sounds to finish and a big testing phase...

Oh and the CONFIG variables to add :)

http://code.google.com/p/diddy/source/detail?r=376


Shinkiro1(Posted 2012) [#45]
Awesome guys.


therevills(Posted 2012) [#46]
Just updated MonkeyMax to be up-to-date with Monkey v56b and uploaded a new zip file which includes various fixes:

http://diddy.googlecode.com/files/monkeymax_r379.zip


therevills(Posted 2012) [#47]
Oh BTW Mark, if you are reading this, I managed to test the Diddy's GUI example which is very heavy on interfaces and it compiled and ran, although the mouse input didnt work, but it displayed the GUI fine!! So you Interface Kludge worked great!


slenkar(Posted 2012) [#48]
I tried to compile a box2d demo for a laugh,

got an error on this line of the generated code:
t_b.f_m_flags&=~bb_b2body_b2_1Body.g_e_island_1Flag;

I think its the & symbol? or maybe the ~ symbol?

the error message mentions the &

also in my font class I have this "~" which doesnt compile because its an escape character in blitzmax


therevills(Posted 2012) [#49]
Good testing!!

Its the &= operator, I forgot to include that one, and I've just fixed it (so it gets translated to :& for BlitzMax).

I've checked it in so if you want can you try it again...

also in my font class I have this "~" which doesnt compile because its an escape character in blitzmax
Yeah I've seen this before, I need to fix this one later... ...Fixed... :)


Karja(Posted 2012) [#50]
This is awesome - you've done great stuff lately! :) I feel a bit bad for digging this up and then letting you do all the nasty work, but I blame a new job, family visits over Easter...and the fact that I bought a PS3 and Disgaea 3...


therevills(Posted 2012) [#51]
I feel a bit bad for digging this up and then letting you do all the nasty work

LOL! Well you can help by doing some testing ;)

@slenkar, the fix above does get Box2D compiled, but it looks like there is a calculation error somewhere as the bodies do not draw correctly. The best example which works is the buoyancy one.


slenkar(Posted 2012) [#52]
thanks for the fixes


hey do you think this might be a good idea?

Put the code that is common to all blitzmax programs in a blitzmax MODULE
then when compiling, you are only compiling game logic stuff.

Also I have a GUI module in monkey,(code that is rarely changed) maybe there could be a way of excluding this from the main blitzmax file as I would put it in a module.

the best way of doing that could be excluding stuff that is imported, and allowing users to convert that code to blitzmax another way e.g. when someone alters their gui module

re:box2d drawing
blitzmax and monkey are based on the way opengl works
directx works differently e.g. when scaling something negatively it doesnt mirror, it merely disappears from the screen, mark wrote code to fix these differences in blitzmax.<-just in case you didnt already know.

I found another error BTW:
In my monkey file the line looks like this:
If String(world_map.inst.minutes).Length=1

but in blitzmax the line doesnt convert the 'minutes' float to a string, it just puts the float in extra brackets
it looks like this:
If((bb_worldmapclass_world_map.g_inst.f_minutes).length = 1) Then



therevills(Posted 2012) [#53]
Yeah that sounds like a good idea with the module, once this is solid I'll have a lot at that.

re:box2d - I believe its a calculation error as when I output the vertices they are different on BlitzMax compared to the other targets.

re: another error - Thanks I'll look at this one soon :)


therevills(Posted 2012) [#54]
but in blitzmax the line doesnt convert the 'minutes' float to a string, it just puts the float in extra brackets


Just fixed this one... but in your example you talk about a float which isnt going to be the same for all targets (HTML5 will be 1, C++ will be 3, for BlitzMax it will be 10).


therevills(Posted 2012) [#55]
You can now use the Box2D module in MonkeyMax :)

(I had the CosR, SinR etc commands wrong)

http://code.google.com/p/diddy/source/detail?r=384

And heres an updated zip: http://diddy.googlecode.com/files/monkeymax_r384.zip


Skn3(Posted 2012) [#56]
wow! this has really progressed fast! Good work :D.. should soooo become an official target ;)


Soap(Posted 2012) [#57]
+1 to official target!


therevills(Posted 2012) [#58]
Heres a video of MonkeyMax in action with Box2d:




DruggedBunny(Posted 2012) [#59]
Wow, amazing work! My first test (a reasonably complex demo with changing autofit scaling) worked perfectly on the first attempt. Brilliant stuff!

I did run into a minor problem you might want to look at, using this crappy example: on all other platforms, reducing the delta-timed framerate below the default 60 (in-game via the down cursor) keeps the game at the same speed, but on BMAX the game speeds up. (Yet increasing the framerate via the up cursor works as per the other platforms, ie. stays steady.)


therevills(Posted 2012) [#60]
Hey James, yeah I've seen that before too, but did'nt really look into it till now.

I've just committed a fix I hope works, its based off the HTML5 and Android Mojo which adds a delay after render based on the nextupdate-now... MonkeyMax's Mojo is based off Flash's which doesnt have this delay.

Can you please try it, by just replacing the mojo.bmax.bmx file with this one: http://code.google.com/p/diddy/source/detail?r=385


Neuro(Posted 2012) [#61]
I got a linking error : "D:/BlitzMax/bin/ld.exe: cannot find" even though its clearly there. Any ideas?


DruggedBunny(Posted 2012) [#62]
@therevills: Sorry for the delay in getting back, but that certainly seems to do the trick!


therevills(Posted 2012) [#63]
@James, no worries - I was asleep anyway :P Glad it worked :)

@Neuro - No ideas, sorry, but a quick google might ;) Try creating a little program in BlitzMax and see if that works, if not try reinstalling BlitzMax.


zoqfotpik(Posted 2012) [#64]
Thanks very much, this must have been crazy difficult.


ErikT(Posted 2012) [#65]
Found a minor snag with translated DrawImage functionality. Drawing images with scale x or y set to -1 doesn't flip them as in monkey; instead they get rotated or something.

This is super though, great going :D


Goodlookinguy(Posted 2012) [#66]
I started running through and testing this on several tests I've made as well as other stuff I have sitting around. I noticed that Monkey Blob Monster kind-of freaks out on BlitzMax target while every other target is fine. I don't know if it's their code or yours. Hope this helps with something.


therevills(Posted 2012) [#67]
@ErikT... that minor snag is quite a major headache to fix!! LOL

@GLG - thanks for that, it might actually be related to Erik's issue, and it is our code which is the issue ;)


Samah(Posted 2012) [#68]
Scaling stuff fixed and checked in. See this post: http://www.monkeycoder.co.nz/Community/post.php?topic=2683&post=27129


therevills(Posted 2012) [#69]
Top work, Samah!

That was very hard to fix!!

I've just uploaded a new zip with the matrix fix and the logic rate fix:

http://diddy.googlecode.com/files/monkeymax_r387.zip

And the matrix fix also did fixed the Monkey Blob Monster too :D


NoOdle(Posted 2012) [#70]
Great job guys this is a very interesting project and something that will definitely come in handy. I need to write editors for my projects and I was dreading having to rewrite my framework in BlitzMax first. This should allow me to do it with ease. I'll be testing this out very soon, I'll let you know how I get on.


Samah(Posted 2012) [#71]
Top work, Samah!

That was very hard to fix!!

Bloody matrices... my head hurts.

orz


Goodlookinguy(Posted 2012) [#72]
Good job on figuring that out. Now all of my newer code seems to work. A bit of my old stuff keeps compiling and, only in the bmax target, quits with an error that says it's attempting to access a method/field of a null object. Which is bull crap in some of them and I'm not sure what's causing that. In fact, at least one of Challenger GUI's examples quits with that as well.


slenkar(Posted 2012) [#73]
I tried the latest version, the matrix handling is a big improvement with one small difference, when I use the transform command the results dont look the same,
this is the code needed to see the difference:
http://monkeycoder.co.nz/Community/posts.php?topic=503
youll need an image 64x64 or 128x128

The only other difference is the default screen size of blitzmax is larger than 640x480
every other target has 640x480 default


therevills(Posted 2012) [#74]
when I use the transform command the results dont look the same

You are making us cry now :'(

every other target has 640x480 default

Fixed!


slenkar(Posted 2012) [#75]
sorry :'{


therevills(Posted 2012) [#76]
Actually, this might be a limitation on BlitzMax... I'm not sure it can shear images...


therevills(Posted 2012) [#77]
quits with an error that says it's attempting to access a method/field of a null object.

@GLG - Have you got a small of example of that error?


ErikT(Posted 2012) [#78]
Works great!

Except now another bug has popped up. Nothing to worry about though, minor snag :)

The framerate in max always ends up running at half the speed I set it to in Monkey. If I set SetUpdateRate to 60 then the bmax version runs at 30 fps, 120 gives 60 fps etc. This didn't happen in r384.


therevills(Posted 2012) [#79]
If I set SetUpdateRate to 60 then the bmax version runs at 30 fps, 120 gives 60 fps etc

Can you show my your timing methods and where you are calculating it?

I added a delay function on r385 (http://www.monkeycoder.co.nz/Community/post.php?topic=2560&post=26932) to try to match the other targets.

When I set it SetUpdateRate to 60 and use this crappy fps counter:
		frames+=1
		Local e:=Millisecs()-time
		If e>=1000
			fps=frames
			frames=0
			time+=e
		Endif


In OnRender it does output 60FPS... but if I set it the update rate to 30 it does 15FPS.

I think it might be due to how BlitzMax locks itself to the monitor refresh rate (or something)...


ErikT(Posted 2012) [#80]
Apart from SetUpdateRate which is called in OnCreate() I don't use any timing methods at all. Everything runs within OnRender() though, don't know if that makes any difference...


therevills(Posted 2012) [#81]
Ah sorry, I was talking about your FPS calculations (how do you know its running at half the speed?).


ErikT(Posted 2012) [#82]
Oh right. Er, I just eyeball it :] It runs consistently at half the speed of whatever I set it to so I know it's not because the computer's struggling or anything.

EDIT: Gimme a sec, I'll check the fps with fraps.

EDIT2:

SetUpdateRate 120 = 59-60 fps
SetUpdateRate 60 = 30-31 fps
SetUpdateRate 30 = 30-31 fps

Hmm... yeah sorry, was wrong about SetUpdateRate 30.


therevills(Posted 2012) [#83]
No worries ErikT, I'll look at it later. Which example or code were you running?

@GLG - I've managed to get ChallengerGUI compiling and running on MonkeyMax... stupid backwards String slicing (Oi! ZIGGY!!!!)


Shinkiro1(Posted 2012) [#84]
What about setting the update rate in BMax with Graphics (...., hertz)?


ErikT(Posted 2012) [#85]
I've been running my own stuff and yeah; Graphics 800,600,32,60 gives me the correct speed/update rate.


therevills(Posted 2012) [#86]
Hmmm, that command (Graphics 800,600,32,60) will make the game run in full-screen mode... and I'm pretty sure if we do this Graphics 800,600,0,60 BlitzMax will ignore the 60hz.


ErikT(Posted 2012) [#87]
It works fine now. I'm unable to reproduce the issue. Windowed mode, fullscreen mode, with or without setting 60hz in Graphics, it all works. Seems like maybe my system has been acting up and then just stopped for some reason. So yeah, false alarm I guess. Sorry :X


Playniax(Posted 2012) [#88]
Hi,

The BMAX target for Monkey is great! :)

However, I was testing your BMAX target And I found a problem with LoadString.

Problem is that all 'official' targets return a NULL object when the file was not found and I use this as a trick sometimes to stop loading when LoadString returns NULL.

But the BMAX target stops and returns error 'Error reading from stream'

Of course I can find some work arounds For this but I can imagine more programmers use this trick so I was hoping you can have BMAX to behave in exacly the same way as the other targets.

I tested my framework and this is the only part that causes a problem translating to the BMAX target.

But all in all a good job on your part :) I am really impressed with how good this works!

Thanks!

Btw, does Mark gave any plans to make this official?


therevills(Posted 2012) [#89]
But the BMAX target stops and returns error 'Error reading from stream'


Fixed, once I learnt how BlitzMax's Try/Catch works (it would have been nice to have a list of the exceptions that can be caught!!!) :)

but I can imagine more programmers use this trick so I was hoping you can have BMAX to behave in exacly the same way as the other targets.


Well thats the plan, to get MonkeyMax as close as possible to the other targets... currently the only blocking is the shearing stuff.


Playniax(Posted 2012) [#90]
Great! When is the new version up? I don't have SVN installed :(


therevills(Posted 2012) [#91]
Just apply the change to mojo.bmax.bmx:

http://code.google.com/p/diddy/source/detail?r=395

	Method LoadString:String( path:String )
		path = "data/" + path
		Try
			Return LoadText( path )
		Catch ReadFail:Object
			Return Null
		EndTry
	EndMethod


You dont need to recompile trans for changes to mojo.


Playniax(Posted 2012) [#92]
Tested it and works, thanks! :)


visionastral(Posted 2012) [#93]
- I finally found the good thread... -

Hello therevills, monkeymax is really an excellent work!
I just installed and tested it, and I must say I didn't expected it to work so flawlessly!
I compiled a 2.5D engine I made for xna and it ran at full speed without any show stopper. Only some 2D glitches are present related to the blend mode in BlitzMax, wich is MASK instead of ALPHA by default, and thus gives a different output for some graphics.
It's a shame the code becomes so much difficult to read, but I suppose it can't be better!
The only things that had prevented me from compiling are:

- open gl
- SaveString (wich I use a lot for writing to disk in proprietary format)

I thought BMX has native support for OpenGL (I'm a beginner in bmx so I can be wrong) I wonder if you plan to support it? It would be nice to make MonkeyMax compatible with miniB3D or any other OpenGL based module.
The SaveString thing, however, should be easy to fix, doesn't it?

Anyway, a really powerful work there Therevills, congratulations!


therevills(Posted 2012) [#94]
Hey visionastral, glad you like it :)

This project has been very much a collaboration of the minds, yes I did start this and got the basics working, but Karja and Samah has helped alot and even Mark Sibly helped heaps with the interfaces :)

Only some 2D glitches are present related to the blend mode in BlitzMax, wich is MASK instead of ALPHA by default

Could you give us an example?

It's a shame the code becomes so much difficult to read

Yeah, but I've got use to it now. LOL! Most of the BlitzMax code at the top of the file is really just Mojo stuff, your Monkey code will be near the bottom of the file.

I thought BMX has native support for OpenGL

Yes it does... I might look into it in the future.

The SaveString thing, however, should be easy to fix

Yeah, it should be pretty easy to add, same with LoadState and SaveState.


matt(Posted 2012) [#95]
Awesome work guys!


Neuro(Posted 2012) [#96]
Ok...so i finally got this to work. And it sure as hell works awesome :)!!


therevills(Posted 2012) [#97]
Ok...so i finally got this to work

Cool! How did you fix your linking error?


Raz(Posted 2012) [#98]
I've got nothing too worthwhile to add to this apart from the fact I really appreciate seeing so many updates to MonkeyMax :)


Neuro(Posted 2012) [#99]
Cool! How did you fix your linking error?

Administrator issues with the D: drive. I just reinstalled Max back onto the C: drive, updated the links, and it just smoothly "worked" :).

But is it me or does running the target on Max seems to run faster than GFLW?? Although executable file size is a lot bigger though :).


Neuro(Posted 2012) [#100]
Also, is it possible yet to use external BMax functions in monkey too? Like the Hidemouse function?


therevills(Posted 2012) [#101]
Like the Hidemouse function?

We added HideMouse ages ago in Diddy and we have added it to Diddy for MonkeyMax too.

http://code.google.com/p/diddy/source/browse/trunk/monkeymax/modules/diddy/native/diddy.bmax.bmx


Neuro(Posted 2012) [#102]
Ahh thanks, exactly what i was looking for!


slenkar(Posted 2012) [#103]
Theres a thingy called titaniumGL it works with any OpenGL game and intercepts opengl calls and uses DirectX because its faster,

So, pure opengl commands could be used for monkeymax and just let people install titaniumgl DLL into their game folder if they want it to be as fast as directx

http://titaniumgl.tk/


slenkar(Posted 2012) [#104]
ok I converted the blitzmax mojo to pure opengl
so now its 100% compatible with monkey

here is BlitzMax\mod\keef.mod\gldraw.mod\gldraw.bmx

you just compile this in blitzmax with Ctrl-D


here is mojo.bmax.bmx


here is Monkey/targets/bmax/monkeygame.bmx

[bbcode]
SuperStrict
Framework keef.gldraw
Import brl.linkedlist
Import brl.audio
import brl.standardio
Import brl.textstream
Import Pub.FreeJoy
Import BRL.PolledInput
Global _errStack:TList = New TList;
Global _errInfo:String="";

initgl(640,480,0,30)

bbInit();
bbMain();[/bbcode]


The only command missing is DrawOval cos I dont know how to do that in OpenGL


Theres only 3 things left now,
DrawOval

Drawimage with extra arguments (as used in horsey demo)
This can easily be done with gltranslate,glscale,glrotate


Some kind of module system where you can compile modules seperately so compilation doesnt take as long
Like not including blitzmax imports into the MonkeyGame.bmx and being able to compile them seperately.

Moving monkey boilerplate code like mojo to a blitzmax module would also help.


Samah(Posted 2012) [#105]
Unfortunately that makes the MonkeyMax target OpenGL dependent. We were sorta hoping to allow DirectX support for Max2D, so unless you want to do that too... ;)


slenkar(Posted 2012) [#106]
http://titaniumgl.tk/ <- this makes your PC use DirectX even for OpenGL games


therevills(Posted 2012) [#107]
Malwarebytes blocks that link Slenkar...


slenkar(Posted 2012) [#108]
I tried it on marks bouncy alien demo and it said 'unable to calculate tex size' and didnt work :(


ErikT(Posted 2012) [#109]
Hullo.

Converting this:
Field map:tlQuadTreeNode[][]

produces an error in the translated code:
Field f_map:bb_rigzcollision_tl_1Quad_1Tree_1Node[][]=New bb_rigzcollision_tl_1Quad_1Tree_1Node[[0],[0]];

(Unable to convert from 'Int Array' to 'Int')

... which goes away by commenting out:
=New bb_rigzcollision_tl_1Quad_1Tree_1Node[[0],[0]];


Here's the whole class:
Class tlQuadTree

	Field maxlevels:Int
	Field Box:tlBox
	Field rootnode:tlQuadTreeNode
	Field maxpernode:Int
	Field areacheckcount:Int
	
	Field objectsfound:Int
	Field objectsupdated:Int
	Field totalobjectsintree:Int
	
	Field min_nodewidth:Float
	Field min_nodeheight:Float
	
'	Field map:tlQuadTreeNode[,]
	Field map:tlQuadTreeNode[][]
	
	Field dimension:Int

	#rem
		bbdoc: Create a New tlQuadTree
		returns: A New quadtree
		about: Creates a New quad tree with the coordinates And dimensions given. _maxlevels determines how many times the quadtree can be sub divided. A
		quadtreenode is only subdivided when a certain amount of objects have been added, which is set by passing _maxpernode. There's no optimum values for
		these, it largely depends on your specific needs, so you will probably do well To experiment.
	#End
	Method Create:tlQuadTree(x:Float, y:Float, w:Float, h:Float, _maxlevels:Int = 4, _maxpernode:Int = 4)
		Box = New tlBox.Create(x, y, w, h)
		maxlevels = _maxlevels
		maxpernode = _maxpernode
		rootnode = New tlQuadTreeNode.Create(x, y, w, h, Self)
		dimension = Pow(2,(maxlevels-1))'2 ^ (maxlevels - 1)
		min_nodewidth = w / dimension
		min_nodeheight = h / dimension
'		map = New tlQuadTreeNode[dimension, dimension]
		map = New tlQuadTreeNode[dimension][dimension]
		For Local x:Int = 0 To dimension - 1
			For Local y:Int = 0 To dimension - 1
'				map[x, y] = rootnode
				map[x][y] = rootnode
			Next
		Next
		rootnode.dimension = dimension
		Return Self
	End Method
	
	#rem
		bbdoc: Add a New bounding box To the Quadtree
		returns: False If the box doesn't overlap the qaudtree, otherwise True.
		about: A quadtree isn't much use without any objects. Use this to add a #tlBox to the quadtree. If the bounding box does not overlap the 
		quadtree Then Null is returned.
	#End
	Method AddBox:Int(r:tlBox)
		If Box.BoundingBoxOverlap(r)
			r.quadtree = Self
			rootnode.AddBox(r)
			totalobjectsintree+=1
			Return True
		Else
			Return False
		End If
	End Method

	#rem
		bbdoc: Query the Quadtree To find objects with an area
		about: When you want To find objects within a particular area of the quadtree you can use this Method.  Pass the area coordinates And dimensions
		that you want to check, an object that can be anything that you want To pass through To the callback Function, And the Function callback that you want 
		To perform whatever tasks you need on the objects that are found within the area.
		The callback Function you create needs To have 2 parameters: ReturnedObject:Object which will be the tlBox/circle/poly, And Data:Object which can be
		and object you want to pass through to the call back Function.
	#End
	
	#rem
		bbdoc: Find out how many objects are currently in the quadtree
		returns: Number of Total Objects in Tree
		about: Use this To retrieve the total amount of objects that are stored in the quadtree.
	#End
	Method GetTotalObjects:Int()
		Return totalobjectsintree
	End Method
	
	#rem
		bbdoc: Perform some house keeping on the quadtree
		about: This will search the quadtree tree For any empty #tlQuadTreeNodes And unpartition them If necessary. 
	#End
	Method RunMaintenance()
		rootnode.UnpartitionEmptyQuads()
	End Method
	
	#rem
		bbdoc: Draw the quadtree
		about: This can be used For debugging purposes. *Warning: This will be very slow If the quadtree has more Then 6 Or 7 levels!*
	#End
	Method Draw(offsetx:Float = 0, offsety:Float = 0)
		rootnode.Draw(offsetx, offsety)
	End Method
	
	'Internal Stuff-----------------------------------
	Method UpdateRect(r:tlBox)
		'This is run automatically when a tlBox decides it needs to be moved within the quadtree
		r.RemoveFromQuadTree()
		objectsupdated+=1
		AddBox(r)
	End Method

	Method GetQuadNode:tlQuadTreeNode(x:Float, y:Float)
		Local tx:Int = x / min_nodewidth
		Local ty:Int = y / min_nodeheight
		If tx >= 0 And tx < dimension And ty >= 0 And ty < dimension
'			Return map[tx, ty]
			Return map[tx][ty]
		End If
		Return Null
	End Method
End





therevills(Posted 2012) [#110]
I'll have a look tonight, thanks for the code :)


therevills(Posted 2012) [#111]
Okay, think I've fixed it:

http://code.google.com/p/diddy/source/detail?r=409


ErikT(Posted 2012) [#112]
Great, thanks a lot :)

The new trans_winnt.exe gives me an empty build rollout though? Tried it with 56b and 58.

EDIT:
Nevermind, my firewall blocked it :P The array code compiles and runs without any problems. Good going :)


therevills(Posted 2012) [#113]
Glad it worked :)

This thread is getting pretty long, so I've created a new one here:
http://www.monkeycoder.co.nz/Community/posts.php?topic=3018#30717

Mark, Simon or James, could you please lock this thread :)