summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source
diff options
context:
space:
mode:
Diffstat (limited to 'crawl-ref/source')
-rw-r--r--crawl-ref/source/acr.cc26
-rw-r--r--crawl-ref/source/message.cc126
-rw-r--r--crawl-ref/source/message.h83
-rw-r--r--crawl-ref/source/stuff.cc3
4 files changed, 128 insertions, 110 deletions
diff --git a/crawl-ref/source/acr.cc b/crawl-ref/source/acr.cc
index b37ec439eb..909e33c039 100644
--- a/crawl-ref/source/acr.cc
+++ b/crawl-ref/source/acr.cc
@@ -234,10 +234,10 @@ int main( int argc, char *argv[] )
init_tutorial_options();
if (game_start || Options.always_greet)
{
- mpr_stream << "Welcome, " << you.your_name << " the "
- << species_name( you.species,you.experience_level )
- << " " << you.class_name << "."
- << std::endl;
+ msg::stream << "Welcome, " << you.your_name << " the "
+ << species_name( you.species,you.experience_level )
+ << " " << you.class_name << "."
+ << std::endl;
// Starting messages can go here as this should only happen
// at the start of a new game -- bwr
@@ -312,12 +312,11 @@ int main( int argc, char *argv[] )
Options.tut_just_triggered = true;
// print stats and everything
prep_input();
- int ch = 'x';
- mpr_stream << setchan(MSGCH_TUTORIAL)
- << "Press any key to start the tutorial intro, "
- << "or Escape to skip it."
- << std::endl;
- ch = c_getch();
+ msg::streams(MSGCH_TUTORIAL)
+ << "Press any key to start the tutorial intro, "
+ "or Escape to skip it."
+ << std::endl;
+ const int ch = c_getch();
if (ch != ESCAPE)
tut_starting_screen();
@@ -2834,15 +2833,14 @@ static bool initialise(void)
init_monsters(mcolour); // this needs to be way up top {dlb}
init_spell_descs(); // this needs to be way up top {dlb}
- // Ensure no buffering on the mpr() stream.
- mpr_stream << std::nounitbuf;
+ msg::initialise_mpr_streams();
// init item array:
for (int i = 0; i < MAX_ITEMS; i++)
- init_item( i );
+ init_item(i);
// empty messaging string
- strcpy(info, "");
+ info[0] = 0;
for (int i = 0; i < MAX_MONSTERS; i++)
menv[i].reset();
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 )
diff --git a/crawl-ref/source/message.h b/crawl-ref/source/message.h
index 96a2094f40..a5e3385bc3 100644
--- a/crawl-ref/source/message.h
+++ b/crawl-ref/source/message.h
@@ -78,26 +78,12 @@ private:
bool msuppressed;
};
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr
- * *********************************************************************** */
-void replay_messages(void);
+bool any_messages();
+void replay_messages();
-
-// last updated 12may2000 {dlb}
-/* ***********************************************************************
- * called from: acr - it_use3 - items - religion
- * *********************************************************************** */
void set_colour(char set_message_colour);
-// last updated 18mar2001 {dlb}
-/* ***********************************************************************
- * called from: acr
- * *********************************************************************** */
-bool any_messages(void);
-
// last updated 13oct2003 {dlb}
/* ***********************************************************************
* called from: chardump
@@ -106,34 +92,45 @@ std::string get_last_messages(int mcount);
int channel_to_colour( int channel, int param = 0 );
-struct setchan
+namespace msg
{
- setchan(msg_channel_type chan);
- msg_channel_type m_chan;
-};
-
-struct setparam
-{
- setparam(int param);
- int m_param;
-};
-
-std::ostream& operator<<(std::ostream& os, const setchan& sc);
-std::ostream& operator<<(std::ostream& os, const setparam& sp);
-
-class mpr_stream_buf : public std::streambuf
-{
-public:
- mpr_stream_buf();
-protected:
- int overflow(int c);
-private:
- static const int INTERNAL_LENGTH = 500;
- char internal_buf[500]; // if your terminal is wider than this, too bad
- int internal_count;
-};
-
-extern std::ostream mpr_stream;
+ extern std::ostream stream;
+ std::ostream& streams(msg_channel_type chan = MSGCH_PLAIN);
+
+ struct setparam
+ {
+ setparam(int param);
+ int m_param;
+ };
+
+ struct mute
+ {
+ mute(bool value = true);
+ bool m_value;
+ };
+
+ class mpr_stream_buf : public std::streambuf
+ {
+ public:
+ mpr_stream_buf(msg_channel_type chan);
+ void set_param(int p);
+ void set_muted(bool m);
+ protected:
+ int overflow(int c);
+ private:
+ static const int INTERNAL_LENGTH = 500;
+ char internal_buf[500]; // if your terminal is wider than this, too bad
+ int internal_count;
+ int param;
+ bool muted;
+ msg_channel_type channel;
+ };
+
+ void initialise_mpr_streams();
+ void deinitalise_mpr_streams();
+}
+
+std::ostream& operator<<(std::ostream& os, const msg::setparam& sp);
#endif
diff --git a/crawl-ref/source/stuff.cc b/crawl-ref/source/stuff.cc
index 0a0fbbe1d8..4c5d1ff876 100644
--- a/crawl-ref/source/stuff.cc
+++ b/crawl-ref/source/stuff.cc
@@ -16,6 +16,7 @@
#include "AppHdr.h"
#include "database.h"
#include "direct.h"
+#include "message.h"
#include "monplace.h"
#include "stuff.h"
#include "view.h"
@@ -347,6 +348,8 @@ void cio_cleanup()
deinit_libw32c();
#endif
+ msg::deinitalise_mpr_streams();
+
io_inited = false;
}