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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines