Console: which implementation-style prefered?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
apriori
Posts: 1
Joined: Sun Oct 02, 2005 6:17 pm

Console: which implementation-style prefered?

Post by apriori »

Hello everybody!

Sorry for the long post in advance!

I'm rather new to irrlicht and began to develop a quake-style console-class (yes, i know irrconsole, but don't like it though it is good work) and just want to ask you a question concerning the implementation of command execution.

Which way would you prefer?

1. class inheritance: Each command has to inherit a base class ( say CCommand ) and reimplement a run/invoke function. Parsed arguments are handled by the implemenation of the respective command. (the way irrconsole does it)

2. function pointers: Each command is represented by a function (say with parameters format [ representing the order of arguments, e.g. "ffss" for "float" "float" "string" "string" ] and the args-array). (my way)

Just an example how an implementation of a setcolor function would look like:

Code: Select all

void ConFn_Color( const core::stringw &format, const parameters &params, CCommand *cmd )
{
	CConsole *con = CConsole::getInstance();
	
	if( format == L"iiii" )
	{
		video::SColor color( params[3], params[0], params[1], params[2] );
		
		con->printf( L"changed color to (red: %i, green: %i, blue: %i, alpha: %i)",
			color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() );
		con->setConsoleColor( color );
	}
	if( format == L"iii" )
	{
		video::SColor color( 255, params[0], params[1], params[2] );
		
		con->printf( L"changed color to (red: %i, green: %i, blue: %i, alpha: %i)",
			color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha() );
		con->setConsoleColor( color );
	}
	if( format == L"0" )
	{
		
		video::SColor color = con->getConsoleColor();
			
		con->printf( L"current Color is (%i, %i, %i, %i )",
				color.getRed(),
				color.getGreen(),
				color.getBlue(),
				color.getAlpha() );
	}
}
the registration of the command looks like this:

Code: Select all

CConsole *console = CConsole::getInstance();
console->regCmd( ConFn_Color,                             // function pointer
			 L"color",                                // name of the command 
			 L"0\n"                                   // syntax formats, one format per line, 
			  "f(red)f(green)f(blue)f(alpha)\n"       // 0 = without args 
			  "f(red)f(green)f(blue)\n"
			  "i(red)i(green)i(blue)i(alpha)\n"       // 4 args version with type int	
                                                                  // params named (used to build the desc) 
			  "i(red)i(green)i(blue)",                // 3 args version 
			 L"changes the color of the console\n"    // description text 
			  "color is defined in the rgba combination\n "
			  "note: three parameter versions default alpha to the maximum value"
I think this is the easiest way or is it a bad idea to use function pointers just for simplicity reasons?

-------------

Next problem I got is, that Irrlicht apparently ignores the alpha color component when drawing fonts (with guifont) and drawing an image using draw2DImage leading to a black background of my console while it is moving out. Do I have to use materials for that purpose ?
Does anyone know how to fix this?


Thx in advance,
apriori
puh
Posts: 356
Joined: Tue Aug 26, 2003 3:53 pm

Post by puh »

http://irrlicht.sourceforge.net/phpBB2/ ... hp?p=30735

Ah, sorry, just noticed that you know it already...
Post Reply