View previous topic :: View next topic |
Author |
Message |
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Sat Nov 19, 2005 11:01 am Post subject: raknet |
|
|
I've created a binding for the C++ library Raknet.
www.rakkarsoft.com
I'm not going to commit them just yet, but if anyone wants a head start on getting raknet working for D, look here --> http://svn.dsource.org/projects/warbots/trunk/cinterface/
chat.d, lineserver.d, and line.d all work as advertised. Before I commit I'll make sure it works on windows and I might whip up some ddoc's.
Note that I havn't exposed the whole raknet interface, only the parts that I want to use. I'll add more as I need. If anyone has any requests for exposed functionality just ask here, and I'll whip them in. |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Wed Nov 23, 2005 10:46 pm Post subject: |
|
|
Well, I've since learned that it is currently impossible to get the raknet bindings to work with windows due to linker issues. Somebody please prove me wrong
Linux users, get your raknet bindings here --> http://svn.dsource.org/projects/bindings/trunk/raknet/
Some mighty windows programmer, get raknet to work on windows |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Wed Nov 23, 2005 11:48 pm Post subject: |
|
|
I'm no mighty windows programmer, but I'm very curious to figure out what's going on here. I've struggled with similar problems with dmc several times before over that last few years (huge amounts of annoyance; sometimes solved, sometimes not).
Maybe I can fiddle with it and see what's going on. No promises, though. Honestly, I don't know why I'm doing this to myself: I'm likely to start banging my head on my keyboard in frustration.... I can see it coming again...
-JJR |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
Posted: Thu Nov 24, 2005 2:15 am Post subject: |
|
|
clayasaurus wrote: | Well, I've since learned that it is currently impossible to get the raknet bindings to work with windows due to linker issues. Somebody please prove me wrong |
Mike84 from the Damage project did it I was a tester. Works |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Thu Nov 24, 2005 3:43 am Post subject: |
|
|
Hmmm... I never had a close look at the damage project. It seems to have no listing in the project tab anymore. |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Thu Nov 24, 2005 11:51 am Post subject: |
|
|
Yeah, I saw it when you first pointed it out. I was just a little surprised that it was hidden. Maybe Brad can get it linked up again.
It's too bad Mike84 doesn't have any source in the trunk section. It would make the code much easier to browse. Having to download the large archived files (like source.tar) with dialup is a bit of a pain.
It's good to see that he's got raknet working on windows, though. I had already started trying to get dmc and tools working with Clay's port. I've got exactly two symbol conflicts in the link process now. I think it's the way Clay has the C++ set up. I don't think dmc likes it. Acutally, dmc goes into contortions on the regular raknet code. I was surprised at how much code I had to change to get it to progress through the code. (this was while I was experimenting in trying to compile the whole C++ RakNet project with dmc; didn't get too far yet)
With Clay's rakglue source:
For example, each rakglue/*.h file includes the raknet/include/networktypes.h file. When you compile each rakglue/*.cpp file, it appears that you are including separate instances of the global PlayerID struct constant, UNASSIGNED_PLAYER_ID. I have no idea how to make dmc see it as a single instance so that the lib command doesn't pull it in 3 times, once for each object file. Also the "extern" directive in rakglue on the dataStream variable doesn't see to do the job. The linker can't see it when I try to compile chat.d.
We'll see how Mike84 did it. It's likely that he's saved me a huge amount of trouble.
-JJR |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
Posted: Thu Nov 24, 2005 12:01 pm Post subject: |
|
|
JJR wrote: | It's too bad Mike84 doesn't have any source in the trunk section. It would make the code much easier to browse. Having to download the large archived files (like source.tar) with dialup is a bit of a pain. |
Yup... but he's not working on the project. He was looking for someone to pick up where he'd left the code. IIRC he was too busy due to some college stuff.
Quote: | I was surprised at how much code I had to change to get it to progress through the code. (this was while I was experimenting in trying to compile the whole C++ RakNet project with dmc; didn't get too far yet) |
Isn't it why we all love C++ so much ?
Quote: | We'll see how Mike84 did it. It's likely that he's saved me a huge amount of trouble. |
IIRC, he's done a simple wrapper DLL using Visual Studio. He then loads just one function from it. The function in turn returns a struct which contains all the needed function pointers to C wrapper functions over the C++ interface... |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Thu Nov 24, 2005 1:07 pm Post subject: |
|
|
Yeah... I see how he did it now. It's deceptively simple. He basically added a file to the original RakNet source that includes a single exported C function. This function, getAPI, is compiled into the RakNet.dll as __declspec(dllexport), and is therefore loadable by a D program. getAPI initializes a struct that contains pointers to all the wrapped functions in that source file (main.cpp). Build the RakNet project with Visual C++ and voila! The D program just has to load the single function from the DLL.
His method is simple and effective. It's a good method to remember for future ports.
Clay, Mike84 has done all the hard work for you (and me).
-JJR |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Thu Nov 24, 2005 1:14 pm Post subject: |
|
|
h3r3tic wrote: | Quote: | I was surprised at how much code I had to change to get it to progress through the code. (this was while I was experimenting in trying to compile the whole C++ RakNet project with dmc; didn't get too far yet) |
Isn't it why we all love C++ so much ?
|
You can say that again!!! I can't stand it! There are so many inter-compiler differences, I don't know how C++ has survived. It's absolutely, positively disgusting. The templates were such an eyesore in RakNet, I almost went blind! Death to C++!
-JJR |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Thu Nov 24, 2005 11:47 pm Post subject: |
|
|
Two things I don't understand about mike's port...
1) It doesn't define PlayerID
2) Packet is align( 8 ), why is that? *confused*
anyway, hopefully my playerID works with it |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Fri Nov 25, 2005 12:16 am Post subject: |
|
|
1) PlayerID was hard to find. It's defined in shared/s_shared.d:
Code: |
align(8) struct PlayerID
{
uint binaryAddress;
ushort port;
} |
2) I don't know about Packet. I believe it means align the structure members at 8 byte (64 bit) boundaries.
I'm not sure why this is necessary, but perhaps mike found that the connection to RakNet didn't work without this alignment. Perhaps it was necessary to match the default alignment of Visual C++ builds. If the RakNet library had been built with DMC, I doubt that this explicit alignment would be necessary.
I was looking at your playerID earlier. I'm not so sure it will work. At the very least, it's probably wise to remove the operator overloads for now. They shouldn't be needed external to the library anyway. That's the safe thing to do, I guess.
-JJR |
|
Back to top |
|
|
h3r3tic
Joined: 30 Mar 2004 Posts: 261 Location: Torun, Poland
|
Posted: Fri Nov 25, 2005 5:33 am Post subject: |
|
|
JJR wrote: | Death to C++! |
Wow ! Now that sounds great ! I visualize a furious D programmer in a silver medieval armor striking his evil C++ opponents with a new shiny DMD version /+ I aint sick +/
/+ I'm sure Mike would answer any doubts regarding the align ( 8 ) /+ or anything else +/ if PM'ed +/ |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Fri Nov 25, 2005 11:27 am Post subject: |
|
|
Heh... well, I have to apologize. My words may have sounded a little extremist. Mostly I was just venting after playing with a little too much C++. Apparently, it was a shock to my system to try my hand at it again.
Crusader or not, conversion by force isn't a solution.
-JJR |
|
Back to top |
|
|
clayasaurus
Joined: 21 May 2004 Posts: 857
|
Posted: Fri Nov 25, 2005 5:13 pm Post subject: |
|
|
No, we'll have to make do with conversion by subversion Seriously, though, just getting the word out about D is enough. If people are sick of C++ and want a better alternative and know about D, chances are they will start coding in D.
----------------
I got my bindings to work with windows. *hurrahh* I also got my windows box to connect to my linux box with raknet, with my super advanced opengl networked line drawing program : )
I added my hacked windows raknet sources and the linux sources I used and my raknet.lib and raknet.a files. This is so when new versions come out and don't work with these bindings you just grab the sources from here instead, until someone wants to have a go with C++ again or Rakkar decides to support DMC.
Happy networking
~ Clay |
|
Back to top |
|
|
|