-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.cpp
227 lines (185 loc) · 5.21 KB
/
Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//=====================================
//
//ゲーム処理[Game.cpp]
//Author:GP12B332 21 立花雄太
//
//=====================================
#include "input.h"
#include "light.h"
#include "camera.h"
#include "debugWindow.h"
#include "debugTimer.h"
#include "ModelController.h"
#include "PostEffectManager.h"
#include "Particle.h"
/**************************************
マクロ定義
***************************************/
/**************************************
プロトタイプ宣言
***************************************/
void CreateScreenVertexBuffer();
void CreateRenderTarget();
/**************************************
グローバル変数
***************************************/
//ポストエフェクトマネージャインスタンス
PostEffectManager* PostEffectManager::instance = NULL;
//変更後のビューポート
static D3DVIEWPORT9 viewPort;
//描画用テクスチャ&サーフェイス
static LPDIRECT3DTEXTURE9 renderTexture;
static LPDIRECT3DSURFACE9 renderSurface;
//Zマップ用テクスチャ&サーフェイス
static LPDIRECT3DTEXTURE9 zMapTexture;
static LPDIRECT3DSURFACE9 zMapSurface;
//バックバッファへ描画するための頂点バッファ
static LPDIRECT3DVERTEXBUFFER9 screenVtx;
/**************************************
初期化処理
***************************************/
void InitGame(HINSTANCE hInstance, HWND hWnd)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
CreateScreenVertexBuffer();
CreateRenderTarget();
InitInput(hInstance, hWnd);
InitCamera();
InitLight();
InitDebugWindow(hWnd, pDevice);
InitModelController(0);
InitParticle();
RegisterDebugTimer("Main");
}
/**************************************
終了処理
***************************************/
void UninitGame()
{
UninitInput();
UninitLight();
UninitDebugWindow(0);
UninitDebugTimer();
UninitModelController(0);
UninitParticle();
PostEffectManager::Destroy();
}
/**************************************
更新処理
***************************************/
void UpdateGame()
{
UpdateDebugWindow();
UpdateInput();
UpdateLight();
UpdateCamera();
CountDebugTimer("Main", "UpdateModel");
UpdateModelController();
CountDebugTimer("Main", "UpdateModel");
CountDebugTimer("Main", "UpdateParticle");
UpdateParticle();
CountDebugTimer("Main", "UpdateParticle");
CountDebugTimer("Main", "UpdatePostEffect");
PostEffectManager::Instance()->Update();
CountDebugTimer("Main", "UpdatePostEffect");
}
/**************************************
描画処理
***************************************/
void DrawGame()
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//現在のビューポートを退避してレンダーターゲットを切り替え
D3DVIEWPORT9 oldVirwPort;
pDevice->GetViewport(&oldVirwPort);
//バックバッファを退避してレンダーターゲットを切り替え
LPDIRECT3DSURFACE9 oldSuf;
pDevice->GetRenderTarget(0, &oldSuf);
pDevice->SetRenderTarget(0, renderSurface);
pDevice->Clear(0, NULL, (D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER), 0, 1.0f, 0);
//オブジェクトを描画
SetCamera();
CountDebugTimer("Main", "DrawModel");
DrawModelController();
CountDebugTimer("Main", "DrawModel");
CountDebugTimer("Main", "DrawParticle");
DrawParticle();
CountDebugTimer("Main", "DrawParticle");
//ポストエフェクト反映
CountDebugTimer("Main", "DrawPostEffect");
PostEffectManager::Instance()->Draw();
CountDebugTimer("Main", "DrawPostEffect");
//結果をバックバッファへと描画
CountDebugTimer("Main", "DrawBackBuffer");
pDevice->SetViewport(&oldVirwPort);
pDevice->SetRenderTarget(0, oldSuf);
SAFE_RELEASE(oldSuf);
pDevice->SetTexture(0, renderTexture);
pDevice->SetStreamSource(0, screenVtx, 0, sizeof(VERTEX_2D));
pDevice->SetFVF(FVF_VERTEX_2D);
pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, NUM_POLYGON);
CountDebugTimer("Main", "DrawBackBuffer");
DrawDebugTimer("Main");
DrawDebugWindow();
}
/**************************************
描画用頂点バッファ作成
***************************************/
void CreateScreenVertexBuffer()
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
pDevice->CreateVertexBuffer(sizeof(VERTEX_2D) * NUM_VERTEX,
D3DUSAGE_WRITEONLY,
FVF_VERTEX_2D,
D3DPOOL_MANAGED,
&screenVtx,
0);
VERTEX_2D *pVtx;
screenVtx->Lock(0, 0, (void**)&pVtx, 0);
pVtx[0].vtx = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
pVtx[1].vtx = D3DXVECTOR3(SCREEN_WIDTH, 0.0f, 0.0f);
pVtx[2].vtx = D3DXVECTOR3(0.0f, SCREEN_HEIGHT, 0.0f);
pVtx[3].vtx = D3DXVECTOR3(SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f);
pVtx[0].tex = D3DXVECTOR2(0.0f, 0.0f);
pVtx[1].tex = D3DXVECTOR2(1.0f, 0.0f);
pVtx[2].tex = D3DXVECTOR2(0.0f, 1.0f);
pVtx[3].tex = D3DXVECTOR2(1.0f, 1.0f);
pVtx[0].rhw =
pVtx[1].rhw =
pVtx[2].rhw =
pVtx[3].rhw = 1.0f;
pVtx[0].diffuse =
pVtx[1].diffuse =
pVtx[2].diffuse =
pVtx[3].diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
screenVtx->Unlock();
}
/**************************************
レンダーターゲット作成
***************************************/
void CreateRenderTarget()
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
//レンダーテクスチャ作成
pDevice->CreateTexture(SCREEN_WIDTH,
SCREEN_HEIGHT,
1,
D3DUSAGE_RENDERTARGET,
D3DFMT_X8R8G8B8,
D3DPOOL_DEFAULT,
&renderTexture,
0);
renderTexture->GetSurfaceLevel(0, &renderSurface);
//Zバッファ作成
//ビューポート作成
viewPort.Height = 2048;
viewPort.Width = 2048;
viewPort.MinZ = 0.0f;
viewPort.MaxZ = 1.0f;
viewPort.X = 0;
viewPort.Y = 0;
}
LPDIRECT3DTEXTURE9 GetDrawDataTemp()
{
return renderTexture;
}