The online racing simulator
How can I do to add that tells you the time from 0 to 100 km / h?
I'm not sure the language this script uses. I just came to the last page to see the last post, to be honest.

To calculate user acceleration, you need to know the time between 0 and 100 (obvious =)).

Below I will give you an example about how I calculate it:


if (C.PosSpeed > 1 && C.OutPits == 1)
{
C.AccTimer += 100;
}

if (C.PosSpeed >= 100 && C.AccStage == 0)
{
C.AccStage = 1;
double Aceleracao = ((C.AccTimer * 100.0) / C.PosSpeed) / 1000;
InSim.Send_MTC_MessageToConnection("^3› ^7Aceleração 0-100: ^3" + Math.Round(Aceleracao, 1) + "^7 segundos", C.UniqueID, 0);
}



Explanation:

This script is inside a 100ms timer. So, every 100ms, it add 100 to a specific player's variable (AccTimer += 100).

Then, when the player reaches 100Km/H (PosSpeed >= 100), it calculates the time player took to reach 100, considering actual speed (because the speed can be 105 for example on the actual scan).

For example, on the actual scan, the user speed is 110 Km/H and the AccTimer is 600.

So, it means the user reach 110 in 600ms. On the proportion: ((600 * 100) / 110) / 1000 = 0,54545454...

Finally, I do a math.round to remove digits after the coma. The result in the case above will be 0,5 seconds.

I tried to explain everything, and it may be useful for other players. But I hope I answered your question Wink
Quote from Skinzinho :I'm not sure the language this script uses. I just came to the last page to see the last post, to be honest.

To calculate user acceleration, you need to know the time between 0 and 100 (obvious =)).

Below I will give you an example about how I calculate it:


if (C.PosSpeed > 1 && C.OutPits == 1)
{
C.AccTimer += 100;
}

if (C.PosSpeed >= 100 && C.AccStage == 0)
{
C.AccStage = 1;
double Aceleracao = ((C.AccTimer * 100.0) / C.PosSpeed) / 1000;
InSim.Send_MTC_MessageToConnection("^3› ^7Aceleração 0-100: ^3" + Math.Round(Aceleracao, 1) + "^7 segundos", C.UniqueID, 0);
}



Explanation:

This script is inside a 100ms timer. So, every 100ms, it add 100 to a specific player's variable (AccTimer += 100).

Then, when the player reaches 100Km/H (PosSpeed >= 100), it calculates the time player took to reach 100, considering actual speed (because the speed can be 105 for example on the actual scan).

For example, on the actual scan, the user speed is 110 Km/H and the AccTimer is 600.

So, it means the user reach 110 in 600ms. On the proportion: ((600 * 100) / 110) / 1000 = 0,54545454...

Finally, I do a math.round to remove digits after the coma. The result in the case above will be 0,5 seconds.

I tried to explain everything, and it may be useful for other players. But I hope I answered your question Wink

Thanks for the help, but it did not work for me. :/
Hello, I am trying to fix one project using InSim but cant get it built. Tried your event control project for the reference but just cant build it either. (I even downloaded codeblocks to have the least IDE work but somehow there is still a lot of IDE/compiler work to just build it)

Iam using:
-Win 10
-code::blocks
-MinGW using TDM32 installer

I am getting problems around pthread. I am getting warnings of redefined pthread.h definitions as there is one pthread / libpthreadGC2.a related to project and one in search directory of compiler. it looks like it always conflicts. Conflicting struct definitions result in errors

How you setup your compiler / IDE to compile your projects?

Thank you.
pthread library bundled with Event Control is outdated and unnecessary. Development toolchain that comes with CodeBlocks should include a working pthread library. Just use that one and you should be good to go.
Thanks. It really works without that.

I deleted linking of libpthreadGC2.a
pthread.h

And it builts and works. Great!
Quote from denis-takumi :Hello programmers! I added a new OutSimPack.h to library
https://github.com/turbosnail/cinsim/blob/master/OutSimPack.h

Post from Scawen https://www.lfs.net/forum/post/1951461

Hi. thanks for the program. Seems to be crashing at init. Diff for fix below.

diff --git a/CInsim.cpp b/CInsim.cpp
index 51f923f..8cd729e 100644
--- a/CInsim.cpp
+++ b/CInsim.cpp
@@ -408,12 +408,11 @@ int CInsim::init()
switch (peek_packet()) // Check if the packet returned was an IS_VER
{
case ISP_VER: // It was, get it!
- IS_VER *packVer;
- memcpy(packVer, (struct IS_VER*)get_packet(), sizeof(struct IS_VER));
- this->hostProduct = packVer->Product;
- this->hostVersion = packVer->Version;
- this->hostInSimVersion = packVer->InSimVer;
- delete packVer;
+ IS_VER packVer;
+ memcpy(&packVer, (IS_VER*)get_packet(), sizeof(IS_VER));
+ this->hostProduct = packVer.Product;
+ this->hostVersion = packVer.Version;
+ this->hostInSimVersion = packVer.InSimVer;
break;
default: // It wasn't, something went wrong. Quit
if (disconnect() < 0) {

my app work with dinamic struct fine
Quote from krolcyganow :Hi. thanks for the program. Seems to be crashing at init. Diff for fix below.

diff --git a/CInsim.cpp b/CInsim.cpp
index 51f923f..8cd729e 100644
--- a/CInsim.cpp
+++ b/CInsim.cpp
@@ -408,12 +408,11 @@ int CInsim::init()
switch (peek_packet()) // Check if the packet returned was an IS_VER
{
case ISP_VER: // It was, get it!
- IS_VER *packVer;
- memcpy(packVer, (struct IS_VER*)get_packet(), sizeof(struct IS_VER));
- this->hostProduct = packVer->Product;
- this->hostVersion = packVer->Version;
- this->hostInSimVersion = packVer->InSimVer;
- delete packVer;
+ IS_VER packVer;
+ memcpy(&packVer, (IS_VER*)get_packet(), sizeof(IS_VER));
+ this->hostProduct = packVer.Product;
+ this->hostVersion = packVer.Version;
+ this->hostInSimVersion = packVer.InSimVer;
break;
default: // It wasn't, something went wrong. Quit
if (disconnect() < 0) {


sory for my fault it realy wont work. i forgot change it in my code

in right version IS_VER *packVer; must be like IS_VER *packVer = new IS_VER;

but it dont build

i return to static var init in branch w45
"insim.h" compiler error.
Hi. I don't know why but the "insim.h" file gives an error "C2371" when I try to compile (I'm using Visual Studio. I also tried with Code::blocks but it's the same). The 2 errors are:
  • 'Vec' : New definition. Different basic types. Line: 51.
  • 'Vector' : New definition. Different basic types. Line: 57.
These are the code lines where "vec" and "vector" are defined (51 and 57):

typedef struct
{
int x;
int y;
int z;
} Vec;
typedef struct
{
float x;
float y;
float z;
} Vector;

I can't see anything wrong, or if the mistake is on other file. I didn't change anything in the "insim.h" file. Does anyone now how to fix this?

Thx ;D.

C++ - CInsim - A basic C++ InSim library
(162 posts, started )
FGED GREDG RDFGDR GSFDG