Changeset 6197 in orxonox.OLD for branches/network/src/lib
- Timestamp:
- Dec 20, 2005, 6:18:14 PM (19 years ago)
- Location:
- branches/network/src/lib/network
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/network/src/lib/network/converter.cc
r6139 r6197 94 94 mult *= step; 95 95 } 96 97 printf("tara: %i", result); 98 96 99 97 if (a[INTSIZE - 1] >= sgnadd) 100 98 { … … 108 106 } 109 107 110 /*char* Converter::floatToBinString(float x) 108 /*! 109 * Converts a float into a string containing its binary representation 110 */ 111 char* Converter::floatToBinString(float x) 111 112 { 112 113 char* result = new char[200]; 113 114 int pos = 0; 114 115 115 int h = (int)x; 116 if (h > x) 117 h--; 118 x -= h; 119 120 121 while (h > 0 && pos < 200) 122 { 123 //printf("%i ", pos); 124 125 if (h % 2 == 1) 126 { 127 result[pos] = '1'; 128 h -= 1; 129 } 130 else 131 result[pos] = '0'; 132 pos++; 133 h /= 2; 134 } 135 136 //printf("x = %f\n", x); 137 138 139 //invert 140 for (int i = 0; i < pos / 2; i++) 141 { 142 char temp = result[i]; 143 result[i] = result[pos - 1 - i]; 144 result[pos - 1 - i] = temp; 145 } 146 147 148 result[pos++] = '.'; 149 float sub = 0.5; 150 while (x > 0 && pos < 200) 151 { 152 //printf("%i ", pos); 153 154 if (x >= sub) 155 { 156 result[pos] = '1'; 157 x -= sub; 158 } 159 else 160 result[pos] = '0'; 161 pos++; 162 sub /= 2; 163 } 164 165 166 return result; 167 }*/ 168 169 char* Converter::floatToBinString(float x) 170 { 171 char* result = new char[200]; 172 int pos = 0; 116 if (x < 0) 117 { 118 result[pos++] = '-'; 119 x = -x; 120 } 173 121 174 122 float sub = 1; 175 123 while (sub < x) 176 124 sub *= 2; 177 178 //printf("sub = %f\n", sub); 179 180 //while (sub >= 1 && pos < 200) 125 181 126 while ((x > 0 || sub >= 1) && pos < 200) 182 127 { … … 195 140 } 196 141 197 /*result[pos++] = '.'; 198 sub = 0.5; 199 while (x > 0 && pos < 200) 142 return result; 143 } 144 145 const int expmult = 8388608; //2^23 146 147 /*! 148 * Converts a float value into a byte-array 149 * @param x: The float which is to convert 150 * @return: A byte-array which accords the given float 151 */ 152 byte* Converter::floatToByteArray(float x) 153 { 154 int mantisse = 0; 155 int exponent = 128; 156 157 int sgn; 158 if (x < 0) 159 { 160 x = -x; 161 sgn = -1; 162 } 163 else 164 sgn = 1; 165 166 float sub = 1; 167 while (sub < x) 168 { 169 sub *= 2; 170 exponent++; 171 } 172 173 while (x > 0) 200 174 { 201 175 if (x >= sub) 202 176 { 203 result[pos] = '1';177 mantisse += 1; 204 178 x -= sub; 205 179 } 206 else207 result[pos] = '0';208 pos++;180 181 mantisse *= 2; 182 exponent--; 209 183 sub /= 2; 210 184 } 211 */ 212 213 return result; 214 } 185 exponent++; 186 mantisse /= 2; 187 while (mantisse < expmult) 188 { 189 mantisse *= 2; 190 exponent--; 191 } 192 193 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 194 195 mantisse -= expmult; 196 197 int hx = mantisse + expmult * exponent; 198 byte* result = intToByteArray(hx); 199 if (sgn == -1) 200 result[3] += sgnadd; 201 202 return result; 203 } 204 205 206 /*! 207 * Converts a byte-array into a float value 208 * @param a: The byte-array which is to convert 209 * @return: A float value which accords the given byte-array 210 */ 211 float Converter::byteArrayToFloat(byte* a) 212 { 213 int hmant = a[0] + a[1] * 256 + a[2] * 65536; 214 int mantisse = hmant % expmult; 215 mantisse += expmult; 216 217 int hexp = a[2] + a[3] * 256; 218 int exponent = (hexp / 128) % 256 - 128; 219 220 int sgn; 221 if (a[3] >= sgnadd) 222 sgn = -1; 223 else 224 sgn = 1; 225 226 //printf("mantisse = %i exponent = %i \n", mantisse, exponent); 227 228 float emult = 1; 229 if (exponent > 0) 230 for (int i = 0; i < exponent; i++) 231 emult *= 2; 232 else if (exponent < 0) 233 for (int i = 0; i > exponent; i--) 234 emult /= 2; 235 236 float result = mantisse * emult; 237 if (sgn == -1) 238 result = -result; 239 240 return result; 241 } 242 243 /*! 244 * Converts a float value into a byte-array 245 * @param x: The float which is to convert 246 * @return: A byte-array which accords the given float 247 */ 248 byte* Converter::_floatToByteArray(float x) 249 { 250 byte* p = (byte*)&x; 251 byte* result = new byte[4]; 252 for (int i = 0; i < 4; i++) 253 result[i] = p[i]; 254 return result; 255 } 256 257 258 /*! 259 * Converts a byte-array into a float value 260 * @param a: The byte-array which is to convert 261 * @return: A float value which accords the given byte-array 262 */ 263 float Converter::_byteArrayToFloat(byte* a) 264 { 265 float* p = (float*)a; 266 float result = *p; 267 return result; 268 } -
branches/network/src/lib/network/converter.h
r6139 r6197 31 31 static char* floatToBinString(float x); 32 32 33 static byte* floatToByteArray(float x); 34 static float byteArrayToFloat(byte* a); 35 36 static byte* _floatToByteArray(float x); 37 static float _byteArrayToFloat(byte* a); 33 38 private: 34 39 Converter(); -
branches/network/src/lib/network/network_game_manager.cc
r6190 r6197 175 175 void NetworkGameManager::doCreateEntity( ClassID classID, int uniqueID, int owner ) 176 176 { 177 BaseObject * b = Factory::fabricate( classID ); 177 //BaseObject * b = Factory::fabricate( classID ); 178 BaseObject * b = NULL; 178 179 179 180 if ( b->isA(CL_SYNCHRONIZEABLE) )
Note: See TracChangeset
for help on using the changeset viewer.