The online racing simulator
C++ - LFS Session Timing (application/tutorial)
SMALL UPDATE (2008-08-29):

The CInsim library was replaced with a newer version, but in this application no new features are used.


LFS SESSION TIMING v0.1

Ok, here is the application I made based on the example request by Dygear (http://www.lfsforum.net/showthread.php?t=46253).

First of all, I didn't know where to post this, as a reply to Dygear's thread, here as a new thread, or in the unofficial addons sub-forum. As it's more an example/tutorial I've chosen to post it here, moderators feel free to move it elsewhere, merge it with another thread, etc.

Also I'd like people to test it. I haven't tried it for long periods of times with many people connecting and leaving. Give me some feedback please! And take a look at the code!



But, WHAT THE HELL IS THIS?

It's an example InSim console application using the C++ language and my own small library.

It's meant to be used as an example/tutorial, and helping people understand how InSim works.

This application writes tons of stuff to the console. If there are too many players it might be impossible to follow, but if there are just a few, you can keep an eye on the console and pretty soon you will have a good idea on how InSim works, and what the application is doing at any time.

There are a lot of comments in the code too so it's easy to read and analyze



WHAT DOES IT DO?

It just shows extra information every time a driver completes a sector of the track. That info is:
  • Sector time coloured depending on how fast it was. Purple is global best, green is personal best and yellow is used in other cases.
  • Difference to the best lap of the session at that point. Red means you are slower, green means you are faster, and white is used if you are doing the exact same time.
This info is shown to you just below the default race control message that shows your split time, and should disappear approximately at the same time as the default split time RCM.

To achieve this I have used transparent buttons. If you use RCMs they overlap (and erase) the standard split time, and you can't have several RCMs at one point, so buttons are an alternative, although their colors might be a bit too bright for some people.

There are some added features, like consulting lap and sector times for any driver connected to the server, the best times, and disabling the screen messages.

Admins also have more features, like making times permanent or resetable at each restart. By default all times (both individual and global) get reset at each restart, but you can set it so they are permanent. In that case they are reset only when the track is changed. Admins can also reset the times at any given time.



QUICK START

Just run the executable in the zip with 3 arguments: IP PORT ADMIN_PASS
(The PThreads dll must be in the same directory)

I recommend to create a Windows link and add those arguments in the properties.

Connect to the server and the help screen should appear. You can be in the server when the application starts, but be warned that the first thing it does is send everyone to spectators. The help screen is pretty self explanatory.

Start running!



LIMITATIONS

The application doesn't know when you are in shift+F mode, so you have to manually turn screen messages off, because buttons show even when you are in shift+F mode.



NOTES:

A file called insim.h is used. This is the original InSim.txt file included in the docs/ folder of your LFS installation, renamed to a .h. The only change that has been done to this file is in the line 1568:

char Text[112]; // 0 to 240 characters of text

The original button struct does not define a static text size, but permits different sizes. As a novice programmer I didn't know how to use buttons with variable sized texts, so I fixed it to 112. This causes a notable overhead when sending multiple IS_BTN packets to the server. If anyone knows how to use variable sized text with this CInsim library please tell me!!!

I'm also open to suggestions and awaiting for corrections to the code!
Attached files
LFS Session Timing v0.1.zip - 184.1 KB - 851 views
Is this client-sided or server-sided application?
Otherwise thanx i have learned much out this app. keep it going up.
Quote from versusboy :Is this client-sided or server-sided application?
Otherwise thanx i have learned much out this app. keep it going up.

Both, if it's just on the client, it will only show the messages to you (if you input the admin password for the server your connected too it will act as if it where connected to the server). If it's server side, it will show the messages to everyone.
Do you have any screenshots?
Shot in the dark request for help.
I downloaded this, along with Code:Blocks & the latest MinGW.
It doesn't want to link though, and I get the following error:

ld.exe cannot find -lpthreadGC2

I'm guessing it can't see the lib, which is in the project directory.
Can anyone shed some light?
I got TAAs insim demo to build & run. It has no libs though.
The linker tries to link against pthreads, a threading library. (who would have guessed )

It should not be shipped with the project itself, but you can install it from cygwin setup (libs section).

If it is the wrong version (hence gc2 corresponds to gcc 2.9.x and cygwin comes with gcc 4.x ), you would need to adjust the makefile to reflect the installed version.
This is a snail of a thread, pretty much 1 post every ~4 months or more.

Anyways MaKaKaZo, why don't you use the flag provided by InSim to check whether the interface is shown or not. I recently read about it in InSim.txt while I was searching for a solid way to detect certain things.
Thanks for your reply yankman.
It's probably best if I give up now.
Quote from Kiyoshi :Shot in the dark request for help.
I downloaded this, along with Code:Blocks & the latest MinGW.
It doesn't want to link though, and I get the following error:

ld.exe cannot find -lpthreadGC2

I'm guessing it can't see the lib, which is in the project directory.
Can anyone shed some light?
I got TAAs insim demo to build & run. It has no libs though.

Everything is provided within the file, both the pthreads library and the dll (I checked the license terms and I think I can provide the dll as long as I provide all the code of my project).

I don't remember very well, but this was a bit tricky. I think you have to link the project to the '.a' file (the library), and then have the dll file in the same dir as the executable generated. I mean, even if you link to the library during compilation and everything looks fine, you need to have the dll to launch the application. I tried many things and I went through many forums and nobody seemed to have the answer as to how to link the pthreads library statically to the project so you don't need the dll afterwards using code::blocks.

Remember: link project to "libpthreadGC2.a" and then place "pthreadGC2.dll" in the same directory as the binary executable. If you use code::blocks the executables are generated in folders named "release" or "debug". You can't launch the application from there unless you copy the dll to those folders.

Anyway, in the bin/release folder of the zip file you can find an executable which you can copy to the directory where the pthreads dll is and you can run it directly, no need to compile it if you just want to test it.


@blackbird04217:

I know that there's a lot of stuff missing or that could be improved in this app. But I don't know exactly the purpose of doing what you say. What is wrong?

I guess one of the main things to improve would be to detect the kind of session (multiplayer/single player), and connection to either client/host to make some things better. Right now it's designed as server oriented, and you if you connect it to your client it won't work, or work badly.
Hi MaKaKaZo, thanks for your reply. I did get it working - 2a.m. special.

I had something wrong with my Code::Blocks install somehow & it was using the wrong linker. It builds & runs fine now.

Thanks for posting the code - it's just what I wanted to start looking into insim.
If you are starting with insim go pick DarkTimes' InSimSniffer right away:
http://www.lfsforum.net/showthread.php?t=60417

It's the ideal tool to check how insim packets flow so you can understand not only how packets arrive but also it helps you understand the contents of those packets.

C++ - LFS Session Timing (application/tutorial)
(11 posts, started )
FGED GREDG RDFGDR GSFDG