• R/O
  • HTTP
  • SSH
  • HTTPS

hengbandosx: Commit

The master and develop branches track hengband.

OS X development happens on the macos-1-6-2, macos-2-2-1, and macos-develop branches.


Commit MetaInfo

Revision1188a98071fd61303a5dae801724ee2237f54343 (tree)
Time2021-06-13 21:47:30
AuthorDeskull <61610939+sikabane-works@user...>
CommiterGitHub

Log Message

Merge pull request #1207 from sikabane-works/release/3.0.0Alpha27

Release/3.0.0 alpha27

Change Summary

Incremental Difference

--- a/Hengband/Hengband/Hengband.vcxproj
+++ b/Hengband/Hengband/Hengband.vcxproj
@@ -271,6 +271,7 @@
271271 <ClCompile Include="..\..\src\main-win\commandline-win.cpp" />
272272 <ClCompile Include="..\..\src\main-win\graphics-win.cpp" />
273273 <ClCompile Include="..\..\src\main-win\main-win-term.cpp" />
274+ <ClCompile Include="..\..\src\main-win\wav-reader.cpp" />
274275 <ClCompile Include="..\..\src\object-enchant\apply-magic-amulet.cpp" />
275276 <ClCompile Include="..\..\src\object-enchant\apply-magic-ring.cpp" />
276277 <ClCompile Include="..\..\src\object\object-index-list.cpp" />
@@ -949,6 +950,7 @@
949950 <ClInclude Include="..\..\src\main-win\commandline-win.h" />
950951 <ClInclude Include="..\..\src\main-win\graphics-win.h" />
951952 <ClInclude Include="..\..\src\main-win\main-win-term.h" />
953+ <ClInclude Include="..\..\src\main-win\wav-reader.h" />
952954 <ClInclude Include="..\..\src\object-enchant\apply-magic-amulet.h" />
953955 <ClInclude Include="..\..\src\object-enchant\apply-magic-ring.h" />
954956 <ClInclude Include="..\..\src\object\object-index-list.h" />
--- a/Hengband/Hengband/Hengband.vcxproj.filters
+++ b/Hengband/Hengband/Hengband.vcxproj.filters
@@ -2292,6 +2292,9 @@
22922292 <ClCompile Include="..\..\src\main-win\main-win-term.cpp">
22932293 <Filter>main-win</Filter>
22942294 </ClCompile>
2295+ <ClCompile Include="..\..\src\main-win\wav-reader.cpp">
2296+ <Filter>main-win</Filter>
2297+ </ClCompile>
22952298 </ItemGroup>
22962299 <ItemGroup>
22972300 <ClInclude Include="..\..\src\combat\shoot.h">
@@ -4929,6 +4932,9 @@
49294932 <ClInclude Include="..\..\src\main-win\main-win-term.h">
49304933 <Filter>main-win</Filter>
49314934 </ClInclude>
4935+ <ClInclude Include="..\..\src\main-win\wav-reader.h">
4936+ <Filter>main-win</Filter>
4937+ </ClInclude>
49324938 </ItemGroup>
49334939 <ItemGroup>
49344940 <None Include="..\..\src\wall.bmp" />
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -939,6 +939,7 @@ EXTRA_hengband_SOURCES = \
939939 main-win/main-win-term.cpp main-win/main-win-term.h \
940940 main-win/main-win-tokenizer.cpp main-win/main-win-tokenizer.h \
941941 main-win/main-win-utils.cpp main-win/main-win-utils.h \
942+ main-win/wav-reader.cpp main-win/wav-reader.h \
942943 wall.bmp \
943944 stdafx.cpp stdafx.h
944945
--- a/src/info-reader/dungeon-reader.cpp
+++ b/src/info-reader/dungeon-reader.cpp
@@ -146,8 +146,8 @@ errr parse_d_info(std::string_view buf, angband_header *head)
146146 info_set_value(d_ptr->max_m_alloc_chance, tokens[6]);
147147 info_set_value(d_ptr->obj_good, tokens[7]);
148148 info_set_value(d_ptr->obj_great, tokens[8]);
149- info_set_value(d_ptr->pit, tokens[9]);
150- info_set_value(d_ptr->nest, tokens[10]);
149+ info_set_value(d_ptr->pit, tokens[9], 16);
150+ info_set_value(d_ptr->nest, tokens[10], 16);
151151 } else if (tokens[0] == "P") {
152152 // P:wild_y:wild_x
153153 if (tokens.size() < 3)
--- a/src/main-win.cpp
+++ b/src/main-win.cpp
@@ -2497,6 +2497,7 @@ static void hook_quit(concptr str)
24972497 DeleteObject(hbrYellow);
24982498 finalize_bg();
24992499 graphic.finalize();
2500+ finalize_sound();
25002501
25012502 UnregisterClassW(AppName, hInstance);
25022503 if (hIcon)
--- a/src/main-win/main-win-sound.cpp
+++ b/src/main-win/main-win-sound.cpp
@@ -7,12 +7,16 @@
77 #include "main-win/main-win-cfg-reader.h"
88 #include "main-win/main-win-define.h"
99 #include "main-win/main-win-file-utils.h"
10-#include "main-win/main-win-mmsystem.h"
1110 #include "main-win/main-win-utils.h"
11+#include "main-win/wav-reader.h"
1212 #include "util/angband-files.h"
1313
1414 #include "main/sound-definitions-table.h"
1515
16+#include <memory>
17+
18+#include <mmsystem.h>
19+
1620 /*
1721 * Directory name
1822 */
@@ -24,6 +28,103 @@ concptr ANGBAND_DIR_XTRA_SOUND;
2428 CfgData *sound_cfg_data;
2529
2630 /*!
31+ * 効果音データ
32+ */
33+struct sound_res {
34+ sound_res(BYTE* _buf)
35+ {
36+ buf.reset(_buf);
37+ }
38+ ~sound_res()
39+ {
40+ dispose();
41+ }
42+
43+ HWAVEOUT hwo = NULL;
44+ /*!
45+ * PCMデータバッファ
46+ */
47+ std::unique_ptr<BYTE[]> buf;
48+ WAVEHDR wh = { 0 };
49+
50+ void dispose()
51+ {
52+ if (hwo != NULL) {
53+ ::waveOutReset(hwo);
54+ ::waveOutUnprepareHeader(hwo, &wh, sizeof(WAVEHDR));
55+ ::waveOutClose(hwo);
56+ hwo = NULL;
57+ wh.lpData = nullptr;
58+ }
59+ }
60+};
61+/*!
62+ * 効果音リソースの管理キュー
63+ */
64+std::queue<sound_res *> sound_queue;
65+
66+/*!
67+ * 効果音の再生と管理キューへの追加.
68+ *
69+ * @param wf WAVEFORMATEXへのポインタ
70+ * @param buf PCMデータバッファ
71+ * @param bufsize バッファサイズ
72+ * @retval true 正常に処理された
73+ * @retval false 処理エラー
74+ */
75+static bool add_sound_queue(const WAVEFORMATEX *wf, BYTE *buf, DWORD bufsize)
76+{
77+ while (!sound_queue.empty()) {
78+ auto res = sound_queue.front();
79+ if (res->hwo == NULL || (res->wh.dwFlags & WHDR_DONE)) {
80+ delete res;
81+ sound_queue.pop();
82+ continue;
83+ }
84+ break;
85+ }
86+
87+ auto res = new sound_res(buf);
88+ sound_queue.push(res);
89+
90+ MMRESULT mr = ::waveOutOpen(&res->hwo, WAVE_MAPPER, wf, NULL, NULL, CALLBACK_NULL);
91+ if (mr != MMSYSERR_NOERROR) {
92+ return false;
93+ }
94+
95+ WAVEHDR *wh = &res->wh;
96+ wh->lpData = (LPSTR)buf;
97+ wh->dwBufferLength = bufsize;
98+ wh->dwFlags = 0;
99+
100+ ::waveOutPrepareHeader(res->hwo, wh, sizeof(WAVEHDR));
101+ ::waveOutWrite(res->hwo, wh, sizeof(WAVEHDR));
102+
103+ return true;
104+}
105+
106+/*!
107+ * 指定ファイルを再生する
108+ *
109+ * @param buf ファイル名
110+ * @retval true 正常に処理された
111+ * @retval false 処理エラー
112+ */
113+static bool play_sound_impl(char *filename)
114+{
115+ wav_reader reader;
116+ if (!reader.open(filename))
117+ return false;
118+ auto wf = reader.get_waveformat();
119+
120+ auto data_buffer = reader.read_data();
121+ if (data_buffer == nullptr)
122+ return false;
123+
124+ return add_sound_queue(wf, data_buffer, reader.get_data_chunk()->cksize);
125+}
126+
127+/*!
27128 * @brief action-valに対応する[Sound]セクションのキー名を取得する
28129 * @param index "term_xtra()"の第2引数action-valに対応する値
29130 * @param buf 使用しない
@@ -52,6 +153,18 @@ void load_sound_prefs(void)
52153 }
53154
54155 /*!
156+ * @brief 効果音の終了処理
157+ */
158+void finalize_sound(void)
159+{
160+ while (!sound_queue.empty()) {
161+ auto res = sound_queue.front();
162+ delete res;
163+ sound_queue.pop();
164+ }
165+}
166+
167+/*!
55168 * @brief 指定の効果音を鳴らす。
56169 * @param val see sound_type
57170 * @retval 0 正常終了
@@ -68,8 +181,9 @@ errr play_sound(int val)
68181 char buf[MAIN_WIN_MAX_PATH];
69182 path_build(buf, MAIN_WIN_MAX_PATH, ANGBAND_DIR_XTRA_SOUND, filename);
70183
71- if (::PlaySoundW(to_wchar(buf).wc_str(), 0, SND_FILENAME | SND_ASYNC)) {
184+ if (play_sound_impl(buf)) {
72185 return 0;
73186 }
187+
74188 return -1;
75189 }
--- a/src/main-win/main-win-sound.h
+++ b/src/main-win/main-win-sound.h
@@ -7,4 +7,5 @@ extern concptr ANGBAND_DIR_XTRA_SOUND;
77 extern CfgData *sound_cfg_data;
88
99 void load_sound_prefs(void);
10+void finalize_sound(void);
1011 errr play_sound(int val);
--- a/src/main-win/main-win-utils.h
+++ b/src/main-win/main-win-utils.h
@@ -50,7 +50,7 @@ protected:
5050
5151 void kill()
5252 {
53- if (!buf) {
53+ if (buf) {
5454 C_KILL(buf, buf_size, WCHAR);
5555 buf = NULL;
5656 }
@@ -100,7 +100,7 @@ protected:
100100
101101 void kill()
102102 {
103- if (!buf) {
103+ if (buf) {
104104 C_KILL(buf, buf_size, char);
105105 buf = NULL;
106106 }
--- /dev/null
+++ b/src/main-win/wav-reader.cpp
@@ -0,0 +1,69 @@
1+/*!
2+ * @file wav-reader.cpp
3+ * @brief Windows版固有実装(WAVファイル読込)
4+ */
5+
6+#include "main-win/wav-reader.h"
7+#include "main-win/main-win-utils.h"
8+
9+bool wav_reader::open(char *filename)
10+{
11+ close();
12+
13+ this->hmmio = ::mmioOpenW(to_wchar(filename).wc_str(), NULL, MMIO_READ);
14+ if (this->hmmio == NULL)
15+ return false;
16+
17+ MMRESULT mmresult;
18+ LONG read_size;
19+ LONG readed_size;
20+
21+ this->riff_chunk.fccType = mmioFOURCC('W', 'A', 'V', 'E');
22+ mmresult = ::mmioDescend(this->hmmio, &this->riff_chunk, NULL, MMIO_FINDRIFF);
23+ if (mmresult != MMSYSERR_NOERROR)
24+ return false;
25+
26+ this->fmt_chunk.ckid = mmioFOURCC('f', 'm', 't', ' ');
27+ mmresult = ::mmioDescend(this->hmmio, &this->fmt_chunk, &this->riff_chunk, MMIO_FINDCHUNK);
28+ if (mmresult != MMSYSERR_NOERROR)
29+ return false;
30+
31+ if (this->fmt_chunk.cksize > sizeof(this->waveformatex))
32+ return false;
33+ read_size = this->fmt_chunk.cksize;
34+ readed_size = ::mmioRead(this->hmmio, (HPSTR) & this->waveformatex, read_size);
35+ if (readed_size != read_size)
36+ return false;
37+ if (this->waveformatex.wFormatTag != WAVE_FORMAT_PCM)
38+ return false;
39+ mmresult = ::mmioAscend(this->hmmio, &this->fmt_chunk, 0);
40+ if (mmresult != MMSYSERR_NOERROR)
41+ return false;
42+
43+ this->data_chunk.ckid = mmioFOURCC('d', 'a', 't', 'a');
44+ mmresult = ::mmioDescend(this->hmmio, &this->data_chunk, &riff_chunk, MMIO_FINDCHUNK);
45+ if (mmresult != MMSYSERR_NOERROR)
46+ return false;
47+
48+ this->buffer.reset(new BYTE[data_chunk.cksize]);
49+ read_size = this->data_chunk.cksize;
50+ readed_size = ::mmioRead(this->hmmio, (HPSTR)this->buffer.get(), read_size);
51+ if (readed_size != read_size) {
52+ return false;
53+ }
54+
55+ return true;
56+}
57+
58+BYTE *wav_reader::read_data()
59+{
60+ return this->buffer.release();
61+}
62+
63+void wav_reader::close()
64+{
65+ if (this->hmmio != NULL) {
66+ ::mmioClose(this->hmmio, 0);
67+ this->hmmio = NULL;
68+ }
69+}
--- /dev/null
+++ b/src/main-win/wav-reader.h
@@ -0,0 +1,57 @@
1+#pragma once
2+/*!
3+ * @file wav-reader.h
4+ * @brief Windows版固有実装(WAVファイル読込)ヘッダ
5+ */
6+
7+#include <memory>
8+
9+#include <windows.h>
10+#include <mmsystem.h>
11+
12+/*!
13+ * WAVファイルの読み込み
14+ */
15+class wav_reader {
16+public:
17+ wav_reader()
18+ : hmmio(NULL)
19+ {
20+ }
21+ ~wav_reader()
22+ {
23+ close();
24+ }
25+
26+ /*!
27+ * WAVファイルを開く
28+ *
29+ * @param filename
30+ * @retval true 正常に処理された
31+ * @retval false 処理エラー
32+ */
33+ bool open(char *filename);
34+ /*!
35+ * PCMデータ取得
36+ * @details 呼び出し元でdelete[]すること
37+ * @return PCMデータ
38+ */
39+ BYTE* read_data();
40+ const WAVEFORMATEX *get_waveformat()
41+ {
42+ return &waveformatex;
43+ }
44+ const MMCKINFO *get_data_chunk()
45+ {
46+ return &data_chunk;
47+ }
48+ void close();
49+
50+protected:
51+ HMMIO hmmio;
52+ MMCKINFO riff_chunk{};
53+ MMCKINFO fmt_chunk{};
54+ WAVEFORMATEX waveformatex{};
55+ MMCKINFO data_chunk{};
56+ std::unique_ptr<BYTE[]> buffer;
57+};
--- a/src/system/angband-version.h
+++ b/src/system/angband-version.h
@@ -17,7 +17,7 @@
1717 #define H_VER_MAJOR 3 //!< ゲームのバージョン定義(メジャー番号)
1818 #define H_VER_MINOR 0 //!< ゲームのバージョン定義(マイナー番号)
1919 #define H_VER_PATCH 0 //!< ゲームのバージョン定義(パッチ番号)
20-#define H_VER_EXTRA 26 //!< ゲームのバージョン定義(エクストラ番号)
20+#define H_VER_EXTRA 27 //!< ゲームのバージョン定義(エクストラ番号)
2121
2222 /*!
2323 * @brief セーブファイルのバージョン(3.0.0から導入)
Show on old repository browser