Author Topic: Officially supported dotnet wrapper  (Read 8807 times)

Paulus_Newbieus

  • Not-a-newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Officially supported dotnet wrapper
« on: August 06, 2008, 05:02:11 PM »
I have seen a couple of .Net wrappers come and go, and Im not sure if they are currently supported or will continue to be.

I use OgreDotNet (wrapped by Swig) and it is excellant. By far the best networking library out there is RakNet, so I would love to see an official wrapper, something actively supported by the RakNet team. I know it would attract a huge number of new adopters coming from VB .Net and C# backgrounds.

Regards,

Paul

OvermindDL1

  • Anti-Spam Moderator
  • Hero Member
  • ****
  • Posts: 855
  • Karma: 40
  • Programmer
    • View Profile
    • OvermindDL1's Site
Re: Officially supported dotnet wrapper
« Reply #1 on: August 06, 2008, 09:24:03 PM »
Problem is that it would only allow for the basic subset of features of RakNet.  RakNet uses many programming features that exist only in C++ (look at the latest RPC3 for example) that cannot be replicated in any other language besides D or Lisp.  dotNet is very restrictive compared to C++, and if you are willing to deal with the restrictions then it would not be too hard to make a wrapper, you would just be losing some features.  dotNet is more one of those 'play' languages then a real language do remember, made to make things easier, not more powerful.  C++ and Lisp are in those category of languages where you can do *anything*, it may not always be pretty, but they can do everything.

Also, the unlikeliness of seeing an official one stems from the fact I do not think Rak'kar has ever even used a dotNet language, that is kind of a prerequisite to being officially supported. :)

If you have a specific set of features of RakNet that you are wanting to use, might be easy enough to whip up a quick wrapper for you.

Paulus_Newbieus

  • Not-a-newbie
  • *
  • Posts: 3
  • Karma: 0
    • View Profile
Re: Officially supported dotnet wrapper
« Reply #2 on: August 07, 2008, 03:31:57 AM »
dotNet is more one of those 'play' languages then a real language do remember, made to make things easier, not more powerful. 

Ouch! Ok, I wont get drawn into a language superiority debate, but Ive seen flame wars rage for months over comments like that ;)

Regardless, thanks for the reply. I understand RakNet's team (is it just Mr Rak'kar?) probably do not have the experiance (or desire to experiance) any .Net language, in which case this point is moot, and I hope the community creates a solid solution. I just thought I'd throw the idea out there - I do however believe I am one of many that would love to see it happen.

Its interesting though to hear about the programming features in RakNet that can not be replicated in .Net.
This may be the case, but are you sure that this means the function calls cant simply be wrapped regardless? Have you seen/used Swig (http://www.swig.org/exec.html) before? I am no expert but I did think if you could wrap a huge complex C++ library like Ogre3D and expose it to the managed .Net CLR, then the same could be done for RakNet?

OvermindDL1

  • Anti-Spam Moderator
  • Hero Member
  • ****
  • Posts: 855
  • Karma: 40
  • Programmer
    • View Profile
    • OvermindDL1's Site
Re: Officially supported dotnet wrapper
« Reply #3 on: August 07, 2008, 06:15:21 AM »
Sorry for the comment, but doNet was designed for the expressed purpose to make certain things easier, but less powerful. :)

Ogre does not use any features of C++ over C sans classes, which can of course be represented in dotNet.
Just looking at templates alone, which RakNet uses in quite a few places, there is no equal in any dotNet language (sans perhaps IronPython, but that is a good deal slower...).

Think about it this way, try having Boost wrapped into dotNet.  Boost relies on all of those advanced features to make the advanced stuff really easy to use, I cannot really think of any of its sub-libraries that could work.

It just all comes to power versus speed.  If you want ultimate speed you would use some assembly language like X86 or LLVM.  If you want the most power, with a tremendous speed trade-off, you use Python or Lisp.  If you want decent speed, with still an ease of use, but at a tremendous lack of features, you use Java or dotNet.  If you need the best absolute speed, but you need power and you are willing to sacrifice ease-of-use in some situations, then you use C/C++/D.

Just as an example, here is a probably working code (just typing it in here, not tested or anything, but it is right unless I misspelled anything), if this can be converted to dotNet, and I know of no way to do something like this, then RakNet in full 'could' be wrapped:
Code: [Select]
// Assuming all the relevant includes and importing the namespaces

template<typename Func>
typename enable_if<
typename and_<
typename is_class< typename remove_pointer< typename remove_reference<
typename first<typename tail<typename func_parameters<typename Func> >::type
>::type >::type >::type >::type,
typename is_lt<
typename list_length< typename tail<
typename func_parameters<typename Func>::type
>::type >::type,
typename int_<10>::type
>::type
>::type,
typename FuncWrapped<Func> >::type
getFunctionWrapper(Func function)
{
return FuncWrapped<Func>::getOrCreate(function);
}

All that would do is just return a function wrapper of a certain custom class, but the function will not actually exist unless the passed-in function has less then 10 arguments, and the first passed-in argument was a class of some sort, supporting direct passing, pointers, or reference.  I could also do more detailed tests like testing for a specific class or a subclass of it (as is done in RakNet) and so forth.  If they passed in a function that did not meet this requirement then effectively this function call will not exist and you will get an error stating something like no template specialization for passed in type or something like that with a pointer to this function so you can read what it needs.  D would make this so freakishly more pretty, but D is not main-stream, so meh. :P
« Last Edit: August 07, 2008, 06:17:26 AM by OvermindDL1 »

Kain Mikado

  • Not-a-newbie
  • *
  • Posts: 1
  • Karma: 0
    • View Profile
Re: Officially supported dotnet wrapper
« Reply #4 on: August 12, 2008, 07:06:53 PM »
Well that's no good. I agree that RakNet is the best out there for networking and I wanted to include it in the coming versions of my framework. I'm still at the stage where I can switch the things over to C++ from C# but I'm not entirely sure I want to. Thanks for answering my questions as well. xP

OvermindDL1

  • Anti-Spam Moderator
  • Hero Member
  • ****
  • Posts: 855
  • Karma: 40
  • Programmer
    • View Profile
    • OvermindDL1's Site
Re: Officially supported dotnet wrapper
« Reply #5 on: August 12, 2008, 07:31:55 PM »
Limitations of the platform you are working in, as stated above, dotNet is nice to use, but you sacrifice a lot of flexibility with it.  I still do not personally see why anyone would choose C# over C++ because with well made libraries a C++ interface can be a lot more simple and a heck of a lot more powerful, although I do admit that making that initial 'pretty interface' can be hell. :P

sortkatt

  • Not-a-newbie
  • *
  • Posts: 11
  • Karma: 0
    • View Profile
Re: Officially supported dotnet wrapper
« Reply #6 on: August 25, 2008, 02:21:52 AM »
A simplified solution pops to mind that will lets you get the best-from-both-worlds and that is a sane interface between dotNet/C# or similar and RakNet running in a DLL. As RakNet already uses the dllexport keyword for interface functions, you can run function-calls directly from dotNet/C# (after loading the DLL from any dotNet project). The only thing "missing" is the callback-type communication from the DLL to the dotNet/C# application. But this should not cause too much of a problem, as there are many methods of handling this, and google is your friend to find solutions for such things. There are obviously a lot of limitations, and dissimilarities from the dotNet/C#-end but that does not negate the need/possible use of RakNet in a semi-heterogenous environment. In my opinion it all depends on how you see how broad the functionality of the "Wrapper" is. Like it is now, I see no limitations in the setup (It might be a bit of a simple interface, but it is doable using what already exits and some small aditions to handle callbacks)

I'm in the process of creating a project using dotNet/C# for the GUI-interface that controls the network functionality from my own RakNet-based DLL in this manner :) And in this context my usage is pretty simplified. The dotNet/C# end only does simple tasks as setting up buttons and handling simple events and simple data-storage.

This might not be the most efficient use of RakNet, but for simple logger-type or network status applications and similar that just need to exist because one already uses RakNet for other things, it does the task just fine... I would not try to build a business based on such a simple interface, myself... C++ is the way to go for some serious coding ;) There are alot of GUI-toolkits (gtk, wxWindows and similar) that have some really decent resource editors and that fits perfectly with C++ without much hassle, which I could have used instead, but I felt i needed some more C# training...
« Last Edit: August 25, 2008, 02:37:11 AM by sortkatt »

OvermindDL1

  • Anti-Spam Moderator
  • Hero Member
  • ****
  • Posts: 855
  • Karma: 40
  • Programmer
    • View Profile
    • OvermindDL1's Site
Re: Officially supported dotnet wrapper
« Reply #7 on: August 25, 2008, 08:55:42 AM »
That would allow you to access the basics of the library, but not the more advanced stuff, such as RPC for note.

harishb2

  • Not-a-newbie
  • *
  • Posts: 4
  • Karma: 0
    • View Profile
Re: Officially supported dotnet wrapper
« Reply #8 on: November 06, 2008, 10:08:32 AM »
Code: [Select]
// Assuming all the relevant includes and importing the namespaces

template<typename Func>
typename enable_if<
typename and_<
typename is_class< typename remove_pointer< typename remove_reference<
typename first<typename tail<typename func_parameters<typename Func> >::type
>::type >::type >::type >::type,
typename is_lt<
typename list_length< typename tail<
typename func_parameters<typename Func>::type
>::type >::type,
typename int_<10>::type
>::type
>::type,
typename FuncWrapped<Func> >::type
getFunctionWrapper(Func function)
{
return FuncWrapped<Func>::getOrCreate(function);
}
I am not being a trool or any thing, please take it as a compliment
I didn't understand a freaking thing in that code (excuse: gave up after 4 lines or so)  and i have been using C++  on and off for about 2 years now. Shows i have a mountain pile to learn.

chunky

  • Full Member
  • ***
  • Posts: 103
  • Karma: 8
    • View Profile
Re: Officially supported dotnet wrapper
« Reply #9 on: November 08, 2008, 10:43:49 PM »
No-one understands template trainwrecks :-)

Gary (-;

OvermindDL1

  • Anti-Spam Moderator
  • Hero Member
  • ****
  • Posts: 855
  • Karma: 40
  • Programmer
    • View Profile
    • OvermindDL1's Site
Re: Officially supported dotnet wrapper
« Reply #10 on: December 08, 2008, 02:48:44 AM »
Been away for a month, sorry.  :)

But yea, C++ metaprogramming is another programming language entirely.  Practically nothing you know about C++ programming will help you with C++ metaprogramming. :)

EDIT:  Let me go ahead and step through it to describe it.  First of all, the language is more similar to Lisp or a functional language rather then C++, but the first param in a () is to the left of a (), like a function call, and the () are <> instead.  Now, working our way from inner-most to outer-most:

Code: [Select]
template<typename Func>
typename enable_if<
typename and_<
typename is_class< typename remove_pointer< typename remove_reference<
typename first<typename tail<typename func_parameters<typename Func> >::type
>::type >::type >::type >::type,
typename is_lt<
typename list_length< typename tail<
typename func_parameters<typename Func>::type
>::type >::type,
typename int_<10>::type
>::type
>::type,
typename FuncWrapped<Func> >::type
getFunctionWrapper(Func function)
{
return FuncWrapped<Func>::getOrCreate(function);
}

typename func_parameters<typename Func> = This looks at the passed in function and converts it to a vector from its return type and parameter types.  It could take something like void myFunc(int i, float f) and type essentially (in a more C++ style construct) becomes an array of types that are [void, int, float] if you could use a type as a value in C++.

typename tail<...something...>::type = This should be very familiar if you know functional languages, this returns an array, but skipping past the first element, so the [void, int, float] that is returned from above, this "typename tail<typename func_parameters<typename Func> >::type" essentially returns [int, float] as I do not care about the return parameter.

typename first<...something...> = This is also functional, it returns the first element of an array, so from the above it return "int".

typename remove_reference<...something...>::type = If the something is a reference type (like "int&"), it removes the reference (so from "int&" it would return "int").

typename remove_pointer<...something...>::type = This does the same as just above, but for pointers (takes something like "myclass*" and returns "myclass").

typename is_class<...something...>::type = This tests if the something is a class type, if so then type becomes effectively true, else false.

typename list_length<...something...>::type = This takes a template array of types (like the [int, float] from above) and sets its type to the integer value of its length (in the example above, it would return 2).

typename int_<10>::type = You cannot use actual C++ values, like 10, in templates, so this converts a C++ int into a template int_ value.

typename is_lt<...something...>::type = This is a less then test ("<" in C++ parlance) that does the "first < second" and returns true or false (in the example above, it would be if(2 < 10)).

typename and_<...something...>::type = This is && in template format, just a binary compare and (&&) of all given values (can be more then just two).

typename enable_if<...something...>::type[/tt] = This tests that its first parameter is true, if so it returns the second param as its type, else if it is false, it will not allow this function to compile (but does not throw an error either, it lets another function try a test).  In the above code the return type of this becomes the return type of the function.

I was actually still learning template programming while writing that.  Now that is so little and practically nothing compared to what I have written this past month. :P
« Last Edit: December 08, 2008, 03:14:35 AM by OvermindDL1 »