• 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

Revision108 (tree)
Time2015-09-12 22:27:02
Authorxops-mikan

Log Message

各リソースを明示的に解放する設計に変更。デバック用ログ出力機能を修正。

Change Summary

Incremental Difference

--- trunk/datafile.cpp (revision 107)
+++ trunk/datafile.cpp (revision 108)
@@ -85,7 +85,7 @@
8585
8686 #ifdef ENABLE_DEBUGLOG
8787 //ログに出力
88- OutputLog.WriteLog(LOG_CLEANUP, "BD1", "");
88+ //OutputLog.WriteLog(LOG_CLEANUP, "BD1", "");
8989 #endif
9090 }
9191
@@ -382,7 +382,7 @@
382382
383383 #ifdef ENABLE_DEBUGLOG
384384 //ログに出力
385- OutputLog.WriteLog(LOG_CLEANUP, "PD1", "");
385+ //OutputLog.WriteLog(LOG_CLEANUP, "PD1", "");
386386 #endif
387387 }
388388
--- trunk/gamemain.cpp (revision 107)
+++ trunk/gamemain.cpp (revision 108)
@@ -65,7 +65,7 @@
6565 return 1;
6666 }
6767
68- //Directinputの初期化
68+ //Directinput初期化
6969 if( inputCtrl.InitInput(WindowCtrl) ){
7070 WindowCtrl->ErrorInfo("Input initialization error");
7171 return 1;
@@ -148,6 +148,26 @@
148148 return 0;
149149 }
150150
151+//! @brief 基本的な解放処理
152+void CleanupGame()
153+{
154+ //リソースを初期化
155+ Resource.DestroyResource();
156+
157+ //設定値を初期化
158+ GameParamInfo.DestroyInfo();
159+
160+
161+ //DirectX解放
162+ d3dg.DestroyD3D();
163+
164+ //Directinput解放
165+ inputCtrl.DestroyInput();
166+
167+ //EASY DIRECT SOUND 解放
168+ SoundCtrl.DestroySound();
169+}
170+
151171 //! @brief コンストラクタ
152172 opening::opening()
153173 {}
--- trunk/parameter.cpp (revision 107)
+++ trunk/parameter.cpp (revision 108)
@@ -55,18 +55,7 @@
5555 //! @brief ディストラクタ
5656 ParameterInfo::~ParameterInfo()
5757 {
58- //CleanupModelTextureWeapon();
59- //CleanupModelTextureSmallObject();
60-
61- if( Human != NULL ){ delete [] Human; }
62- if( Weapon != NULL ){ delete [] Weapon; }
63- if( SmallObject != NULL ){ delete [] SmallObject; }
64- if( AIlevel != NULL ){ delete [] AIlevel; }
65-
66-#ifdef ENABLE_DEBUGLOG
67- //ログに出力
68- OutputLog.WriteLog(LOG_CLEANUP, "設定値", "");
69-#endif
58+ DestroyInfo();
7059 }
7160
7261 //! @brief 初期化(パラメータの設定)
@@ -1549,6 +1538,38 @@
15491538 #endif
15501539 }
15511540
1541+//! @brief 解放
1542+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
1543+void ParameterInfo::DestroyInfo()
1544+{
1545+ //CleanupModelTextureWeapon();
1546+ //CleanupModelTextureSmallObject();
1547+
1548+ if( (Human == NULL)&&(Weapon == NULL)&&(SmallObject == NULL)&&(AIlevel == NULL) ){ return; }
1549+
1550+ if( Human != NULL ){
1551+ delete [] Human;
1552+ Human = NULL;
1553+ }
1554+ if( Weapon != NULL ){
1555+ delete [] Weapon;
1556+ Weapon = NULL;
1557+ }
1558+ if( SmallObject != NULL ){
1559+ delete [] SmallObject;
1560+ SmallObject = NULL;
1561+ }
1562+ if( AIlevel != NULL ){
1563+ delete [] AIlevel;
1564+ AIlevel = NULL;
1565+ }
1566+
1567+#ifdef ENABLE_DEBUGLOG
1568+ //ログに出力
1569+ OutputLog.WriteLog(LOG_CLEANUP, "設定値", "");
1570+#endif
1571+}
1572+
15521573 //! @brief 人の設定を取得
15531574 //! @param id 番号
15541575 //! @param out_data 受け取るHumanParameter型ポインタ
--- trunk/debug.cpp (revision 107)
+++ trunk/debug.cpp (revision 108)
@@ -43,8 +43,24 @@
4343
4444 //! @brief ディストラクタ
4545 DebugLog::~DebugLog()
46-{}
46+{
47+ //出力フラグを有効ならば、ファイルにフッターを追加
48+ if( OutputFlag == true ){
49+ FILE *fp;
4750
51+ fp = fopen(fname, "a");
52+ if( fp == NULL ){
53+ return;
54+ }
55+
56+ fprintf(fp, "</table>\n");
57+ fprintf(fp, "</body>\n");
58+ fprintf(fp, "</html>\n");
59+
60+ fclose(fp);
61+ }
62+}
63+
4864 //! @brief ログファイルのファイル名を変更
4965 //! @param name ファイル名
5066 void DebugLog::SetLogName(char* name)
--- trunk/resource.cpp (revision 107)
+++ trunk/resource.cpp (revision 108)
@@ -86,15 +86,7 @@
8686 //! @brief ディストラクタ
8787 ResourceManager::~ResourceManager()
8888 {
89- CleanupHumanModel();
90- CleanupHumanTexture();
91- CleanupWeaponModelTexture();
92- CleanupSmallObjectModelTexture();
93-
94- CleanupScopeTexture();
95- CleanupSkyModelTexture();
96- CleanupBulletModelTexture();
97- CleanupEffectTexture();
89+ DestroyResource();
9890 }
9991
10092 //! @brief 参照するParameterInfoクラスを設定
@@ -121,6 +113,21 @@
121113 SoundCtrl = _SoundCtrl;
122114 }
123115
116+//! @brief 解放
117+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
118+void ResourceManager::DestroyResource()
119+{
120+ CleanupHumanModel();
121+ CleanupHumanTexture();
122+ CleanupWeaponModelTexture();
123+ CleanupSmallObjectModelTexture();
124+
125+ CleanupScopeTexture();
126+ CleanupSkyModelTexture();
127+ CleanupBulletModelTexture();
128+ CleanupEffectTexture();
129+}
130+
124131 //! @brief 人のモデルを読み込み
125132 //! @return 成功:0 失敗:1
126133 int ResourceManager::LoadHumanModel()
--- trunk/sound.cpp (revision 107)
+++ trunk/sound.cpp (revision 108)
@@ -42,17 +42,7 @@
4242 //! @brief ディストラクタ
4343 SoundControl::~SoundControl()
4444 {
45- for(int i=0;i<MAX_LOADSOUND; i++){
46- for(int j=0; j<MAX_SOUNDLISTS; j++){
47- if( pDSBuffer[i][j] != NULL ){ pDSBuffer[i][j]->Release(); }
48- }
49- }
50- if( pDSound != NULL ){ pDSound->Release(); }
51-
52-#ifdef ENABLE_DEBUGLOG
53- //ログに出力
54- OutputLog.WriteLog(LOG_CLEANUP, "サウンド", "DirectSound");
55-#endif
45+ DestroySound();
5646 }
5747
5848 //! @brief 初期化
@@ -100,6 +90,31 @@
10090 return 0;
10191 }
10292
93+//! @brief 解放
94+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
95+void SoundControl::DestroySound()
96+{
97+ if( pDSound == NULL ){ return; }
98+
99+ for(int i=0;i<MAX_LOADSOUND; i++){
100+ for(int j=0; j<MAX_SOUNDLISTS; j++){
101+ if( pDSBuffer[i][j] != NULL ){
102+ pDSBuffer[i][j]->Release();
103+ pDSBuffer[i][j] = NULL;
104+ }
105+ }
106+ }
107+ if( pDSound != NULL ){
108+ pDSound->Release();
109+ pDSound = NULL;
110+ }
111+
112+#ifdef ENABLE_DEBUGLOG
113+ //ログに出力
114+ OutputLog.WriteLog(LOG_CLEANUP, "サウンド", "DirectSound");
115+#endif
116+}
117+
103118 //! @brief 再生音量を設定
104119 //! @param volume 再生音量 (0.0=無音 1.0=100%)
105120 void SoundControl::SetVolume(float volume)
@@ -466,25 +481,7 @@
466481 //! @brief ディストラクタ
467482 SoundControl::~SoundControl()
468483 {
469- if( lib == NULL ){ return; }
470-
471- //使用中のサウンドデータ数を数える
472- int total = 0;
473- for(int i=0; i<MAX_LOADSOUND; i++){
474- if( useflag[i] == true ){ total += 1; }
475- }
476-
477- //サウンドデータを開放し、DLLを終了
478- DSrelease(total);
479- DSend();
480-
481- //DLLを開放
482- FreeLibrary(lib);
483-
484-#ifdef ENABLE_DEBUGLOG
485- //ログに出力
486- OutputLog.WriteLog(LOG_CLEANUP, "サウンド", "ezds.dll");
487-#endif
484+ DestroySound();
488485 }
489486
490487 //! @brief 初期化@n
@@ -532,6 +529,32 @@
532529 return 0;
533530 }
534531
532+//! @brief 解放
533+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
534+void SoundControl::DestroySound()
535+{
536+ if( lib == NULL ){ return; }
537+
538+ //使用中のサウンドデータ数を数える
539+ int total = 0;
540+ for(int i=0; i<MAX_LOADSOUND; i++){
541+ if( useflag[i] == true ){ total += 1; }
542+ }
543+
544+ //サウンドデータを開放し、DLLを終了
545+ DSrelease(total);
546+ DSend();
547+
548+ //DLLを開放
549+ FreeLibrary(lib);
550+ lib = NULL;
551+
552+#ifdef ENABLE_DEBUGLOG
553+ //ログに出力
554+ OutputLog.WriteLog(LOG_CLEANUP, "サウンド", "ezds.dll");
555+#endif
556+}
557+
535558 //! @brief 再生音量を設定
536559 //! @param volume 再生音量 (0.0=無音 1.0=100%)
537560 void SoundControl::SetVolume(float volume)
--- trunk/d3dgraphics-directx.cpp (revision 107)
+++ trunk/d3dgraphics-directx.cpp (revision 108)
@@ -62,16 +62,7 @@
6262 //! @brief ディストラクタ
6363 D3DGraphics::~D3DGraphics()
6464 {
65- //リソース解放
66- CleanupD3Dresource();
67-
68- if( pd3dDevice != NULL ) pd3dDevice->Release();
69- if( pD3D != NULL ) pD3D->Release();
70-
71-#ifdef ENABLE_DEBUGLOG
72- //ログに出力
73- OutputLog.WriteLog(LOG_CLEANUP, "グラフィック", "DirectX");
74-#endif
65+ DestroyD3D();
7566 }
7667
7768 //! @brief 初期化@n
@@ -244,6 +235,30 @@
244235 return 0;
245236 }
246237
238+//! @brief 解放
239+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
240+void D3DGraphics::DestroyD3D()
241+{
242+ if( (pd3dDevice == NULL)&&(pD3D == NULL) ){ return; }
243+
244+ //リソース解放
245+ CleanupD3Dresource();
246+
247+ if( pd3dDevice != NULL ){
248+ pd3dDevice->Release();
249+ pd3dDevice = NULL;
250+ }
251+ if( pD3D != NULL ){
252+ pD3D->Release();
253+ pD3D = NULL;
254+ }
255+
256+#ifdef ENABLE_DEBUGLOG
257+ //ログに出力
258+ OutputLog.WriteLog(LOG_CLEANUP, "グラフィック", "DirectX");
259+#endif
260+}
261+
247262 //! @brief 描画関係の細部設定
248263 //! @attention 初期化時に1度だけ実行してください。
249264 int D3DGraphics::InitSubset()
@@ -320,7 +335,10 @@
320335 pxmsfont->Release();
321336 pxmsfont = NULL;
322337 }
323- if( ptextsprite != NULL ){ ptextsprite->Release(); }
338+ if( ptextsprite != NULL ){
339+ ptextsprite->Release();
340+ ptextsprite = NULL;
341+ }
324342
325343 CleanupMapdata();
326344
--- trunk/input.cpp (revision 107)
+++ trunk/input.cpp (revision 108)
@@ -38,6 +38,8 @@
3838 pDI = NULL;
3939 pDIDevice = NULL;
4040 pMouse = NULL;
41+#else
42+ InitFlag = false;
4143 #endif
4244
4345 //キーボード設定値初期化
@@ -58,31 +60,7 @@
5860 //! @brief ディストラクタ
5961 InputControl::~InputControl()
6062 {
61-#ifdef INPUT_DIRECTINPUT
62- //キーボードデバイスを開放
63- if( pDIDevice != NULL ){
64- pDIDevice->Unacquire();
65- pDIDevice->Release();
66- }
67-
68- //マウスデバイスを開放
69- if( pMouse != NULL ){
70- pMouse->Unacquire();
71- pMouse->Release();
72- }
73-
74- //DirectInputを開放
75- if( pDI != NULL) pDI->Release();
76-#endif
77-
78-#ifdef ENABLE_DEBUGLOG
79- //ログに出力
80- #ifdef INPUT_DIRECTINPUT
81- OutputLog.WriteLog(LOG_CLEANUP, "入力", "DirectInput");
82- #else
83- OutputLog.WriteLog(LOG_CLEANUP, "入力", "WinAPI");
84- #endif
85-#endif
63+ DestroyInput();
8664 }
8765
8866 //! @brief 初期化
@@ -127,6 +105,10 @@
127105 //カーソルを非表示
128106 ShowCursor(false);
129107
108+#ifndef INPUT_DIRECTINPUT
109+ InitFlag = true;
110+#endif
111+
130112 #ifdef ENABLE_DEBUGLOG
131113 //ログに出力
132114 OutputLog.WriteLog(LOG_COMPLETE, "", "");
@@ -135,6 +117,50 @@
135117 return 0;
136118 }
137119
120+//! @brief 解放
121+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
122+void InputControl::DestroyInput()
123+{
124+#ifdef INPUT_DIRECTINPUT
125+ if( (pDI == NULL)&&(pDIDevice == NULL)&&(pMouse == NULL) ){ return; }
126+#else
127+ if( InitFlag == false ){ return; }
128+#endif
129+
130+#ifdef INPUT_DIRECTINPUT
131+ //キーボードデバイスを開放
132+ if( pDIDevice != NULL ){
133+ pDIDevice->Unacquire();
134+ pDIDevice->Release();
135+ pDIDevice = NULL;
136+ }
137+
138+ //マウスデバイスを開放
139+ if( pMouse != NULL ){
140+ pMouse->Unacquire();
141+ pMouse->Release();
142+ pMouse = NULL;
143+ }
144+
145+ //DirectInputを開放
146+ if( pDI != NULL){
147+ pDI->Release();
148+ pDI = NULL;
149+ }
150+#else
151+ InitFlag = false;
152+#endif
153+
154+#ifdef ENABLE_DEBUGLOG
155+ //ログに出力
156+ #ifdef INPUT_DIRECTINPUT
157+ OutputLog.WriteLog(LOG_CLEANUP, "入力", "DirectInput");
158+ #else
159+ OutputLog.WriteLog(LOG_CLEANUP, "入力", "WinAPI");
160+ #endif
161+#endif
162+}
163+
138164 //! @brief 入力デバイスの状態を更新
139165 //! @param mousemode マウスの座標取得 絶対値(座標):false 相対値(移動量):true
140166 void InputControl::GetInputState(bool mousemode)
--- trunk/d3dgraphics-opengl.cpp (revision 107)
+++ trunk/d3dgraphics-opengl.cpp (revision 108)
@@ -78,32 +78,7 @@
7878 //! @brief ディストラクタ
7979 D3DGraphics::~D3DGraphics()
8080 {
81- for(int i=0; i<MAX_MODEL; i++){
82- CleanupModel(i);
83- }
84- for(int i=0; i<MAX_TEXTURE; i++){
85- CleanupTexture(i);
86- }
87-
88- if( SystemFont != NULL ){
89- DeleteObject(SystemFont);
90- }
91- if( now_SystemFontUStr != NULL ){
92- delete [] now_SystemFontUStr;
93- }
94- if( SystemFontListIdx != 0 ){
95- glDeleteLists(SystemFontListIdx, SystemFontListIdxSize);
96- }
97-
98- if( hGLRC != NULL ){ wglDeleteContext(hGLRC); }
99-
100-#ifdef ENABLE_DEBUGLOG
101- //ログに出力
102- OutputLog.WriteLog(LOG_CLEANUP, "グラフィック", "OpenGL");
103-#endif
104-
105- //libjpeg解放
106- jpeg_destroy_decompress(&cinfo);
81+ DestroyD3D();
10782 }
10883
10984 //! @brief 初期化@n
@@ -252,6 +227,46 @@
252227 return 2;
253228 }
254229
230+//! @brief 解放
231+//! @attention 本関数は自動的に呼び出されますが、明示的に呼び出すことも可能です。
232+void D3DGraphics::DestroyD3D()
233+{
234+ if( hGLRC == NULL ){ return; }
235+
236+ for(int i=0; i<MAX_MODEL; i++){
237+ CleanupModel(i);
238+ }
239+ for(int i=0; i<MAX_TEXTURE; i++){
240+ CleanupTexture(i);
241+ }
242+
243+ if( SystemFont != NULL ){
244+ DeleteObject(SystemFont);
245+ SystemFont = NULL;
246+ }
247+ if( now_SystemFontUStr != NULL ){
248+ delete [] now_SystemFontUStr;
249+ now_SystemFontUStr = NULL;
250+ }
251+ if( SystemFontListIdx != 0 ){
252+ glDeleteLists(SystemFontListIdx, SystemFontListIdxSize);
253+ SystemFontListIdx = 0;
254+ }
255+
256+ if( hGLRC != NULL ){
257+ wglDeleteContext(hGLRC);
258+ hGLRC = NULL;
259+ }
260+
261+#ifdef ENABLE_DEBUGLOG
262+ //ログに出力
263+ OutputLog.WriteLog(LOG_CLEANUP, "グラフィック", "OpenGL");
264+#endif
265+
266+ //libjpeg解放
267+ jpeg_destroy_decompress(&cinfo);
268+}
269+
255270 //! @brief モデルファイルを読み込む(.x)
256271 //! @param filename ファイル名
257272 //! @return 成功:モデル認識番号(0以上) 失敗:-1
--- trunk/gamemain.h (revision 107)
+++ trunk/gamemain.h (revision 108)
@@ -68,6 +68,7 @@
6868 #include "main.h"
6969
7070 int InitGame(WindowControl *WindowCtrl);
71+void CleanupGame();
7172
7273 //! ゲームの状態を受け渡しする構造体
7374 struct GameInfo{
--- trunk/main.cpp (revision 107)
+++ trunk/main.cpp (revision 108)
@@ -120,7 +120,7 @@
120120
121121 #ifdef ENABLE_DEBUGLOG
122122 //ログに出力
123- OutputLog.WriteLog(LOG_CHECK, "起動", "メインループ");
123+ OutputLog.WriteLog(LOG_CHECK, "起動", "メインループ突入");
124124 #endif
125125
126126 unsigned int framecnt = 0;
@@ -139,6 +139,15 @@
139139
140140 #ifdef ENABLE_DEBUGLOG
141141 //ログに出力
142+ OutputLog.WriteLog(LOG_CHECK, "終了", "メインループ脱出");
143+#endif
144+
145+
146+ //基本的な解放処理
147+ CleanupGame();
148+
149+#ifdef ENABLE_DEBUGLOG
150+ //ログに出力
142151 OutputLog.WriteLog(LOG_CHECK, "終了", "エントリーポイント終了");
143152 #endif
144153 return 0;
--- trunk/parameter.h (revision 107)
+++ trunk/parameter.h (revision 108)
@@ -134,6 +134,7 @@
134134 ParameterInfo();
135135 ~ParameterInfo();
136136 void InitInfo();
137+ void DestroyInfo();
137138 int GetHuman(int id, HumanParameter *out_data);
138139 int GetHumanTexturePath(int id, char *out_str);
139140 int GetWeapon(int id, WeaponParameter *out_data);
--- trunk/resource.h (revision 107)
+++ trunk/resource.h (revision 108)
@@ -89,6 +89,7 @@
8989 void SetParameterInfo(ParameterInfo *_ParamInfo);
9090 void SetD3DGraphics(D3DGraphics *_d3dg);
9191 void SetSoundControl(SoundControl *_SoundCtrl);
92+ void DestroyResource();
9293
9394 int LoadHumanModel();
9495 void GetHumanModel(int out_upmodel[], int out_armmodel[], int *legmodel, int out_walkmodel[], int out_runmodel[]);
--- trunk/sound.h (revision 107)
+++ trunk/sound.h (revision 108)
@@ -79,6 +79,7 @@
7979 SoundControl();
8080 ~SoundControl();
8181 int InitSound(WindowControl *WindowCtrl);
82+ void DestroySound();
8283 void SetVolume(float volume);
8384 void SetCamera(float x, float y, float z, float rx);
8485 int LoadSound(char* filename);
@@ -109,6 +110,7 @@
109110 SoundControl();
110111 ~SoundControl();
111112 int InitSound(WindowControl *WindowCtrl);
113+ void DestroySound();
112114 void SetVolume(float volume);
113115 void SetCamera(float x, float y, float z, float rx);
114116 int LoadSound(char* filename);
--- trunk/input.h (revision 107)
+++ trunk/input.h (revision 108)
@@ -58,6 +58,8 @@
5858 LPDIRECTINPUT8 pDI; //!< DIRECTINPUT8のポインタ
5959 LPDIRECTINPUTDEVICE8 pDIDevice; //!< DIRECTINPUTDEVICE8のポインタ・キーボード用
6060 LPDIRECTINPUTDEVICE8 pMouse; //!< DIRECTINPUTDEVICE8のポインタ・マウス用
61+#else
62+ bool InitFlag; //!< 初期化フラグ
6163 #endif
6264 char keys[256]; //!< キー情報を格納する配列
6365 char keys_lt[256]; //!< (前回の)キー情報を格納する配列
@@ -73,6 +75,7 @@
7375 InputControl();
7476 ~InputControl();
7577 int InitInput(WindowControl *WindowCtrl);
78+ void DestroyInput();
7679 void GetInputState(bool mousemode);
7780 void MoveMouseCenter();
7881 bool CheckKeyNow(int id);