ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.199 by root, Mon May 8 15:12:39 2006 UTC vs.
Revision 1.215 by root, Mon May 15 00:15:08 2006 UTC

37use CFClient; 37use CFClient;
38use CFClient::UI; 38use CFClient::UI;
39use CFClient::MapWidget; 39use CFClient::MapWidget;
40 40
41$Event::DIED = sub { 41$Event::DIED = sub {
42 # TODO: display dialog box or so
42 CFClient::error $_[1]; 43 CFClient::error $_[1];
43}; 44};
44 45
45#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d# 46#$SIG{__WARN__} = sub { Carp::cluck $_[0] };#d#
46 47
59our $NOW; 60our $NOW;
60 61
61our $CFG; 62our $CFG;
62our $CONN; 63our $CONN;
63our $FAST; # fast, low-quality mode, possibly useful for software-rendering 64our $FAST; # fast, low-quality mode, possibly useful for software-rendering
65
66our $WANT_REFRESH;
67our $CAN_REFRESH;
64 68
65our @SDL_MODES; 69our @SDL_MODES;
66our $WIDTH; 70our $WIDTH;
67our $HEIGHT; 71our $HEIGHT;
68our $FULLSCREEN; 72our $FULLSCREEN;
90our $SDL_MIXER; 94our $SDL_MIXER;
91our @SOUNDS; # event => file mapping 95our @SOUNDS; # event => file mapping
92our %AUDIO_CHUNKS; # audio files 96our %AUDIO_CHUNKS; # audio files
93 97
94our $ALT_ENTER_MESSAGE; 98our $ALT_ENTER_MESSAGE;
95our $STATUS_LINE; 99our $STATUSBOX;
96our $DEBUG_STATUS; 100our $DEBUG_STATUS;
97 101
98our $INVWIN; 102our $INVWIN;
99our $INV; 103our $INV;
100 104
101sub status { 105sub status {
102 $STATUS_LINE->set_text ($_[0]); 106 $STATUSBOX->add ($_[0], pri => -10, group => "status", timeout => 20, fg => [1, 1, 0, 1]);
103 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
104} 107}
105 108
106sub debug { 109sub debug {
107 $DEBUG_STATUS->set_text ($_[0]); 110 $DEBUG_STATUS->set_text ($_[0]);
108 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 111 my ($w, $h) = $DEBUG_STATUS->size_request;
112 $DEBUG_STATUS->move ($WIDTH - $w, 0);
109} 113}
110 114
111sub start_game { 115sub start_game {
112 $LOGIN_BUTTON->set_text ("Logout");
113
114 status "logging in..."; 116 status "logging in...";
115 117
116 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 118 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
117 119
118 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}"; 120 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
119
120 $MAP = new CFClient::Map $mapsize, $mapsize; 121 $MAP = new CFClient::Map $mapsize, $mapsize;
121 122
122 my ($host, $port) = split /:/, $CFG->{host}; 123 my ($host, $port) = split /:/, $CFG->{host};
123 124
124 $CONN = eval { 125 $CONN = eval {
131 maph => $mapsize, 132 maph => $mapsize,
132 ; 133 ;
133 }; 134 };
134 135
135 if ($CONN) { 136 if ($CONN) {
137 $LOGIN_BUTTON->set_text ("Logout");
138
136 status "login successful"; 139 status "login successful";
137 140
138 CFClient::lowdelay fileno $CONN->{fh}; 141 CFClient::lowdelay fileno $CONN->{fh};
139 } else { 142 } else {
140 status "unable to connect"; 143 status "unable to connect";
141 stop_game(); 144 stop_game();
142 } 145 }
143} 146}
144 147
145sub stop_game { 148sub stop_game {
149 return unless $CONN;
150
146 status "connection closed"; 151 status "connection closed";
147 $LOGIN_BUTTON->set_text ("Login"); 152 $LOGIN_BUTTON->set_text ("Login");
153 $CONN->destroy;
154 $CONN = 0; # false, does not autovivify
155
156 undef $MAPCACHE;
148 undef $CONN; 157 undef $MAP;
149} 158}
150 159
151sub client_setup { 160sub client_setup {
152 my $dialog = new CFClient::UI::FancyFrame 161 my $dialog = new CFClient::UI::FancyFrame
153 title => "Client Setup", 162 title => "Client Setup",
360# local $GAUGES->{win}{parent};#d# 369# local $GAUGES->{win}{parent};#d#
361# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D; 370# use PApp::Util; open D, ">:utf8", "d"; print D PApp::Util::dumpval $GAUGES->{win}; close D;
362} 371}
363 372
364sub make_gauge_window { 373sub make_gauge_window {
365 my $gh = int ($HEIGHT * $CFG->{gauge_size}); 374 my $gh = int $HEIGHT * $CFG->{gauge_size};
366# my $gw = int ($WIDTH * $CFG->{gauge_w_size});
367 375
368 my $win = new CFClient::UI::Frame ( 376 my $win = new CFClient::UI::Frame (
369 y => $HEIGHT - $gh, x => 0, user_w => $WIDTH, user_h => $gh 377 req_y => -1,
378 user_w => $WIDTH,
379 user_h => $gh,
370 ); 380 );
381
371 $win->add (my $hbox = new CFClient::UI::HBox 382 $win->add (my $hbox = new CFClient::UI::HBox
372 children => [ 383 children => [
373 (new CFClient::UI::HBox expand => 1), 384 (new CFClient::UI::HBox expand => 1),
374 ($FLOORBOX = new CFClient::UI::VBox), 385 (new CFClient::UI::VBox children => [
386 (new CFClient::UI::Empty expand => 1),
387 (new CFClient::UI::Frame bg => [0, 0, 0, 0.4], child => ($FLOORBOX = new CFClient::UI::VBox)),
388 ]),
375 (my $vbox = new CFClient::UI::VBox), 389 (my $vbox = new CFClient::UI::VBox),
376 ], 390 ],
377 ); 391 );
378 392
379 $vbox->add (new CFClient::UI::HBox 393 $vbox->add (new CFClient::UI::HBox
689 703
690 $METASERVER = metaserver_dialog; 704 $METASERVER = metaserver_dialog;
691 705
692 $vbox->add (new CFClient::UI::Flopper 706 $vbox->add (new CFClient::UI::Flopper
693 expand => 1, 707 expand => 1,
694 text => "Metaserver", 708 text => "Server List",
695 other => $METASERVER, 709 other => $METASERVER,
696 tooltip => "Show a list of avaible crossfire servers", 710 tooltip => "Show a list of available crossfire servers",
697 connect_open => sub { 711 connect_open => sub {
698 update_metaserver $HOST; 712 update_metaserver $HOST;
699 } 713 }
700 ); 714 );
701 } 715 }
823 837
824 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN 838 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
825 or die "SDL_SetVideoMode failed!\n"; 839 or die "SDL_SetVideoMode failed!\n";
826 840
827 $SDL_ACTIVE = 1; 841 $SDL_ACTIVE = 1;
828
829 $LAST_REFRESH = time - 0.01; 842 $LAST_REFRESH = time - 0.01;
830 843
831 CFClient::gl_init; 844 CFClient::gl_init;
832 845
833 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 846 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
834 847
848 $CFClient::UI::ROOT->configure (0, 0, $WIDTH, $HEIGHT);#d#
849
835 ############################################################################# 850 #############################################################################
836 851
852 unless ($DEBUG_STATUS) {
853 # create the widgets
854
837 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 855 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, req_x => -1;
838 $DEBUG_STATUS->show; 856 $DEBUG_STATUS->show;
839 857
840 $STATUS_LINE = new CFClient::UI::Label 858 $STATUSBOX = new CFClient::UI::Statusbox;
841 padding => 0, 859 $STATUSBOX->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, color => [1, 1, 1, 0.8]);
842 y => $HEIGHT - $FONTSIZE * 1.8;
843 $STATUS_LINE->show;
844 860
845 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 861 (new CFClient::UI::Frame
846 padding => 0, 862 bg => [0, 0, 0, 0.4],
847 fontsize => 0.8, 863 req_y => -1,
848 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 864 child => $STATUSBOX,
849 $ALT_ENTER_MESSAGE->show; 865 )->show;
850 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
851 866
852 CFClient::UI::FancyFrame->new ( 867 CFClient::UI::FancyFrame->new (
853 border_bg => [1, 1, 1, 192/255], 868 border_bg => [1, 1, 1, 192/255],
854 bg => [1, 1, 1, 0], 869 bg => [1, 1, 1, 0],
855 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 870 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
856 )->show; 871 )->show;
857 872
858 $MAPWIDGET = new CFClient::MapWidget; 873 $MAPWIDGET = new CFClient::MapWidget;
859 $MAPWIDGET->connect (activate_console => sub { 874 $MAPWIDGET->connect (activate_console => sub {
860 my ($mapwidget, $preset) = @_; 875 my ($mapwidget, $preset) = @_;
861 876
862 if ($CONSOLE) { 877 if ($CONSOLE) {
863 $CONSOLE->{input}->{auto_activated} = 1; 878 $CONSOLE->{input}->{auto_activated} = 1;
864 $CONSOLE->{input}->focus_in; 879 $CONSOLE->{input}->focus_in;
865 880
866 if ($preset && $CONSOLE->{input}->get_text eq '') { 881 if ($preset && $CONSOLE->{input}->get_text eq '') {
867 $CONSOLE->{input}->set_text ($preset); 882 $CONSOLE->{input}->set_text ($preset);
883 }
868 } 884 }
869 } 885 });
870 });
871 $MAPWIDGET->show; 886 $MAPWIDGET->show;
872 $MAPWIDGET->focus_in; 887 $MAPWIDGET->focus_in;
873 888
874 $BUTTONBAR = new CFClient::UI::HBox; 889 $BUTTONBAR = new CFClient::UI::HBox;
875 890
876 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup); 891 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
877 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup); 892 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
878 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window); 893 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
879 894
880 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D 895 make_gauge_window->show; # XXX: this has to be set before make_stats_window as make_stats_window calls update_stats_window which updated the gauges also X-D
881 896
882 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window); 897 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Stats Window", other => make_stats_window);
883 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window); 898 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Inventory", other => make_inventory_window);
884 899
885 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub { 900 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
886 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc"; 901 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
887 status "Configuration Saved"; 902 status "Configuration Saved";
888 }); 903 });
889 904
890 $BUTTONBAR->show; 905 $BUTTONBAR->show;
891 906
907 $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
908
909 # delay till geometry is constant
910 $CFClient::UI::ROOT->on_post_alloc (startup => sub {
892 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 911 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
912 my $widget = $GAUGES->{win};
913 $widget->move (0, $HEIGHT - $widget->{h});#d# to in toplevel
914 });
915 force_refresh ();
916 }
893} 917}
894 918
895sub video_shutdown { 919sub video_shutdown {
896 $CFClient::UI::ROOT->{children} = [];
897 undef $CFClient::UI::GRAB;
898 undef $CFClient::UI::HOVER;
899 undef $SDL_ACTIVE; 920 undef $SDL_ACTIVE;
900} 921}
901 922
902my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# 923my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
903my $bgmusic;#TODO#hack#d# 924my $bgmusic;#TODO#hack#d#
955} 976}
956 977
957my %animate_object; 978my %animate_object;
958my $animate_timer; 979my $animate_timer;
959 980
960my $want_refresh;
961my $can_refresh;
962
963my $fps = 9; 981my $fps = 9;
964 982
965sub force_refresh { 983sub force_refresh {
966 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 984 $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
967 debug sprintf "%3.2f", $fps; 985 debug sprintf "%3.2f", $fps;
968 986
969 $want_refresh = 0;
970 $can_refresh = 0;
971
972 $CFClient::UI::ROOT->draw; 987 $CFClient::UI::ROOT->draw;
973
974 CFClient::SDL_GL_SwapBuffers; 988 CFClient::SDL_GL_SwapBuffers;
975 989
990 $WANT_REFRESH = 0;
991 $CAN_REFRESH = 0;
976 $LAST_REFRESH = $NOW; 992 $LAST_REFRESH = $NOW;
977} 993}
978 994
979my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 995my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
980 $NOW = time; 996 $NOW = time;
982 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 998 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
983 for CFClient::SDL_PollEvent; 999 for CFClient::SDL_PollEvent;
984 1000
985 if (%animate_object) { 1001 if (%animate_object) {
986 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 1002 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
987 $want_refresh++; 1003 $WANT_REFRESH++;
988 } 1004 }
989 1005
990 if ($want_refresh) { 1006 if ($WANT_REFRESH) {
991 force_refresh; 1007 force_refresh;
992 } else { 1008 } else {
993 $can_refresh = 1; 1009 $CAN_REFRESH = 1;
994 } 1010 }
995}); 1011});
996
997sub refresh {
998 $want_refresh++;
999}
1000 1012
1001sub animation_start { 1013sub animation_start {
1002 my ($widget) = @_; 1014 my ($widget) = @_;
1003 $animate_object{$widget} = $widget; 1015 $animate_object{$widget} = $widget;
1004} 1016}
1316 [0.55, 0.41, 0.13], 1328 [0.55, 0.41, 0.13],
1317 [0.99, 0.77, 0.26], 1329 [0.99, 0.77, 0.26],
1318 [0.74, 0.65, 0.41], 1330 [0.74, 0.65, 0.41],
1319 ); 1331 );
1320 1332
1333 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
1334
1335 $text =~ s/&/&amp;/g; $text =~ s/</&lt;/g;
1336 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
1337 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
1338
1321 $LOGVIEW->add_paragraph ($color[$color], $text); 1339 $LOGVIEW->add_paragraph ($color[$color],
1340 join "\n", map "$time $_", split /\n/, $text);
1341
1342 $STATUSBOX->add ($text,
1343 group => $text,
1344 fg => $color[$color],
1345 timeout => 60,
1346 tooltip_font => $::FONT_FIXED,
1347 );
1348}
1349
1350sub conn::drawextinfo {
1351 my ($self, $color, $type, $subtype, $message) = @_;
1352
1353 $self->drawinfo ($color, $message);
1322} 1354}
1323 1355
1324sub conn::spell_add { 1356sub conn::spell_add {
1325 my ($self, $spell) = @_; 1357 my ($self, $spell) = @_;
1326 1358
1339 1371
1340 for my $skill (values %{$self->{skill_info}}) { 1372 for my $skill (values %{$self->{skill_info}}) {
1341 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'"); 1373 $MAPWIDGET->add_command ("ready_skill $skill", "Ready the skill '$skill'");
1342 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'"); 1374 $MAPWIDGET->add_command ("use_skill $skill", "Immediately use the skill '$skill'");
1343 } 1375 }
1376
1377 $MAPWIDGET->add_command ("pet\\_mode defend", "Tell pets to stay close to you and defend you");
1378 $MAPWIDGET->add_command ("pet\\_mode arena", "Same as petmode attack, but also attack other players");
1379 $MAPWIDGET->add_command ("pet\\_mode sad", "Search &amp; Destroy - tell pets to roam about and attack enemies");
1380 $MAPWIDGET->add_command ("kill\\_pets", "kill your pets");
1381}
1382
1383sub conn::eof {
1384 stop_game;
1344} 1385}
1345 1386
1346sub update_floorbox { 1387sub update_floorbox {
1347 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub { 1388 $CFClient::UI::ROOT->on_refresh ($FLOORBOX => sub {
1389 return unless $CONN;
1390
1348 $FLOORBOX->clear; 1391 $FLOORBOX->clear;
1349 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1392 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1350 1393
1351 # we basically have to use the same sorting as everybody else 1394 my $count = 4;
1352 for my $item (@{ $CONN->{container}{0} }) { 1395 for (@{ $CONN->{container}{0} }) {
1396 if (--$count) {
1353 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1397 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1398 } else {
1399 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
1400 last;
1401 }
1354 } 1402 }
1355 }); 1403 });
1356 refresh; 1404
1405 $WANT_REFRESH++;
1357} 1406}
1358 1407
1359sub conn::container_add { 1408sub conn::container_add {
1360 my ($self, $id, $items) = @_; 1409 my ($self, $tag, $items) = @_;
1361 1410
1362 update_floorbox if $id == 0; 1411 update_floorbox if $tag == 0;
1363 if ($self->{player}{tag} == $id) { 1412
1364 $INV->set_items ($self->{container}{$self->{player}{tag}}); 1413 $INV->set_items ($self->{container}{$self->{player}{tag}})
1365 } 1414 if $tag == $self->{player}{tag};
1415
1366 # $self-<{player}{tag} => player inv 1416 # $self-<{player}{tag} => player inv
1367 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}}; 1417 #use PApp::Util; warn PApp::Util::dumpval $self->{container}{$self->{player}{tag}};
1368} 1418}
1369 1419
1370sub conn::container_clear { 1420sub conn::container_clear {
1371 my ($self, $id) = @_; 1421 my ($self, $tag) = @_;
1372 1422
1373 update_floorbox if $id == 0; 1423 update_floorbox if $tag == 0;
1374 if ($self->{player}{tag} == $id) { 1424
1375 $INV->set_items ($self->{container}{$id}); 1425 $INV->set_items ($self->{container}{$tag})
1376 } 1426 if $tag == $self->{player}{tag};
1377 1427
1378# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0}; 1428# use PApp::Util; warn PApp::Util::dumpval $self->{container}{0};
1379} 1429}
1380 1430
1381sub conn::item_delete { 1431sub conn::item_delete {
1382 my ($self, @items) = @_; 1432 my ($self, @items) = @_;
1383 1433
1384 for (@items) { 1434 for (@items) {
1385 update_floorbox if $_->{container} == 0; 1435 update_floorbox if $_->{container} == 0;
1386 if ($self->{player}{tag} == $_->{container}) { 1436
1387 $INV->set_items ($self->{container}{$_->{container}}); 1437 $INV->set_items ($self->{container}{$_->{container}})
1388 } 1438 if $_->{container} == $self->{player}{tag};
1389 } 1439 }
1390} 1440}
1391 1441
1392sub conn::item_update { 1442sub conn::item_update {
1393 my ($self, $item) = @_; 1443 my ($self, $item) = @_;
1394 1444
1395 update_floorbox if $item->{container} == 0; 1445 update_floorbox if $item->{container} == 0;
1396 if ($self->{player}{tag} == $item->{container}) { 1446
1397 $INV->set_items ($self->{container}{$item->{container}}); 1447 $INV->set_items ($self->{container}{$item->{container}})
1398 } 1448 if $item->{container} == $self->{player}{tag};
1399} 1449}
1400 1450
1401%SDL_CB = ( 1451%SDL_CB = (
1402 CFClient::SDL_QUIT => sub { 1452 CFClient::SDL_QUIT => sub {
1403 Event::unloop -1; 1453 Event::unloop -1;
1404 }, 1454 },
1405 CFClient::SDL_VIDEORESIZE => sub { 1455 CFClient::SDL_VIDEORESIZE => sub {
1406 }, 1456 },
1407 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1457 CFClient::SDL_VIDEOEXPOSE => sub {
1458 $WANT_REFRESH++;
1459 },
1408 CFClient::SDL_ACTIVEEVENT => sub { 1460 CFClient::SDL_ACTIVEEVENT => sub {
1409# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1461# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1410 }, 1462 },
1411 CFClient::SDL_KEYDOWN => sub { 1463 CFClient::SDL_KEYDOWN => sub {
1412 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1464 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1433 1485
1434############################################################################# 1486#############################################################################
1435 1487
1436$SIG{INT} = $SIG{TERM} = sub { exit }; 1488$SIG{INT} = $SIG{TERM} = sub { exit };
1437 1489
1438CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1439
1440$TILECACHE = CFClient::db_table "tilecache";
1441$FACEMAP = CFClient::db_table "facemap";
1442
1443my %DEF_CFG = (
1444 sdl_mode => 0,
1445 width => 640,
1446 height => 480,
1447 fullscreen => 0,
1448 fast => 0,
1449 map_scale => 0.5,
1450 fow_enable => 1,
1451 fow_intensity => 0.45,
1452 fow_smooth => 0,
1453 gui_fontsize => 1,
1454 log_fontsize => 1,
1455 gauge_fontsize => 1,
1456 gauge_size => 0.35,
1457 stat_fontsize => 1,
1458 mapsize => 100,
1459 host => "crossfire.schmorp.de",
1460 say_command => 'say',
1461 audio_enable => 1,
1462 bgm_enable => 1,
1463 bgm_volume => 0.25,
1464);
1465
1466while (my ($k, $v) = each %DEF_CFG) {
1467 $CFG->{$k} = $v unless exists $CFG->{$k};
1468}
1469
1470sdl_init;
1471
1472@SDL_MODES = reverse
1473 grep $_->[0] >= 640 && $_->[1] >= 480,
1474 CFClient::SDL_ListModes;
1475
1476@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1477
1478$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1479
1480{ 1490{
1491 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1492
1493 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1494
1495 $TILECACHE = CFClient::db_table "tilecache";
1496 $FACEMAP = CFClient::db_table "facemap";
1497
1498 my %DEF_CFG = (
1499 sdl_mode => 0,
1500 width => 640,
1501 height => 480,
1502 fullscreen => 0,
1503 fast => 0,
1504 map_scale => 0.5,
1505 fow_enable => 1,
1506 fow_intensity => 0.45,
1507 fow_smooth => 0,
1508 gui_fontsize => 1,
1509 log_fontsize => 1,
1510 gauge_fontsize=> 1,
1511 gauge_size => 0.35,
1512 stat_fontsize => 1,
1513 mapsize => 100,
1514 host => "crossfire.schmorp.de",
1515 say_command => 'say',
1516 audio_enable => 1,
1517 bgm_enable => 1,
1518 bgm_volume => 0.25,
1519 );
1520
1521 while (my ($k, $v) = each %DEF_CFG) {
1522 $CFG->{$k} = $v unless exists $CFG->{$k};
1523 }
1524
1525 sdl_init;
1526
1527 @SDL_MODES = reverse
1528 grep $_->[0] >= 640 && $_->[1] >= 480,
1529 CFClient::SDL_ListModes;
1530
1531 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1532
1533 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1534
1535 {
1481 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1536 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1482 DejaVuSans.ttf 1537 DejaVuSans.ttf
1483 DejaVuSansMono.ttf 1538 DejaVuSansMono.ttf
1484 DejaVuSans-Bold.ttf 1539 DejaVuSans-Bold.ttf
1485 DejaVuSansMono-Bold.ttf 1540 DejaVuSansMono-Bold.ttf
1486 DejaVuSans-Oblique.ttf 1541 DejaVuSans-Oblique.ttf
1487 DejaVuSansMono-Oblique.ttf 1542 DejaVuSansMono-Oblique.ttf
1488 DejaVuSans-BoldOblique.ttf 1543 DejaVuSans-BoldOblique.ttf
1489 DejaVuSansMono-BoldOblique.ttf 1544 DejaVuSansMono-BoldOblique.ttf
1490 ); 1545 );
1491 1546
1492 CFClient::add_font $_ for @fonts; 1547 CFClient::add_font $_ for @fonts;
1493 1548
1549 CFClient::pango_init;
1550
1494 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1551 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1495 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1552 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1496 1553
1497 $FONT_PROP->make_default; 1554 $FONT_PROP->make_default;
1498} 1555 }
1499 1556
1500video_init; 1557 video_init;
1501audio_init; 1558 audio_init;
1559}
1502 1560
1503Event::loop; 1561Event::loop;
1504 1562
1505END { CFClient::SDL_Quit } 1563END { CFClient::SDL_Quit }
1506 1564

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines