Skip to content

Commit

Permalink
Merge branch 'develop' into macos-develop
Browse files Browse the repository at this point in the history
  • Loading branch information
backwardsEric committed Aug 1, 2024
2 parents 5edda25 + fe3bcfc commit fa25839
Show file tree
Hide file tree
Showing 23 changed files with 136 additions and 158 deletions.
4 changes: 2 additions & 2 deletions lib/edit/ArtifactDefinitions.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6072,7 +6072,7 @@
],
"flavor": {
"ja": "後に王となる湖の街の陰気面バルドが龍を射抜いた伝説の黒い矢だ。彼が龍を射抜いたこの矢は歌に唄われ語り継がれている。",
"en": "Dealiest of arrows, imbued with elemental strength, this shaft is feared especially by the wyrmkin."
"en": "Deadliest of arrows, imbued with elemental strength, this shaft is feared especially by the wyrmkin."
}
},
//# The Blade of Chaos 'Soulcrusher'
Expand Down Expand Up @@ -10130,4 +10130,4 @@
}
}
]
}
}
2 changes: 1 addition & 1 deletion src/core/game-play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static void init_riding_pet(PlayerType *player_ptr, bool new_game)

MonsterRaceId pet_r_idx = pc.equals(PlayerClassType::CAVALRY) ? MonsterRaceId::HORSE : MonsterRaceId::YASE_HORSE;
auto *r_ptr = &monraces_info[pet_r_idx];
auto m_idx = place_specific_monster(player_ptr, 0, player_ptr->y, player_ptr->x - 1, pet_r_idx, (PM_FORCE_PET | PM_NO_KAGE));
auto m_idx = place_specific_monster(player_ptr, player_ptr->y, player_ptr->x - 1, pet_r_idx, (PM_FORCE_PET | PM_NO_KAGE));
auto *m_ptr = &player_ptr->current_floor_ptr->m_list[*m_idx];
m_ptr->mspeed = r_ptr->speed;
m_ptr->maxhp = r_ptr->hit_dice.floored_expected_value();
Expand Down
2 changes: 1 addition & 1 deletion src/core/player-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static void process_fishing(PlayerType *player_ptr)
msg_print(nullptr);
if (MonraceList::is_valid(r_idx) && one_in_(2)) {
const auto pos = player_ptr->get_neighbor(player_ptr->fishing_dir);
if (auto m_idx = place_specific_monster(player_ptr, 0, pos.y, pos.x, r_idx, PM_NO_KAGE)) {
if (auto m_idx = place_specific_monster(player_ptr, pos.y, pos.x, r_idx, PM_NO_KAGE)) {
const auto m_name = monster_desc(player_ptr, &floor_ptr->m_list[*m_idx], 0);
msg_print(_(format("%sが釣れた!", m_name.data()), "You have a good catch!"));
success = true;
Expand Down
2 changes: 1 addition & 1 deletion src/dungeon/quest-monster-placer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool place_quest_monsters(PlayerType *player_ptr)
return false;
}

if (place_specific_monster(player_ptr, 0, pos.y, pos.x, quest.r_idx, mode)) {
if (place_specific_monster(player_ptr, pos.y, pos.x, quest.r_idx, mode)) {
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/floor/fixed-map-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ static void parse_qtw_D(PlayerType *player_ptr, qtwg_type *qtwg_ptr, char *s)
}
}

const auto m_idx = place_specific_monster(player_ptr, 0, *qtwg_ptr->y, *qtwg_ptr->x, r_idx, (PM_ALLOW_SLEEP | PM_NO_KAGE));
const auto m_idx = place_specific_monster(player_ptr, *qtwg_ptr->y, *qtwg_ptr->x, r_idx, (PM_ALLOW_SLEEP | PM_NO_KAGE));
if (clone && m_idx) {
floor_ptr->m_list[*m_idx].mflag2.set(MonsterConstantFlagType::CLONED);
r_ref.cur_num = old_cur_num;
Expand Down
4 changes: 2 additions & 2 deletions src/floor/floor-generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static void generate_challenge_arena(PlayerType *player_ptr)
player_place(player_ptr, y, x);
auto &entries = ArenaEntryList::get_instance();
const auto &monrace = entries.get_monrace();
if (place_specific_monster(player_ptr, 0, player_ptr->y + 5, player_ptr->x, monrace.idx, PM_NO_KAGE | PM_NO_PET)) {
if (place_specific_monster(player_ptr, player_ptr->y + 5, player_ptr->x, monrace.idx, PM_NO_KAGE | PM_NO_PET)) {
return;
}

Expand Down Expand Up @@ -240,7 +240,7 @@ static void generate_gambling_arena(PlayerType *player_ptr)
build_battle(player_ptr, &y, &x);
player_place(player_ptr, y, x);
for (MONSTER_IDX i = 0; i < 4; i++) {
const auto m_idx = place_specific_monster(player_ptr, 0, player_ptr->y + 8 + (i / 2) * 4, player_ptr->x - 2 + (i % 2) * 4, battle_mon_list[i], (PM_NO_KAGE | PM_NO_PET));
const auto m_idx = place_specific_monster(player_ptr, player_ptr->y + 8 + (i / 2) * 4, player_ptr->x - 2 + (i % 2) * 4, battle_mon_list[i], (PM_NO_KAGE | PM_NO_PET));
if (m_idx) {
floor_ptr->m_list[*m_idx].set_friendly();
}
Expand Down
1 change: 1 addition & 0 deletions src/game-option/disturbance-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bool flush_failure; /* Flush input on various failures */
bool flush_disturb; /* Flush input whenever disturbed */
bool disturb_move; /* Disturb whenever any monster moves */
bool disturb_high; /* Disturb whenever high-level monster moves */
bool disturb_unknown; /* Disturb whenever unknown-level monster moves */
bool disturb_near; /* Disturb whenever viewable monster moves */
bool disturb_pets; /* Disturb when visible pets move */
bool disturb_panel; /* Disturb whenever map panel changes */
Expand Down
1 change: 1 addition & 0 deletions src/game-option/disturbance-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern bool flush_failure; /* Flush input on various failures */
extern bool flush_disturb; /* Flush input whenever disturbed */
extern bool disturb_move; /* Disturb whenever any monster moves */
extern bool disturb_high; /* Disturb whenever high-level monster moves */
extern bool disturb_unknown; /* Disturb whenever unknown-level monster moves */
extern bool disturb_near; /* Disturb whenever viewable monster moves */
extern bool disturb_pets; /* Disturb when visible pets move */
extern bool disturb_panel; /* Disturb whenever map panel changes */
Expand Down
5 changes: 4 additions & 1 deletion src/game-option/option-types-table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ const std::vector<option_type> option_info = {

{ &disturb_move, false, OPT_PAGE_DISTURBANCE, 0, 20, "disturb_move", _("どこのモンスターが動いても行動を中止する", "Disturb whenever any monster moves") },

{ &disturb_high, false, OPT_PAGE_DISTURBANCE, 1, 3, "disturb_high",
{ &disturb_high, true, OPT_PAGE_DISTURBANCE, 1, 3, "disturb_high",
_("レベルの高いモンスターが動いたら行動を中止する", "Disturb whenever high-level monster moves") },

{ &disturb_unknown, true, OPT_PAGE_DISTURBANCE, 0, 26, "disturb_unknown",
_("レベル不明のモンスターが動いたら行動を中止する", "Disturb whenever unknown-level monster moves") },

{ &disturb_near, true, OPT_PAGE_DISTURBANCE, 0, 21, "disturb_near",
_("視界内のモンスターが動いたら行動を中止する", "Disturb whenever viewable monster moves") },

Expand Down
109 changes: 43 additions & 66 deletions src/main-win/main-win-sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <memory>
#include <mmsystem.h>
#include <queue>
#include <span>

/*
* Directory name
Expand All @@ -30,24 +31,33 @@ std::optional<CfgData> sound_cfg_data;
* 効果音データ
*/
struct sound_res {
sound_res(BYTE *_buf)
sound_res(std::vector<uint8_t> &&_buf)
: buf(std::move(_buf))
{
buf.reset(_buf);
this->wh.lpData = reinterpret_cast<LPSTR>(this->buf.data());
this->wh.dwBufferLength = this->buf.size();
this->wh.dwFlags = 0;
}
sound_res(const sound_res &) = delete;
sound_res &operator=(const sound_res &) = delete;

~sound_res()
{
dispose();
if (this->hwo == nullptr) {
return;
}

::waveOutReset(this->hwo);
::waveOutUnprepareHeader(this->hwo, &this->wh, sizeof(WAVEHDR));
::waveOutClose(this->hwo);
}

HWAVEOUT hwo = NULL;
/*!
* PCMデータバッファ
*/
std::unique_ptr<BYTE[]> buf;
WAVEHDR wh = { 0 };
std::vector<uint8_t> buf;
WAVEHDR wh{};

/*!
* 再生完了判定
Expand All @@ -58,22 +68,12 @@ struct sound_res {
{
return (this->hwo == NULL) || (this->wh.dwFlags & WHDR_DONE);
}

void dispose()
{
if (hwo != NULL) {
::waveOutReset(hwo);
::waveOutUnprepareHeader(hwo, &wh, sizeof(WAVEHDR));
::waveOutClose(hwo);
hwo = NULL;
wh.lpData = NULL;
}
}
};

/*!
* 効果音リソースの管理キュー
*/
std::queue<sound_res *> sound_queue;
std::queue<std::unique_ptr<sound_res>> sound_queue;

/*!
* @brief PCMデータの振幅を変調する
Expand All @@ -84,12 +84,11 @@ std::queue<sound_res *> sound_queue;
* サンプリングビット数で有効なのは 8 か 16 のみであり、それ以外の値が指定された場合はなにも行わない。
*
* @param bits_per_sample PCMデータのサンプリングビット数 (8 or 16)
* @param pcm_buf PCMデータバッファ領域へのポインタ
* @param bufsize PCMデータバッファ領域のサイズ
* @param pcm_buf PCMデータ
* @param mult 振幅変調倍率 mult/div の mult
* @param div 振幅変調倍率 mult/div の div
*/
static void modulate_amplitude(int bits_per_sample, BYTE *pcm_buf, size_t bufsize, int mult, int div)
static void modulate_amplitude(int bits_per_sample, std::span<uint8_t> pcm_buf, int mult, int div)
{
auto modulate = [mult, div](auto sample, int standard = 0) {
using sample_t = decltype(sample);
Expand All @@ -102,17 +101,17 @@ static void modulate_amplitude(int bits_per_sample, BYTE *pcm_buf, size_t bufsiz

switch (bits_per_sample) {
case 8:
for (auto i = 0U; i < bufsize; ++i) {
pcm_buf[i] = modulate(pcm_buf[i], 128);
for (auto &sample : pcm_buf) {
sample = modulate(sample, 128);
}
break;

case 16:
for (auto i = 0U; i < bufsize; i += 2) {
const auto sample = static_cast<int16_t>((static_cast<uint16_t>(pcm_buf[i + 1]) << 8) | static_cast<uint16_t>(pcm_buf[i]));
const auto modulated_sample = modulate(sample);
pcm_buf[i + 1] = static_cast<uint16_t>(modulated_sample) >> 8;
pcm_buf[i] = static_cast<uint16_t>(modulated_sample) & 0xFF;
for (auto i = 0; i < std::ssize(pcm_buf) - 1; i += 2) {
const auto sample = static_cast<int16_t>(pcm_buf[i] | (pcm_buf[i + 1] << 8));
const auto modulated_sample = static_cast<uint16_t>(modulate(sample));
pcm_buf[i + 1] = modulated_sample >> 8;
pcm_buf[i] = modulated_sample & 0xff;
}
break;

Expand All @@ -125,54 +124,40 @@ static void modulate_amplitude(int bits_per_sample, BYTE *pcm_buf, size_t bufsiz
* 効果音の再生と管理キューへの追加.
*
* @param wf WAVEFORMATEXへのポインタ
* @param buf PCMデータバッファ。使用後にdelete[]すること。
* @param bufsize バッファサイズ
* @param buf PCMデータバッファ
* @retval true 正常に処理された
* @retval false 処理エラー
*/
static bool add_sound_queue(const WAVEFORMATEX *wf, BYTE *buf, DWORD bufsize, int volume)
static bool add_sound_queue(const WAVEFORMATEX *wf, std::vector<uint8_t> &&buf, int volume)
{
if (buf.empty()) {
return false;
}

// 再生完了データをキューから削除する
while (!sound_queue.empty()) {
auto res = sound_queue.front();
if (res->isDone()) {
delete res;
sound_queue.pop();
continue;
if (!sound_queue.front()->isDone()) {
break;
}
break;
sound_queue.pop();
}

auto res = new sound_res(buf);
sound_queue.push(res);
modulate_amplitude(wf->wBitsPerSample, buf, volume, SOUND_VOLUME_MAX);

auto res = std::make_unique<sound_res>(std::move(buf));

MMRESULT mr = ::waveOutOpen(&res->hwo, WAVE_MAPPER, wf, NULL, NULL, CALLBACK_NULL);
if (mr != MMSYSERR_NOERROR) {
if (auto mr = ::waveOutOpen(&res->hwo, WAVE_MAPPER, wf, NULL, NULL, CALLBACK_NULL); mr != MMSYSERR_NOERROR) {
return false;
}

modulate_amplitude(wf->wBitsPerSample, buf, bufsize, volume, SOUND_VOLUME_MAX);

WAVEHDR *wh = &res->wh;
wh->lpData = (LPSTR)buf;
wh->dwBufferLength = bufsize;
wh->dwFlags = 0;

mr = ::waveOutPrepareHeader(res->hwo, wh, sizeof(WAVEHDR));
if (mr != MMSYSERR_NOERROR) {
res->dispose();
if (auto mr = ::waveOutPrepareHeader(res->hwo, &res->wh, sizeof(WAVEHDR)); mr != MMSYSERR_NOERROR) {
return false;
}

mr = ::waveOutWrite(res->hwo, wh, sizeof(WAVEHDR));
if (mr != MMSYSERR_NOERROR) {
res->dispose();
if (auto mr = ::waveOutWrite(res->hwo, &res->wh, sizeof(WAVEHDR)); mr != MMSYSERR_NOERROR) {
return false;
}

sound_queue.push(std::move(res));
while (sound_queue.size() >= 16) {
auto over = sound_queue.front();
delete over;
sound_queue.pop();
}

Expand All @@ -192,14 +177,8 @@ static bool play_sound_impl(const std::filesystem::path &path, int volume)
if (!reader.open(path)) {
return false;
}
auto wf = reader.get_waveformat();

auto data_buffer = reader.read_data();
if (data_buffer == NULL) {
return false;
}

return add_sound_queue(wf, data_buffer, reader.get_data_chunk()->cksize, volume);
return add_sound_queue(reader.get_waveformat(), reader.retrieve_data(), volume);
}

/*!
Expand Down Expand Up @@ -237,8 +216,6 @@ void load_sound_prefs(void)
void finalize_sound(void)
{
while (!sound_queue.empty()) {
auto res = sound_queue.front();
delete res;
sound_queue.pop();
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/main-win/wav-reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,24 @@ bool wav_reader::open(const std::filesystem::path &path)
return false;
}

this->buffer.reset(new BYTE[data_chunk.cksize]);
this->buffer.resize(data_chunk.cksize);
read_size = this->data_chunk.cksize;
readed_size = ::mmioRead(this->hmmio, (HPSTR)this->buffer.get(), read_size);
readed_size = ::mmioRead(this->hmmio, reinterpret_cast<HPSTR>(this->buffer.data()), read_size);
if (readed_size != read_size) {
return false;
}

return true;
}

BYTE *wav_reader::read_data()
std::vector<uint8_t> wav_reader::retrieve_data()
{
return this->buffer.release();
return std::move(this->buffer);
}

void wav_reader::close()
{
this->buffer.clear();
if (this->hmmio != NULL) {
::mmioClose(this->hmmio, 0);
this->hmmio = NULL;
Expand Down
14 changes: 6 additions & 8 deletions src/main-win/wav-reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ class wav_reader {
* @retval false 処理エラー
*/
bool open(const std::filesystem::path &path);

/*!
* PCMデータ取得
* @details 呼び出し元でdelete[]すること
*
* @return PCMデータ
*/
BYTE *read_data();
const WAVEFORMATEX *get_waveformat()
std::vector<uint8_t> retrieve_data();

const WAVEFORMATEX *get_waveformat() const
{
return &waveformatex;
}
const MMCKINFO *get_data_chunk()
{
return &data_chunk;
}
void close();

protected:
Expand All @@ -57,5 +55,5 @@ class wav_reader {
MMCKINFO fmt_chunk{};
WAVEFORMATEX waveformatex{};
MMCKINFO data_chunk{};
std::unique_ptr<BYTE[]> buffer;
std::vector<uint8_t> buffer;
};
Loading

0 comments on commit fa25839

Please sign in to comment.