Skip to content

Commit a690806

Browse files
committed
Cleanups
1 parent d08748a commit a690806

2 files changed

Lines changed: 22 additions & 31 deletions

File tree

src/gui/efglayout.cc

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ using namespace Gambit;
3737
// class gbtNodeEntry: Member functions
3838
//-----------------------------------------------------------------------
3939

40-
gbtNodeEntry::gbtNodeEntry(GameNode p_node)
40+
gbtNodeEntry::gbtNodeEntry(const GameNode &p_node)
4141
: m_node(p_node), m_parent(nullptr), m_x(-1), m_y(-1), m_nextMember(nullptr), m_inSupport(true),
4242
m_size(20), m_token(GBT_NODE_TOKEN_CIRCLE), m_branchStyle(GBT_BRANCH_STYLE_LINE),
4343
m_branchLabel(GBT_BRANCH_LABEL_HORIZONTAL), m_branchLength(0), m_sublevel(0), m_actionProb(0)
@@ -58,7 +58,7 @@ int gbtNodeEntry::GetChildNumber() const
5858
// Draws the node token itself, as well as the incoming branch
5959
// (if not the root node)
6060
//
61-
void gbtNodeEntry::Draw(wxDC &p_dc, GameNode p_selection, bool p_noHints) const
61+
void gbtNodeEntry::Draw(wxDC &p_dc, const GameNode &p_selection, bool p_noHints) const
6262
{
6363
if (m_node->GetParent() && m_inSupport) {
6464
DrawIncomingBranch(p_dc);
@@ -128,8 +128,8 @@ void gbtNodeEntry::DrawIncomingBranch(wxDC &p_dc) const
128128
// Draw in the highlight indicating action probabilities
129129
if (m_actionProb >= Rational(0)) {
130130
p_dc.SetPen(*wxThePenList->FindOrCreatePen(*wxBLACK, 4, wxPENSTYLE_SOLID));
131-
p_dc.DrawLine(xStart, yStart, xStart + (int)((double)(xEnd - xStart) * (double)m_actionProb),
132-
yStart + (int)((double)(yEnd - yStart) * (double)m_actionProb));
131+
p_dc.DrawLine(xStart, yStart, xStart + (int)((double)(xEnd - xStart) * m_actionProb),
132+
yStart + (int)((double)(yEnd - yStart) * m_actionProb));
133133
}
134134

135135
int textWidth, textHeight;
@@ -307,7 +307,7 @@ bool gbtNodeEntry::NodeHitTest(int p_x, int p_y) const
307307
}
308308

309309
if (m_token == GBT_NODE_TOKEN_LINE) {
310-
const int DELTA = 8; // a fudge factor for "almost" hitting the node
310+
constexpr int DELTA = 8; // a fudge factor for "almost" hitting the node
311311
return (p_y >= m_y - DELTA && p_y <= m_y + DELTA);
312312
}
313313
else {
@@ -385,7 +385,7 @@ GameNode gbtTreeLayout::InfosetHitTest(int p_x, int p_y) const
385385
return nullptr;
386386
}
387387

388-
wxString gbtTreeLayout::CreateNodeLabel(const std::shared_ptr<gbtNodeEntry> p_entry,
388+
wxString gbtTreeLayout::CreateNodeLabel(const std::shared_ptr<gbtNodeEntry> &p_entry,
389389
int p_which) const
390390
{
391391
const GameNode n = p_entry->GetNode();
@@ -444,7 +444,7 @@ wxString gbtTreeLayout::CreateNodeLabel(const std::shared_ptr<gbtNodeEntry> p_en
444444
}
445445
}
446446

447-
wxString gbtTreeLayout::CreateBranchLabel(const std::shared_ptr<gbtNodeEntry> p_entry,
447+
wxString gbtTreeLayout::CreateBranchLabel(const std::shared_ptr<gbtNodeEntry> &p_entry,
448448
int p_which) const
449449
{
450450
const GameNode parent = p_entry->GetParent()->GetNode();
@@ -490,8 +490,7 @@ wxString gbtTreeLayout::CreateBranchLabel(const std::shared_ptr<gbtNodeEntry> p_
490490

491491
std::shared_ptr<gbtNodeEntry> gbtTreeLayout::GetValidParent(const GameNode &e)
492492
{
493-
auto n = GetNodeEntry(e->GetParent());
494-
if (n) {
493+
if (auto n = GetNodeEntry(e->GetParent())) {
495494
return n;
496495
}
497496
return GetValidParent(e->GetParent());
@@ -512,7 +511,7 @@ std::shared_ptr<gbtNodeEntry> gbtTreeLayout::GetValidChild(const GameNode &e)
512511
return nullptr;
513512
}
514513

515-
std::shared_ptr<gbtNodeEntry> gbtTreeLayout::GetEntry(const GameNode &p_node) const
514+
std::shared_ptr<gbtNodeEntry> gbtTreeLayout::GetNodeEntry(const GameNode &p_node) const
516515
{
517516
for (const auto &entry : m_nodeList) {
518517
if (entry->GetNode() == p_node) {
@@ -524,8 +523,7 @@ std::shared_ptr<gbtNodeEntry> gbtTreeLayout::GetEntry(const GameNode &p_node) co
524523

525524
GameNode gbtTreeLayout::PriorSameLevel(const GameNode &p_node) const
526525
{
527-
auto entry = GetEntry(p_node);
528-
if (entry) {
526+
if (auto entry = GetNodeEntry(p_node)) {
529527
auto e = std::next(std::find(m_nodeList.rbegin(), m_nodeList.rend(), entry));
530528
while (e != m_nodeList.rend()) {
531529
if ((*e)->GetLevel() == entry->GetLevel()) {
@@ -538,8 +536,7 @@ GameNode gbtTreeLayout::PriorSameLevel(const GameNode &p_node) const
538536

539537
GameNode gbtTreeLayout::NextSameLevel(const GameNode &p_node) const
540538
{
541-
auto entry = GetEntry(p_node);
542-
if (entry) {
539+
if (auto entry = GetNodeEntry(p_node)) {
543540
auto e = std::next(std::find(m_nodeList.begin(), m_nodeList.end(), entry));
544541
while (e != m_nodeList.end()) {
545542
if ((*e)->GetLevel() == entry->GetLevel()) {
@@ -557,7 +554,7 @@ int gbtTreeLayout::LayoutSubtree(const GameNode &p_node, const BehaviorSupportPr
557554
int y1 = -1, yn = 0;
558555
const gbtStyle &settings = m_doc->GetStyle();
559556

560-
auto entry = GetEntry(p_node);
557+
auto entry = GetNodeEntry(p_node);
561558
entry->SetNextMember(nullptr);
562559
if (m_doc->GetStyle().RootReachable() && p_node->GetInfoset() &&
563560
!p_node->GetInfoset()->GetPlayer()->IsChance()) {
@@ -580,7 +577,7 @@ int gbtTreeLayout::LayoutSubtree(const GameNode &p_node, const BehaviorSupportPr
580577

581578
if (!p_node->GetPlayer()->IsChance() && !p_support.Contains(action)) {
582579
(*std::find_if(m_nodeList.begin(), m_nodeList.end(),
583-
[&](std::shared_ptr<gbtNodeEntry> e) {
580+
[&](const std::shared_ptr<gbtNodeEntry> &e) {
584581
return e->GetNode() == p_node->GetChild(action);
585582
}))
586583
->SetInSupport(false);
@@ -633,7 +630,7 @@ int gbtTreeLayout::LayoutSubtree(const GameNode &p_node, const BehaviorSupportPr
633630
// Checks if there are any nodes in the same infoset as e that are either
634631
// on the same level (if SHOWISET_SAME) or on any level (if SHOWISET_ALL)
635632
//
636-
std::shared_ptr<gbtNodeEntry> gbtTreeLayout::NextInfoset(std::shared_ptr<gbtNodeEntry> e)
633+
std::shared_ptr<gbtNodeEntry> gbtTreeLayout::NextInfoset(const std::shared_ptr<gbtNodeEntry> &e)
637634
{
638635
const gbtStyle &draw_settings = m_doc->GetStyle();
639636

@@ -660,7 +657,7 @@ std::shared_ptr<gbtNodeEntry> gbtTreeLayout::NextInfoset(std::shared_ptr<gbtNode
660657
// infoset node+1. Also lengthens the nodes by the amount of space taken up
661658
// by the infoset lines.
662659
//
663-
void gbtTreeLayout::CheckInfosetEntry(std::shared_ptr<gbtNodeEntry> e)
660+
void gbtTreeLayout::CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &e)
664661
{
665662
// Check if the infoset this entry belongs to (on this level) has already
666663
// been processed. If so, make this entry->num the same as the one already

src/gui/efglayout.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class gbtNodeEntry {
5858
const gbtStyle *m_style{nullptr};
5959

6060
public:
61-
explicit gbtNodeEntry(GameNode p_parent);
61+
explicit gbtNodeEntry(const GameNode &p_parent);
6262

6363
GameNode GetNode() const { return m_node; }
6464

@@ -145,7 +145,7 @@ class gbtNodeEntry {
145145
const wxRect &GetOutcomeExtent() const { return m_outcomeRect; }
146146
const wxRect &GetPayoffExtent(int pl) const { return m_payoffRect[pl]; }
147147

148-
void Draw(wxDC &, GameNode selection, bool p_noHints) const;
148+
void Draw(wxDC &, const GameNode &selection, bool p_noHints) const;
149149
void DrawIncomingBranch(wxDC &) const;
150150
void DrawOutcome(wxDC &, bool p_noHints) const;
151151
};
@@ -161,10 +161,8 @@ class gbtTreeLayout : public gbtGameView {
161161

162162
const int c_leftMargin, c_topMargin;
163163

164-
std::shared_ptr<gbtNodeEntry> GetEntry(const GameNode &) const;
165-
166-
std::shared_ptr<gbtNodeEntry> NextInfoset(std::shared_ptr<gbtNodeEntry>);
167-
void CheckInfosetEntry(std::shared_ptr<gbtNodeEntry>);
164+
std::shared_ptr<gbtNodeEntry> NextInfoset(const std::shared_ptr<gbtNodeEntry> &);
165+
void CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &);
168166

169167
void BuildNodeList(const GameNode &, const BehaviorSupportProfile &, int);
170168

@@ -173,8 +171,8 @@ class gbtTreeLayout : public gbtGameView {
173171
void UpdateTableInfosets();
174172
void UpdateTableParents();
175173

176-
wxString CreateNodeLabel(const std::shared_ptr<gbtNodeEntry>, int) const;
177-
wxString CreateBranchLabel(const std::shared_ptr<gbtNodeEntry>, int) const;
174+
wxString CreateNodeLabel(const std::shared_ptr<gbtNodeEntry> &, int) const;
175+
wxString CreateBranchLabel(const std::shared_ptr<gbtNodeEntry> &, int) const;
178176

179177
void RenderSubtree(wxDC &dc, bool p_noHints) const;
180178

@@ -192,11 +190,7 @@ class gbtTreeLayout : public gbtGameView {
192190
void Layout(const BehaviorSupportProfile &);
193191
void GenerateLabels();
194192

195-
// The following member functions are for temporary compatibility only
196-
std::shared_ptr<gbtNodeEntry> GetNodeEntry(const GameNode &p_node) const
197-
{
198-
return GetEntry(p_node);
199-
}
193+
std::shared_ptr<gbtNodeEntry> GetNodeEntry(const GameNode &p_node) const;
200194
std::shared_ptr<gbtNodeEntry> GetValidParent(const GameNode &);
201195
std::shared_ptr<gbtNodeEntry> GetValidChild(const GameNode &);
202196

0 commit comments

Comments
 (0)