From 0bdd1441fc95f70f2f86c89c20eb866a9ca2787b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 18 Jan 2012 23:33:32 -0700 Subject: Rearranged rendering code. --- src/functiondebugstring.cpp | 21 ++++ src/functiondebugstring.h | 19 ++++ src/interfaceconsole.cpp | 218 +---------------------------------------- src/interfaceconsole.h | 15 --- src/interfacegats.cpp | 50 +--------- src/smlrenderer.cpp | 10 ++ src/smlrenderer.h | 17 ++++ src/smlrendererhtml.cpp | 62 ++++++++++++ src/smlrendererhtml.h | 15 +++ src/smlrenderervt100.cpp | 229 ++++++++++++++++++++++++++++++++++++++++++++ src/smlrenderervt100.h | 32 +++++++ 11 files changed, 413 insertions(+), 275 deletions(-) create mode 100644 src/functiondebugstring.cpp create mode 100644 src/functiondebugstring.h create mode 100644 src/smlrenderer.cpp create mode 100644 src/smlrenderer.h create mode 100644 src/smlrendererhtml.cpp create mode 100644 src/smlrendererhtml.h create mode 100644 src/smlrenderervt100.cpp create mode 100644 src/smlrenderervt100.h (limited to 'src') diff --git a/src/functiondebugstring.cpp b/src/functiondebugstring.cpp new file mode 100644 index 0000000..1c138d7 --- /dev/null +++ b/src/functiondebugstring.cpp @@ -0,0 +1,21 @@ +#include "functiondebugstring.h" + +#include +#include "gamestate.h" + +using namespace Bu; + +FunctionDebugString::FunctionDebugString() +{ +} + +FunctionDebugString::~FunctionDebugString() +{ +} + +void FunctionDebugString::call( class GameState &gState ) +{ + Variable v = gState.popDeref(); + gState.push( Variable( Bu::String("%1").arg( v ) ) ); +} + diff --git a/src/functiondebugstring.h b/src/functiondebugstring.h new file mode 100644 index 0000000..cc7c6ac --- /dev/null +++ b/src/functiondebugstring.h @@ -0,0 +1,19 @@ +#ifndef FUNCTION_DEBUG_STRING_H +#define FUNCTION_DEBUG_STRING_H + +#include "function.h" + +class FunctionDebugString : public Function +{ +public: + FunctionDebugString(); + virtual ~FunctionDebugString(); + + virtual Bu::String getName() const { return "debugString"; } + virtual void call( class GameState &gState ); + +private: + Bu::String format( const Bu::String &sSrc ); +}; + +#endif diff --git a/src/interfaceconsole.cpp b/src/interfaceconsole.cpp index 94b45b9..caa13bf 100644 --- a/src/interfaceconsole.cpp +++ b/src/interfaceconsole.cpp @@ -7,6 +7,8 @@ #include +#include "smlrenderervt100.h" + PluginInterface3( plugin_interface_console, console, InterfaceConsole, Interface, "Mike Buland", 1, 0 ); @@ -35,219 +37,9 @@ void InterfaceConsole::run( Game *pGame ) } } -void InterfaceConsole::appendToken( Bu::String &sCurLine, - Bu::String &sNextToken, int &iLineLen, int &iNextLen ) -{ - if( iLineLen + iNextLen + 1 >= 78 ) - { - sio << sCurLine << sio.nl; - iLineLen = 0; - sCurLine = sNextToken; - } - else - { - sCurLine += sNextToken; - } - iLineLen += iNextLen + 1; - sCurLine += " "; - iNextLen = 0; - sNextToken.clear(); -} - -Bu::String InterfaceConsole::getVt100Style( const StyleStack &sStyle ) -{ -#ifdef WIN32 - // Windows...we don't do colors for windows... - return ""; -#endif - - if( sStyle.isEmpty() ) - { - return "\x1B[0m"; - } - - int sCurStyle = 0; - for( StyleStack::const_iterator i = sStyle.begin(); i; i++ ) - { -// sio << "Merging in: " << Fmt::hex() << *i << sio.nl; - if( ((sCurStyle&stTypeMask) & ((*i)&stTypeMask)) == 0 ) - { - sCurStyle |= *i; -// sio << " -> curStyle = " << Fmt::hex() << *i << sio.nl; - } - } - - Bu::String sRet; - -// sio << "Color: " << Fmt::hex() << sCurStyle << sio.nl; - switch( sCurStyle&stColor ) - { - case stRed: - sRet += "\x1B[1;31m"; - break; - - case stGreen: - sRet += "\x1B[1;32m"; - break; - } - - return sRet; -} - -void InterfaceConsole::display( const SmlNode *pNode ) +void InterfaceConsole::display( const class SmlNode *pSml ) { - Bu::String sCurLine; - Bu::String sNextToken; - int iLineLen = 0; - int iNextLen = 0; - int iState = 0; - typedef Bu::List NodeStack; - NodeStack sNode; - - StyleStack sStyle; - - sNode.push( pNode->getChildren().begin() ); - - for(;;) - { - if( !sNode.peek() ) - { - sNode.pop(); - if( sNode.isEmpty() ) - break; - if( sNode.peek() ) - { - // sio << "Pop'd: " << (*sNode.peek())->getText() << sio.nl; - Bu::String sTag = (*sNode.peek())->getText(); - if( sTag == "green" || sTag == "red" ) - { - sStyle.pop(); - sNextToken += getVt100Style( sStyle ); - } - sNode.peek()++; - continue; - } - } - if( sNode.isEmpty() ) - { - break; - } - const SmlNode *pNode = (*sNode.peek()); - switch( pNode->getType() ) - { - case SmlNode::typeRoot: - throw Bu::ExceptionBase("Invalid root."); - - case SmlNode::typeText: - { - // sio << "Process text node: " << pNode->getText() << - // sio.nl; - Bu::String::const_iterator iBgn = pNode->getText().begin(); - Bu::String::const_iterator iEnd = iBgn; - int iTmpLen = 0; - for(;iBgn;) - { - switch( iState ) - { - case 0: // begining of paragraph - if( iBgn && ( *iBgn == ' ' || *iBgn == '\n' || - *iBgn == '\r' || *iBgn == '\t' ) ) - { - iBgn++; - } - else - { - // Here is where you would indent paragraphs - iEnd = iBgn; - iState = 1; - } - break; - - case 1: // non-whitespace - if( !iEnd ) - { - sNextToken.append( iBgn, iEnd ); - iBgn = iEnd; - iNextLen += iTmpLen; - iTmpLen = 0; - } - else if( *iEnd == ' ' || *iEnd == '\n' || - *iEnd == '\r' || *iEnd == '\t' ) - { - sNextToken.append( iBgn, iEnd ); - iNextLen += iTmpLen; - iTmpLen = 0; - iState = 2; - iBgn = iEnd; - } - else - { - iEnd++; - iTmpLen++; - } - break; - - case 2: // Whitespace - if( iBgn && (*iBgn == ' ' || *iBgn == '\n' || - *iBgn == '\r' || *iBgn == '\t') ) - { - iBgn++; - } - else - { - iEnd = iBgn; - iState = 1; - appendToken( sCurLine, sNextToken, - iLineLen, iNextLen ); - } - break; - } - } - } - break; - - case SmlNode::typeTag: - if( pNode->getChildren().isEmpty() ) - { - if( pNode->getText() == "break" ) - { - appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); - if( !sCurLine.isEmpty() ) - sio << sCurLine << sio.nl; - sCurLine.clear(); - iLineLen = 0; - iState = 0; - } - } - else - { -// sio << "Push'd: " << pNode->getText() << sio.nl; - Bu::String sTag = pNode->getText(); - if( sTag == "green" ) - { - sStyle.push( stGreen ); - } - else if( sTag == "red" ) - { - sStyle.push( stRed ); - } - sNextToken += getVt100Style( sStyle ); - sNode.push( pNode->getChildren().begin() ); - continue; -/* for( SmlNode::SmlNodeList::const_iterator i = - pNode->getChildren().begin(); i; i++ ) - { - s - smlToConsole( *i, sCurLine, sNextToken, iLineLen, iState ); - } -*/ - } - break; - } - sNode.peek()++; - } - if( !sNextToken.isEmpty() ) - appendToken( sCurLine, sNextToken, iLineLen, iNextLen ); - sio << sCurLine << sio.nl; + SmlRendererVt100 rend; + rend.render( sio, pSml ); } diff --git a/src/interfaceconsole.h b/src/interfaceconsole.h index 17b07e4..ce48003 100644 --- a/src/interfaceconsole.h +++ b/src/interfaceconsole.h @@ -17,21 +17,6 @@ public: virtual void display( const class SmlNode *pSml ); private: - enum Style - { - stRed = 0x010001, - stGreen = 0x010002, - - stColor = 0x01000f, - - stTypeMask = 0xff0000, - }; - - typedef Bu::List