Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 21, 2005, 1:39:20 PM (18 years ago)
Author:
rennerc
Message:

network_game_manager: implemented some functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/converter.cc

    r6197 r6219  
    5454{
    5555  const int mod = 256; // = 2^8
    56  
    57  
     56
     57
    5858  byte* result = new byte[INTSIZE];
    5959  int sgn;
     
    6565    x = -x;
    6666  }
    67  
     67
    6868  for (int i = 0; i < INTSIZE; i++)
    6969  {
     
    7171    x /= mod;
    7272  }
    73  
     73
    7474  if (sgn == -1)
    7575    result[INTSIZE - 1] += sgnadd;
    76  
    77  
     76
     77
    7878  return result;
    7979}
     
    8484 * @return: An int that accords the given byte-array
    8585 */
    86 int Converter::byteArrayToInt(byte* a)
     86int Converter::byteArrayToInt(const byte* a)
    8787{
    8888  int mult = 1;
     
    102102  else
    103103    result += a[INTSIZE - 1] * mult;
    104  
     104
    105105  return result;
    106106}
     
    113113  char* result = new char[200];
    114114  int pos = 0;
    115  
     115
    116116  if (x < 0)
    117117  {
     
    119119    x = -x;
    120120  }
    121  
     121
    122122  float sub = 1;
    123123  while (sub < x)
     
    135135    pos++;
    136136    sub /= 2;
    137    
     137
    138138    if (sub == 0.5f)
    139139      result[pos++] = '.';
    140140  }
    141  
     141
    142142  return result;
    143143}
     
    154154  int mantisse = 0;
    155155  int exponent = 128;
    156  
     156
    157157  int sgn;
    158158  if (x < 0)
     
    163163  else
    164164    sgn = 1;
    165  
     165
    166166  float sub = 1;
    167167  while (sub < x)
     
    178178      x -= sub;
    179179    }
    180    
     180
    181181    mantisse *= 2;
    182182    exponent--;
     
    190190    exponent--;
    191191  }
    192  
    193   //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 
    194  
     192
     193  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
     194
    195195  mantisse -= expmult;
    196  
     196
    197197  int hx = mantisse + expmult * exponent;
    198198  byte* result = intToByteArray(hx);
    199199  if (sgn == -1)
    200200    result[3] += sgnadd;
    201  
     201
    202202  return result;
    203203}
     
    214214  int mantisse = hmant % expmult;
    215215  mantisse += expmult;
    216  
     216
    217217  int hexp = a[2] + a[3] * 256;
    218218  int exponent = (hexp / 128) % 256 - 128;
    219  
     219
    220220  int sgn;
    221221  if (a[3] >= sgnadd)
     
    223223  else
    224224    sgn = 1;
    225  
     225
    226226  //printf("mantisse = %i exponent = %i \n", mantisse, exponent);
    227  
     227
    228228  float emult = 1;
    229229  if (exponent > 0)
     
    233233    for (int i = 0; i > exponent; i--)
    234234      emult /= 2;
    235  
     235
    236236  float result = mantisse * emult;
    237237  if (sgn == -1)
    238238    result = -result;
    239  
     239
    240240  return result;
    241241}
Note: See TracChangeset for help on using the changeset viewer.