Anunţ

Caută printre mesajele de pe forum înainte de a scrie unul nou!
Formulează corect întrebarea sau problema pe care o ai.
Respectă regulile forumului și Codul de Conduită!
  • Index
  •  » Jocuri
  •  » Un mod foarte bun de a juca jocuri fullscreen

#1 13 Jul 2011 10:19:37

nkn
Membru
Locaţie: Pitesti
Înregistrat: 17 Jul 2009
Mesaje: 466
Site web

Un mod foarte bun de a juca jocuri fullscreen

cum unii stiti, poate altii nu, la majoritatea jocurilor este imposibil sa dai minimize daca este fullscreen. urmatorul script porneste jocul intr-un nou server x. desktop-ul se afla pe CTRL+ALT+F7 iar jocul pe urmatorul adica CTRL+ALT+F8. daca sunt deschise mai multe jocuri, acestea se vor deschide in urmatorul server x fata de cel precedent. pe langa posibilitatea de a da minimize este posibil si jocul sa functioneze mult mai bine (eu am castigat pana la 10 fps in unele jocuri)

din terminal

Cod:

sudo gedit

copiem urmatorul text

Cod:

#!/usr/bin/perl -w
# Script to run games on a separate X session

# Here we dump the script in a huge while loop to keep it running
while (!$quit){
&list;

# Here we look at the given script parameters    
if ($ARGV[0]){
    $switch = $ARGV[0];
} else {
    $switch = "-";
}

if ($switch =~/-[nN]/){
    if (!$ARGV[1] || $ARGV[1] !~/^\d+$/ || $ARGV[1] > @list || $ARGV[1] < 1){
        print ("Invalid number, terminating...\n");
    } else {
        $cmdoption = 1 if $ARGV[2] && $ARGV[2]=~/-c/;
        chomp ($input = $ARGV[1]);
        &checkbin;
    }
    $quit = 1;
} elsif ($switch =~/--help/){
    &help;
    $quit = 1;
} elsif ($switch =~/--add/){
    &gamelist;
    &addition;
    &gamelist;
    $quit = 1;
} elsif ($switch =~/--del/){
    if (@list < 1) {
        print("No games to delete!\n");
    } else {
        &gamelist;
        &delete;
        &gamelist;
    }
    $quit = 1;
} elsif ($switch =~/--edit/){
    if (@list < 1){
        print("No games to edit!\n");
    } else {
        &gamelist;
        &edit;
        &gamelist;
    }
    $quit = 1;
} elsif ($switch =~/--prefs/){
        &preferences;
        $quit = 1;
} elsif ($switch =~/--list/){
    if (@list < 1){
        print("No games to list!\n");
    } else {
        &gamelist;
    }
    $quit = 1;
} elsif ($switch =~/--move/){
    if (@list < 2){
        print("Not enough games to move!\n");
    } else {
        &gamelist;
        &move;
        &gamelist;
    }
    $quit = 1;
} elsif ($switch =~/-d/){
    ($input = (split/\t/,$options[3])[1]) =~s/\n//;
    if ($input !~/^\d+$/ || $input > @list || $input < 1){
        print ("Invalid default game, terminating...\n");
    } else {
        if ($ARGV[1] && $ARGV[1]=~/-c/){
            $cmdoption = 1;
            splice @ARGV, 1, 0, "";
        }
        &checkbin;
    }
    $quit = 1;
} else {
    &gamelist;
    &options;
    &input;
}
}

# Writing out the list when Xgame stops
write_out($gamelist, @list, @options);

# Here come the subroutines
sub input {
    while(!$valid) {
        print ("Please choose your desired game or option: ");
        chomp ($input = <stdin>);
        $input = lc($input);
        $valid = 1;
        if ($input =~ /^\D$/){
            if ($input eq "a"){
                undef $valid;
                &addition;
                &gamelist;
                &options;
            } elsif ($input eq "p"){
                undef $valid;
                &preferences;
                &gamelist;
                &options;
            } elsif ($input eq "d" && @list > 0){
                undef $valid;
                &delete;
                &gamelist;
                &options;
            } elsif ($input eq "e" && @list > 0){
                undef $valid;
                &edit;
                &gamelist;
                &options;
            } elsif ($input eq "m" && @list > 1){
                undef $valid;
                &move;
                &gamelist;
                &options;
            } elsif ($input eq "q"){
                print ("Goodbye!\n");
                $quit = 1;
            } else {
                undef $valid;
                print ("Option not available!\n");
            }
        } else {
            if ($input !~/^\d+$/ || $input > @list || $input < 1){
                undef $valid;
                print ("Invalid number/option!\n");
            } else {
                &checkbin;
            }
        }
    }
}

sub list {
    # Checking if the gamelist exists
    $gamelist = "$ENV{HOME}/.xgamelist";
    write_out($gamelist, "") if !-f "$gamelist";
        
    # Here we grab the list of games
    @list = grep {!/^\s*$/} cat($gamelist);
    if (grep (/\[options\]/, @list)){
        for (0 .. 3){
            unshift @options, (pop @list);
        }
    } else {
        @options = ("[options]\t\n", "xconfig\t\n", "xinitops\t\n", "default\t\n");
    }
}

sub gamelist {
    system "clear";
    # Here we process that gamelist then display it
    print "\t-=<Your Games>=-\n\n";
    $number = 1;
    foreach (@list){
        /(.*?)\t/;
        print "[" . $number++ . "]\t$1\n";
    }
    print "\n";
}

sub checkbin {
    # And this is where we process the choice
    @choice = split/\t/,$list[--$input];

    # Here we make sure the exe is correct and fire up if so
    @exe = split/\s+/,$choice[1];
    chomp $exe[0];
    if ($exe[0] =~/\//){
        chomp ($executable = qx|echo $exe[0]|);
        if (-f "$executable"){
            &startgame;
        } else {
            undef $valid; 
            die ("Invalid executable!\n");
        }
    } elsif (qx|which $exe[0] 2>&1| =~/which\: no $exe[0] in/){
        undef $valid;
        die ("Invalid executable!\n");
    } else {
        &startgame;
    }
}

sub startgame {
    print ("Starting $choice[0]...\n");

    # Checking for another instance of xgame
    chomp ($xinit = (qx|ls ~/.xinitrc.* 2>&1|)[0]);
    $xinit = "$ENV{HOME}/.xinitrc" if $xinit !~ /\.xinitrc\.\w{6,6}/;

    # Backing up existing .xinitrc to random temp file
    chomp ($tmpxinit = qx|mktemp ~/.xinitrc.XXXXXXX|);
    if (-f $xinit){
        write_out($tmpxinit, cat($xinit));
    } else {
        write_out($tmpxinit, "");
    }
    # Creating new .xinitrc from input and defined options
    if ($cmdoption){
        undef $cmdoption;
        for (0, 0, 0){
            splice @ARGV, $_, 1;
        }
        $choice[1] =~s/^(.*)$/$1 @ARGV/;
    }
    chomp ($choice = $choice[1]);
    
    # The new .xinitrc get's written
    ($xinitopts = (split/\t/,$options[2])[1]) =~s/\n//;
    write_out("$ENV{HOME}/.xinitrc", "$xinitopts\n", "exec ck-launch-session $choice");

    # Now we fire up the X server with the specified game
    if ((qx|ls /tmp/.X*lock 2>&1|)[-1] =~ /(\d+)/){
        ($xnumber = $1)++;
    } else {
        $xnumber = 0;
    }
    ($xconfig = (split/\t/,$options[1])[1]) =~s/\n//;
    $xconfig =~s/(.*)/-xf86config $1/ if $xconfig ne "";
    
    system "startx -- :$xnumber $xconfig";

    # Placing the backup back to where it belongs
    unlink $xinit;
    if (cat($tmpxinit) ne ""){
        rename ($tmpxinit, "$ENV{HOME}/.xinitrc") or die "Error moving file: $!\n";
    } else {
        unlink $tmpxinit;
    }
    $quit = 1;
}

sub help {
    print ("Usage: xgame [OPTION] <enter> or: xgame <enter>\n");
    print ("Options:\n\t-d,\t\t use the specified default game\n");
    print ("\t-n,\t\t instantly run the choosen game (-n <number>)\n");
    print ("\t-n/-d <> -c <>,\t run the chosen/default game with commandline arguments (-c <commandline args>)\n");
    print ("\t--add,\t\t add a game to the gamelist\n");
    print ("\t--del,\t\t delete a game from the gamelist\n");
    print ("\t--edit,\t\t edit a game on the gamelist\n");
    print ("\t--move,\t\t move a game on the gamelist\n");
    print ("\t--list,\t\t display the gamelist\n");
    print ("\t--prefs,\t change the preferences\n");
    print ("\t--help,\t\t this message\n");
    print ("Gamelist specific:\n");
    print ("\tThe gamelist is located at ~/.xgamelist.\n");
    print ("\tIt must be edited and maitained at all times through Xgame.\n");
    print ("\tNot doing this could result in failure!\n");
}

sub options {
    print "\t-=<Options>=-\n\n[A]\tAdd a game to the gamelist\n";
    print "[D]\tDelete a game from the gamelist\n[E]\tEdit a game on the gamelist\n" if @list > "0";
    print "[M]\tMove a game on the gamelist\n" if @list > "1";
    print "[P]\tXgame Preferences\n[Q]\tQuit\n\n";
}

sub preferences {
    while(!$pref_done){
        ($xconfig = (split/\t/,$options[1])[1]) =~s/\n//;
        ($xinitopts = (split/\t/,$options[2])[1]) =~s/\n//;
        ($input = (split/\t/,$options[3])[1]) =~s/\n//;
        system "clear";
        print "\t-=<Preferences>=-\n\n";
        print "[1]\tX server config file is \"$xconfig\"\n";
        print "[2]\tExtra startcommand on game launch \"$xinitopts\"\n";
        print "[3]\tDefault game specified by it's number \"$input\"\n";
        print "[S]\tSort the gamelist alphabetically\n";
        print "[Q]\tExit these preferences\n\n";
        print "Please choose your desired preference: ";
        chomp ($pref_input = <stdin>);
        $pref_input = lc($pref_input);
        $pref_done = 1;
        if ($pref_input =~ /(1)/ || $pref_input =~ /(2)/ || $pref_input =~ /(3)/){
            @_ = ("", "Please give the new X config file \(example: xorg.conf\) or hit <enter> to leave empty: ", "Please specify the extra startcommand on game launch or hit <enter> to leave empty: ", "Please specify the default game or hit <enter> to leave empty: ");
            print $_[$1];
            chomp ($newpref = <stdin>);
            $options[$1] =~s/(.*?\t).*/$1$newpref/;
            undef $pref_done;
        } elsif ($pref_input eq "s"){
            @list = sort {uc($a) cmp uc($b)} @list;
            undef $pref_done;
        } elsif ($pref_input ne "q"){
            undef $pref_done;
        }
    }
    undef $pref_done;
}

sub addition {
    # this is where we add games to the list
    print ("Please give the name of the game you'd like to add: ");
    chomp ($game = <stdin>);
    print ("Please give the command related to the game: ");
    chomp ($bin = <stdin>);
    
    # here the game get's added
    push (@list, "$game\t$bin\n");
}

sub delete {
    # Here we check which game the user wants deleted
    print "Please choose the game you'd like to delete: ";
    chomp ($del = <stdin>);
    while ($del !~/^\d+$/ || $del > @list || $del < 1){
        print "Invalid number, please choose again: ";
        chomp ($del = <stdin>);
    }
    
    # Here we create a new list without the choosen game
    splice @list, --$del, 1;
}

sub move {
    # First we ask which game has to be moved
    print "Please choose the game you'd like to move: ";
    chomp ($move = <stdin>);
    while ($move !~/^\d+$/ || $move > @list || $move < 1){
        print "Invalid number, please choose again: ";
        chomp ($move = <stdin>);
    }
    
    # Then we ask the destination for the game
    print "Please choose the destination: ";
    chomp ($destin = <stdin>);
    while ($destin !~/^\d+$/ || $destin > @list || $destin < 1){
        print "Invalid number, please choose again: ";
        chomp ($destin = <stdin>);
    }
    
    #Here we write the new gamelist
    $moving = $list[--$move];
    splice @list, $move, 1;
    splice @list, --$destin, 0, $moving;
}

sub edit {
    # First we ask which game has to be edited
    print "Please choose the game you'd like to edit: ";
    chomp ($edit = <stdin>);
    while ($edit !~/^\d+$/ || $edit > @list || $edit < 1){
        print "Invalid number, please choose again: ";
        chomp ($edit = <stdin>);
    }
    @display = split/\t/,$list[--$edit];
    chomp $display[1];
    print "You choose to edit: \"$display[0]\" with command: \"$display[1]\"\n";
    
    # Here we grab the name to be used
    print "Please give the new name or hit enter to use the existing one: ";
    $name = <stdin>;
    $name = $display[0] if $name eq "\n";
    chomp $name;
    
    # Here we grab the command to be used
    print "Please give the new command or hit enter to use the existing one: ";
    $command = <stdin>;
    $command = $display[1] if $command eq "\n";
    chomp $command;
    
    # Now onto changing the entry in the gamelist
    $list[$edit] = "$name\t$command\n";
}

sub cat {
    open MYFILE, $_[0] or die "$!";
    @_ = <MYFILE>; 
    close MYFILE; 
    return (wantarray) ? @_ : join("",  @_);
}

sub write_out {
    $_ = shift @_;
    open WRITE, ">", $_ or die "Error writing '$_': $!\n";
    print WRITE @_;
    close WRITE;
}

salvam in  /usr/bin/xgame
din nou din terminal

Cod:

sudo chmod +x /usr/bin/xgame

editam /etc/X11/Xwrapper.config

Cod:

sudo gedit /etc/X11/Xwrapper.config

si setam allowed_users=anybody
sau

Cod:

sudo dpkg-reconfigure x11-common

si selectam anybody

apoi deschidem aplicatia cu "xgame" din terminal
aici adaugam jocuri, editam locatia si numele lor din lista, etc
pentru a adauga un joc in meniu care sa fie deschis intr-un nou server x, doar adaugati jocul in xgame iar in meniu la comanda scrieti "xgame -n #" (fara ghilimele iar # este numarul jocului din lista din xgame)
daca deschideti jocul din terminal din xgame, nu uitati sa inchideti jocul mai intai si nu terminalul

daca apare eroarea "Error writing '/home/USER/.xinitrc': Permission denied" scrieti in terminal

Cod:

sudo chown USER ~/.xinitrc

pentru cei care au probleme cu sunetul, instalati pulseaudio, deschideti un joc si schimbati pe desktop, deschideti PulseAudio Volume Control ( pavucontrol ) si jucati-va cu setarile

Editat ultima oară de nkn (16 Jul 2011 23:53:27)

Offline

 

#2 18 Jul 2011 11:50:18

pop.horea
Membru
Locaţie: Turda jud. Cluj
Înregistrat: 18 Apr 2010
Mesaje: 548

Re: Un mod foarte bun de a juca jocuri fullscreen

Am reușit să fac până la ultimul cod.
Aparent pare că începe să ruleze jocul openarena dar apoi se închide terminalul cu xgame și iasă din joc sau din ce e.


Open source are viitorul cel mai bun în puncte.

Offline

 

#3 18 Jul 2011 12:21:54

nkn
Membru
Locaţie: Pitesti
Înregistrat: 17 Jul 2009
Mesaje: 466
Site web

Re: Un mod foarte bun de a juca jocuri fullscreen

deschide terminalul si de acolo ruleaza xgame, ce eroare da? si asigura-te ca comanda de pornire a jocului e corecta

Offline

 

#4 18 Jul 2011 13:22:49

pop.horea
Membru
Locaţie: Turda jud. Cluj
Înregistrat: 18 Apr 2010
Mesaje: 548

Re: Un mod foarte bun de a juca jocuri fullscreen

În terminal am rulat xgame.
Nu pot vedea ce eroare dă deoarece se închide prea repede terminalul.
Comanda i-am dat [1]


Open source are viitorul cel mai bun în puncte.

Offline

 

#5 18 Jul 2011 13:46:45

nkn
Membru
Locaţie: Pitesti
Înregistrat: 17 Jul 2009
Mesaje: 466
Site web

Re: Un mod foarte bun de a juca jocuri fullscreen

daca la comanda de la openarena scrii /usr/games/openarena merge? alte jocuri merg?

Offline

 
Feed
  • Index
  •  » Jocuri
  •  » Un mod foarte bun de a juca jocuri fullscreen

Antet forum

Powered by FluxBB