From d6bd9b45e09b1fc1bbb1ea09fa59509b7c494388 Mon Sep 17 00:00:00 2001 From: Martin Read Date: Tue, 12 Nov 2013 16:09:55 +0000 Subject: [PATCH] Adjustment of constants relating to vision/display; possibly some more will need catching --- display-nc.cc | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++------- fov.hh | 10 ++++++- 2 files changed, 93 insertions(+), 12 deletions(-) diff --git a/display-nc.cc b/display-nc.cc index bc513bd..883c907 100644 --- a/display-nc.cc +++ b/display-nc.cc @@ -37,6 +37,8 @@ #include #include +#define DISP_NC_RADIUS (10) +#define DISP_NC_SIDE (DISP_NC_RADIUS * 2 + 1) void set_inventory_message(const char *s, bool allow_nil); void reset_inventory_message(void); void hide_inv(void); @@ -144,21 +146,29 @@ static void draw_status_line(void) mvwprintw(status_window, 1, 44, "Agility: %02d/%02d", u.agility - u.adam, u.agility); } +/*! \brief Get pointer to cchar_t object for specified terrain + */ static const cchar_t *terrain_char(Terrain terrain_type) { return terrain_tiles + terrain_type; } +/*! \brief Get pointer to cchar_t object for specified monster + */ static const cchar_t *monster_char(int monster_id) { return permon_tiles + monster_id; } +/*! \brief Get pointer to cchar_t object for specified object + */ static const cchar_t *object_char(int object_id) { return permobj_tiles + object_id; } +/*! \brief Call newsym() on the entire level and request a hard redraw + */ void touch_back_buffer(void) { Coord c; @@ -173,6 +183,12 @@ void touch_back_buffer(void) hard_redraw = 1; } +/*! \brief Update symbol at specified location + * + * newsym() notifies the display layer that the state of position 'c' has + * changed in a way that should change its graphical representation (e.g. + * there was a monster there and now there isn't). + */ void newsym(Coord c) { const cchar_t *ch; @@ -210,18 +226,20 @@ void newsym(Coord c) } } +/*! \brief Update the map window + */ static void draw_world(void) { int i; int j; Coord c; - for (i = 0; i < 21; i++) + for (i = 0; i < DISP_NC_SIDE; i++) { - c.y = u.pos.y + i - 10; - for (j = 0; j < 21; j++) + c.y = u.pos.y + i - DISP_NC_RADIUS; + for (j = 0; j < DISP_NC_SIDE; j++) { - c.x = u.pos.x + j - 10; + c.x = u.pos.x + j - DISP_NC_RADIUS; if ((c.y < 0) || (c.x < 0) || (c.y >= DUN_HEIGHT) || (c.x >= DUN_WIDTH)) { @@ -234,7 +252,7 @@ static void draw_world(void) else if (hard_redraw || (front_buffer[i][j] != back_buffer[c.y][c.x])) { mvwadd_wch(world_window, i, j, back_buffer[c.y][c.x]); - if (!player_fov.affected[i][j]) + if (!player_fov.test(i - DISP_NC_RADIUS + MAX_FOV_RADIUS, j - DISP_NC_RADIUS + MAX_FOV_RADIUS)) { mvwchgat(world_window, i, j, 1, A_BOLD, Gcol_d_grey, NULL); } @@ -246,6 +264,8 @@ static void draw_world(void) /* extern funcs */ +/*! \brief Wait for the user to press RETURN + */ void press_enter(void) { int ch; @@ -260,6 +280,8 @@ void press_enter(void) } } +/*! \brief Update any parts of the display that need it + */ void display_update(void) { if (status_updated) @@ -276,6 +298,13 @@ void display_update(void) doupdate(); } +/*! \brief Initialize the display subsystem + * + * Yes, this architecture does mean we only support one display subsystem at + * compile time. + * + * \todo Rename this and put appropriate glue elsewhere to make it work + */ int display_init(void) { int i; @@ -377,6 +406,8 @@ int display_init(void) return 0; } +/*! \brief Get string input from the player + */ int read_input(char *buffer, int length) { echo(); @@ -387,6 +418,10 @@ int read_input(char *buffer, int length) return strlen(buffer); } +/*! \brief Print some text in the message window + * + * \todo Handle the message window getting resized + */ void print_msg(const char *fmt, ...) { va_list ap; @@ -403,6 +438,8 @@ void print_msg(const char *fmt, ...) display_update(); } +/*! \brief Set a message and whether 'nothing' should be listed in inventory + */ void set_inventory_message(const char *s, bool allow_nil) { mvwprintw(inventory_window, 0, 0, "%-57s\n", s); @@ -416,6 +453,8 @@ void set_inventory_message(const char *s, bool allow_nil) } } +/*! \brief Clear any inventory message + */ void reset_inventory_message(void) { wattrset(inventory_window, colour_attrs[Gcol_l_grey]); @@ -423,6 +462,8 @@ void reset_inventory_message(void) mvwprintw(inventory_window, 20, 0, " "); } +/*! \brief Make the inventory visible + */ void show_inv(void) { show_panel(inventory_panel); @@ -430,6 +471,8 @@ void show_inv(void) doupdate(); } +/*! \brief Hide the inventory if necessary on this display type + */ void hide_inv(void) { show_panel(message_panel); @@ -438,6 +481,10 @@ void hide_inv(void) doupdate(); } +/*! \brief Update the inventory window to reflect the filter in force + * + * \todo Switch to using a function pointer + private argument for filtering + */ void update_inv(enum poclass_num filter) { int i; @@ -476,6 +523,10 @@ void update_inv(enum poclass_num filter) } } +/*! \brief Select an inventory item + * + * \todo Take function pointer and private arg for smarter filtering + */ int inv_select(enum poclass_num filter, const char *action, int accept_blank) { int selection; @@ -541,9 +592,9 @@ tryagain: case 'q': case 'r': case 's': - /* I am assuming that we're in a place where the character - * set is a strict superset of ASCII. IF we're not, the - * following code may break. */ + /* I am assuming that we're in a place where the input character set is + * a strict superset of ASCII. IF we're not, the following code may + * break. */ selection = ch - 'a'; if ((u.inventory[selection] != NO_OBJ) && ((filter == POCLASS_NONE) || (permobjs[objects[u.inventory[selection]].obj_id].poclass == filter))) { @@ -556,6 +607,10 @@ tryagain: } } +/*! \brief Ask the player to choose a direction + * + * \todo Consider making this accommodate up/down/self as well as compass directions + */ Pass_fail select_dir(Offset *pstep) { int ch; @@ -618,6 +673,10 @@ Pass_fail select_dir(Offset *pstep) return You_pass; } +/*! \brief Read the player's next command + * + * \todo Consider redesigning in a way friendlier to non-terminal platforms + */ enum game_cmd get_command(void) { int ch; @@ -732,6 +791,8 @@ enum game_cmd get_command(void) return QUIT; } +/*! \brief Shut down the display subsystem + */ int display_shutdown(void) { display_update(); @@ -742,12 +803,16 @@ int display_shutdown(void) return 0; } +/*! \brief Prompt the player to press any key + */ void pressanykey(void) { print_msg("Press any key to continue.\n"); wgetch(message_window); } +/*! \brief Prompt the player for a relatively paranoid 'Y' + */ int getYN(const char *msg) { int ch; @@ -761,6 +826,8 @@ int getYN(const char *msg) return 0; } +/*! \brief Get a yes/no response from the player + */ int getyn(const char *msg) { int ch; @@ -785,6 +852,10 @@ int getyn(const char *msg) } } +/*! \brief Print some basic help for the player + * + * \todo Consider providing a more capable help system. + */ void print_help(void) { print_msg("MOVEMENT\n"); @@ -827,7 +898,7 @@ void print_help(void) print_msg("OTHER COMMANDS\n"); print_msg("S save and exit\n"); print_msg("X quit without saving\n"); - print_msg("i print your inventory\n"); + print_msg("i show your inventory\n"); print_msg("I examine an item you are carrying\n"); print_msg("# show underlying terrain of occupied squares\n"); print_msg("\\ list all recognised items\n"); @@ -853,16 +924,18 @@ void print_help(void) print_msg("\nThis is all the help you get. Good luck!\n"); } +/*! \brief Call newsym() for all locations in camera range of a position + */ void touch_one_screen(Coord c) { Coord c2; - for (c2.y = c.y - 10; c2.y <= c.y + 10; c2.y++) + for (c2.y = c.y - DISP_NC_RADIUS; c2.y <= c.y + DISP_NC_RADIUS; c2.y++) { if ((c2.y < 0) || (c2.y >= DUN_HEIGHT)) { continue; } - for (c2.x = c.x - 10; c2.x <= c.x + 10; c2.x++) + for (c2.x = c.x - DISP_NC_RADIUS; c2.x <= c.x + DISP_NC_RADIUS; c2.x++) { if ((c2.x < 0) || (c2.x >= DUN_WIDTH)) { diff --git a/fov.hh b/fov.hh index e5381c4..007c201 100644 --- a/fov.hh +++ b/fov.hh @@ -30,6 +30,7 @@ #define FOV_HH #define MAX_FOV_RADIUS 10 +#define FOV_SIDE (2 * MAX_FOV_RADIUS + 1) /*! \brief Specifies order in which to affect tiles * @@ -53,7 +54,7 @@ typedef enum rad_eval_order Rad_eval_order; typedef uint8_t Vision_flags; /* 8 bits should do for now */ struct radiance_data { - Vision_flags affected[MAX_FOV_RADIUS * 2 + 1][MAX_FOV_RADIUS * 2 + 1]; + Vision_flags affected[FOV_SIDE][FOV_SIDE]; int centre_y; int centre_x; int radius; @@ -62,6 +63,13 @@ struct radiance_data void *pvt; bool (*opaque_fun)(int y, int x); bool (*effect_fun)(int y, int x, void *pvt); + bool test(int y, int x) const { + if ((y >= 0) && (x >= 0) && (y < FOV_SIDE) && (x < FOV_SIDE)) + { + return affected[y][x]; + } + return false; + } }; typedef struct radiance_data Radiance; -- 2.11.0