Jump to content

LW in IronPython


marrat
 Share

Recommended Posts

It works pretty good. Too bad elipse is somewhat lacking in terms of code completion.. Otherwise python lovers should really try LW in python.

 

This is a converted sample:

'''
Created on Aug 24, 2011

@author: rndbit
'''

import clr
clr.AddReference('IronPython')
clr.AddReference('StdLib')
clr.AddReference('LE.NET')

from LeadwerksEngine import *
import System, sys

def UpdateCallback(ent):
   LE.TurnEntity(ent, TVec3(LE.AppSpeed() * 0.5));  

def ErrOut( message ):
   System.Console.WriteLine( message );

def main(argv):
   # Initialize
   LE.Initialize()
   LE.SetAppTitle('Test')
   LE.RegisterAbstractPath('C:/Leadwerks Engine SDK') 

   # Set graphics mode        
   if LE.Graphics(800,600) == 0:
       ErrOut( "Failed to set graphics mode."  )
       return

   # Create framework object and set it to a global object so other scripts can access it
   fw = LE.CreateFramework()
   if not fw.IsValid:    
       ErrOut( "Failed to initialize engine." )        
       return

   # Set Lua framework object        
   LE.SetGlobalObject( "fw", fw.Handle )        

   # Set Lua framework variable        
   lua = LE.GetLuaState()
   LE.lua_pushobject( lua, fw.Handle )
   LE.lua_setglobal( lua, "fw" )
   LE.lua_pop( lua, 1 )

   # Get framework main camera        
   camera = LE.GetLayerCamera( LE.GetFrameworkLayer(0) )
   LE.PositionEntity( camera, TVec3(0,0,-2) )

   # Create cube
   material = LE.LoadMaterial( "abstract::cobblestones.mat" )
   mesh = LE.CreateCube(TEntity())
   LE.PaintEntity( mesh, material )

   # Apply callback
   cb = LE.EntityUpdateWorldCallback(UpdateCallback)
   LE.SetEntityCallback(mesh.Entity, cb )

   # Create ground
   ground = LE.CreateCube(TEntity())
   LE.ScaleEntity( ground, TVec3(10,1,10) )
   LE.PositionEntity( ground, TVec3(0,-2,0) )
   LE.PaintEntity( ground, material )

   # Add some light
   light = LE.CreateDirectionalLight(TEntity())
   LE.RotateEntity( light, TVec3(45,45,45) )

   # Spin cube until user hits Escape
   while not LE.KeyHit() and not LE.AppTerminate():
       if not LE.AppSuspended():
           LE.TurnEntity( mesh, TVec3( LE.AppSpeed()*0.5 ) )     

           LE.UpdateFramework()        
           LE.RenderFramework()        

           LE.DrawText("C# LE.NET", 0, 20)
           LE.Flip( 0 )


if __name__ == '__main__':
   main(sys.argv)

Link to comment
Share on other sites

Hi rndbit, awesome!

 

This is using LE.NET, right?

 

Did you also had a look at Cython, to call the C part of LW directly?

 

For Code Completion in Eclipse to work you would need to provide a own file I think...

i am aware of cython, however did not try it. i imagine debugging cython would be major pain in the rear end so i rather stay away from it :o

Link to comment
Share on other sites

It's really great.

 

I wonder if it would run in Mono too :-) and via Silverlight in a Browser window?

 

How much is the overhead? Could you make some small measurements?

When calling a specific thing in C++ and when calling it in Iron Python via LE.NET...

I would say at least LE.NET will add some latency to it, right? How much, does anybody knows?

 

Also when installing a game written in IronPython you would need to install .NET, IronPython and LE, right?

 

Sorry for the many questions, I'm just excited!

Link to comment
Share on other sites

It's really great.

 

I wonder if it would run in Mono too :-) and via Silverlight in a Browser window?

 

How much is the overhead? Could you make some small measurements?

When calling a specific thing in C++ and when calling it in Iron Python via LE.NET...

I would say at least LE.NET will add some latency to it, right? How much, does anybody knows?

 

Also when installing a game written in IronPython you would need to install .NET, IronPython and LE, right?

 

Sorry for the many questions, I'm just excited!

MONO is a bit vague about IronPython support http://www.mono-project.com/Python Current version of ironpython is 2.7, and mono is talking about 1.0

 

No idea if it would run in the browser. But even if it did - would require downloading leadwerks dlls somewhere along with other resources. thats quite a long shot IMO.

 

Installing game would require only .NET to be installed. IronPython runtime can be bundled with your app. Furthermore ironpython can be compiled to .NET executable/dll. If so then you just need to bundle ironpython dlls, no interpreter exe is needed.

 

As for performance - ironpython is significantly slower than c# or CPython, however framerate of demo application is same on both ironpython and c# demo apps.

 

Sorry i got to turn you down on benchmarking. At the moment im quite occupied with work and i will not be using LW anyway so i got no interest in tinkering with it further :o If anyone interested - sided with Unity3d because LW uses lua as scripting language, and boy lua is gay in my opinion :) Should not be hard to integrate ironpython into Unity3d since its all c# so.. :)

Link to comment
Share on other sites

The framerate should be the same, of course.

After all it's LE looping alone when once you finished setting up the scene.

The question which and how many calls you can make to LE when running through LE / IronPython.

Let's say you can give LE 50 "commands" per frame when using C++ the question would be now on how much the overhead on calling LE is when using .NET/IronPython.

Maybe you can just issue 20 "commands" per frame without lag.

 

Performance wise I wouldn't give IronPython so less credit. It's slightly as fast as CPython, depending on the test you do of course.

 

I would however like seeing PyPy using LE... :-)

 

If you get IronPython into Unity3D let me know!! :-)

Calling Lua gay is maybe over the roof but I don't like it very much either.

 

I'm still trying to plan my world-viewer.

Imagine you have the map of the world and want to stream it via modelled environment in junks via LE.

So I would set up a small C-part (or Cython) which would just receive GMF-objects and feed them into LE when needed. Plus some wasd movement stuff to move the camera.

Another process then would run in the background, parsing the huge databases about the world, trying to extract needed junks with different LODs and put them into GMF objects, sending it to the C-part. The good thing is that you could just spawn more of those background processes if you need them.

I'm not sure about the "handover" process of the GMF objects. Shared MEM? Pipe? Some kind of in-mem database? I think I would prefer an in-mem File System like a RamDrive. :-)

 

Maybe I will wait until LE3 comes out which will feature a bigger terrain...

Link to comment
Share on other sites

Performance wise I wouldn't give IronPython so less credit. It's slightly as fast as CPython, depending on the test you do of course.

well i did some benchmarking comparing C++, PyPy, CPython, IronPython and C#. C++ ofc was fastest, but PyPy was insignificantly slower. Then went C#, which was pretty fast still, CPython was as slow as expected and IronPython came in last. By the way compiled and interpreted IronPython does not differ in execution speed. I used this benchmark for tests, maybe it is ****, i dont know :]

 

I would however like seeing PyPy using LE... :-)

PyPy supports ctypes i think. Since LW exports c api there should not be many problems making a wrapper. You dont even need swig.

 

If you get IronPython into Unity3D let me know!! :-)

i will :]

 

Calling Lua gay is maybe over the roof but I don't like it very much either.

That is just a matter of perspective. To me syntax of lua is so gay.. As gay as say pascal.. But yanno everyone has their taste. Someone thinks python is gay and im perfectly good with that - i just silently giggle knowing how much they loose not using python ;D

 

I'm not sure about the "handover" process of the GMF objects. Shared MEM? Pipe? Some kind of in-mem database? I think I would prefer an in-mem File System like a RamDrive. :-)

If you can manage it - use shared memory. It is the fastest IPC ever. I tried named pipes - could not get them work the way i wanted, probably because i suck.. anyway :o

Link to comment
Share on other sites

Nice!

Though this thread has gotten a little bit offtopic I really like your personal benchmark results.

 

A benchmark of a small and not generalized problem and some guy who tries to write perfect in 6 different programming languages normally is the best way to start flame wars galore.

(Quote Joey: "I never understood why microbenchmarks are run with bad algorithms.")

 

As somebody wrote on that testing page he got down to 6 lines python and he said that the example code is about how *not* to write python.

While I certainly didn't see all the possibilities (I just saw one thing I would make faster as the other stuff would spoil readability) I don't know if I would choose another programming style.

I have much to learn. And I do hope that some JIT will get my stuff straight somehow.

 

On big problems:

I would guess in the end it's all about moving patterns using arrays/lists. If you get down to that there is a big speed difference when using static typed languages or not...

But maybe not much more...

 

But it's all how you set up the test and write the code.

I would say that IronPython maybe could be a lot better, but who knows...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...