-
Notifications
You must be signed in to change notification settings - Fork 113
Add menu_strs observations. #207
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,13 @@ NetHackRL::fill_obs(nle_obs *obs) | |
obs->misc[0] = in_yn_function; | ||
obs->misc[1] = in_getlin; | ||
obs->misc[2] = xwaitingforspace; | ||
obs->misc[3] = false; | ||
for (int i = 0; i < windows_.size(); ++i) { | ||
// We have a Non-Inventory Menu Window | ||
if (i != WIN_INVEN && windows_[i].get()->type == NHW_MENU) { | ||
obs->misc[3] = true; | ||
} | ||
} | ||
} | ||
|
||
if ((!program_state.something_worth_saving && !program_state.in_moveloop) | ||
|
@@ -353,6 +360,50 @@ NetHackRL::fill_obs(nle_obs *obs) | |
std::memset(obs->message, 0, NLE_MESSAGE_SIZE); | ||
} | ||
} | ||
|
||
if (obs->menu_strs) { | ||
bool found_menu = false; | ||
for (int i = 0; i < windows_.size(); ++i) { | ||
if (i != WIN_INVEN && windows_[i].get()->type == NHW_MENU) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll have to very carefully check the logic here. I'm especially surprised there's no Will get back to this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes - I'm not sure what to do if there are two windows - so I didn't put a break while testing to see if I could trigger it. If we go with a solution like this we should have a break. |
||
// We have a new menu window to be rendered on screen! | ||
// The menu can either have 'rl_menu_items' in init, or | ||
// simple text. In this case we expect only one of the two | ||
// to be available, and this one goes into menu_strs | ||
found_menu = true; | ||
rl_window *win = windows_[i].get(); | ||
assert(!win->menu_items.empty() ^ !win->strings.empty()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that |
||
|
||
int rows = max(win->menu_items.size(), win->strings.size()); | ||
int blank_rows = max(NLE_MENU_SIZE - rows, 0); | ||
bool do_full_menu = !win->menu_items.empty(); | ||
|
||
for (int i = 0; i < NLE_MENU_SIZE; ++i) { | ||
if (i >= rows) | ||
break; | ||
if (do_full_menu) { | ||
// we would need to send over the mappings etc in | ||
// different arrays | ||
std::strncpy( | ||
(char *) &obs->menu_strs[i * NLE_MENU_STR_LENGTH], | ||
win->menu_items[i].str.c_str(), | ||
NLE_MENU_STR_LENGTH); | ||
} else { | ||
// here we simply would put defaults or indicators | ||
std::strncpy( | ||
(char *) &obs->menu_strs[i * NLE_MENU_STR_LENGTH], | ||
win->strings[i].c_str(), NLE_MENU_STR_LENGTH); | ||
} | ||
} | ||
std::memset(&obs->menu_strs[rows * NLE_MENU_STR_LENGTH], 0, | ||
blank_rows * NLE_MENU_STR_LENGTH); | ||
} | ||
} | ||
if (!found_menu) { | ||
std::memset(&obs->menu_strs[0], 0, | ||
NLE_MENU_SIZE * NLE_MENU_STR_LENGTH); | ||
} | ||
} | ||
|
||
if (obs->blstats) { | ||
if (!u.dz) { | ||
/* Tricky hack: On "You descend the stairs.--More--" we are | ||
|
@@ -670,6 +721,7 @@ NetHackRL::destroy_nhwindow_method(winid wid) | |
{ | ||
DEBUG_API("rl_destroy_nhwindow(wid=" << wid << ")" << std::endl); | ||
windows_[wid].reset(nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could just remove this and save the reset resize |
||
windows_.resize(wid); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems strange? (1) It renders the line before needless. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes for some reason I thought the windows were stored in a stack-style data structure (largely verified in practice) but maybe this is all wrong. Either way should probably go read more code. |
||
tty_destroy_nhwindow(wid); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful with C++ booleans like
true/false
vs Cbools
. They can in some situations not be the same thing and map to objects that evaluate to different logical values (!)In this case it's ok because the lhs is an int, so the type will just get casted. Given that, it might make sense to write an int here in the first place.