From dfda276192319251804dd53a266e2549fd99a710 Mon Sep 17 00:00:00 2001 From: Robert Vollmert Date: Mon, 9 Nov 2009 22:18:58 +0100 Subject: Split up monster_grid into update and non-update part. --- crawl-ref/source/showsymb.h | 6 ++++ crawl-ref/source/view.cc | 73 ++++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 27 deletions(-) (limited to 'crawl-ref/source') diff --git a/crawl-ref/source/showsymb.h b/crawl-ref/source/showsymb.h index 0a8640d5d9..db70462af0 100644 --- a/crawl-ref/source/showsymb.h +++ b/crawl-ref/source/showsymb.h @@ -3,6 +3,12 @@ struct show_type; +struct glyph +{ + unsigned ch; + unsigned short col; +}; + void get_item_glyph(const item_def *item, unsigned *glych, unsigned short *glycol); void get_mons_glyph(const monsters *mons, unsigned *glych, diff --git a/crawl-ref/source/view.cc b/crawl-ref/source/view.cc index a97911d0ba..8968ea16fc 100644 --- a/crawl-ref/source/view.cc +++ b/crawl-ref/source/view.cc @@ -381,47 +381,24 @@ void force_monster_shout(monsters* monster) } #endif -void monster_grid(bool do_updates) +void monster_grid_updates() { - do_updates = do_updates && !crawl_state.arena; - for (int s = 0; s < MAX_MONSTERS; ++s) { monsters *monster = &menv[s]; if (monster->alive() && mons_near(monster)) { - if (do_updates && (monster->asleep() - || mons_is_wandering(monster)) + if ((monster->asleep() || mons_is_wandering(monster)) && check_awaken(monster)) { behaviour_event(monster, ME_ALERT, MHITYOU, you.pos(), false); handle_monster_shouts(monster); } - // [enne] - It's possible that mgrd and monster->x/y are out of - // sync because they are updated separately. If we can see this - // monster, then make sure that the mgrd is set correctly. - if (mgrd(monster->pos()) != s) - { - // If this mprf triggers for you, please note any special - // circumstances so we can track down where this is coming - // from. - mprf(MSGCH_ERROR, "monster %s (%d) at (%d, %d) was " - "improperly placed. Updating mgrd.", - monster->name(DESC_PLAIN, true).c_str(), s, - monster->pos().x, monster->pos().y); - ASSERT(!monster_at(monster->pos())); - mgrd(monster->pos()) = s; - } - - if (!env.show.update_monster(monster)) + if (!monster->visible_to(&you)) continue; -#ifdef USE_TILE - tile_place_monster(monster->pos().x, monster->pos().y, s, true); -#endif - good_god_follower_attitude_change(monster); beogh_follower_convert(monster); slime_convert(monster); @@ -430,6 +407,46 @@ void monster_grid(bool do_updates) } } +static void _check_monster_pos(const monsters* monster, int s) +{ + ASSERT(mgrd(monster->pos()) == s); + + // [enne] - It's possible that mgrd and monster->x/y are out of + // sync because they are updated separately. If we can see this + // monster, then make sure that the mgrd is set correctly. + if (mgrd(monster->pos()) != s) + { + // If this mprf triggers for you, please note any special + // circumstances so we can track down where this is coming + // from. + mprf(MSGCH_ERROR, "monster %s (%d) at (%d, %d) was " + "improperly placed. Updating mgrd.", + monster->name(DESC_PLAIN, true).c_str(), s, + monster->pos().x, monster->pos().y); + ASSERT(!monster_at(monster->pos())); + mgrd(monster->pos()) = s; + } +} + +void monster_grid() +{ + for (int s = 0; s < MAX_MONSTERS; ++s) + { + monsters *monster = &menv[s]; + + if (monster->alive() && mons_near(monster)) + { + _check_monster_pos(monster, s); + env.show.update_monster(monster); + +#ifdef USE_TILE + if (monster->visible_to(&you)) + tile_place_monster(monster->pos().x, monster->pos().y, s, true); +#endif + } + } +} + void update_monsters_in_view() { unsigned int num_hostile = 0; @@ -1262,7 +1279,9 @@ void viewwindow(bool draw_it, bool do_updates) env.show.init(); - monster_grid(do_updates); + monster_grid(); + if (do_updates && !crawl_state.arena) + monster_grid_updates(); #ifdef USE_TILE tile_draw_rays(true); -- cgit v1.2.3-54-g00ecf