Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

player_type から時限ステータスを分離した (朦朧のみ) #1548

Merged
merged 15 commits into from Sep 18, 2021

Conversation

Hourier
Copy link
Member

@Hourier Hourier commented Sep 18, 2021

#553 の前段対応で、#1498 の設計変更を実施しました
ご確認下さい

  • TimedEffectsは、今後paralyzed やconfused 等、各種時限効果を移していく予定です。それによりplayer_type を軽くすることを意図します
  • 朦朧の蓄積に関する仕様は現行のままです。おかしい点があればご連絡下さい
  • 本当はフィールド変数はunique_ptr にした方がいいのかもしれませんが、player_type でそこまでやると影響が大きすぎるのと、各種演算子オーバーライドが面倒だったのでスルーしました
  • ある意味一番面倒なset_stun() について、このブランチで弄るのは差分が増えすぎるので丁重に放置中です

@Hourier Hourier added the refactor 処理の整理、可読性の向上 label Sep 18, 2021
@Hourier Hourier added this to the 3.0.0Alpha38Release milestone Sep 18, 2021
@Hourier Hourier self-assigned this Sep 18, 2021
@Hourier Hourier added this to In Progress in C++移行 via automation Sep 18, 2021
@Hourier Hourier force-pushed the feature/Create-TimedEffects-Class branch from 4e473b2 to 9ddef9e Compare September 18, 2021 08:42
@@ -10,6 +10,7 @@
#include "player/player-sex.h"
#include "system/angband.h"
#include "system/system-variables.h"
#include "timed-effect/timed-effects.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここまでヘッダ同士の依存を減らす方向で来ているので、ここでのインクルードは無くして実装ファイルのコンストラクタで timed_efffect を初期化するようにしたほうがいいのではないでしょうか。
TimeEffects を使用する実装ファイルすべてでインクルードが必要になりますが依存を減らしていく方針ではしかたないかと思います。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

作業途中の名残でした (下記とも絡む)
削除し、実装ファイル側でインクルードしていきます

std::shared_ptr<TimedEffects> effects() const;

private:
std::shared_ptr<TimedEffects> timed_effects = std::shared_ptr<TimedEffects>(new TimedEffects());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::shared_ptr の初期化は特に理由が無い限り、以下の点で std::make_shared を使用したほうがいいです。

  • 同じ型を何度も書く必要がない
  • クラス本体とコントロールブロックのメモリ領域の確保がまとめて行われるので効率的

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実装途中はmake_shared() だと実行時エラーでソフトが落ちていました (この形式だと何故かOKだった)が、設計が完成した現在は大丈夫なようです
問題ないようなのでmake_shared() の方に切り替えます

@@ -19,8 +20,9 @@ enum class RF_ABILITY;

struct floor_type;
struct object_type;
;
typedef struct player_type {
class TimedEffects;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上述したようにヘッダの依存を減らすのであれば前方宣言が必要ですが、"timed-effects.h"をplayer-type-definition.hからインクルードする方針なのであれば必要ありません。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前方宣言を残す方針にします

#include <string>
#include <tuple>

enum class StunRank {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

モンスターにも朦朧状態はあるので、PlayerStunRankにしたほうが良いです。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Playerを付けます

short current() const;
StunRank get_rank() const;
StunRank get_rank(short value) const;
std::string_view get_stun_mes(StunRank stun_rank) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引数付きの get_rank() と、get_stun_mes はインスタンス変数に依存しないので、static メンバ関数にしたほうがいいです。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

staticにします

StunRank get_rank(short value) const;
std::string_view get_stun_mes(StunRank stun_rank) const;
int decrease_chance() const;
short decrease_damage() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decrese は他動詞として使うのが一般的なので、意味が通じにくいかもしれません。(名詞として使うにしても、chance_decreseのように単語の順序を逆にするのが適切のように感じます)
get_chance_penalty のような名前にしたらどうでしょうか。

@@ -0,0 +1,16 @@
#pragma once

#include "timed-effect/player-stun.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

player-type-definition.h でのコメントと同様、ヘッダファイルの依存を減らすならここでインクルードするのはやめたほうがよいと思います。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここも設計途中にコンパイルエラーが出ていたのみの部分です
削除します

@Hourier Hourier force-pushed the feature/Create-TimedEffects-Class branch from 9ddef9e to de79b7d Compare September 18, 2021 12:07
@Hourier
Copy link
Member Author

Hourier commented Sep 18, 2021

頂いた指摘を修正し、更に言語が正しく選択されない場合がある事象を解決させました
ご確認下さい

Copy link
Member

@habu1010 habu1010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1点だけコメントしました。


player_type::player_type()
{
this->timed_effects = std::make_shared<TimedEffects>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

細かいところですが、メンバ初期化子で初期化できるときはそうしたほうがよいので、

player_type::player_type()
    : timed_effects(std::make_shared<TimedEffects>())
{
}

としたほうが良いでしょう。(TimedEffects クラスも同様)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

スマートポインタを初期化子リストで初期化する方法が分からなかったので放置してました
ぜひ採用します!

@Hourier Hourier force-pushed the feature/Create-TimedEffects-Class branch from de79b7d to 130d537 Compare September 18, 2021 13:10
@Hourier
Copy link
Member Author

Hourier commented Sep 18, 2021

コメントを反映させてforce pushしました
ご確認下さい

Copy link
Member

@habu1010 habu1010 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対応おつかれさまです。修正を確認しました。
朦朧の動作自体は大丈夫そうなので、Approveします。

@Hourier Hourier merged commit ccee6c1 into hengband:develop Sep 18, 2021
C++移行 automation moved this from In Progress to Done Sep 18, 2021
@Hourier Hourier deleted the feature/Create-TimedEffects-Class branch September 18, 2021 13:24
@Hourier
Copy link
Member Author

Hourier commented Sep 18, 2021

レビュー・動作確認ありがとうございました!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor 処理の整理、可読性の向上
Development

Successfully merging this pull request may close these issues.

朦朧効果のリニューアル準備 (TimedEffects/PlayerStunクラスの定義)
2 participants