Hi Diaboli,

Just looking through the code... I found the problem with the floating point conversion I think.

I believe its down to the function calcDistance. You are using Pythagoras for the case where the difference between the X and Y values isn't 0, but why not ditch all the comparisons and float to string (and back again) conversions? I know its all floating point, but in this day and age, I wouldn't have thought its too much of a burden.

I'm trying to get it working so I've modified the routine to this:-

Code:
Function CalcDistance(X1,Y1,X2,Y2: Integer): Integer;
begin
  result:=round(sqrt(sqr(x1-x2)+sqr(y1-y2)));
end;
Based on the fact that your routine was doing a lot of float to string (and back again) conversion, this should also be faster.

You mention the fact that it seems to get laggy when there are a few people on.

Having just looked at some of the code, I would suggest that you consider changing the routines that feed information to and receive it from the server. In particular, RecPlayers and RecPlayerPos.

You are spending a lot of time locating delimiters and then manipulating the strings that contain the data. You could still move the data around with strings, but you would be better off tightly formatting the data so that a particular item is always the same length and always in the same position. Then you only need to copy the data. I've also just noticed that you are locating the delimiters twice. Once to locate the end of the data (with your leftStr routine) and then again to delete the data (with your rightStr) routine. I'm just changing the code to use standard routines, like this:-

Code:
idxpos:=pos('|',rec);
dataitem:=copy(rec,1,idxPos-1);
delete(rec,1,idxPos);
So as a complete example... this....

Code:
Function RecPlayerPos(Rec: String): Boolean;
var
  i: Integer;
  iPos: Integer;
  IsSelf, PID, Name, X, Y, Dir, Speed, House: String;
  bIsSelf: Boolean;
begin
  while Length(Rec) > 0 do
  begin
    PID:= LeftStr(Rec,Pos('|',Rec)-1);
    Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
    X:= LeftStr(Rec,Pos('|',Rec)-1);
    Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
    Y:= LeftStr(Rec,Pos('|',Rec)-1);
    Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
    Dir:= LeftStr(Rec,Pos('|',Rec)-1);
    Rec:= RightStr(Rec,Length(Rec)-Pos('|',Rec));
    Speed:= LeftStr(Rec,Pos('#',Rec)-1);
    Rec:= RightStr(Rec,Length(Rec)-Pos('#',Rec));
    if (StrIsInt(PID)) and (StrIsInt(X)) and (StrIsInt(Y)) and (StrIsInt(Dir)) and (StrIsInt(Speed)) then
      SetPlayerPos(StrToInt(PID),StrToInt(X),StrToInt(Y),StrToInt(Dir),StrToInt(Speed))
    else
      Rec:='';
  end;
end;
becomes....


Code:
Function RecPlayerPos(Rec: String): Boolean;
var
  i: Integer;
  iPos: Integer;
  IsSelf, PID, Name, X, Y, Dir, Speed, House: String;
  bIsSelf: Boolean;
  idxPos : integer;
begin
  while Length(Rec) > 0 do
  begin
       idxPos:=pos('|',rec);
       pid:=copy(rec,1,idxPos-1);
       delete(rec,1,idxPos);

       idxPos:=pos('|',rec);
       x:=copy(rec,1,idxPos-1);
       delete(rec,1,idxPos);

       idxPos:=pos('|',rec);
       y:=copy(rec,1,idxPos-1);
       delete(rec,1,idxPos);

       idxPos:=pos('|',rec);
       dir:=copy(rec,1,idxPos-1);
       delete(rec,1,idxPos);

       idxPos:=pos('#',rec);
       speed:=copy(rec,1,idxPos-1);
       delete(rec,1,idxPos);

    if (StrIsInt(PID)) and (StrIsInt(X)) and (StrIsInt(Y)) and (StrIsInt(Dir)) and (StrIsInt(Speed)) then
      SetPlayerPos(StrToInt(PID),StrToInt(X),StrToInt(Y),StrToInt(Dir),StrToInt(Speed))
    else
      Rec:='';
  end;
end;
This also gives you the chance of spotting bad packets, since if you don't find a delimiter when you expect one, you can simply ditch that packet and move on. Another option would be to create objects that contain the data and then use streaming to move the object data from server/client/server.

Please bear in mind, that the first client based game I worked on was our competition entry. There are many people far more experienced than me on here who may spot big problems with some of my suggestions, but I just compiled it (with Delphi 5) with the changes I made in and I can run around and move from room to room. That said, I don't have anyone else to try it with at the moment, but a bit later on, I'll give it a go.

I hope you finish it... there aren't enough old style games around. Too much emphasis is put on fancy graphics and environment which need a monster PC to play.