Error printing call for Console, the NYAN CAT!

develop
Petr Mrázek 2011-07-14 11:15:23 +02:00
parent f2b46274ec
commit d21b196766
5 changed files with 97 additions and 24 deletions

@ -153,6 +153,18 @@ int Console::print( const char* format, ... )
return ret;
}
int Console::printerr( const char* format, ... )
{
color(12);
va_list args;
va_start( args, format );
int ret = vfprintf( d->dfout_C, format, args );
va_end( args );
reset_color();
return ret;
}
int Console::get_columns(void)
{
winsize ws;
@ -236,6 +248,7 @@ void Console::color(int index)
void Console::reset_color( void )
{
print(RESETCOLOR);
fflush(d->dfout_C);
}
void Console::cursor(bool enable)

@ -21,6 +21,43 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
/*
Some functions are based on the linenoise win32 port:
linenoise_win32.c -- Linenoise win32 port.
Modifications copyright 2010, Jon Griffiths <jon_p_griffiths at yahoo dot com>.
All rights reserved.
Based on linenoise, copyright 2010, Salvatore Sanfilippo <antirez at gmail dot com>.
The original linenoise can be found at: http://github.com/antirez/linenoise
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Redis nor the names of its contributors may be used
to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#include <windows.h>
#include <conio.h>
#include <stdarg.h>

@ -127,7 +127,7 @@ int fIOthread(void * iodata)
Console & con = core->con;
if(plug_mgr == 0 || core == 0)
{
con.print("Something horrible happened in Core's constructor...\n");
con.printerr("Something horrible happened in Core's constructor...\n");
return 0;
}
con.print("DFHack is ready. Have a nice day! Type in '?' or 'help' for help.\n");
@ -187,12 +187,12 @@ int fIOthread(void * iodata)
command_result res = plug_mgr->InvokeCommand(first, parts);
if(res == CR_NOT_IMPLEMENTED)
{
con.print("Invalid command.\n");
con.printerr("Invalid command.\n");
clueless_counter ++;
}
else if(res == CR_FAILURE)
{
con.print("ERROR!\n");
con.printerr("ERROR!\n");
}
}
}
@ -234,7 +234,7 @@ bool Core::Init()
p = new DFHack::Process(vif);
if (!p->isIdentified())
{
con.print("Couldn't identify this version of DF.\n");
con.printerr("Couldn't identify this version of DF.\n");
errorstate = true;
delete p;
p = NULL;
@ -246,7 +246,7 @@ bool Core::Init()
AccessMutex = SDL_CreateMutex();
if(!AccessMutex)
{
con.print("Mutex creation failed\n");
con.printerr("Mutex creation failed\n");
errorstate = true;
return false;
}
@ -255,7 +255,7 @@ bool Core::Init()
plug_mgr = new PluginManager(this);
if(!plug_mgr)
{
con.print("Failed to create the Plugin Manager.\n");
con.printerr("Failed to create the Plugin Manager.\n");
errorstate = true;
return false;
}

@ -40,6 +40,8 @@ namespace DFHack
bool shutdown( void );
/// Print a formatted string, like printf
int print(const char * format, ...);
/// Print a formatted string, like printf, in red
int printerr(const char * format, ...);
/// Clear the console, along with its scrollback
void clear();
/// Position cursor at x,y. 1,1 = top left corner

@ -26,7 +26,7 @@ DFhackCExport const char * plugin_name ( void )
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
{
commands.clear();
commands.push_back(PluginCommand("kittens","Rainbow kittens. What else?",kittens));
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens));
commands.push_back(PluginCommand("ktimer","Time events...",ktimer));
return CR_OK;
}
@ -36,7 +36,7 @@ DFhackCExport command_result plugin_shutdown ( Core * c )
shutdown_flag = true;
while(!final_flag)
{
c->con->msleep(60);
c->con.msleep(60);
}
return CR_OK;
}
@ -50,7 +50,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
uint64_t time2 = GetTimeMs64();
uint64_t delta = time2-timeLast;
timeLast = time2;
dfout << "Time delta = " << delta << " ms" << std::endl;
c->con << "Time delta = " << delta << " ms" << std::endl;
}
return CR_OK;
}
@ -66,7 +66,7 @@ DFhackCExport command_result ktimer (Core * c, vector <string> & parameters)
c->Suspend();
c->Resume();
uint64_t timeend = GetTimeMs64();
dfout << "Time to suspend = " << timeend - timestart << " ms" << std::endl;
c->con << "Time to suspend = " << timeend - timestart << " ms" << std::endl;
timeLast = timeend;
timering = true;
return CR_OK;
@ -75,7 +75,28 @@ DFhackCExport command_result ktimer (Core * c, vector <string> & parameters)
DFhackCExport command_result kittens (Core * c, vector <string> & parameters)
{
final_flag = false;
Console * con = c->con;
Console & con = c->con;
// http://evilzone.org/creative-arts/nyan-cat-ascii/
const char * nyan []=
{
"NYAN NYAN NYAN NYAN NYAN NYAN NYAN",
"+ o + o ",
" + o + +",
"o +",
" o + + +",
"+ o o + o",
"-_-_-_-_-_-_-_,------, o ",
"_-_-_-_-_-_-_-| /\\_/\\ ",
"-_-_-_-_-_-_-~|__( ^ .^) + + ",
"_-_-_-_-_-_-_-\"\" \"\" ",
"+ o o + o",
" + +",
"o o o o +",
" o +",
"+ + o o + ",
"NYAN NYAN NYAN NYAN NYAN NYAN NYAN",
0
};
const char * kittenz1 []=
{
" ____",
@ -88,32 +109,32 @@ DFhackCExport command_result kittens (Core * c, vector <string> & parameters)
" '.,,/'.,,mrf",
0
};
con->cursor(false);
con->clear();
con.cursor(false);
con.clear();
int color = 1;
while(1)
{
if(shutdown_flag)
{
final_flag = true;
c->con->reset_color();
dfout << std::endl << "MEOW!" << std::endl << std::flush;
con.reset_color();
con << std::endl << "MEOW!" << std::endl << std::flush;
return CR_OK;
}
con->color(color);
con.color(color);
int index = 0;
const char * kit = kittenz1[index];
con->gotoxy(1,1);
dfout << "Your DF is now full of kittens!" << std::endl;
const char * kit = nyan[index];
con.gotoxy(1,1);
//con << "Your DF is now full of kittens!" << std::endl;
while (kit != 0)
{
con->gotoxy(5,5+index);
dfout << kit;
con.gotoxy(1,1+index);
con << kit;
index++;
kit = kittenz1[index];
kit = nyan[index];
}
dfout.flush();
con->msleep(60);
con.flush();
con.msleep(60);
color ++;
if(color > 15)
color = 1;