Leadwerks Engine 2.41 for Monkey V32

Monkey Archive Forums/Monkey Projects/Leadwerks Engine 2.41 for Monkey V32

Canardian(Posted 2011) [#1]
The integration is really easy, I just need to type out all commands now:


This LE2MINGW target will be available for free for all registered Leadwerks Engine 2 users (you'll find the download in the Leadwerks Downloads when it's out).
You will probably need the full version of Monkey too, I don't know if making new targets for the free Monkey version works, or is it even allowed by marksibly.

Some cool bonus I found: It takes only 2 seconds to compile an LE2MINGW target. So it's much faster than compiling a GLFW or GLFWMINGW target, and also much faster than compiling a normal LE2 project with VS2008 or VS2010.

Now I have started typing out commands, and I only need to type commands which use pointers, the rest of the LE2 commands are imported directly to Monkey, that's really cool!

Now my Monkey demo source code looks like this:
Import LE2
Function Main()
	Initialize
	Graphics
	CreateFramework
	Local cube=CreateCube
	Local camera=GetLayerCamera(GetFrameworkLayer(0))
	MoveEntity camera,0,0,-2
	Local light=CreateSpotLight
	MoveEntity light,0,0,-2
	While Not KeyHit
		UpdateFramework
		TurnEntity cube,AppSpeed,AppSpeed,AppSpeed
		RenderFramework
		Flip
	End
	Terminate
End



Xaron(Posted 2011) [#2]
OMG... Now THAT is awesome!


degac(Posted 2011) [#3]
Oh! Thank!
Nice to have a 3d engine ready for BlitzMax and now for Monkey!


pinete(Posted 2011) [#4]
amazing!


Canardian(Posted 2011) [#5]
Finished demo3:

Import LE2
Function Main()
        Initialize
        Graphics 800,600
        CreateFramework

        Local cube=CreateCube
        EntityColor cube,.5,1,.5,1
        MoveEntity cube,.8,0,0
        MoveEntity CreateSphere(32),-1.2,0,0            ' combined parameters

        Local camera=GetLayerCamera(GetFrameworkLayer(0))
        MoveEntity camera,0,0,-2
        
        Local light=CreateSpotLight
        MoveEntity light,0,0,-2
        Local yellow:Vec4=New Vec4(1,1,0,1)    ' yellow
        EntityColor light,yellow               ' Vec4 works also as parameter

        Local ground=CreateCube
        ScaleMesh ground,10000,1,10000
        MoveEntity ground,0,-1,0

        AmbientLight .1,.1,.3
        SetShadowmapSize light,4096     ' might not work on worse than GeForce 8800
        SetShadowQuality 1
        SetShadowSoftness light,.5
        SetFarDOF 1
        SetNearDOF 1
        SetBloom 1
        SetWater 1
        SetWaterHeight -.2
        SetWaterSoftness 1.6
        SetReflectionElements 1
        SetWaterColor .5,.5,1,.5,1,1,1,.5
        While Not KeyHit
                UpdateFramework
                TurnEntity cube,AppSpeed        ' default parameters work
                RenderFramework
                Flip 1
        End
        Terminate
End



Indiepath(Posted 2011) [#6]
Nice, but why?


Canardian(Posted 2011) [#7]
Actually I hesitated at first also to start making a Monkey module for LE2, since LE3 would make much more sense, as it's multi-platform.

However, the module code will be almost identical, and current LE2 developers can already benefit from the Monkey language, since it's insane fast to compile and insane easy to program with. Many less experienced programmers prefer Lua, since it's BASIC like, but I think they might like Monkey now too. That increases BRL and Leadwerks sales as a nice side-effect, and customers want their vendors to increase sales so they get new updates and new stuff, either for free or for a small donation. I always market any product I buy, because I invested money in the product, so I want it to get better :)

Monkey serves as a replacement for BlitzMax 1, and also as a better language over VS2008/VS2010.

After considering those benefits, I decided to start already now, since I won't use C++ either anymore, because Monkey is so much easier to program with, and the same Monkey source can produce many output languages. So I don't throw time and efforts away by programming in only one language, since Monkey is a multi-language.

Multi-language, multi-platform, that's the recipe for success.


matt(Posted 2011) [#8]
I've not heard of Leadwerks Engine before, so I have a question.

Care to describe the breakdown of what is in the binary? How much is monkey?


Canardian(Posted 2011) [#9]
Mostly it is pure C++ (.cpp files) which Monkey can import directly, and like I said in the first post, I need to type Monkey code only for functions which use pointers, because unsigned char* = Int and vice versa in Monkey.

In LE2 the actual engine.dll file was written with BlitzMax, but since LE2 uses like 98% GPU only, it doesn't make any noticable speed difference as opposed as if it was written in C++. Then there are also the newton.dll and openal.dll which are already written in pure C.

I think after I get the procedural Monkey version ready, I will also make an OOP Monkey version. In the next demo/unit test I will already make an App Class like in mojo, so the Monkey source code will be still standardized to Monkey/mojo manners.


Virtech(Posted 2011) [#10]
Keep up the good work Lumooja!


Hima(Posted 2011) [#11]
This is a great idea :) I like coding in Monkey too...It's just so easy and comfortable to work with. Too bad LE2 cost another $199 :( Maybe in the future I might be able to make use of this. Still, keep up the good work!


Canardian(Posted 2011) [#12]
In Demo 4 the App class is used:
Import Leadwerks

Class Game Extends App
	Field fw
	Field cube
	
	Method OnCreate()
		SetAppTitle "Leadwerks Monkey"
		Graphics 800,600
		fw=CreateFramework
		DebugPhysics 0
		SetupScene
	End
	
	Method SetupScene()
		SetupCube
		SetupBall
		SetupLight
		SetupGround
		Local camera=GetLayerCamera(GetFrameworkLayer(0))
		MoveEntity camera,0,0,-2
		AmbientLight .02,.02,.03
	
		Local blue:Vec4=New Vec4(0,0,0.1,1)
		SetBackgroundColor blue
		SetShadowQuality 1
		SetFarDOF 1
		SetNearDOF 1
		SetBloom 1
	
		Collisions
	End
	
	Method SetupCube()
		cube=CreateBodyBox
		Local cubemesh=CreateCube(cube)
		EntityColor cubemesh,0.5,1,0.5,1
		MoveEntity cube,0.8,10,1
		SetBodyMass cube,1
		EntityType cube,1
	End
	
	Method SetupBall()
		Local ball=CreateBodySphere
		Local ballmesh=CreateSphere(32,ball)
		MoveEntity ball,-1.2,10,0
		SetBodyMass ball,1
		EntityType ball,1
		SetBodyElasticity ball,2
	End
	
	Method SetupLight()
		Local light=CreateSpotLight
		MoveEntity light,0,1,-2
		TurnEntity light,10,0,0
		Local yellow:Vec4=New Vec4(1,1,.5,1)
		EntityColor light,yellow			' Vec4 works also as parameter
		SetShadowmapSize light,4096			' might not work on worse than GeForce 8800
		SetShadowSoftness light,.5
	End
	
	Method SetupGround()
		Local ground=CreateBodyBox(10000,1,10000)
		Local groundmesh=CreateCube(ground)
		ScaleMesh groundmesh,10000,1,10000
		MoveEntity ground,0,-1,0
		EntityType ground,1
	End

	Method OnRender()	
		If KeyHit Then Quit
		UpdateFramework
		AddBodyTorque cube,0,35,35,0
		RenderFramework
		Flip 0
	End
	
End

Function Main()
	Local game:Game=New Game
	game.Delete
End


I wonder if procedural commands are needed/wanted at all, or should I make it fully OOP style? Like:
	Local cube:Cube=New Cube
	cube.Move 0.8,10,1
	cube.SetMass 1
	cube.SetType 1
instead of:
	Local cube=CreateCube
	MoveEntity cube,0.8,10,1
	SetBodyMass cube,1
	EntityType cube,1


EDIT: Ah, nevermind, it seems the procedural commands are available anyway since the OOP interface needs them also. So you can use both mixed.


Canardian(Posted 2011) [#13]
Demo 5 shows how Demo 4 can be done as OOP version:

Import Leadwerks

Class Game Extends App
	Field fw:Framework
	Field cube:BodyBox
	
	Method OnCreate()
		SetAppTitle "Leadwerks Monkey"
		Graphics 800,600
		fw=New Framework
		DebugPhysics 0
		SetupScene
	End
	
	Method SetupScene()
		SetupCube
		SetupBall
		SetupLight
		SetupGround

		Local camera:Camera=New Camera(0,fw.main.camera)
		camera.Move 0,0,-2
		AmbientLight .02,.02,.03
	
		Local blue:Vec4=New Vec4(0,0,0.1,1)
		SetBackgroundColor blue
		SetShadowQuality 1
		SetFarDOF 1
		SetNearDOF 1
		SetBloom 1
	
		Collisions
		
		Local cube2:Cube=New Cube
		cube2.Move 0,0,3
		'cube2=0				' not sure what this does, but it does something
		cube2.Delete
	End
	
	Method SetupCube()
		cube=New BodyBox
		Local cubemesh:Cube=New Cube(cube)		' parent the mesh to the physics body
		cubemesh.SetColor .2,.6,.2,1
		cube.Move .8,10,1
		cube.SetMass 1
		cube.SetType 1
	End
	
	Method SetupBall()
		Local ball:BodySphere=New BodySphere
		Local ballmesh:Sphere=New Sphere(32,ball)	' parent the mesh to the physics body
		ballmesh.SetColor .6,.2,.2,1
		ball.Move -1.2,10,0
		ball.SetMass 1
		ball.SetType 1
		ball.SetElasticity 2
	End
	
	Method SetupLight()
		Local light:SpotLight=New SpotLight
		light.Move 0,1,-2
		light.Turn 10,0,0
		Local yellow:Vec4=New Vec4(1,1,.5,1)
		light.SetColor yellow				' Vec4 works also as parameter
		light.SetShadowmapSize 4096			' might not work on worse than GeForce 8800
		light.SetShadowSoftness .5
	End
	
	Method SetupGround()
		Local ground:BodyBox=New BodyBox(10000,1,10000)
		Local groundmesh:Cube=New Cube(ground)
		groundmesh.Scale 10000,1,10000
		ground.Move 0,-1,0
		ground.SetType 1
	End

	Method OnRender()	
		If KeyHit Then Quit
		fw.Update
		cube.AddTorque 0,35,35,0
		fw.Render
		Flip 0
	End
	
End

Function Main()
	Local game:Game=New Game
	game.Delete
End



kmac(Posted 2011) [#14]
Keen to see this released...


Canardian(Posted 2011) [#15]
I'm working hard on it! :)
Today I got the development speed up a lot, because I found out how to use properly Strings and custom classes to interface with C++ classes in Monkey. Now it's just routine work to finish it.


kmac(Posted 2011) [#16]
Excellent!


Virtech(Posted 2011) [#17]
Just curious, have you considered doing a port of some 3D engine for the Android/iOS targets in the furure? I take it LE2 dont work on those, or?


Canardian(Posted 2011) [#18]
I could theoretically port LE2 also to other platforms which have OpenGL and Shader Model 3, but it would be a waste of time, since LE3 has already low-end support built-in, and comes in full C++ source code. So porting LE3 to all targets will be much, much easier than porting LE2, and it will work on all low and high end machines. Of course open source languages like WebGL would work also, but I don't think the license allows that. However, if you sell your WebGL game including LE3 source code, it would be possible, just in case someone really needs it (like some NASA or other big institution), it's possible :)

Leadwerks Monkey will be the same though, no matter if it's using LE2 or LE3, so you can already start now making games for Windows, and later on you just compile the same game for other platforms.


Hima(Posted 2011) [#19]
Do we need .cpp in order to port something like what you're doing? I want to use a Japanese game library with Monkey. The library is written in C and it comes with .lib and .h, not cpp. I read your tutorial of how to extend monkey by importing .cpp file from your site, but I would like to know if this applies to .lib or .dll as well.


Canardian(Posted 2011) [#20]
Basically .lib is the same as .c/.cpp from the functionality, it's just in binary form. You don't import directly anyway the 3rd party library .c/.cpp/.lib, but you need to write a wrapper in .cpp for Monkey, which calls the C++ functions from the real .c/.cpp/.lib and does some small type conversions, because Monkey needs Int for all pointers, and String for all C (unsigned char*) and C++ string (std::string). The 3rd party library usually uses also .dlls which its .lib/.c/.cpp loads.


Hima(Posted 2011) [#21]
Ah, that makes sense now. Just write a .cpp file to wrap all the functions in the .dll/.lib Thank you very much! :)


Canardian(Posted 2011) [#22]
You don't even need to wrap all functions, since most functions work directly in Monkey. You only need to wrap the functions which use pointers and C strings (which are also pointers). Sometimes you might need to wrap also functions which use classes as parameters, but it depends on the class.
But all functions which use the core C/C++ types work directly in Monkey: void, int, float, double, bool, char, etc....


Hima(Posted 2011) [#23]
Wow, that is really awesome! One thing though, did you have to rename all functions/command like in this page? http://www.monkeytools.net/articles/Adding_new_commands_to_Monkey

To be specific, I'm talking about this line
Extern
    ' the C++ or javascript function mytestfunc1 is renamed as MyFunc1 in Monkey
    Function MyFunc1:Void()="mytestfunc1"



Canardian(Posted 2011) [#24]
No, for most commands in Leadwerks engine, I don't add the ="somename" at all. Only for functions which I need to wrap, I added a unique name like ="MonkeyTurnEntity", so that in Monkey the wrapped command is then TurnEntity, so it's the same as in Leadwerks Engine/Blitz3D.


Hima(Posted 2011) [#25]
That is incredible! Thank you ^^ And keep up the good work with LE port!


pinete(Posted 2011) [#26]
What's are your plans Lumooja? are you going to release it? I'm waiting for it so in that case I will acquire Leadwerks engine to play around :)
regards!


Kauffy(Posted 2012) [#27]
Any more work on this? Just curious as Josh is coming down the home stretch on LE3.