OSDN Git Service

Boost.MSMでメニュー部分を実装
[shooting3/shootinggame.git] / ShootingGame / GameMain.h
1 ////// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
2 //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
3 //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
4 //// PARTICULAR PURPOSE.
5 ////
6 //// Copyright (c) Microsoft Corporation. All rights reserved
7
8 #pragma once
9
10 #include "DirectXBase.h"
11 #include "SampleOverlay.h"
12 #include "AutoThrottle.h"
13 #include "BasicSprites.h"
14 #include "BasicLoader.h"
15 #include "GameStateMachine.h"
16 #include "SoundManager.h"
17
18 namespace ShootingGame {
19   
20
21   struct CharacterData
22   {
23     float2 pos;
24     float2 vel;
25     float rot;
26     float rotVel;
27     float scale;
28   };
29
30 //  ref class MainPage;
31   
32   ref class GameMain : public DirectXBase
33   {
34   internal:
35     
36     delegate void SubFrameFuncDelegate(Windows::UI::Xaml::Controls::Page^ p);
37     delegate void IsBackButtonEnabledDelgate(bool v);
38
39     explicit GameMain();
40     ~GameMain();
41     virtual void CreateDeviceIndependentResources() override;
42     virtual void CreateDeviceResources() override;
43     virtual void CreateWindowSizeDependentResources() override;
44     virtual void Render() override;
45
46     void Initialize(
47       _In_ Windows::UI::Core::CoreWindow^ window,
48       _In_ Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
49       _In_ float dpi
50       ) ;
51
52     void Update(float timeTotal, float timeDelta);
53
54     static const float BACKBUFFER_WIDTH;
55     static const float BACKBUFFER_HEIGHT;
56
57     sf::SoundManager& GameMain::SoundManager()
58     {
59       return *soundManager_;
60     }
61
62     sf::SoundDriver& GameMain::SoundDriver()
63     {
64       return *soundDriver_;
65     }
66
67     BasicSprites::SpriteBatch^ GameMain::SpriteBatch()
68     {
69       return spriteBatch_;
70     }
71
72     ::AutoThrottle^ GameMain::AutoThrottle() {return autoThrottle_;}
73     ::SampleOverlay^ GameMain::SampleOverlay() {return sampleOverlay_;}
74
75     //  void InitSound();
76     float RandFloat(float min, float max);
77     void StartSound();
78     void StopSound();
79     void ClearScreen();
80     void RenderScreen();
81
82     void LoadTexture(const std::wstring& filename,ID3D11Texture2D** texPtrAddr);
83
84     void Subframe(Windows::UI::Xaml::Controls::Page^ p)
85     {
86       subFrameFunction_(p);
87     }
88
89     void SetSubFrameFunc(SubFrameFuncDelegate^ func)
90     {
91         subFrameFunction_ = func;
92     }
93
94     ShootingGame::GameStateMachine&  GameMain::GameStateMachine()
95     {
96       return state_;
97     }
98
99     void SetIsBackButtonEnabledDelgate(IsBackButtonEnabledDelgate^ d)
100     {
101       isBackButtonEnabledDelgate_ = d;
102     }
103
104     void IsBackButtonEnabled(bool v)
105     {
106       isBackButtonEnabledDelgate_(v);
107     }
108
109   private:
110 //    std::function<void(Windows::UI::Xaml::Controls::Page^ p)> subFrameFunction_;
111     SubFrameFuncDelegate^ subFrameFunction_;
112     IsBackButtonEnabledDelgate^ isBackButtonEnabledDelgate_;
113     ShootingGame::GameStateMachine state_;
114     void ExecuteSoundThread();
115     ::SampleOverlay^ sampleOverlay_;
116     ::AutoThrottle^ autoThrottle_;
117     BasicSprites::SpriteBatch^ spriteBatch_;
118     Microsoft::WRL::ComPtr<ID3D11Texture2D> backBuffer_;
119     Microsoft::WRL::ComPtr<ID3D11RenderTargetView>  backBufferRenderTargetView_;
120     //  Microsoft::WRL::ComPtr<ID3D11DepthStencilView>  backBufferDepthStencilView_;
121     //  Microsoft::WRL::ComPtr<ID3D11DepthStencilState> backBufferDepthStencilState_;
122     float scale_;
123     CD3D11_VIEWPORT backBufferViewPort_;
124     CD3D11_VIEWPORT swapChainViewPort_;
125     std::vector<CharacterData> characters_;
126     bool isDestroy_;
127     Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel_;
128     std::unique_ptr<sf::SoundManager> soundManager_;
129     std::unique_ptr<sf::SoundDriver> soundDriver_;
130     concurrency::task<void> soundTask_;
131     sf::handle_holder eventHolder_;
132   };
133 }