Crossfire Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A few thoughts on client/server in multi-player games



  tmp = *((char*)&net)[0];
On Sun, 10 Apr 1994, Carl Edman wrote:

> Ah, yes, there's the rub.  As I've been trying to explain in a recent  
> post on this subject, ASCII packets are not necessarily larger or  
> slower.  And contrary to popular perception parsing ASCII packets does  
> not have a signficant impact on CPU performance.  Remember that we are  
> not trying to parse arbitray ambiguous natural language sentences here  
> like an adventure game would.  Those packets will almost always be  
> machine generated and clear.  Generating and parsing such ASCII can be  
> done extremely quickly.

Hmm, thinking atoi function (roughly)

short int = atoi(char *str = "123")
  lenght = strlen(str)    # lenght of string, about 4 steps
  exp = 1                 # exponent multiplier, 1 step

  for(i = lenght; i; i--) # checkin loop, 1 step
    res += *(str+i) * exp # calculating & adding, 4 steps
    exp *= 10             # updating exp, 1 step
                          
  # there were 3 number, so 6 * 3 = 18 steps
  # there were no handling for sign

so the atoi takes 23 steps.

And thinking ntohs.

Many machines, like sun, has a same byte order an network
so ntohs is: #define ntohs(n) (0 step) . Some machines, like
PC, the byte order is opposite, then

short int = ntohs(short int net)
  char tmp                              # do the swap
  tmp = *((char*)&net)[0]               # store tmp, 1 step
  ((char*)&net)[0] = ((char*)&net)[1]   # 1st part, 1 step
  ((char*)&net)[1] = tmp                # 2th part, 1 step

so 3 steps. Ie. the parsing ascii is about 23/3 = 8 times
slower than using net-host conversion direct. 

And there should be able to transmit 121 (11*11) points
at 10 fps. Every point have 2 numbers so the comparision
is 2783 vs. 363 steps. This might be singnificant.

And note from space. The size of trafferred data is
overall unsignificant, but it makes the protocol somewhat
faster in the packets fits into one IP packet. There
is no need splitting and rerouting the another packets.

-- <A HREF="http://www.lut.fi/~hevi/">The Page</A> --