2011-06-19 20:29:38 -06:00
|
|
|
#include <dfhack/Core.h>
|
2011-06-22 00:14:21 -06:00
|
|
|
#include <dfhack/Console.h>
|
2011-06-19 20:29:38 -06:00
|
|
|
#include <dfhack/Export.h>
|
2011-06-24 21:35:29 -06:00
|
|
|
#include <dfhack/PluginManager.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2011-07-11 14:23:13 -06:00
|
|
|
#include "dfhack/extra/stopwatch.h"
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
//FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core.
|
|
|
|
bool shutdown_flag = false;
|
|
|
|
bool final_flag = true;
|
2011-07-11 14:23:13 -06:00
|
|
|
bool timering = false;
|
|
|
|
uint64_t timeLast = 0;
|
2011-06-24 21:35:29 -06:00
|
|
|
|
|
|
|
DFhackCExport command_result kittens (Core * c, vector <string> & parameters);
|
2011-07-11 14:23:13 -06:00
|
|
|
DFhackCExport command_result ktimer (Core * c, vector <string> & parameters);
|
2011-06-19 20:29:38 -06:00
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "kittens";
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
commands.clear();
|
2011-07-14 03:15:23 -06:00
|
|
|
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens));
|
2011-07-11 14:23:13 -06:00
|
|
|
commands.push_back(PluginCommand("ktimer","Time events...",ktimer));
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
shutdown_flag = true;
|
|
|
|
while(!final_flag)
|
|
|
|
{
|
2011-07-14 03:15:23 -06:00
|
|
|
c->con.msleep(60);
|
2011-06-24 21:35:29 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-11 14:23:13 -06:00
|
|
|
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_onupdate ( Core * c )
|
|
|
|
{
|
|
|
|
if(timering == true)
|
|
|
|
{
|
|
|
|
uint64_t time2 = GetTimeMs64();
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
uint64_t delta = time2-timeLast;
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
timeLast = time2;
|
2011-07-15 07:55:01 -06:00
|
|
|
c->con.print("Time delta = %d ms\n", delta);
|
2011-07-11 14:23:13 -06:00
|
|
|
}
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result ktimer (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
if(timering)
|
|
|
|
{
|
|
|
|
timering = false;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
uint64_t timestart = GetTimeMs64();
|
|
|
|
c->Suspend();
|
|
|
|
c->Resume();
|
|
|
|
uint64_t timeend = GetTimeMs64();
|
2011-07-15 07:55:01 -06:00
|
|
|
c->con.print("Time to suspend = %d ms\n",timeend - timestart);
|
2011-07-17 03:06:45 -06:00
|
|
|
// harmless potential data race here...
|
2011-07-11 14:23:13 -06:00
|
|
|
timeLast = timeend;
|
|
|
|
timering = true;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:35:29 -06:00
|
|
|
DFhackCExport command_result kittens (Core * c, vector <string> & parameters)
|
2011-06-19 20:29:38 -06:00
|
|
|
{
|
2011-06-24 21:35:29 -06:00
|
|
|
final_flag = false;
|
2011-07-14 03:15:23 -06:00
|
|
|
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
|
|
|
|
};
|
2011-06-19 20:29:38 -06:00
|
|
|
const char * kittenz1 []=
|
|
|
|
{
|
|
|
|
" ____",
|
|
|
|
" (. \\",
|
|
|
|
" \\ | ",
|
|
|
|
" \\ |___(\\--/)",
|
|
|
|
" __/ ( . . )",
|
|
|
|
" \"'._. '-.O.'",
|
|
|
|
" '-. \\ \"|\\",
|
|
|
|
" '.,,/'.,,mrf",
|
|
|
|
0
|
|
|
|
};
|
2011-07-14 03:15:23 -06:00
|
|
|
con.cursor(false);
|
|
|
|
con.clear();
|
2011-07-15 07:55:01 -06:00
|
|
|
Console::color_value color = Console::COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
while(1)
|
|
|
|
{
|
2011-06-24 21:35:29 -06:00
|
|
|
if(shutdown_flag)
|
|
|
|
{
|
|
|
|
final_flag = true;
|
2011-07-14 03:15:23 -06:00
|
|
|
con.reset_color();
|
2011-07-14 04:21:07 -06:00
|
|
|
con << std::endl << "NYAN!" << std::endl << std::flush;
|
2011-06-24 21:35:29 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2011-07-14 03:15:23 -06:00
|
|
|
con.color(color);
|
2011-06-19 20:29:38 -06:00
|
|
|
int index = 0;
|
2011-07-14 03:15:23 -06:00
|
|
|
const char * kit = nyan[index];
|
|
|
|
con.gotoxy(1,1);
|
|
|
|
//con << "Your DF is now full of kittens!" << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
while (kit != 0)
|
|
|
|
{
|
2011-07-14 03:15:23 -06:00
|
|
|
con.gotoxy(1,1+index);
|
2011-07-15 16:15:20 -06:00
|
|
|
con << kit << std::endl;
|
2011-06-19 20:29:38 -06:00
|
|
|
index++;
|
2011-07-14 03:15:23 -06:00
|
|
|
kit = nyan[index];
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
2011-07-14 03:15:23 -06:00
|
|
|
con.flush();
|
|
|
|
con.msleep(60);
|
2011-07-15 07:55:01 -06:00
|
|
|
((int&)color) ++;
|
|
|
|
if(color > Console::COLOR_MAX)
|
|
|
|
color = Console::COLOR_BLUE;
|
2011-06-19 20:29:38 -06:00
|
|
|
}
|
|
|
|
}
|