The online racing simulator
Understanding and solving the MCI limits [inc examples in various languages]
Leechers/Non programmers move on. This isn't a source.


"There is no MCI 8 player limit!"
Read the following code until you get it.
for (int i = 0; i < Players.Count; i++)
{
//Do something with MCI[i]
}

Players is a collection which changes constantly as players join and leave. MCI is an array of 8 elements and always is. So when you have 9 players, you are trying to access the 9th element of MCI which doesn't exist which will give you an MCI exception.

"Ok so lets just change all Players.Count to MCI.NumC"
Well MCI.NumC at max can be 8. So if you have 9 players, that last player wont be updated.

"But it would send 8 and then 1!"

So you would be updating the first players stuff with the 9th players when you get the 1.

"Ok so what do we do?"
I did the simplest thing. I added the CompCar Packet struct to the clsPlayer structure. Here is an example of how I changed MCI.
//CompCar is the CompCar packet structure I added to clsPlayer
int idx = 0;
for (int i = 0; i < MCI.NumC; i++)
{
idx = GetPlyIdx(MCI.Info[i].PLID);
Players[idx].CompCar.AngVel = MCI.Info[i].AngVel; //They aren't structures so you cant serialize!
Players[idx].CompCar.Direction = MCI.Info[i].Direction;
Players[idx].CompCar.Heading = MCI.Info[i].Heading;
Players[idx].CompCar.Info = MCI.Info[i].Info;
Players[idx].CompCar.Lap = MCI.Info[i].Lap;
Players[idx].CompCar.Node = MCI.Info[i].Node;
Players[idx].CompCar.PLID = MCI.Info[i].PLID;
Players[idx].CompCar.Position = MCI.Info[i].Position;
Players[idx].CompCar.Speed = MCI.Info[i].Speed;
Players[idx].CompCar.X = MCI.Info[i].X;
Players[idx].CompCar.Y = MCI.Info[i].Y;
Players[idx].CompCar.Z = MCI.Info[i].Z;
}

So now we always have data for the cars in the clsPlayer structure. Now we can access the cars data anywhere. Unlike before were we could only access the cars data from the MCI thread. Now you can rewrite a lot of code and remove most of the MCI stuff and put it in different spots. No more waiting until MCI is executed to engage a target.

This fixes so many problems.

1. Not being able to access car data anywhere but the MCI thread.
2. Out of bounds error from Players being larger than MCI.
3. Lots more (brain fart)


I am working on this, just this should be enough to get ya started.

<?php 
onMCIPacket
() {
    
$MCI $this->parent->packets;
    
$Nmb $this->parent->STA->NumP;
    for (
$m 0$m <= $Nmb$m++) {
        for (
$i 0$i <= $MCI[$m]->NumC$i++) {
            
$return[$MCI[$m]->Info[$i]->PLID] = $MCI[$m]->Info[$i];
        }
    }
    return 
$return;
}
?>

I think that is how I would handle it, but that's just me, and I've not tested the code myself.
Quote from Dygear :

<?php 
onMCIPacket
() {
    
$MCI $this->parent->packets;
    
$Nmb $this->parent->STA->NumP;
    for (
$m 0$m <= $Nmb$m++) {
        for (
$i 0$i <= $MCI[$m]->NumC$i++) {
            
$return[$MCI[$m]->Info[$i]->PLID] = $MCI[$m]->Info[$i];
        }
    }
    return 
$return;
}
?>

I think that is how I would handle it, but that's just me, and I've not tested the code myself.

I am not sure how the php library is so can't say XD.
It's really good to see more American programmers. Keep up the good work!
#5 - nikka
static int player_number = 0;

for (int i = 0; i < MCI.NumC; i++)
{
Players[player_number].CompCar.AngVel = MCI.Info[i].AngVel;
..
..
..

if ( (MCI.Info[i].Info & CCI_LAST) == CCI_LAST)
player_number = 0;
else
player_number++;
}



(this is C though, don't know how to use static variables in C#)
#6 - jur
Quote from nikka :
(this is C though, don't know how to use static variables in C#)

the same
Great fix, I'll update the cruise project later
#8 - ReVoX
nice fix in a loop, go to test it
Great fix, but i have a little problem where i have to put it on the clsplayer.cs ? or the main project of form1.cs thanks
Quote from Evilvan911 :Great fix, but i have a little problem where i have to put it on the clsplayer.cs ? or the main project of form1.cs thanks

Quote from OP :Leechers/Non programmers move on.

Was it that hard to just read?
Quote :I am working on this, just this should be enough to get ya started.

When it is finished being worked on, Are you including it in a next version

Mick
I dont get it...


"Ok so lets just change all Players.Count to MCI.NumC"
Well MCI.NumC at max can be 8. So if you have 9 players, that last player wont be updated.

Problem is, when you have 9 players, you will get TWO MCI packets.
One with players 1-8, and one with player #9.
So changing it to MCI.NumC will work (and does, my app is using it).

read this: (from mcgas's first post and on)
http://www.lfsforum.net/showthread.php?t=42147

To make it short, the trick is to request an mci packet from insim, and nothing else.
THEN in the method that will parse the mci packet, just let him update the car's stats - the 8 that will be in the mci packet, and tag them via carID.
On the surface seems like it wont work, only will update the first 8, but you'd be wrong:


requestMCIPacket();
--> insim sends back one MCI packet, with players 1-8.
--> MCI packet is received, appropriate method is fired up.
mciPacketHandler iterates through all 8 players, updates them in the clsPlayer. (the other n players are still not updated).
-->insim sends ANOTHER MCI packet, still responding to your original request, this time with players 9-17.
-->MCI packet is received, appropriate method is fired up.
mciPacketHandler iterates through all 8 players, updates them in the clsPlayer. (the other n players are still not updated, but players 1-17 are done).


And so forth till insim stops sending packets cause it reached the bottom of the conn list.

The whole code for updating the list is 2 lines long (4 if you count the curlybraces lines, or 1 if you put it all in one line).
Stigpt: Oh, more symply, thanks to mcgas and to you for post the link of the thread
Quote from Stigpt :"Ok so lets just change all Players.Count to MCI.NumC"
Well MCI.NumC at max can be 8. So if you have 9 players, that last player wont be updated.

Unless something has changed since I last looked at InSim, you should always get multiple MCI packets if there are more than 8 players (it would be stupid if you didn't). You never need to request any MCI packets, if you've enabled then, and even then if you did you get the same behaviour.

Edit: Sorry, I've re-read the post by Stigpt, he doesn't make it very clear that he was explaining things again. I've ammended this post as appropriate.
Yes, you do get multiple packets. If there's 9 players, you'll get 2 packets, one with 8 players, the other with 1 player. It will still have 8 structs, but I think that the other 7 become illegible or something as there's no player there

I haven't put this into the open source cruise project, as frankly, I can't be arsed Someone else can update it

I have put it into my copy, and it works like a charm
Quote :I haven't put this into the open source cruise project, as frankly, I can't be arsed Someone else can update it

Hopefully someone will then i can get back to running it )

Mick
Quote from dougie-lampkin :It will still have 8 structs, but I think that the other 7 become illegible or something as there's no player there

This is true, to an extent. LFS External uses a static array size for converting the MCI packet. Meaning if there is 1 Compcar, or 8 Compcars, You will always get 8 via LFS External. The rest is just rubbish and just isnt used. The only way you can change that, is to write your own insim library.

Edit - Np to the guys who said thanks for the MCI thing.
Could someone post a fixed version

Thank you
Mick
I did, mikjen - see the thread I linked, and read it from mcgass001 's post and down.
I'm not trying to be rude here, but can someone rename this thread? LFS External doesn't contain any MCI code by default, Only the MCI event handler. Therefor this problem is not with LFS External, but the end user of the library.

Edit - Thanks.
It's not even really a problem. Just some examples like the open source C# cruise server didn't handle the packets right.
Well i tried adding the code, etc etc, lol

But wouldnt debug,

Anyone care to do it for me

pretty please

mick
I have changed MCI but what do I add to clsPlayer.cs?
Quote from elmohellno :Leechers/Non programmers move on. This isn't a source.

Shaun, learn how to read, or do they not teach that anymore before you turn 6 in England?
He was having a dig at me

Mick
1

FGED GREDG RDFGDR GSFDG