3 #include "CD3DDisplay.h"
5 #include "WindowPositions.h"
8 #include "CD3DApplication.h"
13 // static
\82È
\82â
\82Â
\82ç
14 LPDIRECTDRAW7 CD3DApplication::pDD = NULL;
15 LPDIRECTDRAWSURFACE7 CD3DApplication::pddsFrontBuffer = NULL;
16 LPDIRECTDRAWSURFACE7 CD3DApplication::pddsBackBuffer = NULL;
17 LPDIRECT3D7 CD3DApplication::pD3D = NULL;
18 LPDIRECT3DDEVICE7 CD3DApplication::pD3DDevice = NULL;
19 CD3DDisplay CD3DApplication::D3DDisplay;
20 HWND CD3DApplication::hWnd = NULL;
21 int CD3DApplication::nBpp = 16;
23 //
\8bÇ
\8f\8a\95Ï
\90\94
24 static CD3DApplication* s_pD3DApp = NULL; // WndProc
\97p
27 LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
29 return ( s_pD3DApp ) ? s_pD3DApp->WndProc( hWnd, uMsg, wParam, lParam ) : DefWindowProc( hWnd, uMsg, wParam, lParam );
32 CD3DApplication::CD3DApplication()
34 //
\8aO
\95\94\95Ï
\90\94\82Ì
\8f\89\8aú
\89»
37 //
\93à
\95\94\95Ï
\90\94\82Ì
\8f\89\8aú
\89»
41 this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h = false;
43 this->b
\90\82\92¼
\8bA
\90ü
\93¯
\8aú = true;
44 this->dw
\95`
\89æ
\8aÔ
\8au = 3;
46 this->bActive = false;
47 this->strWindowTitle = _T("FDK10 Application");
48 this->strWindowClass = _T("FDK10 WindowClass");
49 this->dw
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_VISIBLE;
50 this->dw
\91S
\89æ
\96Ê
\83X
\83^
\83C
\83\8b = WS_POPUP | WS_VISIBLE;
51 this->bScreenSaverEnable = false;
53 HRESULT CD3DApplication::Create( HINSTANCE hInst, LPCTSTR strCmdLine )
57 this->hInstance = hInst;
59 // IME
\82ð
\96³
\8cø
\89»
61 WINNLSEnableIME( NULL, FALSE );
64 //
\83E
\83B
\83\93\83h
\83E
\8dì
\90¬
\82ª
\82Ü
\82¾
\82È
\82ç
\82±
\82±
\82Å
\8dì
\90¬
\82·
\82é
66 if( this->hWnd == NULL )
69 0, //
\83N
\83\89\83X
\83X
\83^
\83C
\83\8b
70 FDK::AppBase::WndProc, //
\83\81\83b
\83Z
\81[
\83W
\83v
\83\8d\83V
\81[
\83W
\83\83
73 this->hInstance, //
\83C
\83\93\83X
\83^
\83\93\83X
74 NULL, //
\83E
\83B
\83\93\83h
\83E
\83A
\83C
\83R
\83\93
75 LoadCursor( NULL, IDC_ARROW ), //
\83}
\83E
\83X
\83A
\83C
\83R
\83\93
76 (HBRUSH)GetStockObject( WHITE_BRUSH ), //
\94w
\8ci
\83u
\83\89\83V
77 NULL, //
\83\81\83j
\83\85\81[
\96¼
78 this->strWindowClass //
\83N
\83\89\83X
\96¼
80 ::RegisterClass( &wndClass );
82 RECT rc = { 0, 0, this->nWidth, this->nHeight };
83 ::AdjustWindowRect( &rc, this->dw
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b, FALSE );
84 this->hWnd = ::CreateWindow(
87 (this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h) ? this->dw
\91S
\89æ
\96Ê
\83X
\83^
\83C
\83\8b : this->dw
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b,
88 CW_USEDEFAULT, CW_USEDEFAULT,
89 (rc.right-rc.left), (rc.bottom-rc.top), 0L,
90 NULL, this->hInstance, 0L );
94 //
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\81i
\83X
\83N
\83\8a\81[
\83\93\8dÀ
\95W
\81j
\82Ì
\8eæ
\93¾
\81E
\95Û
\91¶
96 this->t
\8c»
\8dÝ
\82Ì
\83E
\83B
\83\93\83h
\83E
\82Ì
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\82Æ
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
\82ð
\8eæ
\93¾
\82·
\82é();
99 //
\83A
\83_
\83v
\83^
\81^
\83f
\83o
\83C
\83X
\81^
\83\82\81[
\83h
\82Ì
\97ñ
\8b\93
101 if( FAILED( hr = this->D3DDisplay.EnumerateDevices() ) )
102 return hr; //
\8e¸
\94s
105 //
\82R
\82c
\8aÂ
\8b«
\82Ì
\8d\
\92z
107 if( FAILED( hr = t3D
\8aÂ
\8b«
\82Ì
\8d\
\92z() ) )
111 //
\83A
\83v
\83\8a\82Ì
\88ê
\93x
\82¾
\82¯
\82Ì
\8f\89\8aú
\89»
113 if( FAILED( hr = OneTimeSceneInit() ) ) {
114 t3D
\8aÂ
\8b«
\82Ì
\94j
\8aü();
119 //
\83f
\83o
\83C
\83X
\88Ë
\91¶
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\8f\89\8aú
\89»
121 if( FAILED( hr = InitDeviceObjects() ) ) {
122 t3D
\8aÂ
\8b«
\82Ì
\94j
\8aü();
127 //
\83f
\83o
\83C
\83X
\88Ë
\91¶
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\8d\
\92z
129 if( FAILED( hr = RestoreDeviceObjects() ) ) {
130 t3D
\8aÂ
\8b«
\82Ì
\94j
\8aü();
135 //
\8f\80\94õ
\8a®
\97¹
140 HRESULT CD3DApplication::t3D
\8aÂ
\8b«
\82Ì
\8d\
\92z()
144 D3DAdapterInfo* pAdapter = this->D3DDisplay.pAdapter;
145 D3DDeviceInfo* pDevice = pAdapter->pDevice;
147 //
\83\82\83j
\83^
\82Ì
\93d
\8c¹
\90Ý
\92è
\82ð
\88ê
\8e\9e\93I
\82É
\96³
\8cø
\82É
\82·
\82é
149 this->exeState = ::SetThreadExecutionState( ES_DISPLAY_REQUIRED | ES_CONTINUOUS );
152 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\82Ì
\97L
\8cø
\81E
\96³
\8cø
\82ð
\8eæ
\93¾
\82µ
\81A
\82»
\82Ì
\8cã
\88ê
\8e\9e\93I
\82É
\96³
\8cø
\82É
\82·
\82é
154 HKEY hKeyScreenSaver = NULL;
156 long lScreenSaver = 0;
159 if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKeyScreenSaver ) == ERROR_SUCCESS )
161 this->bScreenSaverEnable =
162 ( RegQueryValueEx( hKeyScreenSaver, TEXT("SCRNSAVE.EXE"), NULL, NULL, NULL, &dwData ) == ERROR_SUCCESS ) ? true : false;
164 RegCloseKey( hKeyScreenSaver );
165 hKeyScreenSaver = NULL;
167 //
\96³
\8cø
\82É
\82·
\82é
168 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, FALSE, 0, SPIF_SENDWININICHANGE );
171 //
\91S
\83E
\83B
\83\93\83h
\83E
\88Ê
\92u
\82Ì
\95Û
\91¶
173 WindowPositions::Save();
176 //
\83^
\83C
\83}
\82Ì
\8f\89\8aú
\89»;
\83^
\83C
\83}
\8eí
\95Ê
\82ð
\95Ï
\8dX
\82·
\82é
\8fê
\8d\87\82Í
\81A
\88ê
\93x Term()
\82µ
\82Ä Init()
\82µ
\82È
\82¨
\82·
\82±
\82Æ
\81B
178 this->timer.Init( TIMERTYPE_TIMEGTTIME );
181 // D3DX
\82Ì
\8f\89\8aú
\89»
183 if( FAILED( hr = D3DXInitialize() ) )
187 // DirectDraw7
\82Ì
\8dì
\90¬
189 if( FAILED( hr = DirectDrawCreateEx( NULL, (VOID**)&this->pDD, IID_IDirectDraw7, NULL ) ) ) {
195 //
\8b¦
\92²
\83\82\81[
\83h
\82Ì
\90Ý
\92è
197 if( FAILED( hr = this->pDD->SetCooperativeLevel( this->hWnd, this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ? (DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN) : (DDSCL_NORMAL|DDSCL_NOWINDOWCHANGES) ) ) )
199 SAFE_RELEASE( this->pDD );
205 //
\83f
\83B
\83X
\83v
\83\8c\83C
\83\82\81[
\83h
\82Ì
\90Ý
\92è
\81i
\91S
\89æ
\96Ê
\83\82\81[
\83h
\8e\9e\82Ì
\82Ý
\81j
207 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
209 if( FAILED( hr = this->pDD->SetDisplayMode( this->nWidth, this->nHeight, this->nBpp, 0, 0 ) ) )
211 SAFE_RELEASE( this->pDD );
218 //
\83v
\83\89\83C
\83}
\83\8a\81\95\83o
\83b
\83N
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8dì
\90¬
220 // a.
\91S
\89æ
\96Ê
\83\82\81[
\83h
\82Ì
\8fê
\8d\87
221 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
224 ZeroMemory( &ddsd, sizeof( ddsd ) );
225 ddsd.dwSize = sizeof( ddsd );
226 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
227 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
228 ddsd.dwBackBufferCount = 1;
229 if( FAILED( hr = this->pDD->CreateSurface( &ddsd, &this->pddsFrontBuffer, NULL ) ) ) {
231 SAFE_RELEASE( this->pDD );
232 return hr; //
\83v
\83\89\83C
\83}
\83\8a\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8dì
\90¬
\82É
\8e¸
\94s
235 ZeroMemory( &ddscaps, sizeof( ddscaps ) );
236 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
237 if( FAILED( hr = this->pddsFrontBuffer->GetAttachedSurface( &ddscaps, &this->pddsBackBuffer ) ) )
240 SAFE_RELEASE( this->pddsFrontBuffer );
241 SAFE_RELEASE( this->pDD );
242 return hr; //
\83o
\83b
\83N
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8eæ
\93¾
\82É
\8e¸
\94s
246 // b.
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\82Ì
\8fê
\8d\87
250 ZeroMemory( &ddsd, sizeof( ddsd ) );
251 ddsd.dwSize = sizeof( ddsd );
252 ddsd.dwFlags = DDSD_CAPS;
253 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
254 if( FAILED( hr = this->pDD->CreateSurface( &ddsd, &this->pddsFrontBuffer, NULL ) ) ) {
255 SAFE_RELEASE( this->pDD );
257 return hr; //
\83v
\83\89\83C
\83}
\83\8a\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8dì
\90¬
\82É
\8e¸
\94s
259 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
260 ddsd.ddsCaps.dwCaps = DDSCAPS_3DDEVICE | DDSCAPS_OFFSCREENPLAIN;
261 ddsd.dwWidth = this->nWidth;
262 ddsd.dwHeight = this->nHeight;
263 if( FAILED( hr = this->pDD->CreateSurface( &ddsd, &this->pddsBackBuffer, NULL ) ) ) {
264 SAFE_RELEASE( this->pddsFrontBuffer );
265 SAFE_RELEASE( this->pDD );
267 return hr; //
\83o
\83b
\83N
\83T
\81[
\83t
\83F
\83C
\83X
\82Ì
\8dì
\90¬
\82É
\8e¸
\94s
272 //
\83N
\83\8a\83b
\83p
\81[
\82Ì
\8dì
\90¬
\81i
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\8e\9e\82Ì
\82Ý
\81j
274 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
276 LPDIRECTDRAWCLIPPER pClipper;
277 if( FAILED( hr = this->pDD->CreateClipper( 0, &pClipper, NULL ) ) )
279 SAFE_RELEASE( this->pddsBackBuffer );
280 SAFE_RELEASE( this->pddsFrontBuffer );
281 SAFE_RELEASE( this->pDD );
283 return hr; //
\83N
\83\8a\83b
\83p
\81[
\82Ì
\8dì
\90¬
\82É
\8e¸
\94s
285 pClipper->SetHWnd( 0, this->hWnd );
286 this->pddsFrontBuffer->SetClipper( pClipper );
287 SAFE_RELEASE( pClipper );
291 // Direct3D
\82Ì
\8eæ
\93¾
293 if( FAILED( hr = this->pDD->QueryInterface( IID_IDirect3D7, (LPVOID *) &this->pD3D ) ) )
295 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) SAFE_RELEASE( this->pddsBackBuffer );
296 SAFE_RELEASE( this->pddsFrontBuffer );
297 SAFE_RELEASE( this->pDD );
299 return hr; // Direct3D7
\82Ì
\8eæ
\93¾
\82É
\8e¸
\94s
303 // Direct3D
\83f
\83o
\83C
\83X
\82Ì
\8dì
\90¬
305 if( FAILED( hr = this->pD3D->CreateDevice( IID_IDirect3DTnLHalDevice, this->pddsBackBuffer, &this->pD3DDevice ) ) ) // TnLHAL
\82Å
\83g
\83\89\83C
307 if( FAILED( hr = this->pD3D->CreateDevice( IID_IDirect3DHALDevice, this->pddsBackBuffer, &this->pD3DDevice ) ) ) // HAL
\82Å
\83g
\83\89\83C
309 if( FAILED( hr = this->pD3D->CreateDevice( IID_IDirect3DMMXDevice, this->pddsBackBuffer, &this->pD3DDevice ) ) ) // MMX
\82Å
\83g
\83\89\83C
311 if( FAILED( hr = this->pD3D->CreateDevice( IID_IDirect3DRGBDevice, this->pddsBackBuffer, &this->pD3DDevice ) ) ) // RGB
\82Å
\83g
\83\89\83C
313 SAFE_RELEASE( this->pD3D );
314 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) SAFE_RELEASE( this->pddsBackBuffer );
315 SAFE_RELEASE( this->pddsFrontBuffer );
316 SAFE_RELEASE( this->pDD );
318 return hr; // Direct3DDevice
\82Ì
\8dì
\90¬
\82É
\8e¸
\94s
320 Debug::Msg( _T("Direct3D RGB
\83f
\83o
\83C
\83X
\82ð
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B\n") );
322 Debug::Msg( _T("Direct3D MMX
\83f
\83o
\83C
\83X
\82ð
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B\n") );
324 Debug::Msg( _T("Direct3D HAL
\83f
\83o
\83C
\83X
\82ð
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B\n") );
326 Debug::Msg( _T("Direct3D T&L HAL
\83f
\83o
\83C
\83X
\82ð
\8dì
\90¬
\82µ
\82Ü
\82µ
\82½
\81B\n") );
329 //
\83f
\83o
\83C
\83X
\82É
\83r
\83\85\81[
\83|
\81[
\83g
\82ð
\90Ý
\92è
331 D3DVIEWPORT7 vp = { 0, 0, this->nWidth, this->nHeight, 0.0f, 1.0f };
332 if( FAILED( hr = this->pD3DDevice->SetViewport( &vp ) ) )
334 SAFE_RELEASE( this->pD3DDevice );
335 SAFE_RELEASE( this->pD3D );
336 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) SAFE_RELEASE( this->pddsBackBuffer );
337 SAFE_RELEASE( this->pddsFrontBuffer );
338 SAFE_RELEASE( this->pDD );
340 return hr; //
\83r
\83\85\81[
\83|
\81[
\83g
\82Ì
\90Ý
\92è
\82É
\8e¸
\94s
344 //
\95s
\95Ï
\82Ì
\83\8c\83\93\83_
\83\8a\83\93\83O
\83X
\83e
\81[
\83^
\83X
\82Ì
\90Ý
\92è
346 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, FALSE );
347 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
348 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ANTIALIAS, FALSE );
349 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE );
350 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, TRUE );
351 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHAREF, 10 );
352 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHAFUNC, D3DCMP_GREATER );
353 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
354 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
355 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
356 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
357 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
358 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_POINT );
359 this->pD3DDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFN_POINT );
362 //
\93K
\8bX
\95Ï
\8dX
\82³
\82ê
\82é
\83\8c\83\93\83_
\83\8a\83\93\83O
\83X
\83e
\81[
\83^
\83X
\82Ì
\90Ý
\92è
364 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_COLORKEYENABLE, FALSE );
365 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );
366 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
367 this->pD3DDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );
370 //
\8eË
\89e
\8ds
\97ñ
\82ð
\83f
\83t
\83H
\83\8b\83g
\82Ì
\82à
\82Ì
\82©
\82ç
\95Ï
\8dX
374 CD3DApplication::GetProjectionParam( &d, &t, &a );
375 D3DXMatrixPerspectiveFovLH( &proj, t, 1.0f, 0.0000001f, 50.0f );
377 this->pD3DDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &pm );
380 //
\83}
\83E
\83X
\83J
\81[
\83\
\83\8b\95\
\8e¦ON/OFF
382 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) {
383 while( ShowCursor( FALSE ) >= 0 )
392 void CD3DApplication::t3D
\8aÂ
\8b«
\82Ì
\94j
\8aü()
394 this->bActive = false;
395 this->bReady = false;
397 //
\83A
\83v
\83\8a\91¤
\82Ì
\8fI
\97¹
\8f\88\97\9d
399 InvalidateDeviceObjects();
400 DeleteDeviceObjects();
404 //
\83f
\83B
\83X
\83v
\83\8c\83C
\83\82\81[
\83h
\82Ì
\95\9c\8c³
406 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
407 this->pDD->RestoreDisplayMode();
410 //
\8ae DirectX
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\89ð
\95ú
412 this->pDD->SetCooperativeLevel( this->hWnd, DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES );
413 SAFE_RELEASE( this->pD3DDevice );
414 SAFE_RELEASE( this->pD3D );
415 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) SAFE_RELEASE( this->pddsBackBuffer );
416 SAFE_RELEASE( this->pddsFrontBuffer );
417 SAFE_RELEASE( this->pDD );
421 //
\91S
\83E
\83B
\83\93\83h
\83E
\82Ì
\88Ê
\92u
\82ð
\95\9c\8c³
\81i
\91S
\89æ
\96Ê
\83\82\81[
\83h
\8e\9e\82Ì
\82Ý
\81j
423 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
424 WindowPositions::Load();
425 WindowPositions::Clear(); //
\93à
\95\94\83\8a\83X
\83g
\89ð
\95ú
428 //
\83^
\83C
\83}
\8fI
\97¹
433 //
\83X
\83N
\83\8a\81[
\83\93\83Z
\81[
\83o
\82ª
\97L
\8cø
\82¾
\82Á
\82½
\82È
\82ç
\82à
\82Æ
\82É
\96ß
\82·
435 if( this->bScreenSaverEnable )
436 SystemParametersInfo( SPI_SETSCREENSAVEACTIVE, TRUE, 0, SPIF_SENDWININICHANGE );
439 //
\83\82\83j
\83^
\93d
\8c¹
\90Ý
\92è
\82Ì
\95\9c\8c³
441 ::SetThreadExecutionState( this->exeState );
444 HRESULT CD3DApplication::t3D
\8aÂ
\8b«
\82Ì
\8dÄ
\8d\
\92z( bool b
\90V
\91S
\89æ
\96Ê
\83\82\81[
\83h )
448 this->bReady = false;
450 //
\82·
\82×
\82Ä
\82Ì
\83f
\83o
\83C
\83X
\88Ë
\91¶
\83I
\83u
\83W
\83F
\83N
\83g
\82ð
\89ð
\95ú
\82·
\82é
452 InvalidateDeviceObjects();
455 //
\8c»
\8dÝ
\91S
\89æ
\96Ê
\83\82\81[
\83h
\82È
\82ç
\83f
\83B
\83X
\83v
\83\8c\83C
\83\82\81[
\83h
\82ð
\95\9c\8c³
\82·
\82é
457 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
458 this->pDD->RestoreDisplayMode();
461 //
\8ae DirectX
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\89ð
\95ú
463 this->pDD->SetCooperativeLevel( this->hWnd, DDSCL_NORMAL | DDSCL_NOWINDOWCHANGES );
464 SAFE_RELEASE( this->pD3DDevice );
465 SAFE_RELEASE( this->pD3D );
466 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) SAFE_RELEASE( this->pddsBackBuffer );
467 SAFE_RELEASE( this->pddsFrontBuffer );
468 SAFE_RELEASE( this->pDD );
472 //
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b\82Ì
\90Ý
\92è
474 //
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b\82ð
\95Ï
\8dX
\82µ
\82½
\8fê
\8d\87\82Í
\81ASetWindowsPos()
\82Å
\93à
\95\94\83L
\83\83\83b
\83V
\83\85\82ð
\83N
\83\8a\83A
\82·
\82é
\95K
\97v
\82ª
\82 \82é
\81B
475 if( b
\90V
\91S
\89æ
\96Ê
\83\82\81[
\83h )
477 ::SetWindowLongPtr( this->hWnd, GWL_STYLE, this->dw
\91S
\89æ
\96Ê
\83X
\83^
\83C
\83\8b );
478 ::SetWindowPos( this->hWnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED );
482 ::SetWindowLongPtr( this->hWnd, GWL_STYLE, this->dw
\83E
\83B
\83\93\83h
\83E
\83X
\83^
\83C
\83\8b );
483 ::SetWindowPos( this->hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW );
487 //
\91S
\83E
\83B
\83\93\83h
\83E
\88Ê
\92u
\82Æ
\83T
\83C
\83Y
\82Ì
\95\9c\8c³
\81i
\91S
\89æ
\96Ê
\83\82\81[
\83h
\8e\9e\82Ì
\82Ý
\81j
489 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
491 //
\83E
\83B
\83\93\83h
\83E
\88Ê
\92u
\95\9c\8c³
492 WindowPositions::Load();
493 WindowPositions::Clear();
495 this->t
\8c»
\8dÝ
\82Ì
\83E
\83B
\83\93\83h
\83E
\82Ì
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\82Æ
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
\82ð
\8eæ
\93¾
\82·
\82é();
499 //
\83f
\83o
\83C
\83X
\82Ì
\8d\
\92z
501 bool b
\95Û
\91¶ = this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h;
502 this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h = b
\90V
\91S
\89æ
\96Ê
\83\82\81[
\83h; // t3D
\8aÂ
\8b«
\82Ì
\8d\
\92z()
\82Ì
\91O
\82É this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h
\82Ì
\90Ý
\92è
\82ª
\95K
\97v
504 if( FAILED( hr = this->t3D
\8aÂ
\8b«
\82Ì
\8d\
\92z() ) ) {
505 this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h = b
\95Û
\91¶;
510 //
\83f
\83o
\83C
\83X
\88Ë
\91¶
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\95\9c\8c³
\82Ì
\91O
\82É
\81AWait a moment
\89æ
\91\9c\82ð
\8fo
\82µ
\82Ä
\82¨
\82
\81B
\81i
\95\9c\8c³
\82ª
\92·
\88ø
\82¢
\82½
\82Æ
\82«
\82Ì
\82½
\82ß
\81j
512 CTexture::BeginScene();
513 this->tWaitAMoment
\82Ì
\95`
\89æ();
514 CTexture::EndScene();
515 this->tFlip
\82Ü
\82½
\82ÍBlt();
518 //
\83f
\83o
\83C
\83X
\88Ë
\91¶
\83I
\83u
\83W
\83F
\83N
\83g
\82Ì
\95\9c\8c³
520 if( FAILED( hr = this->RestoreDeviceObjects() ) )
524 //
\8f\80\94õ
\8a®
\97¹
529 HRESULT CD3DApplication::t3D
\8aÂ
\8b«
\82Ì
\95`
\89æ()
533 //
\8b¦
\92²
\83\8c\83x
\83\8b\82ð
\83`
\83F
\83b
\83N
\82·
\82é
535 if( FAILED( hr = this->pDD->TestCooperativeLevel() ) )
539 case DDERR_EXCLUSIVEMODEALREADYSET: //
\81i
\8e©
\95ª
\82ª
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\82Ì
\82Æ
\82«
\81j
\91¼
\82Ì
\83A
\83v
\83\8a\82ª
\94r
\91¼
\83\82\81[
\83h
\82É
\93ü
\82Á
\82½
540 case DDERR_NOEXCLUSIVEMODE: //
\94r
\91¼
\82ð
\8e¸
\82Á
\82½
\81iAlt+TAB
\82È
\82Ç
\81j
541 Sleep( 1000 ); //
\91¼
\82Ì
\83A
\83v
\83\8a\82ª
\94r
\91¼
\83\82\81[
\83h
\82É
\93ü
\82Á
\82Ä
\82¢
\82é
\82Ì
\82Å
\91Ò
\8b@
\82·
\82é
\81B
\96³
\91Ê
\82ÉCPU
\82ð
\8eg
\82í
\82È
\82¢(2006/5/6)
544 case DDERR_WRONGMODE: //
\83f
\83B
\83X
\83v
\83\8c\83C
\83\82\81[
\83h
\82ª
\95Ï
\8dX
\82³
\82ê
\82½
\81B
\91S
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\94j
\8aü
\82µ
\82Ä
\8dì
\82è
\92¼
\82µ
\82ª
\95K
\97v
\81B
545 if( this->D3DDisplay.pAdapter->pDevice->bWindowed )
547 hr = this->t3D
\8aÂ
\8b«
\82Ì
\8dÄ
\8d\
\92z( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h );
560 // Render()
\82ª true
\82ð
\95Ô
\82µ
\82½
\82ç WM_CLOSE
\82ð
\91\97\90M
\82·
\82é
\81B
561 SendMessage( this->hWnd, WM_CLOSE, 0, 0 );
565 this->tFPS
\82ð
\8eZ
\8fo
\82·
\82é();
570 if( FAILED( hr = this->tFlip
\82Ü
\82½
\82ÍBlt() ) )
572 if( hr == DDERR_SURFACELOST )
574 //
\83T
\81[
\83t
\83F
\83C
\83X
\82ð
\82·
\82×
\82Ä
\95\9c\8c³
\82µ
\81A
\8dÄ
\8d\
\92z
\81B
575 this->pDD->RestoreAllSurfaces();
576 return this->RestoreDeviceObjects();
579 return hr; //
\82»
\82Ì
\91¼
\82Ì
\83G
\83\89\81[
585 HRESULT CD3DApplication::tFlip
\82Ü
\82½
\82ÍBlt()
589 if( this->pddsFrontBuffer == NULL )
590 return FDKERR_
\8f\89\8aú
\89»
\82³
\82ê
\82Ä
\82È
\82¢;
592 //
\91S
\89æ
\96Ê
\83\82\81[
\83h
\8e\9e\81F
593 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
595 if( this->b
\90\82\92¼
\8bA
\90ü
\93¯
\8aú )
597 hr = this->pddsFrontBuffer->Flip( NULL, DDFLIP_WAIT );
602 return this->t
\90\82\92¼
\93¯
\8aú
\82ð
\8eg
\82í
\82È
\82¢
\83E
\83F
\83C
\83g
\82ÆBlt( NULL );
606 //
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\8e\9e\81F
609 return this->t
\90\82\92¼
\93¯
\8aú
\82ð
\8eg
\82í
\82È
\82¢
\83E
\83F
\83C
\83g
\82ÆBlt( &this->rc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ );
614 HRESULT CD3DApplication::t
\90\82\92¼
\93¯
\8aú
\82ð
\8eg
\82í
\82È
\82¢
\83E
\83F
\83C
\83g
\82ÆBlt( LPRECT prc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ )
616 static bool bBltFast
\82ð
\8eg
\82¤ = true; //
\8f\89\89ñ
\82Ì
\82Ý BltFast
\82Å
\8e\8e\82µ
\81A
\83_
\83\81\82È
\82ç
\82»
\82ê
\88È
\8d~
\82ÍBlt
\82ð
\8eg
\82¤
\81B
617 static double db
\91O
\89ñ
\82Ì
\95`
\89æ
\8aJ
\8en
\8e\9e\8d\8f = INIT_TIME;
621 if( db
\91O
\89ñ
\82Ì
\95`
\89æ
\8aJ
\8en
\8e\9e\8d\8f != INIT_TIME )
623 double db
\8co
\89ß
\8e\9e\8aÔ = this->timer.GetSysTime() - db
\91O
\89ñ
\82Ì
\95`
\89æ
\8aJ
\8en
\8e\9e\8d\8f;
624 double db
\97]
\8fè
\8e\9e\8aÔ = (double)this->dw
\95`
\89æ
\8aÔ
\8au - db
\8co
\89ß
\8e\9e\8aÔ;
625 if( db
\97]
\8fè
\8e\9e\8aÔ > 0 )
626 ::Sleep( (DWORD)db
\97]
\8fè
\8e\9e\8aÔ ); //
\97]
\8fè
\8e\9e\8aÔ
\82¾
\82¯
\96°
\82é
630 if( bBltFast
\82ð
\8eg
\82¤ )
632 RECT rcBack = { 0, 0, this->nWidth, this->nHeight };
633 if( FAILED( hr = this->pddsFrontBuffer->BltFast( 0, 0, this->pddsBackBuffer, &rcBack, DDBLTFAST_WAIT ) ) )
635 bBltFast
\82ð
\8eg
\82¤ = false; // BltFast()
\82É
\8e¸
\94s
\82µ
\82½
\82Ì
\82Å
\81A
\88È
\8cã
\82Í Blt()
\82ð
\8eg
\82¤
\81B
640 hr = this->pddsFrontBuffer->Blt( prc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ, this->pddsBackBuffer, NULL, DDBLT_WAIT, NULL );
642 db
\91O
\89ñ
\82Ì
\95`
\89æ
\8aJ
\8en
\8e\9e\8d\8f = this->timer.GetSysTime();
647 void CD3DApplication::t
\91S
\89æ
\96Ê
\81E
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\82ð
\90Ø
\82è
\91Ö
\82¦
\82é()
651 //
\8c»
\8dÝ
\83E
\83B
\83\93\83h
\83E
\83\82\81[
\83h
\82È
\82ç
\91S
\83E
\83B
\83\93\83h
\83E
\82Ì
\88Ê
\92u
\82ð
\95Û
\91¶
\82·
\82é
652 if( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
653 WindowPositions::Save();
655 //
\83f
\83o
\83C
\83X
\90Ø
\82è
\91Ö
\82¦
656 if( FAILED( hr = t3D
\8aÂ
\8b«
\82Ì
\8dÄ
\8d\
\92z( ! this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) ) )
658 //
\8e¸
\94s
\82µ
\82½
\82ç
\8c³
\82É
\96ß
\82·
\81i
\82P
\89ñ
\82¾
\82¯
\81j
659 if( FAILED( hr = t3D
\8aÂ
\8b«
\82Ì
\8dÄ
\8d\
\92z( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h ) ) )
660 return; //
\82±
\82ê
\82Å
\82à
\83G
\83\89\81[
\82ª
\8fo
\82½
\82ç
\96³
\8e\8b
664 void CD3DApplication::t
\8c»
\8dÝ
\82Ì
\83E
\83B
\83\93\83h
\83E
\82Ì
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\82Æ
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
\82ð
\8eæ
\93¾
\82·
\82é()
666 //
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\82Ì
\8eæ
\93¾
667 GetWindowRect( this->hWnd, &this->rc
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ );
669 //
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
\82Ì
\8eæ
\93¾
670 GetClientRect( this->hWnd, &this->rc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ );
671 ClientToScreen( this->hWnd, (POINT*)&this->rc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ.left ); // left, top
\82ð
\83X
\83N
\83\8a\81[
\83\93\8dÀ
\95W
\82Ö
672 ClientToScreen( this->hWnd, (POINT*)&this->rc
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ.right ); // right, bottom
\82ð
\83X
\83N
\83\8a\81[
\83\93\8dÀ
\95W
\82Ö
675 void CD3DApplication::tWaitAMoment
\82Ì
\95`
\89æ()
678 \88È
\89º
\82Í
\83T
\83\93\83v
\83\8b
681 sf.InitDeviceObjectsFromFile( _T("Wait a moment"), _T("sysdata/ses_frame.jpg") );
682 if( SUCCEEDED( sf.RestoreDeviceObjects() ) )
685 sf.InvalidateDeviceObjects();
687 sf.DeleteDeviceObjects();
691 void CD3DApplication::tFPS
\82ð
\8eZ
\8fo
\82·
\82é()
693 static double fpstime = INIT_TIME;
697 if( fpstime == INIT_TIME )
699 fpstime = this->timer.GetSysTime();
700 this->nFPS = fps = 0;
703 //
\82P
\95b
\8co
\89ß
\82²
\82Æ
\82É
\8cv
\8eZ
704 while( this->timer.GetSysTime() - fpstime >= 1000.0 )
713 INT CD3DApplication::Run()
719 if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
721 if( msg.message == WM_QUIT )
723 TranslateMessage( &msg );
724 DispatchMessage( &msg );
728 if( this->bReady && this->bActive )
730 if( FAILED( t3D
\8aÂ
\8b«
\82Ì
\95`
\89æ() ) ) {
731 Debug::Msg( _T("3D
\8aÂ
\8b«
\82Ì
\95`
\89æ
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\81B
\8fI
\97¹
\82µ
\82Ü
\82·
\81B\n") );
732 SendMessage( this->hWnd, WM_CLOSE, 0, 0 );
737 return (INT)msg.wParam;
739 LRESULT CD3DApplication::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
745 this->bActive = false;
746 this->t3D
\8aÂ
\8b«
\82Ì
\94j
\8aü();
750 PostQuitMessage( 0 );
754 //
\83E
\83B
\83\93\83h
\83E
\82ª
\91S
\95\94\89B
\82ê
\82½
\82è
\8dÅ
\8f¬
\89»
\82³
\82ê
\82½
\82è
\82µ
\82½
\82ç this->bActive = false
\82É
\82·
\82é
\81B
755 this->bActive = ( wParam == SIZE_MAXHIDE || wParam == SIZE_MINIMIZED ) ? false : true;
759 //
\90V
\82µ
\82¢
\97Ì
\88æ
\8dÀ
\95W
\82ð
\8eæ
\93¾
\82µ
\82Ä
\82¨
\82
760 this->t
\8c»
\8dÝ
\82Ì
\83E
\83B
\83\93\83h
\83E
\82Ì
\83E
\83B
\83\93\83h
\83E
\97Ì
\88æ
\82Æ
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
\82ð
\8eæ
\93¾
\82·
\82é();
763 case WM_GETMINMAXINFO:
764 //
\83A
\83v
\83\8a\82Ì
\8dÅ
\8f¬
\83T
\83C
\83Y
\82Ì
\96â
\82¢
\8d\87\82í
\82¹
\82Ö
\82Ì
\89ñ
\93\9a\81B
765 ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 100;
766 ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 100;
770 if( this->b
\91S
\89æ
\96Ê
\83\82\81[
\83h )
771 return HTCLIENT; //
\82·
\82×
\82Ä
\82ª
\83N
\83\89\83C
\83A
\83\93\83g
\97Ì
\88æ
774 return DefWindowProc( hWnd, uMsg, wParam, lParam );