• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。


Commit MetaInfo

Revision334 (tree)
Time2022-10-17 01:14:13
Authorxops-mikan

Log Message

バイトオーダーが絡む数値変換を関数化

Change Summary

Incremental Difference

--- trunk/d3dgraphics-directx.cpp (revision 333)
+++ trunk/d3dgraphics-directx.cpp (revision 334)
@@ -788,10 +788,7 @@
788788 for(int i=0; i<headersize; i++){ bmpdata[i] = 0x00; }
789789 bmpdata[0x00] = 'B';
790790 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);
795792 bmpdata[0x0A] = (unsigned char)headersize;
796793 bmpdata[0x0E] = (unsigned char)(headersize - 14);
797794 bmpdata[0x12] = (unsigned char)width;
@@ -799,10 +796,7 @@
799796 bmpdata[0x1A] = 1;
800797 bmpdata[0x1C] = 24;
801798 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);
806800
807801 datacnt = headersize;
808802
--- trunk/d3dgraphics-opengl.cpp (revision 333)
+++ trunk/d3dgraphics-opengl.cpp (revision 334)
@@ -2394,10 +2394,7 @@
23942394 VertexAry[3] = (float)x2*-1; VertexAry[4] = (float)y2; VertexAry[5] = (float)z2;
23952395
23962396 //色情報配列を用意
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);
24012398 memcpy(&(ColorAry[4]), ColorAry, sizeof(unsigned char)*4);
24022399
24032400 //配列有効化
@@ -2747,10 +2744,7 @@
27472744 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
27482745
27492746 //色情報配列を用意
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);
27542748 for(int i=1; i<strlens*6; i++){
27552749 memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4);
27562750 }
@@ -2894,10 +2888,7 @@
28942888 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
28952889
28962890 //色情報配列を用意
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);
29012892 for(int i=1; i<strlens*6; i++){
29022893 memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4);
29032894 }
@@ -2966,10 +2957,7 @@
29662957 VertexAry[2] = (float)x2; VertexAry[3] = (float)y2;
29672958
29682959 //色情報配列を用意
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);
29732961 memcpy(&(ColorAry[4]), ColorAry, sizeof(unsigned char)*4);
29742962
29752963 //配列有効化
@@ -3014,10 +3002,7 @@
30143002 }
30153003
30163004 //色情報配列を用意
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);
30213006 for(int i=1; i<16+1; i++){
30223007 memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4);
30233008 }
@@ -3063,10 +3048,7 @@
30633048 VertexAry[6] = (float)x2; VertexAry[7] = (float)y2;
30643049
30653050 //色情報配列を用意
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);
30703052 for(int i=1; i<4; i++){
30713053 memcpy(&(ColorAry[i*4]), ColorAry, sizeof(unsigned char)*4);
30723054 }
@@ -3234,14 +3216,8 @@
32343216 header[0x00] = 'B';
32353217 header[0x01] = 'M';
32363218 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());
32453221 header[0x1C] = 24;
32463222
32473223 //ヘッダーを書き込む
--- trunk/datafile.cpp (revision 333)
+++ trunk/datafile.cpp (revision 334)
@@ -131,10 +131,8 @@
131131
132132 //データ数を取得
133133 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; }
138136
139137 //ブロックデータ数分取得
140138 for(int i=0; i<datas; i++){
@@ -441,10 +439,8 @@
441439
442440 //データ数を取得
443441 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; }
448444
449445 //ポイントデータ数分処理する
450446 for(int i=0; i<datas; i++){
--- trunk/main.cpp (revision 333)
+++ trunk/main.cpp (revision 334)
@@ -331,4 +331,92 @@
331331 for(; r > (float)M_PI; r -= (float)M_PI*2){}
332332 for(; r < (float)M_PI*-1; r += (float)M_PI*2){}
333333 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+}
--- trunk/main.h (revision 333)
+++ trunk/main.h (revision 334)
@@ -161,5 +161,13 @@
161161
162162 bool CheckCommandParameter(const char *param, const char *cmd);
163163 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);
164172
165173 #endif
\ No newline at end of file
--- trunk/sound-directsound.cpp (revision 333)
+++ trunk/sound-directsound.cpp (revision 334)
@@ -273,8 +273,8 @@
273273 int byte = 0;
274274 for(int i=0; i<dwSize; i+=4){
275275 /*
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]));
278278 ((BYTE*)pBuffer)[byte+0] = (BYTE)((mix>>8)&0x00FF);
279279 ((BYTE*)pBuffer)[byte+1] = (BYTE)(mix)&0x00FF;
280280 byte += 2;