PDA

View Full Version : .NET library


sdether
10th August 2005, 22:04
Those coming over from the RSC programmers forum are likely already aware of this, but since this is a nice clean new board, i figured I'd just point out that there is a .NET wrapper around InSim, for those working in .NET and not wanting to have to figure out the InSim protocol.

Current version is 0.06b

Current NDoc (http://www.claassen.net/geek/lfs/insimlib/)

Release Notes (http://www.claassen.net/geek/lfs/NOTES.txt)

Source Release (http://www.claassen.net/geek/lfs/InSim-0.06b.zip)

Binary Release w/ Sample (http://www.claassen.net/geek/lfs/Tester-0.06b.zip)

xaotik
17th August 2005, 09:31
Ah - hey, thanks for this. :)

Bruce314
17th August 2005, 09:47
As developper, I looked for the protocol and found a post on RSC forum with a link which seems dead : http://www.liveforspeed.net/file_rsc.php?name=LFS_S1G_DEDI.zip

Can someone tell me where I could find the protocol specification? As Linux user, a .net library doesn't please me too much, I was thinking of java or perl but I'd like to have a look to the protocol before speaking of my ideas ;-)

See ya later

Bruce

the_angry_angel
17th August 2005, 10:32
Most of the "documentation" (inline code commentry, iirc) is within Scawen's LFS Control - but unfortunately that isnt on the site at the moment. Other than that, I dont know of any more detailed information about InSim's protocol.

When I get home, I maybe able to dig out the original LFS Control zip for you.

Incidentally, you could try running this on Mono, but I dont think it'll hold up too well tbh, and there is a Python InSim library on RSC, somewhere - but its out of date.

Edit:
Perhaps if sdether or Messiah have time, they could write us up some docs for InSim - I know that I'd really like a quick reference at least :)

*pretty* please guys?

xaotik
17th August 2005, 10:37
Can someone tell me where I could find the protocol specification?

<lfs_install_dir>/docs/InSim.txt ?

the_angry_angel
17th August 2005, 10:59
:doh:

Bruce314
17th August 2005, 12:03
I'm caught : looking from documentation from work, I had no lfs install on my local drive (just try to find why :-p )
In fact, I could download the self-working server on a third party server (thx google) and found the file bundled inside. I've had a quick look, it seems quite easy to use... I'll make some test and let you know of my ideas later. I wish I could set a useless server on my local computer at work, but I'm not sure everyone will be pleased with that...
By the way, I think about writing an interface in java, to be able to use it on every environment and take benefit of this wonderful language... Time to go back to my IRL work...
Thx a lot to all and excuse my stupid question...

Bruce

sdether
17th August 2005, 13:57
Can someone tell me where I could find the protocol specification? As Linux user, a .net library doesn't please me too much, I was thinking of java or perl but I'd like to have a look to the protocol before speaking of my ideas ;-)

As has been pointed out the full docs are in the zip file for LFS. However, may I suggest taking a look at Mono (www.mono-project.com). You may not be able to use the tester application (yet), since Windows.Forms isn't complete yet, but the rest is fine under linux.

I was a perl programmer on linux for about 8 years before I started with C#, so i wanted to make sure that I didn't tie my future career to MS with accepting a .NET position. My experience with Mono makes me believe that it's a very viable platform on unix. Novell's been doing an excellent job supporting it and a lot of smart people from various Open Source projects are working on it.

Of course, having said this, someone building a good Perl library for InSim would be quite nice as well, and a worthy addition to CPAN.

Edit: Or you could take my lib to Java (it's GPL after all). There's some esoteric stuff in there, mostly all the Sequential layout structs for loading the data, but it may be easier to take the C# and translate it to java than starting from scratch.

BurnOut69
20th August 2005, 20:45
Hi guys,

Nice to see that you can mess with LFS 2 from a programming point of view, being a programmer myself I've been messing with a lot of other sims I played (SCGT, Nascar Heat) but this is way better.

Even better to see things developed in .NET as I am a C# freak myself :)

As soon as I get back from my holidays I'll look into it.

A programming sub forum in a racing sim forum! :D Just awesome

Cya around or on the track

GhostVE
25th August 2005, 11:03
Just a quick question to make sure I am not missing something :

Except the CarInfo structure which provides the car's speed is there any other structure that reports while racing telemetry data - RPM, current gear and so on ? My guess is no, because I could not find anything related, in case I am wrong can you point me to the right direction ?

Bruce314
25th August 2005, 11:20
thought I read somewhere something about an outSim, which can be setup from root to choose on which port it interacts (there are some configuration files, choosing the rate). First handshake udp paquet sent on inSim has a flag to choose whereas you want to start spooling these paquets. Never tried myself (hugh, I've a job and a wife IRL), but it seems to give informations for cockpit simulators (accelerations, position, speed...) Can't remember exactly - too hard to find time to read doc, write code and play a little - but you should find some info related to this in your root lfs folder and root/doc...
Have fun!

GeForz
25th August 2005, 11:24
Just a quick question to make sure I am not missing something :

Except the CarInfo structure which provides the car's speed is there any other structure that reports while racing telemetry data - RPM, current gear and so on ? My guess is no, because I could not find anything related, in case I am wrong can you point me to the right direction ?
Did you read the "Car Position Packets" part in the InSim.txt file which is about OutSim? (leading to the end of the README.txt) perhaps that helps you

GhostVE
25th August 2005, 15:12
thought I read somewhere something about an outSim, which can be setup from root to choose on which port it interacts (there are some configuration files, choosing the rate). First handshake udp paquet sent on inSim has a flag to choose whereas you want to start spooling these paquets. Never tried myself (hugh, I've a job and a wife IRL), but it seems to give informations for cockpit simulators (accelerations, position, speed...) Can't remember exactly - too hard to find time to read doc, write code and play a little - but you should find some info related to this in your root lfs folder and root/doc...
Have fun!


Did you read the "Car Position Packets" part in the InSim.txt file which is about OutSim? (leading to the end of the README.txt) perhaps that helps you


First of all thank you for responding... If I quote from the README.txt

Each update sends the following UDP packet :
unsigned int :time in milliseconds (to check order)
Angular Velocity :3 floats
Orientation :3 floats Heading, Pitch, Roll
Acceleration :3 floats X, Y, Z
Velocity :3 floats X, Y, Z
Position :3 ints X, Y, Z (metres x 65536)
Game ID :1 int (optional ID - if specified in cfg.txt)

Maybe I did not express my question well (english is not my native language).
What I am asking is whether there is some other structure where you can pull out from OutSim information about engine RPM, currect gear, how much fuel left and so on... What I want to do is hook up a few gauges with servo motors and have my program read these values from LFS in order to drive the gauges....

sdether
25th August 2005, 16:14
Maybe I did not express my question well (english is not my native language).
What I am asking is whether there is some other structure where you can pull out from OutSim information about engine RPM, currect gear, how much fuel left and so on... What I want to do is hook up a few gauges with servo motors and have my program read these values from LFS in order to drive the gauges....

You are quite correct. A lot of telemetry information is not currently available. Outsim is primarily for physics data, supporting motion simulators and the like.

What is missing (and plans are unknown) is technical data about the car's state such as current gear, rpm, tire condition, brake condition, pedal positions, steering wheel position, fuel level, etc. All data that's available to the driver, but not in a data format outside the game.


I can think of two reasons why this information doesn't yet exist:

1) It would open up all sorts of new aids that could be programmed and might be considered undesirable. I doubt this is the reasons, since the existing data already opens up a lot of possibilities

2) Of all the data in LFS, this is the most volative, just looking at what all
has changed since S1 alone. I can see not wanting to define packets for this information until car features are more locked down.

I would love that data however. One application that I would try to undertake if I could access it is either create an interface to feed the data into a real Motec HUD to be used on the steering wheel for the FOX and FO8, or build a Motec replica that does the same thing.

While I'm babbling about this, I would like to see this data as a subscription based set of packets, so you could tell InSim which set of data you want to listen to (all data could be a lot of data) and what player you want to listen for. Since a large number of applications for telemetry would be client side, it would be nice to be able to just get info on the active car.

GhostVE
25th August 2005, 16:34
Thanks sdether, just wanted to make sure I did not miss anything while reading through the InSim/OutSim specs and your lib. By the way nice work wrapping up all the InSim/OutSim protocol, keep it up. I guess I'll give Nascar 2003 a try, although I mostly play LFS.
I totally agree with you that it would be nice to have this data available, imagine the possibilities ....

xaotik
28th April 2006, 14:12
Heads up. :)

http://www.lfsforum.net/showthread.php?t=7321

sdether
29th April 2006, 18:38
Yeah, saw the spec for OutGauge. Awesome. I hope to have a new version of the my lib out in the next week that has the packet changes for S/T/U in insim and adds OutGauge support

CrazyICE
2nd May 2006, 17:00
nice one!
maybe there is also a source of OutSim and/or OutGauge?

sdether
2nd May 2006, 17:10
I created a separate DLL for OutGauge. Figured there was no reason to force dependence on the InSim DLL. Ihave not done one for OutSim. But really creating OutSim should be trivial based on OutGauge.. Basically just a matter of swapping out the data structures and accessors. I will package it up and post it tonight, dll, source and test app.

CrazyICE
2nd May 2006, 19:25
nice...
i'm currently starting with c#!
i use delphi 7 atm...
so, i'm not used to c#!

thx!

sdether
2nd May 2006, 21:44
nice...
i'm currently starting with c#!
i use delphi 7 atm...
so, i'm not used to c#!

thx!

Hope you'll enjoy it. I started using it a couple of years ago and being and OO bigot, have found it to be very enjoyable. My mainstay for the 5 or so years before that was perl and with the odd java in there as well. Before that was C/C++ and before that was LISP. Started in Turbo Pascal about 20 years ago, which i guess is an ancestor of Delphi.

CrazyICE
3rd May 2006, 10:11
yep...
i learned turbo pascal 7 at school, and thenm VB (also at school), then,
I made the network-admin and then started to be a programmer and therefor
with delphi!
but i like to change my job and want to start using c#...

c# is nice, but different to delphi :)

Tanuva
15th May 2006, 15:26
eehm... if possible, how do I get this code loaded correctly in VC++ ExpressEdition? I always get an empty solution... Or can I get it somehow loaded into Dev-C++? :shrug:

Or doesn't it work in C++ at all and I have to learn C#? :really:

sdether
15th May 2006, 16:12
eehm... if possible, how do I get this code loaded correctly in VC++ ExpressEdition? I always get an empty solution... Or can I get it somehow loaded into Dev-C++? :shrug:

Or doesn't it work in C++ at all and I have to learn C#? :really:

It's C#, so it probably won't load up in the C++ Express edition. The DLLs should be usable from C++ though.

Vain
15th May 2006, 16:19
Oh, and if I may say something personal on the topic:
Die C#, die!
Thanks for paying attention. :)

Vain

AndroidXP
15th May 2006, 16:27
And why did you feel the need to such a comment? Atleast add a reason for your disliking of C#.

Vain
15th May 2006, 16:31
I dislike it for the same reason I dislike java: I don't like it.
I tried it, got to a point where I could write programs easily, and dropped it. Just like java.
Try looking at it this way: Some people like Live For Speed and nKpro. Some people like LFS and dislike nKpro. Some people like nKpro and dislike LFS. Some people don't like either. I dislike C# and java, but like Cpp.

Vain

Tanuva
15th May 2006, 16:31
It's C#, so it probably won't load up in the C++ Express edition. The DLLs should be usable from C++ though.
Okay, then I gonna try them.

@Adroid XP: I can imagine a reason: It's microsoft-made :nod:

AndroidXP
15th May 2006, 20:09
...Hmm, okay, I instantly disliked Java but on the contrary instantly fell in love with C#. I started out with C++, but having to do everything myself got very boring very fast. For me, C++ seems to be for people who either really need that last bit of performance (in games programming f.e.) or who simply think it's cool to write unreadable code ;). For application and web development (what I do) it would be a waste of time (wait, can you even do web stuff with C++ :confused:).

MonkOnHotTinRoof
15th May 2006, 21:33
Hmm, okay, I instantly disliked Java but on the contrary instantly fell in love with C#.

Same here.


(wait, can you even do web stuff with C++ :confused:).


Sure you can. CGI for example can be binary executable.
My personal favourite was assembly language. Haven't used it for a long time now though :(.

@Tanuva: If you don't like MS (hardly anyone does really), you can use Mono or DotGNU.

the_angry_angel
15th May 2006, 23:29
Same here.



Sure you can. CGI for example can be binary executable.
My personal favourite was assembly language. Haven't used it for a long time now though :(.

@Tanuva: If you don't like MS (hardly anyone does really), you can use Mono or DotGNU.
You used ASM for web cgi? Do you have no fear?

Messiah
16th May 2006, 14:07
Okay, then I gonna try them.

@Adroid XP: I can imagine a reason: It's microsoft-made :nod:
Hm if its Managed C++ using .NET you should be able to add the library as a "Reference" like the .NET Assemblies in the GAC (System, System.Data, System.Windows.Form, ...). Just "Browse" for it in the add dialog.

I dislike C# and java, but like Cpp.
Its not a suprise to me, that C++ programmers dislike C# without giving any good reasons... no, its usually because they don't know any good practice on C#, the languages seem very similar but differ in many points significantly. So most of the time people dislike it because they don't know s.it about it and things don't work as expected for them. Thanks for paying attention :P

sdether
16th May 2006, 16:30
What the heck.. I wasn't going to jump into the language arguments, but they are so much fun :) What follows is off topic and just my reasoning for using the languages I like to use.

I like C# and java, but both as languages, not as religions. Coming from LISP, C++ always gave me headaches with its syntax. If i have to do my own memory management in an OO language, I try to use Objective C instead, however fringe it is now. That said, writing code in a modern framework without a GUI with an object browser would drive me back to C any day, rolling my own terse code. Verbosity in frameworks is only good if the computer takes over the book keeping of what exists and how to call it.

I haven't had a need for the speed of C or C++ in ages. If perl and php are fast enough for webapps, then the java's speed is not an issue. Java isn't slow. Building giant black-box EJB, n-tier systems is slow and would be in any language.

C# is nice and fast (comparatively) and with managed DirectX, i can do full 3D programming without having to switch to a lower level. I'm not saying LFS could be done as efficiently in Managed DirectX.. maybe it could, probably it can't... But so far I've not had the need for that kind of performance in any of my jobs or hobbies.

Hollywood
16th May 2006, 17:57
C# is nice and fast (comparatively) and with managed DirectX, i can do full 3D programming without having to switch to a lower level. I'm not saying LFS could be done as efficiently in Managed DirectX.. maybe it could, probably it can't... But so far I've not had the need for that kind of performance in any of my jobs or hobbies.

Sdether,

Took a look at the .NET library, looks really good and quite solid although I haven't done an in-depth look at it; but glad I checked here first before I started to bring my old InSim.NET up to .NET 2.0. :) Just from a quick-hit standpoint, I'd be a bit concerned about the foreaching through the InvocationList and calling BeginInvoke on it. Otherwise at least quick glancing most of my objections are cosmetic (i.e. the #s in the regions are a bit much, and I always use the underscore prefix to differeniate member variables from local variables, etc.)

Oh, a trick with Log4Net is do the following:

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase. GetCurrentMethod().DeclaringType);

That way you can just macro the line and plop it at the top of any of your classes easily.

Have you run it through fxCop yet? If not, I highly recommend it.

Gah, you would use the viral GPL license. Its probably fine for a project such as this where there are is absolutely no real excuse for not sharing the source of applications that make use of the framework. However, there *are* far better open source licenses out there. :)

As far as Managed DirectX, no one should be fooled into thinking that it is anything more than a managed wrapper to the DirectX COM objects since its not (quite check using Reflector shows this to be the case). This *may* change to some degree with DirectX10 (interesting to note that WPF will wrap some DirectX10 functionality, and actually does wrap some DirectX9 functionality in the beta in a more 'managed' fashion, but also limits your ability to use all of the DirectX functionality).

The performance penalities from writing something like LFS in C# come from the bridge between the .NET IL objects and the DirectX COM objects and the .NET virtual machine. There is available from MS with VS2005 generators that will take .NET assemblies and generate machine code executables from them so that generally takes away the .NET virtual machine penalities. As most C/C++ developers know, there are plenty of optimizations you can do with pointers and thats one thing that the managed environment doesn't and won't have, so those optimizations just won't be there unless you really get down into the IL.

I forget the name of the game, but there was a retail RTS released recently that was written all in .NET and using the managed DirectX wrapper.

Hollywood
16th May 2006, 18:08
Building giant black-box EJB, n-tier systems is slow and would be in any language.

Yes, actually architecting and developing large n-tier systems is a time consuming process no matter what technology you use but performance on the other hand is very good if the hardware has been spec'd out correctly based on predicted loads, etc. But all sorta off topic.

sdether
16th May 2006, 18:15
Yes, actually architecting and developing large n-tier systems is a time consuming process no matter what technology you use but performance on the other hand is very good if the hardware has been spec'd out correctly based on predicted loads, etc. But all sorta off topic.

I agree.. It's just 99% of the "enterprise" systems I've dealt with were built as a magic bullet to let developers write EJBs without knowing anything about the system and without enforcing proper architecture on the whole system, which ended up with amazing resource hogs that were never planned for and sysadmins constantly having to reboot the jvm because it wasn't tuned right for the new component that was just deployed.

sdether
16th May 2006, 18:24
Took a look at the .NET library, looks really good and quite solid although I haven't done an in-depth look at it; but glad I checked here first before I started to bring my old InSim.NET up to .NET 2.0. :)
I actually have my stuff in 2.0 and have been backporting it to 1.1 for release, since i didn't want to force people to go 2.0 quite yet.

Just from a quick-hit standpoint, I'd be a bit concerned about the foreaching through the InvocationList and calling BeginInvoke on it. Otherwise at least quick glancing most of my objections are cosmetic (i.e. the #s in the regions are a bit much, and I always use the underscore prefix to differeniate member variables from local variables, etc.)

The reason i use the InvocationList and BeginInvoke is to allow asyncronous event handling. I think i set it up so you can choose via config whether you want that behavior, but basically i didn't want some process receiving events to be able to block the reader thread from receiving more data. And i don't want event handler exceptions to kill the event sending.


Oh, a trick with Log4Net is do the following:

private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase. GetCurrentMethod().DeclaringType);

That way you can just macro the line and plop it at the top of any of your classes easily.

yeah, found that trick a couple of months after i started the insim project and never went back to clean it up :(


Have you run it through fxCop yet? If not, I highly recommend it.

Honestly, I've been afraid of what it would bitch at me about :)


Gah, you would use the viral GPL license. Its probably fine for a project such as this where there are is absolutely no real excuse for not sharing the source of applications that make use of the framework. However, there *are* far better open source licenses out there. :)

Basically, i use the GPL to put things out there. Doesn't mean I am not open to other licenses if someone wanted one. It's just if someone wants to use it and not deal with me, then they get the GPL.


As far as Managed DirectX, no one should be fooled into thinking that it is anything more than a managed wrapper to the DirectX COM objects since its not (quite check using Reflector shows this to be the case). This *may* change to some degree with DirectX10 (interesting to note that WPF will wrap some DirectX10 functionality, and actually does wrap some DirectX9 functionality in the beta in a more 'managed' fashion, but also limits your ability to use all of the DirectX functionality).

Yeah, i was switching things over to MDX 2.0 to get all the lovely generic stuff, and then they did the XNA announcement and pulled the rug from underneath me. So until the plans for XNA firm up i'm stuck with the slower MDX 1.0 stuff which has some issues under .NET 2.0, but for my uses, it's plenty fast.

Vain
16th May 2006, 18:38
I started the discussion on "I like C# vs I don't like C#" here so I'd like to end it:
I refer to C# and java as "get the job done"-languages. A program in java can look simple, can be easy to write and there are great developer-enviroments that help you to get code that works quickly.
But I like C++ for other reasons. I learned programming with C++ and behind every line of code I see pointers and memory-addresses. I get enormeous joy from using a pointers like dart-arrows and producing code that is about as unreadable as the debuggeroutput of self modifying assemblercode. In a library I made for myself and a friend I once wrote the comment behind a dangerous line of code that pretty much hits it on the head:
/* The user is propably about to shoot himself in the foot - well, I won't stop him! */
That's what I like about Cpp. :)

Vain

AndroidXP
16th May 2006, 19:39
So I was right, afterall :razz:

Dygear
16th May 2006, 21:11
I ... ya know, this should go into the off topic programming thread ... see ya there.

Hollywood
17th May 2006, 01:01
The reason i use the InvocationList and BeginInvoke is to allow asyncronous event handling. I think i set it up so you can choose via config whether you want that behavior, but basically i didn't want some process receiving events to be able to block the reader thread from receiving more data. And i don't want event handler exceptions to kill the event sending.

Right, I realize that and you actually have to especially if using Windows Forms.

However, I was just making a comment that it was a tad concerning with the invoking in a foreach loop which does casting to the Delegate and then you do casting to the actual delegate. Also, I believe (at least for 1.1) I recall that foreach was actually slower than a for. So you might want to switch to a for loop that casts to the actual delegate, that way there is only one casting going on.

yeah, found that trick a couple of months after i started the insim project and never went back to clean it up :(

Yeah... lots of little tricks to log4net. Do like it though, sure better than the Microsoft "logging". :/

Basically, i use the GPL to put things out there. Doesn't mean I am not open to other licenses if someone wanted one. It's just if someone wants to use it and not deal with me, then they get the GPL.

No problem. Like I said, GPL works ok for this type of project where there really isn't a compelling reason to not keep projects that utilize your framework open. I've been writing a bunch of non-related frameworks that I've been thinking about putting to open source and I've been completely turned off by the GPL, LGPL and the FSF. Especially because of the viral nature of the GPL.

Yeah, i was switching things over to MDX 2.0 to get all the lovely generic stuff, and then they did the XNA announcement and pulled the rug from underneath me. So until the plans for XNA firm up i'm stuck with the slower MDX 1.0 stuff which has some issues under .NET 2.0, but for my uses, it's plenty fast.

Yeah, pretty much. I actually am using the Irrlicht engine with their .NET wrapper; saves me the hassle of dealing with all the MDX/XNA, etc. plans and basically comes out to be the same thing as MDX plus some. Ogre and its .NET wrapper would do the same thing.

As far as this non-sensical "discussion" about C#/.NET platform. Its just another tool. Use it or don't, but really discussions about what language is better are really rather pointless in the end. Personally I've written applications in everything from C/C++ to Forth to Fortran to Pascal to VB to Java and others. It matters little other than whats available to do a certain job based on the requirements and environments of the job.

And no, just because C#, and any .NET managed language implementation, and Java (and actually any languages written to compile to the JVM) or even VB, Pascal, etc. don't expose pointers does not mean that its "easy" to write a quality application or even a framework such as what sdether and Messiah, respectively, put together.

sdether
17th May 2006, 03:54
Yeah... lots of little tricks to log4net. Do like it though, sure better than the Microsoft "logging". :/

Sweet Jesus.. i know, i shouldn't keep this back and forth going--sounds like it could go on for a while--but, at my other gig, we initially tried the Logging Application Block from MS. Hey, the system we were building was supposed to be a proper MS enterprise application and all. I finally just pulled rank, instituted log4net and, really, everybody's been a lot happier and productive.

Tanuva
17th May 2006, 12:36
Hm if its Managed C++ using .NET you should be able to add the library as a "Reference" like the .NET Assemblies in the GAC (System, System.Data, System.Windows.Form, ...). Just "Browse" for it in the add dialog.
Yep, thats what I've got until now - seems like I just have to learn a fat bunch of cpp until I get it to work :D

CrazyICE
17th May 2006, 12:40
me is going to learn C# right now...
i think this is a language for the future, so go on, sdether, and finish this .net
lib :D hehehe

sdether
17th May 2006, 13:59
CrazyICE,

I'm trying, i'm trying :) Seriously, I hope to have the new version with single lib InSim, OutSim and OutGauge finished in a matter of days. It's just other tasks keep intruding.

the_angry_angel
17th May 2006, 14:15
I've been writing a bunch of non-related frameworks that I've been thinking about putting to open source and I've been completely turned off by the GPL, LGPL and the FSF. Especially because of the viral nature of the GPL.Sounds like you want the MIT or Apache licenses (sorry if you've already mentioned this)..

CrazyICE
17th May 2006, 14:18
CrazyICE,

I'm trying, i'm trying :) Seriously, I hope to have the new version with single lib InSim, OutSim and OutGauge finished in a matter of days. It's just other tasks keep intruding.

don't panic :D
i know that problem very well :D