OSDN Git Service

XAudio2を試す前のバックアップ。
authorsfpgmr <sfpg@users.sourceforge.jp>
Fri, 4 May 2012 03:54:05 +0000 (12:54 +0900)
committersfpgmr <sfpg@users.sourceforge.jp>
Fri, 4 May 2012 03:54:05 +0000 (12:54 +0900)
13 files changed:
ShootingGame/App.xaml.cpp
ShootingGame/App.xaml.h
ShootingGame/GameMain.cpp [moved from ShootingGame/SimpleSprites.cpp with 97% similarity]
ShootingGame/GameMain.h [moved from ShootingGame/SimpleSprites.h with 94% similarity]
ShootingGame/ShootingGame.vcxproj
ShootingGame/SoundDriver.cpp [new file with mode: 0644]
ShootingGame/SoundDriver.h [new file with mode: 0644]
ShootingGame/exception.cpp [new file with mode: 0644]
ShootingGame/exception.h [new file with mode: 0644]
ShootingGame/explosion.png [new file with mode: 0644]
ShootingGame/pch.h
ShootingGame/sf_memory.h [new file with mode: 0644]
ShootingGame/test1.png [new file with mode: 0644]

index e280a76..16c7a3e 100644 (file)
@@ -62,12 +62,13 @@ void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEvent
        Window::Current->Activated += ref new WindowActivatedEventHandler(this, &App::OnWindowActivationChanged);
        Window::Current->Activate();
 
-       simpleSprites_ = ref new SimpleSprites();
-       simpleSprites_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
+       gameMain_ = ref new GameMain();
+       gameMain_->Initialize(Window::Current->CoreWindow,mainPage,DisplayProperties::LogicalDpi);
 
        eventToken_ = 
                CompositionTarget::Rendering::add
                (ref new EventHandler<Object^>(this, &App::OnRendering));
+
        ApplicationView::GetForCurrentView()->ViewStateChanged +=
                ref new TypedEventHandler<ApplicationView^, ApplicationViewStateChangedEventArgs^>(
                this,
@@ -118,9 +119,9 @@ void App::OnRendering(
        )
 {
        timer_->Update();
-       simpleSprites_->Update(timer_->Total,timer_->Delta);
-       simpleSprites_->Render();
-       simpleSprites_->Present();
+       gameMain_->Update(timer_->Total,timer_->Delta);
+       gameMain_->Render();
+       gameMain_->Present();
 
 }
 //--------------------------------------------------------------------------------------
@@ -129,7 +130,7 @@ void App::OnWindowSizeChanged(
        _In_ WindowSizeChangedEventArgs^ args
        )
 {
-       simpleSprites_->UpdateForWindowSizeChange();
+       gameMain_->UpdateForWindowSizeChange();
 
 }
 //--------------------------------------------------------------------------------------
@@ -137,7 +138,7 @@ void App::OnLogicalDpiChanged(
        _In_ Object^ sender
        )
 {
-       simpleSprites_->SetDpi(DisplayProperties::LogicalDpi);
+       gameMain_->SetDpi(DisplayProperties::LogicalDpi);
 }
 //--------------------------------------------------------------------------------------
 void App::OnWindowActivationChanged(
index 0cd5235..379a455 100644 (file)
@@ -7,7 +7,8 @@
 
 #include "pch.h"
 #include "App.g.h"
-#include "SimpleSprites.h"
+#include "SoundDriver.h"
+#include "GameMain.h"
 #include "BasicTimer.h"
 
 namespace ShootingGame
@@ -23,7 +24,7 @@ namespace ShootingGame
 
        private:
                void OnSuspending(Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e);
-               SimpleSprites^ simpleSprites_;
+               GameMain^ gameMain_;
                BasicTimer^ timer_;
         Windows::Foundation::EventRegistrationToken         eventToken_;
         void OnResuming(
similarity index 97%
rename from ShootingGame/SimpleSprites.cpp
rename to ShootingGame/GameMain.cpp
index 41e1dba..425e413 100644 (file)
@@ -6,7 +6,8 @@
 //// Copyright (c) Microsoft Corporation. All rights reserved
 
 #include "pch.h"
-#include "SimpleSprites.h"
+#include "SoundDriver.h"
+#include "GameMain.h"
 #include "BasicLoader.h"
 #include "windows.ui.xaml.media.dxinterop.h"
 
@@ -26,14 +27,15 @@ using namespace D2D1;
 
 using namespace BasicSprites;
 
-const float SimpleSprites::BACKBUFFER_WIDTH = 320.0f;
-const float SimpleSprites::BACKBUFFER_HEIGHT = 240.0f;
+const float GameMain::BACKBUFFER_WIDTH = 320.0f;
+const float GameMain::BACKBUFFER_HEIGHT = 240.0f;
 
-SimpleSprites::SimpleSprites() : backBufferViewPort_(0.0f,0.0f,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT)
+GameMain::GameMain() : backBufferViewPort_(0.0f,0.0f,BACKBUFFER_WIDTH,BACKBUFFER_HEIGHT)
 {
+       soundDriver_.reset(new sf::SoundDriver());
 }
 
-void SimpleSprites::CreateDeviceIndependentResources()
+void GameMain::CreateDeviceIndependentResources()
 {
     DirectXBase::CreateDeviceIndependentResources();
 
@@ -42,7 +44,7 @@ void SimpleSprites::CreateDeviceIndependentResources()
     autoThrottle_ = ref new AutoThrottle(1.0f / 60.0f);
 }
 
-    void SimpleSprites::Initialize(
+    void GameMain::Initialize(
         _In_ Windows::UI::Core::CoreWindow^ window,
         _In_ Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ swapChainPanel,
         _In_ float dpi
@@ -52,7 +54,7 @@ void SimpleSprites::CreateDeviceIndependentResources()
                Initialize(window,dpi);
        }
 
-void SimpleSprites::CreateDeviceResources()
+void GameMain::CreateDeviceResources()
 {
     DirectXBase::CreateDeviceResources();
 
@@ -97,7 +99,7 @@ void SimpleSprites::CreateDeviceResources()
 
 }
 
-void SimpleSprites::CreateWindowSizeDependentResources()
+void GameMain::CreateWindowSizeDependentResources()
 {
 //     DirectXBase::CreateWindowSizeDependentResources();
     // Store the window bounds so the next time we get a SizeChanged event we can
@@ -329,7 +331,7 @@ void SimpleSprites::CreateWindowSizeDependentResources()
 
 }
 
-void SimpleSprites::Update(float timeTotal, float timeDelta)
+void GameMain::Update(float timeTotal, float timeDelta)
 {
     // Update the performance throttler.
 
@@ -470,7 +472,7 @@ void SimpleSprites::Update(float timeTotal, float timeDelta)
     //}
 }
 
-void SimpleSprites::Render()
+void GameMain::Render()
 {
        static int frame_count = 0;
 
@@ -603,7 +605,7 @@ void SimpleSprites::Render()
        sampleOverlay_->Render();
 }
 
-float SimpleSprites::RandFloat(float min, float max)
+float GameMain::RandFloat(float min, float max)
 {
     return (static_cast<float>(rand() % RAND_MAX) / static_cast<float>(RAND_MAX)) * (max - min) + min;
 }
similarity index 94%
rename from ShootingGame/SimpleSprites.h
rename to ShootingGame/GameMain.h
index 082bb5a..dfeb2c1 100644 (file)
@@ -21,10 +21,10 @@ struct CharacterData
     float scale;
 };
 
-ref class SimpleSprites : public DirectXBase
+ref class GameMain : public DirectXBase
 {
 public:
-    SimpleSprites();
+    GameMain();
     virtual void CreateDeviceIndependentResources() override;
     virtual void CreateDeviceResources() override;
     virtual void CreateWindowSizeDependentResources() override;
@@ -56,4 +56,5 @@ private:
        CD3D11_VIEWPORT swapChainViewPort_;
        std::vector<CharacterData> characters_;
        Windows::UI::Xaml::Controls::SwapChainBackgroundPanel^ panel_;
+       std::unique_ptr<sf::SoundDriver> soundDriver_;
 };
index d5ea043..18b8683 100644 (file)
     <ClInclude Include="DDSTextureLoader.h" />
     <ClInclude Include="DirectXBase.h" />
     <ClInclude Include="DirectXSample.h" />
+    <ClInclude Include="exception.h" />
     <ClInclude Include="pch.h" />
     <ClInclude Include="Common\BindableBase.h" />
     <ClInclude Include="Common\BooleanToVisibilityConverter.h" />
       <DependentUpon>MainPage.xaml</DependentUpon>
     </ClInclude>
     <ClInclude Include="SampleOverlay.h" />
-    <ClInclude Include="SimpleSprites.h" />
+    <ClInclude Include="GameMain.h" />
+    <ClInclude Include="SoundDriver.h" />
   </ItemGroup>
   <ItemGroup>
     <ApplicationDefinition Include="App.xaml">
       <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
     </ClCompile>
     <ClCompile Include="SampleOverlay.cpp" />
-    <ClCompile Include="SimpleSprites.cpp" />
+    <ClCompile Include="GameMain.cpp" />
+    <ClCompile Include="SoundDriver.cpp" />
   </ItemGroup>
   <ItemGroup>
     <FxCompile Include="BasicSprites.GeometryShader.gs.hlsl">
diff --git a/ShootingGame/SoundDriver.cpp b/ShootingGame/SoundDriver.cpp
new file mode 100644 (file)
index 0000000..12896a1
--- /dev/null
@@ -0,0 +1,149 @@
+#include "pch.h"
+#include "sf_memory.h"
+#include "SoundDriver.h"
+
+using namespace std;
+using namespace Windows::Foundation;
+using namespace Windows::Foundation::Collections;
+using namespace Windows::Devices::Enumeration;
+using namespace Windows::Media::Devices;
+using namespace Concurrency;
+using namespace Platform;
+#pragma comment(lib, "mmdevapi.lib")
+
+namespace sf {
+
+  void makeWaveFormat(WAVEFORMATEXTENSIBLE& format,
+    int sample_rate = 44100,int channels = 2,int bits_per_sample = 32,int valid_bits_per_sample = 32,
+    uint32_t type = WAVE_FORMAT_EXTENSIBLE,
+    const GUID& sub_type = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT)
+  {
+    ZeroMemory(&format,sizeof(WAVEFORMATEXTENSIBLE));
+    format.Format.wFormatTag = type;
+    format.Format.cbSize = sizeof(WAVEFORMATEXTENSIBLE) - sizeof(WAVEFORMATEX);
+    format.SubFormat = sub_type;
+    format.Format.nSamplesPerSec = sample_rate;
+    format.Format.nChannels = channels;
+    format.Format.wBitsPerSample = bits_per_sample;
+    format.Format.nBlockAlign = (format.Format.wBitsPerSample / 8) * format.Format.nChannels;
+    format.Format.nAvgBytesPerSec = format.Format.nSamplesPerSec  * format.Format.nBlockAlign;
+    format.Samples.wValidBitsPerSample = valid_bits_per_sample;
+    format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT;
+  }
+
+  void makeWaveFormat(WAVEFORMATEX& format,int sample_rate = 44100,int channels = 2,int bits = 16,uint32_t type = WAVE_FORMAT_PCM)
+  {
+    ZeroMemory(&format,sizeof(WAVEFORMATEX));
+    format.wFormatTag = type;
+    format.nSamplesPerSec = sample_rate;
+    format.nChannels = channels;
+    format.wBitsPerSample = bits;
+    format.nBlockAlign = (format.wBitsPerSample / 8) * format.nChannels;
+    format.nAvgBytesPerSec = format.nSamplesPerSec  * format.nBlockAlign;
+  };
+
+
+SoundDriver::SoundDriver() : rateConvert_(false)
+{
+       //::AvMMAvSetMmThreadCharacteristics
+       String^ deviceID = MediaDevice::GetDefaultAudioRenderId(AudioDeviceRole::Default);
+       ActivateAudioInterface(deviceID->Data(),__uuidof(IAudioClient2),&audioClient_);
+       if(!audioClient_)
+       {
+               throw AudioClientNullException(L"\8aù\92è\82ÌAudioClient\82ð\83A\83N\83e\83B\83x\81[\83g\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
+       }
+
+       // \83I\81[\83f\83B\83I\83t\83H\81[\83}\83b\83g\82Ì\83`\83F\83b\83N
+       // KSDATAFORMAT_SUBTYPE_IEEE_FLOAT,2CH\83X\83e\83\8c\83I,44100KHz\82ð\95W\8f\80\82Æ\82·\82é
+       WAVEFORMATEXTENSIBLE  format;
+       makeWaveFormat(format);
+       sf::co_task_memory<WAVEFORMATEXTENSIBLE> mix_format;
+       audioClient_->GetMixFormat(reinterpret_cast<WAVEFORMATEX**>(&mix_format));
+
+       sf::co_task_memory<WAVEFORMATEXTENSIBLE>  alt_format;
+       HRESULT hr = audioClient_->IsFormatSupported(
+               AUDCLNT_SHAREMODE_SHARED,
+               reinterpret_cast<WAVEFORMATEX*>(&format),
+               reinterpret_cast<WAVEFORMATEX**>(&alt_format));
+       int sample_rate_backup = 0;
+       if(hr == S_FALSE) // FALSE\82Ì\8e\9e\82Í\82¨\82»\82ç\82­\83T\83\93\83v\83\8a\83\93\83O\83\8c\81[\83g\82ª\88á\82¤
+       {
+               // \83T\83\93\83v\83\8a\83\93\83O\83\8c\81[\83g\82Ì\82Ý\82ª\88Ù\82È\82é\82©\83`\83F\83b\83N\82·\82é
+               if(     alt_format->Format.wFormatTag == format.Format.wFormatTag &&
+                       alt_format->Format.nChannels == format.Format.nChannels &&
+                       alt_format->Format.wBitsPerSample == format.Format.wBitsPerSample &&
+                       alt_format->Samples.wValidBitsPerSample == format.Samples.wValidBitsPerSample && 
+                       alt_format->Format.nSamplesPerSec != format.Format.nSamplesPerSec
+                       )
+               {
+                       sample_rate_backup = format.Format.nSamplesPerSec;
+                       // \91ã\91Ö\83t\83H\81[\83}\83b\83g\82Ì\83T\83\93\83v\83\8b\83\8c\81[\83g\82ð\83Z\83b\83g\82·\82é
+                       format.Format.nSamplesPerSec = alt_format->Format.nSamplesPerSec;
+                       // \8dÄ\8cv\8eZ\82·\82é
+                       format.Format.nAvgBytesPerSec = alt_format->Format.nSamplesPerSec * format.Format.nBlockAlign;
+                       // \82à\82¤\88ê\89ñ\83`\83F\83b\83N\82·\82é\81B
+                       // \83T\83\93\83v\83\8b\83\8c\81[\83g\88È\8aO\82Å\83T\83|\81[\83g\82µ\82Ä\82¢\82È\82¢\93_\82ª\82 \82ê\82Î\97á\8aO\82ª\94­\90\82·\82é\81B
+                       alt_format.reset();
+                       ThrowIfErr(audioClient_->IsFormatSupported(
+                               AUDCLNT_SHAREMODE_SHARED,
+                               reinterpret_cast<WAVEFORMATEX*>(&format),
+                               reinterpret_cast<WAVEFORMATEX**>(&alt_format)));
+                       rateConvert_ = true;
+               } else {
+                       throw AudioFormatNotSupportedException(L"\82±\82Ì\83I\81[\83f\83B\83I\83f\83o\83C\83X\82Å\90Ý\92è\82µ\82Ä\82¢\82é\83t\83H\81[\83}\83b\83g\82Í\91Î\89\9e\82µ\82Ä\82¢\82Ü\82¹\82ñ\81B");
+               }
+       }
+
+       // Audio Client\82Ì\8f\89\8aú\89»
+
+       REFERENCE_TIME defaultDevicePeriod,minDevicePriod;
+       audioClient_->GetDevicePeriod(&defaultDevicePeriod,&minDevicePriod);
+       hr = audioClient_->Initialize(
+                       AUDCLNT_SHAREMODE_SHARED,
+                       AUDCLNT_STREAMFLAGS_NOPERSIST | 
+                       AUDCLNT_STREAMFLAGS_EVENTCALLBACK | 
+                       rateConvert_?AUDCLNT_STREAMFLAGS_RATEADJUST:0 ,
+                       minDevicePriod,0,
+                       reinterpret_cast<WAVEFORMATEX*>(&format),NULL);
+       if(hr == AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED)
+       {
+               ThrowIfErr(audioClient_->GetBufferSize(&bufferSize_));
+               latency_ = (double)10000000 * (bufferSize_) / format.Format.nSamplesPerSec;
+               audioClient_.Reset();
+               ActivateAudioInterface(deviceID->Data(),__uuidof(IAudioClient2),&audioClient_);
+               if(!audioClient_)
+               {
+                       throw AudioClientNullException(L"\8aù\92è\82ÌAudioClient\82ð\83A\83N\83e\83B\83x\81[\83g\82Å\82«\82Ü\82¹\82ñ\82Å\82µ\82½\81B");
+               }
+               ThrowIfErr(audioClient_->Initialize(
+                               AUDCLNT_SHAREMODE_SHARED,
+                               AUDCLNT_STREAMFLAGS_NOPERSIST | 
+                               AUDCLNT_STREAMFLAGS_EVENTCALLBACK | 
+                               rateConvert_?AUDCLNT_STREAMFLAGS_RATEADJUST:0,
+                               latency_,0,
+                               reinterpret_cast<WAVEFORMATEX*>(&format),NULL));
+       } else {
+               throw Platform::Exception::CreateException(hr);
+       }
+
+       ThrowIfErr(audioClient_->GetBufferSize(&bufferSize_));
+
+    //// \83T\83\93\83v\83\8b\83\8c\81[\83g\83R\83\93\83o\81[\83^
+    //if(rateConvert_)
+    //{
+    //  ThrowIfErr(audioClient_->GetService(__uuidof(IAudioClockAdjustment),&audioClockAdjustment_));
+    //  // \96{\97\88\82Ì\83T\83\93\83v\83\8b\83\8c\81[\83g\82ð\83Z\83b\83g\82·\82é
+    //  audioClockAdjustment_->SetSampleRate(sample_rate_backup);
+    //}
+
+       audioClient_->GetStreamLatency(&latency_);
+       ThrowIfErr(audioClient_->GetService(__uuidof(IAudioRenderClient),&audioRenderClient_));
+}
+
+SoundDriver::~SoundDriver()
+{
+       audioClient_->Stop();
+       audioRenderClient_.Reset();
+       audioClient_->Reset();
+}
+}
diff --git a/ShootingGame/SoundDriver.h b/ShootingGame/SoundDriver.h
new file mode 100644 (file)
index 0000000..82e7661
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+typedef Microsoft::WRL::ComPtr<IAudioClient2> IAudioClient2Ptr;
+typedef Microsoft::WRL::ComPtr<IAudioClock2> IAudioClock2Ptr;
+typedef Microsoft::WRL::ComPtr<IAudioRenderClient> IAudioRenderClientPtr;
+typedef Microsoft::WRL::ComPtr<IAudioCaptureClient> IAudioCaptureClientPtr;
+//typedef Microsoft::WRL::ComPtr<IAudioClockAdjustment> IAudioClockAdjustmentPtr;
+
+namespace sf {
+
+DefineException(AudioClientNull);
+DefineException(AudioFormatNotSupported);
+
+struct SoundDriver
+{
+       SoundDriver();
+       ~SoundDriver();
+
+private:
+       IAudioClient2Ptr audioClient_;
+       bool rateConvert_;
+       uint32_t bufferSize_;
+       REFERENCE_TIME latency_;
+//     IAudioClockAdjustmentPtr audioClockAdjustment_;
+       IAudioRenderClientPtr audioRenderClient_;
+};
+}
+
diff --git a/ShootingGame/exception.cpp b/ShootingGame/exception.cpp
new file mode 100644 (file)
index 0000000..ce27f56
--- /dev/null
@@ -0,0 +1,124 @@
+#include "pch.h"
+#include "exception.h"
+#include <objbase.h>
+#include <wtypes.h>
+#include <winerror.h>
+#include <avrt.h>
+#include <strsafe.h>
+#include <audioclient.h>
+#include <audiopolicy.h>
+
+
+
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+
+#if _DEBUG
+#define _CRTDBG_MAP_ALLOC
+#include <crtdbg.h>
+#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
+#endif
+
+#include "sf_memory.h"
+
+using namespace boost;
+
+namespace sf
+{
+//typedef CComPtr<IAudioClient> IAudioClientPtr;
+std::map<HRESULT,std::wstring> com_error_  = boost::assign::list_of<std::pair<HRESULT,std::wstring> >
+    (E_POINTER,L"E_POINTER")
+    (E_INVALIDARG,L"E_INVALIDARG")
+    (DWRITE_E_FILEFORMAT,L"DWRITE_E_FILEFORMAT")
+    (DWRITE_E_UNEXPECTED,L"DWRITE_E_UNEXPECTED")
+    (DWRITE_E_NOFONT,L"DWRITE_E_NOFONT")
+    (DWRITE_E_FILENOTFOUND,L"DWRITE_E_FILENOTFOUND")
+    (DWRITE_E_FILEACCESS,L"DWRITE_E_FILEACCESS")
+    (DWRITE_E_FONTCOLLECTIONOBSOLETE,L"DWRITE_E_FONTCOLLECTIONOBSOLETE")
+    (DWRITE_E_ALREADYREGISTERED,L"DWRITE_E_ALREADYREGISTERED")
+       (AUDCLNT_E_NOT_INITIALIZED,L"AUDCLNT_E_NOT_INITIALIZED")
+       (AUDCLNT_E_ALREADY_INITIALIZED,L"AUDCLNT_E_ALREADY_INITIALIZED")
+    (AUDCLNT_E_WRONG_ENDPOINT_TYPE,L"AUDCLNT_E_WRONG_ENDPOINT_TYPE")
+       (AUDCLNT_E_DEVICE_INVALIDATED,L"AUDCLNT_E_DEVICE_INVALIDATED")
+       (AUDCLNT_E_NOT_STOPPED,L"AUDCLNT_E_NOT_STOPPED")
+       (AUDCLNT_E_BUFFER_TOO_LARGE,L"AUDCLNT_E_BUFFER_TOO_LARGE")
+       (AUDCLNT_E_OUT_OF_ORDER,L"AUDCLNT_E_OUT_OF_ORDER")
+       (AUDCLNT_E_UNSUPPORTED_FORMAT,L"AUDCLNT_E_UNSUPPORTED_FORMAT")
+       (AUDCLNT_E_INVALID_SIZE,L"AUDCLNT_E_INVALID_SIZE")
+       (AUDCLNT_E_DEVICE_IN_USE,L"AUDCLNT_E_DEVICE_IN_USE")
+       (AUDCLNT_E_BUFFER_OPERATION_PENDING,L"AUDCLNT_E_BUFFER_OPERATION_PENDING")
+       (AUDCLNT_E_THREAD_NOT_REGISTERED,L"AUDCLNT_E_THREAD_NOT_REGISTERED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED,L"AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED")
+       (AUDCLNT_E_ENDPOINT_CREATE_FAILED,L"AUDCLNT_E_ENDPOINT_CREATE_FAILED")
+       (AUDCLNT_E_SERVICE_NOT_RUNNING,L"AUDCLNT_E_SERVICE_NOT_RUNNING")
+       (AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED,L"AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_ONLY,L"AUDCLNT_E_EXCLUSIVE_MODE_ONLY")
+       (AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL,L"AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL")
+       (AUDCLNT_E_EVENTHANDLE_NOT_SET,L"AUDCLNT_E_EVENTHANDLE_NOT_SET")
+       (AUDCLNT_E_INCORRECT_BUFFER_SIZE,L"AUDCLNT_E_INCORRECT_BUFFER_SIZE")
+  (AUDCLNT_E_CPUUSAGE_EXCEEDED,L"AUDCLNT_E_CPUUSAGE_EXCEEDED")
+  (AUDCLNT_E_BUFFER_ERROR,L"AUDCLNT_E_BUFFER_ERROR")
+  (AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED,L"AUDCLNT_E_BUFFER_SIZE_NOT_ALIGNED")
+  (AUDCLNT_E_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+  (AUDCLNT_E_INVALID_DEVICE_PERIOD,L"AUDCLNT_E_INVALID_DEVICE_PERIOD")
+       (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+       (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED")
+  (AUDCLNT_S_POSITION_STALLED,L"AUDCLNT_S_POSITION_STALLED")
+  (DXGI_ERROR_UNSUPPORTED,L"DXGI_ERROR_UNSUPPORTED ")
+  (DXGI_STATUS_OCCLUDED,L"DXGI_STATUS_OCCLUDED")
+  (DXGI_STATUS_CLIPPED,L"DXGI_STATUS_CLIPPED")
+  ;
+       
+
+win32_error_exception::win32_error_exception(uint32_t hr)
+: std::exception("HRESULT ERROR"),hresult_(hr)
+{
+       local_memory<wchar_t> mem;
+       DWORD 結果 = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,(LPWSTR)&mem,0,0);
+       if(結果 != 0){
+               error_ = mem.get();
+       } else {
+               std::map<HRESULT,std::wstring>::iterator it = com_error_.find(hr);
+               if(it != com_error_.end())
+               {
+                       error_ = it->second;
+               } else {
+                       error_ = (boost::wformat(L"0x%x 不明なCOMエラー") % hr).str();
+               }
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << error_ << std::endl; 
+#endif
+       }
+
+};
+
+win32_error_exception::win32_error_exception()
+{
+       hresult_ = ::GetLastError();
+       local_memory<wchar_t> mem;
+       DWORD rv =  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hresult_,0,(LPWSTR)&mem,0,0);
+       error_ = mem.get();
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << error_ << std::endl; 
+#endif
+
+  //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+std::wstring win32_error_exception::get_last_error_str(uint32_t err)
+{
+//     DWORD err = ::GetLastError();
+  std::wstring err_str;
+       local_memory<wchar_t> mem;
+       DWORD rv =  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,err,0,(LPWSTR)&mem,0,0);
+       err_str = mem.get();
+#ifdef _DEBUG
+  wdout << L"#### Exception Occured ####" << err_str << std::endl; 
+#endif
+  return err_str;
+}
+
+}
\ No newline at end of file
diff --git a/ShootingGame/exception.h b/ShootingGame/exception.h
new file mode 100644 (file)
index 0000000..6b76f38
--- /dev/null
@@ -0,0 +1,24 @@
+#pragma once
+
+namespace sf
+{
+       template <typename ExceptionTag> class ExceptionT :  public std::exception
+       {
+       public:
+               typedef ExceptionTag tag;
+               explicit ExceptionT(const std::wstring& reason)
+               {
+                       m_reason = reason;
+               };
+               const wchar_t * what() {return m_reason.c_str();};
+               const std::wstring& what_str() { return m_reason;};
+       protected:
+               std::wstring m_reason;
+       };
+
+       #define DefineException(x) struct x {}; typedef ExceptionT<x> x## Exception;
+
+       inline void ThrowIfErr(HRESULT hr) {if(hr != S_OK){throw Platform::Exception::CreateException(hr);}}
+
+}
+
diff --git a/ShootingGame/explosion.png b/ShootingGame/explosion.png
new file mode 100644 (file)
index 0000000..c6d686d
Binary files /dev/null and b/ShootingGame/explosion.png differ
index 89ef62e..7edb841 100644 (file)
 #include <stdio.h>
 #include <vector>
 #include <memory>
+
+#include <ppltasks.h>
+
+// Core Audio
+
+#include "avrt.h"
+#include "mmsystem.h"
+#include <mmdeviceapi.h>
+#include <AudioClient.h>
+#include <audiopolicy.h>
+#include "exception.h"
+
 #include "App.xaml.h"
diff --git a/ShootingGame/sf_memory.h b/ShootingGame/sf_memory.h
new file mode 100644 (file)
index 0000000..0078cfa
--- /dev/null
@@ -0,0 +1,124 @@
+#pragma once
+namespace sf {
+// policy class
+struct heap_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::HeapFree( ::GetProcessHeap(), 0, AMemory );
+}
+};
+// policy class
+struct local_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::LocalFree( AMemory );
+}
+};
+// policy class
+struct co_task_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::CoTaskMemFree( AMemory );
+}
+};
+// base guard class
+template< typename T,class TFreePolicy >
+class base_memory
+{
+private:
+T *FMemory;
+
+public:
+base_memory( T* AMemory = NULL )
+: FMemory( AMemory ) {}
+
+virtual ~base_memory( void )
+{ reset(); }
+
+T* release( void )
+{
+T *tmp = FMemory;
+FMemory = NULL;
+return tmp;
+}
+
+void reset( T* AMemory = NULL )
+{
+if( AMemory != FMemory )
+{
+if( NULL != FMemory )
+TFreePolicy( FMemory );
+
+FMemory = AMemory;
+}
+}
+
+T* get( void )
+{ return FMemory; }
+
+T* operator ->(void)
+{
+  return FMemory;
+}
+
+T** operator&( void )
+{ return &FMemory; }
+
+};
+template< typename T >
+class heap_memory : public base_memory< T, 
+heap_memory_free_policy >
+{
+public:
+heap_memory( T* AMemory = NULL )
+: base_memory< T, heap_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class local_memory : public base_memory< T, 
+local_memory_free_policy >
+{
+public:
+local_memory( T* AMemory = NULL )
+: base_memory< T, local_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class co_task_memory : public base_memory< T, co_task_memory_free_policy >
+{
+public:
+co_task_memory( T* AMemory = NULL )
+: base_memory< T, co_task_memory_free_policy >( AMemory )
+{ }
+};
+
+struct handle_deleter {
+  typedef HANDLE pointer;
+  void operator ()(HANDLE handle) {
+      if (handle != INVALID_HANDLE_VALUE) {
+          CloseHandle(handle);
+      }
+  }
+};
+
+typedef std::unique_ptr<HANDLE,handle_deleter> handle_holder;
+
+};
+
+template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+{
+if(ptr)
+{
+    ptr.Reset();
+}
+};
+
diff --git a/ShootingGame/test1.png b/ShootingGame/test1.png
new file mode 100644 (file)
index 0000000..2a7ef14
Binary files /dev/null and b/ShootingGame/test1.png differ