Example #1
0
void UDPTTYRunnable::run(int argc, char ** argv) {
	if (argc < 2) {
		std::cerr << "udp-tty was expecting at least 2 arguments." << std::endl;
		return;
	}
	std::string address(argv[0]);
	unsigned int port;
	std::string portStr(argv[1]);
	std::stringstream ss(portStr);
	ss >> port;
	UDPTTY tty(address, port);
}
Example #2
0
void
MakePrettySymbols( LabData& lab )
    {
    Term::TTY tty( lab.symbuf );

    for( size_t y=0; y < lab.height; ++y )
    for( size_t x=0; x < lab.width; ++x )
        {
        int itile = x + y*lab.width;
        if( lab.walls[ itile ] != IsWall )
            {
            tty.Place(x,y).Put( 176 );
            continue;
            }

        tty.Place(x,y).Put( WallSymbol(lab, itile) );
        }
    }
Example #3
0
int
main( int argc, char* argv[] )
    {
    SDL_Init( SDL_INIT_VIDEO );
    atexit( SDL_Quit );
    atexit( IMG_Quit );

    Term::SDL::Context term( 60, 30 );
    term.Tilemap( "tileset.png" );
    SDL_Surface* screen = SDL_SetVideoMode(
        term.Framebuffer().Width()  * term.TileWidth(),
        term.Framebuffer().Height() * term.TileHeight(),
        32, SDL_SWSURFACE );
    term.RenderTarget( screen );
    term.Framebuffer().ClearChar( Term::Char('\0', 0, BGCOLOR, FONTCOLOR));
    term.Framebuffer().Clear();


    Term::TTY tty(term.Framebuffer());
    tty.Set( Term::TTY::VScroll );
    tty.Set( Term::TTY::Wrap );
    tty.PriColor( BGCOLOR );
    tty.SecColor( FONTCOLOR );

    bool running = true;
    srand (time(NULL));
    while(running)
        {
        SDL_Event event;
        while( SDL_PollEvent(&event) ) switch(event.type)
            {
            case SDL_QUIT:
            case SDL_KEYDOWN:
                running = false; break;
            }

        tty.Put(0x2F + (0x2D * (rand() % 2)));
        term.Print();
        SDL_Flip(screen);
        SDL_Delay(1);
        }
    }
Example #4
0
// Create a separate tty window; return its name in TTYNAME, its
// process id in PID, its terminal type in TERM, and its window id in
// WINDOWID.
static void launch_separate_tty(string& ttyname, pid_t& pid, string& term,
				Window& windowid, Widget origin)
{
    // If we're already running, all is done.
    if (pid > 0 && (remote_gdb() || kill(pid, 0) == 0))
	return;

    string term_command = app_data.term_command;
    term_command.gsub("@FONT@", make_font(app_data, FixedWidthDDDFont));

    static bool canceled;
    canceled = false;

    static Widget dialog = 0;
    if (dialog == 0)
    {
	Arg args[10];
	Cardinal arg = 0;
	XtSetArg(args[arg], XmNdialogStyle, 
		 XmDIALOG_FULL_APPLICATION_MODAL); arg++;
	dialog = verify(XmCreateWorkingDialog(find_shell(origin), 
					      XMST("launch_tty_dialog"), 
					      args, arg));
	XtUnmanageChild(XmMessageBoxGetChild(dialog, 
					     XmDIALOG_OK_BUTTON));
	XtUnmanageChild(XmMessageBoxGetChild(dialog, 
					     XmDIALOG_HELP_BUTTON));
	XtAddCallback(dialog, XmNcancelCallback, CancelTTYCB,
		      XtPointer(&canceled));
    }

    string base = term_command;
    if (base.contains(' '))
	base = base.before(' ');
    MString msg = rm("Starting ") + tt(base) + rm("...");
    XtVaSetValues(dialog, XmNmessageString, msg.xmstring(), XtPointer(0));
    manage_and_raise(dialog);
    wait_until_mapped(dialog);

    StatusDelay delay("Starting execution window");

    // Fill in defaults
    ttyname = "";
    pid     = -1;

    string command = 
	
	// Set up a temporary file in TMP.
	"tmp=${TMPDIR-/tmp}/ddd$$; export tmp; "

	// Be sure to remove it when exiting...
	"trap \"rm -f $tmp\" 0; "

	// ... or being interrupted.
	"trap 'exit 1' 1 2 15; "

	// Now execute the xterm command
	+ term_command +

	// which saves TTY, PID, TERM, and WINDOWID in TMP and goes to
	// sleep forever.  Signal 2 (SIGINT) is blocked for two
	// reasons: first, we don't want ^C to kill the tty window;
	// second, later invocations will send us SIGINT to find out
	// whether we're still alive.
	" '"
	"echo `tty` $$ $TERM $WINDOWID >$tmp; "
	"trap \"\" 2; "
	"while true; do sleep 3600; done"
	"' "

	// The whole thing is redirected and in the background such
	// that rsh won't wait for us.
	">/dev/null </dev/null 2>&1 & "

	// The main file waits for TMP to be created...
	"while test ! -s $tmp; do sleep 1; done; "

	// ...and sends TMP's contents to stdout, where DDD is waiting.
	"cat $tmp";

    if (pid > 0 && remote_gdb())
    {
	// We're already running.  Don't start a new tty
	// if the old one is still running.
	std::ostringstream os;
	os << "kill -2 " << pid << " 2>/dev/null"
	   << " || ( " << command << " )";
	command = string(os);
    }

    command = sh_command(command);

    {
	XtAppContext app_context = XtWidgetToApplicationContext(dialog);
	LiterateAgent tty(app_context, command);

	string reply = "";
	tty.addHandler(Input, GotReplyHP, (void *)&reply);
	tty.start();

	while (!reply.contains('\n') && !canceled && tty.running())
	    XtAppProcessEvent(app_context, XtIMAll);

	if (reply.length() > 2)
	{
	    std::istringstream is(reply.chars());
	    is >> ttyname >> pid >> term >> windowid;
	}

	tty.terminate();
    }
void
generate_texture_atlases(std::vector<TexturePatch::Ptr> * orig_texture_patches,
    Settings const & settings, std::vector<TextureAtlas::Ptr> * texture_atlases) {

    std::list<TexturePatch::ConstPtr> texture_patches;
    while (!orig_texture_patches->empty()) {
        TexturePatch::Ptr texture_patch = orig_texture_patches->back();
        orig_texture_patches->pop_back();

        if (settings.tone_mapping != TONE_MAPPING_NONE) {
            mve::image::gamma_correct(texture_patch->get_image(), 1.0f / 2.2f);
        }

        texture_patches.push_back(texture_patch);
    }

    std::cout << "\tSorting texture patches... " << std::flush;
    /* Improve the bin-packing algorithm efficiency by sorting texture patches
     * in descending order of size. */
    texture_patches.sort(comp);
    std::cout << "done." << std::endl;

    std::size_t const total_num_patches = texture_patches.size();
    std::size_t remaining_patches = texture_patches.size();
    std::ofstream tty("/dev/tty", std::ios_base::out);

    #pragma omp parallel
    {
    #pragma omp single
    {

    while (!texture_patches.empty()) {
        unsigned int texture_size = calculate_texture_size(texture_patches);

        texture_atlases->push_back(TextureAtlas::create(texture_size));
        TextureAtlas::Ptr texture_atlas = texture_atlases->back();

        /* Try to insert each of the texture patches into the texture atlas. */
        std::list<TexturePatch::ConstPtr>::iterator it = texture_patches.begin();
        for (; it != texture_patches.end();) {
            std::size_t done_patches = total_num_patches - remaining_patches;
            int precent = static_cast<float>(done_patches)
                / total_num_patches * 100.0f;
            if (total_num_patches > 100
                && done_patches % (total_num_patches / 100) == 0) {

                tty << "\r\tWorking on atlas " << texture_atlases->size() << " "
                 << precent << "%... " << std::flush;
            }

            if (texture_atlas->insert(*it)) {
                it = texture_patches.erase(it);
                remaining_patches -= 1;
            } else {
                ++it;
            }
        }

        #pragma omp task
        texture_atlas->finalize();
    }

    std::cout << "\r\tWorking on atlas " << texture_atlases->size()
        << " 100%... done." << std::endl;
    util::WallTimer timer;
    std::cout << "\tFinalizing texture atlases... " << std::flush;
    #pragma omp taskwait
    std::cout << "done. (Took: " << timer.get_elapsed_sec() << "s)" << std::endl;

    /* End of single region */
    }
    /* End of parallel region. */
    }
}
Example #6
0
int
main( int argc, char* argv[] )
    {
    srand(time(nullptr));
    LabData lab( 31, 31 );

    // Setup SDL related stuff
    SDL_Init( SDL_INIT_VIDEO );
    atexit( SDL_Quit );
    atexit( IMG_Quit );

    size_t hwin = 17;
    size_t wwin = 16;
    Term::SDL::Context term( wwin, hwin );
    term.Tilemap( "tileset.png" );
    SDL_Surface* screen = SDL_SetVideoMode(
        term.Framebuffer().Width()  * term.TileWidth(),
        term.Framebuffer().Height() * term.TileHeight(),
        32, SDL_SWSURFACE );
    term.RenderTarget( screen );
    Term::Char clearChar('\0');
    clearChar.PriColor( Term::Color::Black );
    clearChar.SecColor( Term::Color::Black );
    term.Framebuffer().ClearChar( clearChar );
    SDL_EnableKeyRepeat( 100, 100 ); // Basically the movementspeed of the player.

    Term::TTY tty( term.Framebuffer() );

    GenerateLabyrinth( lab );
    MakePrettySymbols( lab );

    bool running = true;
    while(running)
        {
        SDL_Event event;
        while( SDL_PollEvent(&event) ) switch( event.type )
            {
            case SDL_QUIT:
                running = false; break;
            case SDL_KEYDOWN: switch( event.key.keysym.sym )
                {
                case SDLK_ESCAPE:
                    running = false; break;
                case SDLK_UP:
                    MovePlayer( lab, 0, -1 ); break;
                case SDLK_DOWN:
                    MovePlayer( lab, 0, 1 ); break;
                case SDLK_LEFT:
                    MovePlayer( lab, -1, 0 ); break;
                case SDLK_RIGHT:
                    MovePlayer( lab, 1, 0 ); break;
                default: break;
                } break;
            }

        if( lab.win )
            {
            std::string winstr( "!!!WIN!!!" );
            int x = rand() % (term.Framebuffer().Width()+winstr.length()) - winstr.length();
            int y = rand() % (term.Framebuffer().Height()+winstr.length()) - winstr.length();
            tty.PriColor( RandomColor() );
            tty.SecColor( RandomColor() );
            tty.Place(x,y).Put( winstr );
            }
        else
            {
            term.Framebuffer().Clear();
            term.Framebuffer().Copy( lab.symbuf, 0, 1,
                -(term.Framebuffer().Width()/2) + lab.xplayer,
                -(term.Framebuffer().Height()/2) + lab.yplayer,
                term.Framebuffer().Width(), term.Framebuffer().Height() );
            tty.Place( term.Framebuffer().Width()/2, term.Framebuffer().Height()/2+1 );
            tty.PriColor( Term::Color::White );
            tty.SecColor( Term::Color::Black );
            tty.Put( 1 );
            for( auto itoken : lab.tokens )
                {
                tty.Place(
                    (itoken % lab.width) +(term.Framebuffer().Width())/2 - lab.xplayer ,
                    (itoken / lab.width) +(term.Framebuffer().Height()/2) - lab.yplayer +1 );
                tty.Put( 9 );
                }
            tty.Place(0,0).PriColor( Term::Color::Black ).SecColor( Term::Color::White );
            if( lab.door == 0 )
                {
                tty.Put( "Tokens left: " );
                std::stringstream ss;
                ss << lab.tokens.size();
                tty.Put( ss.str() );
                }
            else
                {
                tty.Put( "Find the door!" );
                tty.Place(
                    lab.door % lab.width + term.Framebuffer().Width()/2 - lab.xplayer,
                    lab.door / lab.width + term.Framebuffer().Height()/2 + 1 - lab.yplayer );
                tty.Put( 239 );
                }
            }
        term.Print();
        SDL_Flip(screen);
        SDL_Delay(50);
        }
    }