Skip to content

Commit ddd403b

Browse files
committed
Work on LayoutSubtree
1 parent 83da7a5 commit ddd403b

4 files changed

Lines changed: 41 additions & 49 deletions

File tree

src/gui/dlefglayout.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ gbtLayoutNodesPanel::gbtLayoutNodesPanel(wxWindow *p_parent, const gbtStyle &p_s
101101
const int NODE_LENGTH_MIN = 5;
102102
const int NODE_LENGTH_MAX = 100;
103103

104-
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, wxString::Format(_T("%d"), p_settings.NodeSize()),
104+
m_nodeSize = new wxSpinCtrl(this, wxID_ANY, wxString::Format(_T("%d"), p_settings.GetNodeSize()),
105105
wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, NODE_LENGTH_MIN,
106106
NODE_LENGTH_MAX);
107107
gridSizer->Add(m_nodeSize, 1, wxEXPAND | wxALL, 5);

src/gui/efglayout.cc

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -559,62 +559,55 @@ GameNode gbtTreeLayout::NextSameLevel(const GameNode &p_node) const
559559
return nullptr;
560560
}
561561

562-
int gbtTreeLayout::LayoutSubtree(const GameNode &p_node, const BehaviorSupportProfile &p_support,
563-
int &p_maxy, int &p_miny, int &p_ycoord)
562+
void gbtTreeLayout::LayoutSubtree(const GameNode &p_node, const BehaviorSupportProfile &p_support,
563+
int &p_maxy, int &p_miny, int &p_ycoord)
564564
{
565-
int y1 = -1, yn = 0;
566-
const gbtStyle &settings = m_doc->GetStyle();
565+
const auto &settings = m_doc->GetStyle();
567566

568-
auto entry = GetNodeEntry(p_node);
569-
entry->SetNextMember(nullptr);
567+
const auto entry = GetNodeEntry(p_node);
570568
if (m_doc->GetStyle().RootReachable() && p_node->GetInfoset() &&
571569
!p_node->GetInfoset()->GetPlayer()->IsChance()) {
572-
const GameInfoset infoset = p_node->GetInfoset();
573-
for (auto action : p_support.GetActions(infoset)) {
574-
yn = LayoutSubtree(p_node->GetChild(action), p_support, p_maxy, p_miny, p_ycoord);
575-
if (y1 == -1) {
576-
y1 = yn;
570+
const auto actions = p_support.GetActions(p_node->GetInfoset());
571+
for (const auto &action : actions) {
572+
LayoutSubtree(p_node->GetChild(action), p_support, p_maxy, p_miny, p_ycoord);
573+
}
574+
entry->m_y = (GetNodeEntry(p_node->GetChild(actions.front()))->m_y +
575+
GetNodeEntry(p_node->GetChild(actions.back()))->m_y) /
576+
2;
577+
}
578+
else if (!p_node->IsTerminal()) {
579+
const auto actions = p_node->GetInfoset()->GetActions();
580+
for (const auto &action : actions) {
581+
const auto child = p_node->GetChild(action);
582+
LayoutSubtree(child, p_support, p_maxy, p_miny, p_ycoord);
583+
if (!p_node->GetPlayer()->IsChance() && !p_support.Contains(action)) {
584+
GetNodeEntry(child)->m_inSupport = false;
577585
}
578586
}
579-
entry->m_y = (y1 + yn) / 2;
587+
entry->m_y = (GetNodeEntry(p_node->GetChild(actions.front()))->m_y +
588+
GetNodeEntry(p_node->GetChild(actions.back()))->m_y) /
589+
2;
580590
}
581591
else {
582-
if (!p_node->IsTerminal()) {
583-
for (const auto &action : p_node->GetInfoset()->GetActions()) {
584-
yn = LayoutSubtree(p_node->GetChild(action), p_support, p_maxy, p_miny, p_ycoord);
585-
if (y1 == -1) {
586-
y1 = yn;
587-
}
588-
589-
if (!p_node->GetPlayer()->IsChance() && !p_support.Contains(action)) {
590-
GetNodeEntry(p_node->GetChild(action))->m_inSupport = false;
591-
}
592-
}
593-
entry->m_y = (y1 + yn) / 2;
594-
}
595-
else {
596-
entry->m_y = p_ycoord;
597-
p_ycoord += settings.TerminalSpacing();
598-
}
592+
entry->m_y = p_ycoord;
593+
p_ycoord += settings.TerminalSpacing();
599594
}
600595

601596
if (settings.GetBranchStyle() == GBT_BRANCH_STYLE_LINE) {
602597
entry->m_x =
603-
c_leftMargin + entry->GetLevel() * (settings.NodeSize() + settings.GetBranchLength());
598+
c_leftMargin + entry->GetLevel() * (settings.GetNodeSize() + settings.GetBranchLength());
604599
}
605600
else {
606-
entry->m_x = c_leftMargin +
607-
entry->GetLevel() *
608-
(settings.NodeSize() + settings.GetBranchLength() + settings.GetTineLength());
601+
entry->m_x =
602+
c_leftMargin + entry->GetLevel() * (settings.GetNodeSize() + settings.GetBranchLength() +
603+
settings.GetTineLength());
609604
}
610605

611-
entry->SetSize(settings.NodeSize());
612-
entry->SetBranchLength(settings.GetBranchLength());
606+
entry->m_size = settings.GetNodeSize();
607+
entry->m_branchLength = settings.GetBranchLength();
613608

614609
p_maxy = std::max(entry->m_y, p_maxy);
615610
p_miny = std::min(entry->m_y, p_miny);
616-
617-
return entry->m_y;
618611
}
619612

620613
//
@@ -660,7 +653,7 @@ void gbtTreeLayout::CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &e)
660653
e->GetLevel() == e1->GetLevel() && e1->GetSublevel() > 0) {
661654
e->SetSublevel(e1->GetSublevel());
662655
if (infoset_entry) {
663-
e->SetNextMember(infoset_entry);
656+
e->m_nextMember = infoset_entry;
664657
}
665658
return;
666659
}
@@ -684,18 +677,18 @@ void gbtTreeLayout::CheckInfosetEntry(const std::shared_ptr<gbtNodeEntry> &e)
684677
}
685678
num++;
686679
e->SetSublevel(num);
687-
e->SetNextMember(infoset_entry);
680+
e->m_nextMember = infoset_entry;
688681
}
689682

690-
void gbtTreeLayout::FillInfosetTable(const GameNode &n, const BehaviorSupportProfile &cur_sup)
683+
void gbtTreeLayout::FillInfosetTable(const GameNode &n, const BehaviorSupportProfile &p_support)
691684
{
692685
const gbtStyle &draw_settings = m_doc->GetStyle();
693686
auto entry = GetNodeEntry(n);
694687
if (!n->IsTerminal()) {
695688
for (const auto &action : n->GetInfoset()->GetActions()) {
696-
const bool in_sup = n->GetPlayer()->IsChance() || cur_sup.Contains(action);
689+
const bool in_sup = n->GetPlayer()->IsChance() || p_support.Contains(action);
697690
if (in_sup || !draw_settings.RootReachable()) {
698-
FillInfosetTable(n->GetChild(action), cur_sup);
691+
FillInfosetTable(n->GetChild(action), p_support);
699692
}
700693
}
701694
}
@@ -755,7 +748,9 @@ void gbtTreeLayout::Layout(const BehaviorSupportProfile &p_support)
755748

756749
const gbtStyle &draw_settings = m_doc->GetStyle();
757750
if (draw_settings.GetInfosetConnect() != GBT_INFOSET_CONNECT_NONE) {
758-
// FIXME! This causes lines to disappear... sometimes.
751+
std::for_each(
752+
m_nodeList.begin(), m_nodeList.end(),
753+
[](const std::shared_ptr<gbtNodeEntry> &p_entry) { p_entry->m_nextMember = nullptr; });
759754
FillInfosetTable(m_doc->GetGame()->GetRoot(), p_support);
760755
UpdateTableInfosets();
761756
}

src/gui/efglayout.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,15 @@ class gbtNodeEntry {
5858
int GetY() const { return m_y; }
5959

6060
std::shared_ptr<gbtNodeEntry> GetNextMember() const { return m_nextMember; }
61-
void SetNextMember(std::shared_ptr<gbtNodeEntry> p_member) { m_nextMember = p_member; }
6261

6362
int GetChildNumber() const
6463
{
6564
return (m_node->GetParent()) ? m_node->GetPriorAction()->GetNumber() : 0;
6665
}
6766

6867
int GetSize() const { return m_size; }
69-
void SetSize(int p_size) { m_size = p_size; }
7068

7169
int GetBranchLength() const { return m_branchLength; }
72-
void SetBranchLength(int p_length) { m_branchLength = p_length; }
7370

7471
int GetLevel() const { return m_level; }
7572
void SetLevel(int p_level) { m_level = p_level; }
@@ -123,7 +120,7 @@ class gbtTreeLayout : public gbtGameView {
123120

124121
void BuildNodeList(const GameNode &, const BehaviorSupportProfile &, int);
125122

126-
int LayoutSubtree(const GameNode &, const BehaviorSupportProfile &, int &, int &, int &);
123+
void LayoutSubtree(const GameNode &, const BehaviorSupportProfile &, int &, int &, int &);
127124
void FillInfosetTable(const GameNode &, const BehaviorSupportProfile &);
128125
void UpdateTableInfosets() const;
129126
void UpdateTableParents();

src/gui/style.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class gbtStyle {
107107
gbtStyle();
108108

109109
// Node styling
110-
int NodeSize() const { return m_nodeSize; }
110+
int GetNodeSize() const { return m_nodeSize; }
111111
void SetNodeSize(int p_nodeSize) { m_nodeSize = p_nodeSize; }
112112

113113
int TerminalSpacing() const { return m_terminalSpacing; }

0 commit comments

Comments
 (0)