X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。
| Revision | 334 (tree) |
|---|---|
| Time | 2022-10-17 01:14:13 |
| Author | |
バイトオーダーが絡む数値変換を関数化
| @@ -788,10 +788,7 @@ | ||
| 788 | 788 | for(int i=0; i<headersize; i++){ bmpdata[i] = 0x00; } |
| 789 | 789 | bmpdata[0x00] = 'B'; |
| 790 | 790 | bmpdata[0x01] = 'M'; |
| 791 | - bmpdata[0x02] = (unsigned char)((bufsize >> 0) & 0x000000FF); | |
| 792 | - bmpdata[0x03] = (unsigned char)((bufsize >> 8) & 0x000000FF); | |
| 793 | - bmpdata[0x04] = (unsigned char)((bufsize >> 16) & 0x000000FF); | |
| 794 | - bmpdata[0x05] = (unsigned char)((bufsize >> 24) & 0x000000FF); | |
| 791 | + Set4ByteLittleEndian(&(bmpdata[0x02]), bufsize); | |
| 795 | 792 | bmpdata[0x0A] = (unsigned char)headersize; |
| 796 | 793 | bmpdata[0x0E] = (unsigned char)(headersize - 14); |
| 797 | 794 | bmpdata[0x12] = (unsigned char)width; |
| @@ -799,10 +796,7 @@ | ||
| 799 | 796 | bmpdata[0x1A] = 1; |
| 800 | 797 | bmpdata[0x1C] = 24; |
| 801 | 798 | bmpdata[0x1E] = 0; |
| 802 | - bmpdata[0x22] = (unsigned char)(( (bufsize - headersize) >> 0 ) & 0x000000FF); | |
| 803 | - bmpdata[0x23] = (unsigned char)(( (bufsize - headersize) >> 8 ) & 0x000000FF); | |
| 804 | - bmpdata[0x24] = (unsigned char)(( (bufsize - headersize) >> 16 ) & 0x000000FF); | |
| 805 | - bmpdata[0x25] = (unsigned char)(( (bufsize - headersize) >> 24 ) & 0x000000FF); | |
| 799 | + Set4ByteLittleEndian(&(bmpdata[0x22]), bufsize - headersize); | |
| 806 | 800 | |
| 807 | 801 | datacnt = headersize; |
| 808 | 802 |
| @@ -2394,10 +2394,7 @@ | ||
| 2394 | 2394 | VertexAry[3] = (float)x2*-1; VertexAry[4] = (float)y2; VertexAry[5] = (float)z2; |
| 2395 | 2395 | |
| 2396 | 2396 | //色情報配列を用意 |
| 2397 | - ColorAry[0] = (color>>24)&0xFF; | |
| 2398 | - ColorAry[1] = (color>>16)&0xFF; | |
| 2399 | - ColorAry[2] = (color>>8)&0xFF; | |
| 2400 | - ColorAry[3] = color&0xFF; | |
| 2397 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 2401 | 2398 | memcpy(&(ColorAry[4]), ColorAry, sizeof(unsigned char)*4); |
| 2402 | 2399 | |
| 2403 | 2400 | //配列有効化 |
| @@ -2747,10 +2744,7 @@ | ||
| 2747 | 2744 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2748 | 2745 | |
| 2749 | 2746 | //色情報配列を用意 |
| 2750 | - ColorAry[0] = (color>>24)&0xFF; | |
| 2751 | - ColorAry[1] = (color>>16)&0xFF; | |
| 2752 | - ColorAry[2] = (color>>8)&0xFF; | |
| 2753 | - ColorAry[3] = color&0xFF; | |
| 2747 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 2754 | 2748 | for(int i=1; i<strlens*6; i++){ |
| 2755 | 2749 | memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4); |
| 2756 | 2750 | } |
| @@ -2894,10 +2888,7 @@ | ||
| 2894 | 2888 | glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
| 2895 | 2889 | |
| 2896 | 2890 | //色情報配列を用意 |
| 2897 | - ColorAry[0] = (color>>24)&0xFF; | |
| 2898 | - ColorAry[1] = (color>>16)&0xFF; | |
| 2899 | - ColorAry[2] = (color>>8)&0xFF; | |
| 2900 | - ColorAry[3] = color&0xFF; | |
| 2891 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 2901 | 2892 | for(int i=1; i<strlens*6; i++){ |
| 2902 | 2893 | memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4); |
| 2903 | 2894 | } |
| @@ -2966,10 +2957,7 @@ | ||
| 2966 | 2957 | VertexAry[2] = (float)x2; VertexAry[3] = (float)y2; |
| 2967 | 2958 | |
| 2968 | 2959 | //色情報配列を用意 |
| 2969 | - ColorAry[0] = (color>>24)&0xFF; | |
| 2970 | - ColorAry[1] = (color>>16)&0xFF; | |
| 2971 | - ColorAry[2] = (color>>8)&0xFF; | |
| 2972 | - ColorAry[3] = color&0xFF; | |
| 2960 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 2973 | 2961 | memcpy(&(ColorAry[4]), ColorAry, sizeof(unsigned char)*4); |
| 2974 | 2962 | |
| 2975 | 2963 | //配列有効化 |
| @@ -3014,10 +3002,7 @@ | ||
| 3014 | 3002 | } |
| 3015 | 3003 | |
| 3016 | 3004 | //色情報配列を用意 |
| 3017 | - ColorAry[0] = (color>>24)&0xFF; | |
| 3018 | - ColorAry[1] = (color>>16)&0xFF; | |
| 3019 | - ColorAry[2] = (color>>8)&0xFF; | |
| 3020 | - ColorAry[3] = color&0xFF; | |
| 3005 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 3021 | 3006 | for(int i=1; i<16+1; i++){ |
| 3022 | 3007 | memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4); |
| 3023 | 3008 | } |
| @@ -3063,10 +3048,7 @@ | ||
| 3063 | 3048 | VertexAry[6] = (float)x2; VertexAry[7] = (float)y2; |
| 3064 | 3049 | |
| 3065 | 3050 | //色情報配列を用意 |
| 3066 | - ColorAry[0] = (color>>24)&0xFF; | |
| 3067 | - ColorAry[1] = (color>>16)&0xFF; | |
| 3068 | - ColorAry[2] = (color>>8)&0xFF; | |
| 3069 | - ColorAry[3] = color&0xFF; | |
| 3051 | + Set4ByteBigEndian(&(ColorAry[0]), color); | |
| 3070 | 3052 | for(int i=1; i<4; i++){ |
| 3071 | 3053 | memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4); |
| 3072 | 3054 | } |
| @@ -3234,14 +3216,8 @@ | ||
| 3234 | 3216 | header[0x00] = 'B'; |
| 3235 | 3217 | header[0x01] = 'M'; |
| 3236 | 3218 | header[0x0E] = 40; |
| 3237 | - header[0x12] = (unsigned char)(GameConfig.GetScreenWidth()&0x000000FF); | |
| 3238 | - header[0x13] = (unsigned char)((GameConfig.GetScreenWidth()&0x0000FF00) >> 8); | |
| 3239 | - header[0x14] = (unsigned char)((GameConfig.GetScreenWidth()&0x00FF0000) >> 16); | |
| 3240 | - header[0x15] = (unsigned char)((GameConfig.GetScreenWidth()&0xFF000000) >> 24); | |
| 3241 | - header[0x16] = (unsigned char)(GameConfig.GetScreenHeight()&0x000000FF); | |
| 3242 | - header[0x17] = (unsigned char)((GameConfig.GetScreenHeight()&0x0000FF00) >> 8); | |
| 3243 | - header[0x18] = (unsigned char)((GameConfig.GetScreenHeight()&0x00FF0000) >> 16); | |
| 3244 | - header[0x19] = (unsigned char)((GameConfig.GetScreenHeight()&0xFF000000) >> 24); | |
| 3219 | + Set4ByteLittleEndian(&(header[0x12]), GameConfig.GetScreenWidth()); | |
| 3220 | + Set4ByteLittleEndian(&(header[0x16]), GameConfig.GetScreenHeight()); | |
| 3245 | 3221 | header[0x1C] = 24; |
| 3246 | 3222 | |
| 3247 | 3223 | //ヘッダーを書き込む |
| @@ -131,10 +131,8 @@ | ||
| 131 | 131 | |
| 132 | 132 | //データ数を取得 |
| 133 | 133 | fread( bdata_header, 1, 2, fp ); |
| 134 | - datas = (int)bdata_header[1]*256 + bdata_header[0]; | |
| 135 | - if( datas > MAX_BLOCKS ){ | |
| 136 | - datas = MAX_BLOCKS; | |
| 137 | - } | |
| 134 | + datas = (int)Get2ByteLittleEndian(&(bdata_header[0])); | |
| 135 | + if( datas > MAX_BLOCKS ){ datas = MAX_BLOCKS; } | |
| 138 | 136 | |
| 139 | 137 | //ブロックデータ数分取得 |
| 140 | 138 | for(int i=0; i<datas; i++){ |
| @@ -441,10 +439,8 @@ | ||
| 441 | 439 | |
| 442 | 440 | //データ数を取得 |
| 443 | 441 | fread( pdata_header, 1, 2, fp ); |
| 444 | - datas = (int)pdata_header[1]*256 + pdata_header[0]; | |
| 445 | - if( datas > MAX_POINTS ){ | |
| 446 | - datas = MAX_POINTS; | |
| 447 | - } | |
| 442 | + datas = (int)Get2ByteLittleEndian(&(pdata_header[0])); | |
| 443 | + if( datas > MAX_POINTS ){ datas = MAX_POINTS; } | |
| 448 | 444 | |
| 449 | 445 | //ポイントデータ数分処理する |
| 450 | 446 | for(int i=0; i<datas; i++){ |
| @@ -331,4 +331,92 @@ | ||
| 331 | 331 | for(; r > (float)M_PI; r -= (float)M_PI*2){} |
| 332 | 332 | for(; r < (float)M_PI*-1; r += (float)M_PI*2){} |
| 333 | 333 | return r; |
| 334 | -} | |
| \ No newline at end of file | ||
| 334 | +} | |
| 335 | + | |
| 336 | +//! @brief 2バイトに数値設定(リトルエンディアン) | |
| 337 | +//! @param outdata 2バイトのポインタ | |
| 338 | +//! @param value 数値 | |
| 339 | +void Set2ByteLittleEndian(unsigned char *outdata, unsigned int value) | |
| 340 | +{ | |
| 341 | + if( outdata == NULL ){ return; } | |
| 342 | + | |
| 343 | + outdata[0] = (unsigned char)(( value >> 0 ) & 0x00FF); | |
| 344 | + outdata[1] = (unsigned char)(( value >> 8 ) & 0x00FF); | |
| 345 | +} | |
| 346 | + | |
| 347 | +//! @brief 4バイトに数値設定(リトルエンディアン) | |
| 348 | +//! @param outdata 4バイトのポインタ | |
| 349 | +//! @param value 数値 | |
| 350 | +void Set4ByteLittleEndian(unsigned char *outdata, unsigned int value) | |
| 351 | +{ | |
| 352 | + if( outdata == NULL ){ return; } | |
| 353 | + | |
| 354 | + outdata[0] = (unsigned char)(( value >> 0 ) & 0x000000FF); | |
| 355 | + outdata[1] = (unsigned char)(( value >> 8 ) & 0x000000FF); | |
| 356 | + outdata[2] = (unsigned char)(( value >> 16 ) & 0x000000FF); | |
| 357 | + outdata[3] = (unsigned char)(( value >> 24 ) & 0x000000FF); | |
| 358 | +} | |
| 359 | + | |
| 360 | +//! @brief 2バイトに数値設定(ビッグエンディアン) | |
| 361 | +//! @param outdata 2バイトのポインタ | |
| 362 | +//! @param value 数値 | |
| 363 | +void Set2ByteBigEndian(unsigned char *outdata, unsigned int value) | |
| 364 | +{ | |
| 365 | + if( outdata == NULL ){ return; } | |
| 366 | + | |
| 367 | + outdata[0] = (unsigned char)(( value >> 8 ) & 0x00FF); | |
| 368 | + outdata[1] = (unsigned char)(( value >> 0 ) & 0x00FF); | |
| 369 | +} | |
| 370 | + | |
| 371 | +//! @brief 4バイトに数値設定(ビッグエンディアン) | |
| 372 | +//! @param outdata 4バイトのポインタ | |
| 373 | +//! @param value 数値 | |
| 374 | +void Set4ByteBigEndian(unsigned char *outdata, unsigned int value) | |
| 375 | +{ | |
| 376 | + if( outdata == NULL ){ return; } | |
| 377 | + | |
| 378 | + outdata[0] = (unsigned char)(( value >> 24 ) & 0x000000FF); | |
| 379 | + outdata[1] = (unsigned char)(( value >> 16 ) & 0x000000FF); | |
| 380 | + outdata[2] = (unsigned char)(( value >> 8 ) & 0x000000FF); | |
| 381 | + outdata[3] = (unsigned char)(( value >> 0 ) & 0x000000FF); | |
| 382 | +} | |
| 383 | + | |
| 384 | +//! @brief 2バイトの数値取得(リトルエンディアン) | |
| 385 | +//! @param indata 2バイトのポインタ | |
| 386 | +//! @return 数値 | |
| 387 | +unsigned int Get2ByteLittleEndian(unsigned char *indata) | |
| 388 | +{ | |
| 389 | + if( indata == NULL ){ return 0; } | |
| 390 | + | |
| 391 | + return (unsigned int)( ((indata[1]<<8)&0xFF00) + ((indata[0]<<0)&0x00FF) ); | |
| 392 | +} | |
| 393 | + | |
| 394 | +//! @brief 4バイトの数値取得(リトルエンディアン) | |
| 395 | +//! @param indata 4バイトのポインタ | |
| 396 | +//! @return 数値 | |
| 397 | +unsigned int Get4ByteLittleEndian(unsigned char *indata) | |
| 398 | +{ | |
| 399 | + if( indata == NULL ){ return 0; } | |
| 400 | + | |
| 401 | + return (unsigned int)( ((indata[3]<<24)&0xFF000000) + ((indata[2]<<16)&0x00FF0000) + ((indata[1]<<8)&0x0000FF00) + ((indata[0]<<0)&0x000000FF) ); | |
| 402 | +} | |
| 403 | + | |
| 404 | +//! @brief 2バイトの数値取得(ビッグエンディアン) | |
| 405 | +//! @param indata 2バイトのポインタ | |
| 406 | +//! @return 数値 | |
| 407 | +unsigned int Get2ByteBigEndian(unsigned char *indata) | |
| 408 | +{ | |
| 409 | + if( indata == NULL ){ return 0; } | |
| 410 | + | |
| 411 | + return (unsigned int)( ((indata[0]<<8)&0xFF00) + ((indata[1]<<0)&0x00FF) ); | |
| 412 | +} | |
| 413 | + | |
| 414 | +//! @brief 4バイトの数値取得(ビッグエンディアン) | |
| 415 | +//! @param indata 4バイトのポインタ | |
| 416 | +//! @return 数値 | |
| 417 | +unsigned int Get4ByteBigEndian(unsigned char *indata) | |
| 418 | +{ | |
| 419 | + if( indata == NULL ){ return 0; } | |
| 420 | + | |
| 421 | + return (unsigned int)( ((indata[0]<<24)&0xFF000000) + ((indata[1]<<16)&0x00FF0000) + ((indata[2]<<8)&0x0000FF00) + ((indata[3]<<0)&0x000000FF) ); | |
| 422 | +} |
| @@ -161,5 +161,13 @@ | ||
| 161 | 161 | |
| 162 | 162 | bool CheckCommandParameter(const char *param, const char *cmd); |
| 163 | 163 | float AngleNormalization(float r); |
| 164 | +void Set2ByteLittleEndian(unsigned char *outdata, unsigned int value); | |
| 165 | +void Set4ByteLittleEndian(unsigned char *outdata, unsigned int value); | |
| 166 | +void Set2ByteBigEndian(unsigned char *outdata, unsigned int value); | |
| 167 | +void Set4ByteBigEndian(unsigned char *outdata, unsigned int value); | |
| 168 | +unsigned int Get2ByteLittleEndian(unsigned char *indata); | |
| 169 | +unsigned int Get4ByteLittleEndian(unsigned char *indata); | |
| 170 | +unsigned int Get2ByteBigEndian(unsigned char *indata); | |
| 171 | +unsigned int Get4ByteBigEndian(unsigned char *indata); | |
| 164 | 172 | |
| 165 | 173 | #endif |
| \ No newline at end of file |
| @@ -273,8 +273,8 @@ | ||
| 273 | 273 | int byte = 0; |
| 274 | 274 | for(int i=0; i<dwSize; i+=4){ |
| 275 | 275 | /* |
| 276 | - //int mix = (((pWavData[i + 0]<<8)&0xFF00) + ((pWavData[i + 1])&0x00FF) + ((pWavData[i + 2]<<8)&0xFF00) + ((pWavData[i + 3])&0x00FF))/2; | |
| 277 | - int mix = ((pWavData[i + 0]<<8)&0xFF00) + ((pWavData[i + 1])&0x00FF); | |
| 276 | + //int mix = (int)(Get2ByteBigEndian(&(pWavData[i + 0])) + Get2ByteBigEndian(&(pWavData[i + 2])))/2; | |
| 277 | + int mix = (int)Get2ByteBigEndian(&(pWavData[i + 0])); | |
| 278 | 278 | ((BYTE*)pBuffer)[byte+0] = (BYTE)((mix>>8)&0x00FF); |
| 279 | 279 | ((BYTE*)pBuffer)[byte+1] = (BYTE)(mix)&0x00FF; |
| 280 | 280 | byte += 2; |