Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

TexturePainter will get MipMapLevelData property in next Lime release (which i plan to release this weekend by the way).
Its nothing more than:
Well, if you have locked mipmap level 0 and your color format is A8R8G8B8, then yes. But Get/SetPixel() methods works with any type of mipmap level and color format. You can see the source how they take into account all the parameters. But still you can do it yourself having "void*" and in native Irrlicht its the only way. I try to wrap things for C#, using of which doesn't require that much knowledge (i'm saying that C# is easier than C++).
What do you think about IntPtr Texture.Lock(...)? IntPtr.Zero could perfectly signal of failure, its as close to original api as it gets and saves us creating a new object.
First of all there is no Texture.Lock() in Lime, so:
1) if you suggest to add one, then i disagree because TexturePainter is a tool exactly for this purpose - it wraps lock()/unlock() and all the routine with "void*". Also if i add Lock()/Unlock() to Texture class, then how do any TexturePainter class will track that its texture was locked? Currently the way its done is locking/unlocking can be made only through TexturePainter so it can track the state. The only thing right now is that i assume that user will create one TexturePainter for a Texture, because actually you don't need to call GetTexturePainter() every time you need to place a single pixel on the texture, you can do it once and work with painter until texture is not unloaded. This is not obvious maybe, but for this pupose i made method GetTexturePainter() (not a get-prop TexturePainter), because it creates new TexturePainter object. I guess i will change that a bit, so it will be more safe and consistent. Any way, my change will be only related to the fact that each Texture may has only one painter object in the program. So user will not have to store it to work with it further. Well, currently is ok to recreate painter even every frame -- that is no problem for app stability, but your painters must not co-exist in one time and be used simultaneously. I mean for now next code shows wrong usage and i treat it as bug and i will fix that:

Code: Select all

Texture t = driver.GetTexture("1.png");
TexturePainter p1 = t.GetTexturePainter();
TexturePainter p2 = t.GetTexturePainter();
p1.Lock();
// now: p1.Locked == true, but p2.Locked == false
 
// ------ after the fix code above will look like next -----------
Texture t = driver.GetTexture("1.png");
TexturePainter p1 = t.Painter;
TexturePainter p2 = t.Painter;
p1.Lock();
// now will be: p1.Locked == true, but p2.Locked == true, t.Painter.Locked == true
2) if you suggest to change return type of TexturePainter.Lock(), then i disagree because if you don't need that IntPtr value (which i assume in most cases will be so), you will have to write stuff like:

Code: Select all

if (painter.Lock() != IntPtr.Zero) { ... }
// instead of simply
if (painter.Lock()) { ... }
And i have another question. Grab/Drop stuff made me wonder..
Yes i can do it, but the problem with finalizers is that you cannot predict when and in what order they will be called by garbage collector. This may lead to things like sometimes your buggy code will work and sometimes - no. That is why we pay a price by explicit call to Drop() -- we call it and we forget about the pointer. If you're not sure when to call Drop(), there is a simple rule: if you called method starting with "Create" word OR you called Grab(), you must call Drop() after. That is why we have code like:

Code: Select all

SceneNodeAnimator anim = scene.CreateFlyCircleAnimator(new Vector3Df(0, 15, 0), 30.0f);
cam.AddAnimator(anim);
anim.Drop();
We created an object, we passed it somewhere, we done with it. If something want to work with it, it will call Grab() and after all - Drop(). The code may looks weird, but that is an example of creating and attaching animator, almost all of them are made this way. I really can try to do what you suggest but i really want the stuff like that to be maximum clear, in fact the more stuff done behind our eye the more we miss and then pay price of long time debugging all around.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

Yes, what you say regarding texture painter makes sense, i agree.

What do you mean we cant predict order of finalizers being called? If you mean we do not know when objects are garbage-collected - im not sure it would be a problem. Afterall before we drop last reference of object we should first remove it from scene graph or wherever else object is attached and/or used by other objects. Programmer can not be protected from every mistake he could make. There can be two identical situations:
In c++ programmer calls drop() and does not remove object from parent object. Result - object stays in scene graph and is being rendered still.
In c# programmer sets all references to child object to null and does not remove it from parent object. Result is still the same.
I am pretty much suggesting this because of same reason like you said - c# is easier than c++ and this manual grab/drop does not quite go along with that mindset of easyness.
I would suggest maybe making it experimental feature that could be turned on/off using preprocessor conditional. In case its big fail - it can be turned off fast, in case its success - its great addition to lime. Hell - we can even make it one liner preprocessor define like #define LIME_FINALIZER(CLASS) !CLASS() { pNativeObject->Drop(); }
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

Version 1.4 has been released

New examples:
Image
L16.SphereCamera // simple implemetation of sphere camera
L17.Minesweeper // minesweeper game

Changes:
- Updated Irrlicht SDK to trunk rev. 4527.
- Fixed bug in SceneNode when OnGetMaterial event was not fired when internal getMaterial() was actually called by the Irrlicht.
- Fixed bug when you couldn't actually pass null as string where you might need it (until now it was treated as an empty line, not null). For example now GUIContextMenu.AddItem(null) will add a separator instead of blank menu item.
- Added Intellisense documentation to all members of Scene and GUI namespaces. Now Lime' Intellisence file should contain all wrapped classes and members.
- Extended IndexBuffer and VertexBuffer (added new stuff and renamed old). Added static methods Create() to each class. Added additional overloadings to VideoDriver's DrawVertexPrimitiveList() and Draw2DVertexPrimitiveList() with arguments of VertexBuffer and IndexBuffer.
- Changed assertion check in Draw*VertexPrimitiveList()s, now if count of vertices or indices is zero, the method will do nothing (was assertion failure).
- Changed Texture class: removed GetTexturePainter() method and added Painter prop. Fixed bug when having more than one TexturePainter per Texture may lead to inconsistency with texture lock state.
- Changed argument order in AddTabControl() in GUIEnvironment. Now id follows parent argument (similar to other "add" methods).
- Changed argument timeForceLost, now it has type of uint and assumes milliseconds (was float in seconds) in ParticleSystemSceneNode.CreateGravityAffector() method.
- Added MipMapLevelData to TexturePainter.
- Added CreateClone() to SceneNodeAnimator.
- Added OSOperator to GUIEnvironment.
- Added Edges and Radius props to AABBox.
- Added WindowPosition to IrrlichtDevice and IrrlichtCreationParameters.
- Added checkSubElements argument to GUIEnvironment.Focused().
- Added TrulyVisible to GUIElement.
- Added UpdateMatrices() to CameraSceneNode.
- Added HeightmapOptimizeMesh() to MeshManipulator.
- Added Compressed, MipMaps props and IsCompressedFormat() static method to Image. Added DXT1-5 values to ColorFormat enum.
- Added overloadings for VideoDriver.Draw2DRectangle(), Draw2DRectangleOutline() and Draw3DLine() which takes separate coordinates directly (e.g. x, y and z).
- Added overloading for VideoDriver.Draw2DPolygon() which takes x and y directly.
- Added overloading for VideoDriver.CreateImage() with single texture argument; it uses all the texture to create software image.
- Added overloading for Rect{i|f|d}.IsPointInside() which takes x and y arguments directly.
- Added TextureCompressedDXT value to VideoDriverFeature enum.
- Added LMTS value to AnimatedMeshType enum.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

Thanks for release! (finally i have something to say besides "thanks", i am uncomfortable with empty "thanks" responses)

So i tried my Drop idea, actually so far it works in my small example. Key idea is to turn reference counted object into something similar to smart pointer.
As we know, for example, scene.AddCubeSceneNode() would add scene node with reference count 1 since cube is used by scene.
What i did is Grab() in ReferenceCounted wrapper constructor, and Drop() in finalizer (with appropriate safety checks and empty destructor).
Result:

Code: Select all

 
SceneNode cube = scene.AddCubeSceneNode(20);    // cube reference count is 2, it is referenced by scene and by wrapper object
cube = null;                                    // cube reference count still 2, will be 1 when wrapper object is collected as garbage
scene.Clear();                                  // cube reference count is decreased by 1 since it is removed from scene graph. if wrapper object was garbage-collected, cube object is deleted, if not - object remains in memory
GC.Collect();                                   // forced garbage collection collects cube wrapper object as garbage for sure, now cube with it's native object are deleted for sure
 
Such setup still allows explicitly using Grab()/Drop() too. Of course there are dangers of using such setup, but such is true in any case when dealing with unmanaged resources. No matter what too much dropping == crash.
So what do you think?
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

This looks not bad, but i need time to test all by myself.
Currently a bit busy.
bdpdonp
Posts: 68
Joined: Sat Oct 10, 2009 6:35 am

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by bdpdonp »

The irrlicht.dll that is included. If I compile with the build you are using, will it work? My reason is I would like to enable DDS format for textures and it is commented out in the standard deploy of Irlicht.

Thanks
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

if you want to build irrlicht for lime yourself - just do what irrlicht\version.txt says. basically you are required to define _IRR_WCHAR_FILESYSTEM, UNICODE and _UNICODE. last time i tried - it did not work with public release, you should use svn trunk version, ideally revision specified in irrlicht\version.txt. and lastly - make sure when building lime to use headers that came with irrlicht src, and not with lime package. i stepped on that rake myself.
bdpdonp
Posts: 68
Joined: Sat Oct 10, 2009 6:35 am

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by bdpdonp »

Thanks, only problemm there is no trunk build 4527 that I can find.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

ofc there is! checkout by specifying revision number:

Code: Select all

svn checkout -r 4527 svn://svn.code.sf.net/p/irrlicht/code/trunk irrlicht-trunk
or if you are adventurous soul just checkout HEAD revision and compile that - may just work!

Code: Select all

svn checkout svn://svn.code.sf.net/p/irrlicht/code/trunk irrlicht-trunk
bdpdonp
Posts: 68
Joined: Sat Oct 10, 2009 6:35 am

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by bdpdonp »

Still no luck. Seems like alot of work to enable one flag.

I suspect it may be I do not have DirectX8 to enable the flag.
If I enable the WCHAR I get about 15 compiler errors.
If I do not enable the flag I get errors from Lime.

If I do not copy modified config file over lime example run but the textures do not work.

I will see if I can get directx 8 somewhere. Honestly will never use it, on DX 9 and hoping if Irllicht 1.9 has DX11 then the new version of Lime will support 11.
roxaz
Posts: 575
Joined: Tue Jan 23, 2007 8:35 pm
Location: LT

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by roxaz »

i did not enable directx 8, its not a requirement really.
as for wchar - i suspect you are compiling irrlicht with multibyte character set selected as default - switch to unicode. that switch automatically defines UNICODE and _UNICODE. is pretty much all it does really..
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

To do not include DirectX renderer you need to comment next lines in \include\IrrCompileConfig.h before you compile Irrlicht

Code: Select all

#define _IRR_COMPILE_WITH_DIRECT3D_8_
#define _IRR_COMPILE_WITH_DIRECT3D_9_
If you do so, you will not need any DirectX SDK.

But here is a link to zip where i have DirectX SDK 8 and 9: https://www.dropbox.com/s/a5lhnrxzz18kghp/DX89SDK.zip
bdpdonp
Posts: 68
Joined: Sat Oct 10, 2009 6:35 am

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by bdpdonp »

Thanks that worked, able to build irrlicht and lime just fine now/
peteym5
Posts: 21
Joined: Wed Sep 12, 2012 3:56 pm

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by peteym5 »

I have developed a 3D Role Playing / Adventure Game builder and game player using Visual Basic.net using the Truevision3D engine. Now TV3D seems dead, no updates in 6 years, I am seriously considering porting the 3D control end of it over to a new wrapper. I am looking for something that takes advantage of features of DirectX 10 and later. TV3D stopped at DX9. IRRLICHT and IRRLICHT LIME appear to be more recently active and is one major alternative. Other considerations is DarkGDK. I admit much of the source code would need to be changed for the areas that control the screen graphics.

The 3D RPG project I developed was last known as "Imperium Magica". Had a 3D dungeon editor, can optionally use it with a terrain. Uses a Microsofts database to store some of the RPG information about characters, objects, dialogs, spells, quests, areas, triggers, etc.

I would prefer to keep it in its original programming language, Visual Basic.net as oppose to converting the whole thing over to c#.net. Reasons include, I am not fluent with C and this is a very, very large project. Hundreds of thousands lines of code. Just porting to another 3D engine is challenging enough.
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: Irrlicht Lime is a .NET wrapper for Irrlicht Engine

Post by greenya »

You can always download Irrlicht Lime and try it with Visual Basic .NET. It has no examples on VB.NET, but as you might know any examples on c# can be easily translated to vb.net, so this should be a problem. Irrlicht Lime has no support for DX10 because native Irrlicht doesn't provide it. DX9 is the highest version.
Post Reply