Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Vulcan

A game debug console - help

This topic is 5649 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this little game debug console thing. It all works nice and fins and everything, I just want to simplyfy the syntax for it. The way I have it now, you can just spit messages out to the console, like so sConsole() << "here is some message"; sConsole().End(); The End() method adds the constructed string finally to the console, and prepares for another msg, etc. what I want to be able to do is sConsole() << "here is some message" << End(); But I cannot figure out for the life of me the syntax to allow this to work. Any help? btw - I dont just have an ''End'' function, I have other functions such as changing the current color of the text, etc... -Vulcan

Share this post


Link to post
Share on other sites
Advertisement
Simple.
You need to overload the ''<<'' operator - check google for C++ operator overloading. A suggestion of mine would be the following:


  

// struct that is used to set the color

struct SetColor
{
int mColor; // actual color value

// constructor that initializes member

SetColor(const int nColor) : mColor(nColor)
{}

// convert to integer

const operator int() const
{
return mColor;
}
};

// just an empty type

struct End {};

class Console
{
// other stuff here


void SetColor(cont int nColor)
{
// change our text color for output here

}

// text output

Console& operator << (const string& strText)
{
// call your printing function here

return *this;
}

// end output

Console& operator << (const End& sEnd)
{
return (*this << "\n"; // or whatever you use to end

}

// change output color

Console& operator << (const SetColor& sColor)
{
SetTextColor(sColor);
return *this;
}

};

// usage example

Console sColor;

sColor << "This is a " << SetColor(GREEN) << "green" << SetColor(GREY) << " text" << End();



Just my 0.02€,
Pat

Share this post


Link to post
Share on other sites
Ohhhhhhh I see now.... so the End() would not actually be a method but a struct/class called End but then overloaded by the Console so simply end the line?

thanks much for the help, i was thinking it would be more of a method than overloading for a constructed object

thx
-Vulcan

[edited by - Vulcan on January 29, 2003 9:17:15 PM]

Share this post


Link to post
Share on other sites
Actually, I was gonna post my SDL based pluggable console here in a bit, but what I did for it was this:


  
class SDL_Console
{
public:
// some stuff

// Stream operators

enum OpFlag
{
Flush = 0x01,
Exec = 0x02,
Term = Flush | Exec
};

SDL_Console& operator<<(OpFlag op);

// some other stuff

};

SDL_Console& SDL_Console::operator<<(SDL_Console::OpFlag of)
{
if(of & Exec)
Execute(m_stringBuffer.str());
if(of & Flush)
{
Out(m_stringBuffer.str());
m_stringBuffer.str("");
}
return *this;
}


That way, you can do things like:


  
con << "echo here" << SDL_Console::Term;
// output: "here"

con << "echo this" << SDL_Console::Exec << " is a test" << Flush;
// output: this

// output: echo this is a test



I hope that makes sense.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!