diff options
author | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-05-07 12:24:40 +0000 |
---|---|---|
committer | haranp <haranp@c06c8d41-db1a-0410-9941-cceddc491573> | 2007-05-07 12:24:40 +0000 |
commit | 80efbb31cad981ef99a5526b895a040fb930d46a (patch) | |
tree | fa3b5327e7760c45c71fdaaa85ceba5dc34e8785 /crawl-ref/source/message.cc | |
parent | 05982cef94ba574904072aada7d1cfadca06f5e0 (diff) | |
download | crawl-ref-80efbb31cad981ef99a5526b895a040fb930d46a.tar.gz crawl-ref-80efbb31cad981ef99a5526b895a040fb930d46a.zip |
Messaging improvements.
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1411 c06c8d41-db1a-0410-9941-cceddc491573
Diffstat (limited to 'crawl-ref/source/message.cc')
-rw-r--r-- | crawl-ref/source/message.cc | 126 |
1 files changed, 73 insertions, 53 deletions
diff --git a/crawl-ref/source/message.cc b/crawl-ref/source/message.cc index 2bdee01794..3c7b2f31f3 100644 --- a/crawl-ref/source/message.cc +++ b/crawl-ref/source/message.cc @@ -47,82 +47,102 @@ int New_Message_Count = 0; static bool suppress_messages = false; static void base_mpr(const char *inf, int channel, int param); -// globals controlling message output -// there must be a better way to do this! -static bool mpr_stream_silent = false; -static msg_channel_type mpr_stream_channel = MSGCH_PLAIN; -static int mpr_stream_param = 0; - -std::ostream mpr_stream(new mpr_stream_buf); - -setchan::setchan(msg_channel_type chan) +namespace msg { - m_chan = chan; -} + std::ostream stream(new mpr_stream_buf(MSGCH_PLAIN)); + std::vector<std::ostream*> stream_ptrs; -setparam::setparam(int param) -{ - m_param = param; -} + std::ostream& streams(msg_channel_type chan) + { + ASSERT(chan >= 0 && + static_cast<unsigned int>(chan) < stream_ptrs.size()); + return *stream_ptrs[chan]; + } -std::ostream& operator<<(std::ostream& os, const setchan& sc) -{ - mpr_stream_channel = sc.m_chan; - return os; -} + void initialise_mpr_streams() + { + for (int i = 0; i < NUM_MESSAGE_CHANNELS; ++i) + { + mpr_stream_buf* pmsb = + new mpr_stream_buf(static_cast<msg_channel_type>(i)); + std::ostream* pos = new std::ostream(pmsb); + (*pos) << std::nounitbuf; + stream_ptrs.push_back(pos); + } + stream << std::nounitbuf; + } -std::ostream& operator<<(std::ostream& os, const setparam& sp) -{ - mpr_stream_param = sp.m_param; - return os; -} + void deinitalise_mpr_streams() + { + for (unsigned int i = 0; i < stream_ptrs.size(); ++i) + delete stream_ptrs[i]; + } -mpr_stream_buf::mpr_stream_buf() -{ - for ( int i = 0; i < INTERNAL_LENGTH; ++i ) - internal_buf[0] = 0; - internal_count = 0; -} -// again, can be improved -int mpr_stream_buf::overflow(int c) -{ - if ( c == '\n' ) + setparam::setparam(int param) { - // null-terminate the string - internal_buf[internal_count] = 0; - - if ( !mpr_stream_silent ) - mpr(internal_buf, mpr_stream_channel, mpr_stream_param); + m_param = param; + } - internal_count = 0; + mpr_stream_buf::mpr_stream_buf(msg_channel_type chan) : + internal_count(0), muted(false), channel(chan) + {} - // reset to defaults (channel changing isn't sticky) - mpr_stream_channel = MSGCH_PLAIN; - mpr_stream_param = 0; + void mpr_stream_buf::set_param(int p) + { + this->param = p; } - else - internal_buf[internal_count++] = c; - if ( internal_count + 3 > INTERNAL_LENGTH ) + void mpr_stream_buf::set_muted(bool m) { - mpr("oops, hit overflow", MSGCH_DANGER); - internal_count = 0; - return std::streambuf::traits_type::eof(); + this->muted = m; + } + + // again, can be improved + int mpr_stream_buf::overflow(int c) + { + if ( muted ) + return 0; + + if ( c == '\n' ) + { + // null-terminate and print the string + internal_buf[internal_count] = 0; + mpr(internal_buf, channel, param); + + internal_count = 0; + + // reset to defaults (param changing isn't sticky) + set_param(0); + } + else + internal_buf[internal_count++] = c; + + if ( internal_count + 3 > INTERNAL_LENGTH ) + { + mpr("oops, hit overflow", MSGCH_DANGER); + internal_count = 0; + return std::streambuf::traits_type::eof(); + } + return 0; } - return 0; +} + +std::ostream& operator<<(std::ostream& os, const msg::setparam& sp) +{ + msg::mpr_stream_buf* ps = dynamic_cast<msg::mpr_stream_buf*>(os.rdbuf()); + ps->set_param(sp.m_param); + return os; } no_messages::no_messages() : msuppressed(suppress_messages) { suppress_messages = true; - mpr_stream_silent = true; } no_messages::~no_messages() { suppress_messages = msuppressed; - mpr_stream_silent = msuppressed; } static char god_message_altar_colour( char god ) |