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.203 by root, Mon May 8 20:55:49 2006 UTC vs.
Revision 1.210 by root, Fri May 12 01:47:04 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;
97 101
98our $INVWIN; 102our $INVWIN;
99our $INV; 103our $INV;
100 104
101sub status { 105sub status {
102 $STATUS_LINE->set_text ($_[0]); 106 $STATUS_LINE->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_refresh ($STATUS_LINE => sub {
108 $STATUS_LINE->move (0, $HEIGHT - $STATUS_LINE->{h});#d# to in toplevel
109 });
104} 110}
105 111
106sub debug { 112sub debug {
107 $DEBUG_STATUS->set_text ($_[0]); 113 $DEBUG_STATUS->set_text ($_[0]);
108 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h}); 114 my ($w, $h) = $DEBUG_STATUS->size_request;
115 $DEBUG_STATUS->move ($WIDTH - $w, 0);
109} 116}
110 117
111sub start_game { 118sub start_game {
112 status "logging in..."; 119 status "logging in...";
113 120
845 $CFClient::UI::ROOT->reconfigure; 852 $CFClient::UI::ROOT->reconfigure;
846 853
847 } else { 854 } else {
848 # create the widgets 855 # create the widgets
849 856
850 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 857 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d#
851 $DEBUG_STATUS->show; 858 $DEBUG_STATUS->show;
852 859
853 $STATUS_LINE = new CFClient::UI::Label 860 $STATUS_LINE = new CFClient::UI::Statusbox;
854 padding => 0, 861 $STATUS_LINE->add ("Use <b>Alt-Enter</b> to toggle fullscreen mode", pri => -100, size => 0.8, color => [1, 1, 1, 0.8]);
855 y => $HEIGHT - $FONTSIZE * 1.8;
856 $STATUS_LINE->show; 862 $STATUS_LINE->show;
857
858 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
859 padding => 0,
860 fontsize => 0.8,
861 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
862 $ALT_ENTER_MESSAGE->show;
863 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
864 863
865 CFClient::UI::FancyFrame->new ( 864 CFClient::UI::FancyFrame->new (
866 border_bg => [1, 1, 1, 192/255], 865 border_bg => [1, 1, 1, 192/255],
867 bg => [1, 1, 1, 0], 866 bg => [1, 1, 1, 0],
868 child => ($MAPMAP = new CFClient::MapWidget::MapMap), 867 child => ($MAPMAP = new CFClient::MapWidget::MapMap),
900 status "Configuration Saved"; 899 status "Configuration Saved";
901 }); 900 });
902 901
903 $BUTTONBAR->show; 902 $BUTTONBAR->show;
904 903
904 # delay till geometry is constant
905 $CFClient::UI::ROOT->on_refresh (startup => sub {
905 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 906 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
907 });
908 force_refresh ();
906 } 909 }
907} 910}
908 911
909sub video_shutdown { 912sub video_shutdown {
910 undef $SDL_ACTIVE; 913 undef $SDL_ACTIVE;
966} 969}
967 970
968my %animate_object; 971my %animate_object;
969my $animate_timer; 972my $animate_timer;
970 973
971my $want_refresh;
972my $can_refresh;
973
974my $fps = 9; 974my $fps = 9;
975 975
976sub force_refresh { 976sub force_refresh {
977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
978 debug sprintf "%3.2f", $fps; 978 debug sprintf "%3.2f", $fps;
979 979
980 $want_refresh = 0;
981 $can_refresh = 0;
982
983 $CFClient::UI::ROOT->draw; 980 $CFClient::UI::ROOT->draw;
984
985 CFClient::SDL_GL_SwapBuffers; 981 CFClient::SDL_GL_SwapBuffers;
986 982
983 $WANT_REFRESH = 0;
984 $CAN_REFRESH = 0;
987 $LAST_REFRESH = $NOW; 985 $LAST_REFRESH = $NOW;
988} 986}
989 987
990my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 988my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
991 $NOW = time; 989 $NOW = time;
993 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 991 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
994 for CFClient::SDL_PollEvent; 992 for CFClient::SDL_PollEvent;
995 993
996 if (%animate_object) { 994 if (%animate_object) {
997 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 995 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
998 $want_refresh++; 996 $WANT_REFRESH++;
999 } 997 }
1000 998
1001 if ($want_refresh) { 999 if ($WANT_REFRESH) {
1002 force_refresh; 1000 force_refresh;
1003 } else { 1001 } else {
1004 $can_refresh = 1; 1002 $CAN_REFRESH = 1;
1005 } 1003 }
1006}); 1004});
1007
1008sub refresh {
1009 $want_refresh++;
1010}
1011 1005
1012sub animation_start { 1006sub animation_start {
1013 my ($widget) = @_; 1007 my ($widget) = @_;
1014 $animate_object{$widget} = $widget; 1008 $animate_object{$widget} = $widget;
1015} 1009}
1327 [0.55, 0.41, 0.13], 1321 [0.55, 0.41, 0.13],
1328 [0.99, 0.77, 0.26], 1322 [0.99, 0.77, 0.26],
1329 [0.74, 0.65, 0.41], 1323 [0.74, 0.65, 0.41],
1330 ); 1324 );
1331 1325
1326 my $time = sprintf "%02d:%02d:%02d", (localtime time)[2,1,0];
1327
1328 $text =~ s/&/&amp;/g; $text =~ s/</&lt;/g;
1329 $text =~ s/\[b\](.*?)\[\/b\]/<b>\1<\/b>/g;
1330 $text =~ s/\[color=(.*?)\](.*?)\[\/color\]/<span foreground='\1'>\2<\/span>/g;
1331
1332 $LOGVIEW->add_paragraph ($color[$color], $text); 1332 $LOGVIEW->add_paragraph ($color[$color],
1333 join "\n", map "$time $_", split /\n/, $text);
1334 $STATUS_LINE->add ($text, color => $color[$color], timeout => 60);
1335}
1336
1337sub conn::drawextinfo {
1338 my ($self, $color, $type, $subtype, $message) = @_;
1339
1340 $self->drawinfo ($color, $message);
1333} 1341}
1334 1342
1335sub conn::spell_add { 1343sub conn::spell_add {
1336 my ($self, $spell) = @_; 1344 my ($self, $spell) = @_;
1337 1345
1368 return unless $CONN; 1376 return unless $CONN;
1369 1377
1370 $FLOORBOX->clear; 1378 $FLOORBOX->clear;
1371 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1379 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1372 1380
1373 # we basically have to use the same sorting as everybody else 1381 my $count = 4;
1374 for my $item (@{ $CONN->{container}{0} }) { 1382 for (@{ $CONN->{container}{0} }) {
1383 if (--$count) {
1375 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1384 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $_);
1385 } else {
1386 $FLOORBOX->add (new CFClient::UI::Label text => "More...");
1387 last;
1388 }
1376 } 1389 }
1377 }); 1390 });
1378 refresh; 1391
1392 $WANT_REFRESH++;
1379} 1393}
1380 1394
1381sub conn::container_add { 1395sub conn::container_add {
1382 my ($self, $tag, $items) = @_; 1396 my ($self, $tag, $items) = @_;
1383 1397
1416 my ($self, $item) = @_; 1430 my ($self, $item) = @_;
1417 1431
1418 update_floorbox if $item->{container} == 0; 1432 update_floorbox if $item->{container} == 0;
1419 1433
1420 $INV->set_items ($self->{container}{$item->{container}}) 1434 $INV->set_items ($self->{container}{$item->{container}})
1421 if $item->{container}; == $self->{player}{tag}; 1435 if $item->{container} == $self->{player}{tag};
1422} 1436}
1423 1437
1424%SDL_CB = ( 1438%SDL_CB = (
1425 CFClient::SDL_QUIT => sub { 1439 CFClient::SDL_QUIT => sub {
1426 Event::unloop -1; 1440 Event::unloop -1;
1427 }, 1441 },
1428 CFClient::SDL_VIDEORESIZE => sub { 1442 CFClient::SDL_VIDEORESIZE => sub {
1429 }, 1443 },
1430 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1444 CFClient::SDL_VIDEOEXPOSE => sub {
1445 $WANT_REFRESH++;
1446 },
1431 CFClient::SDL_ACTIVEEVENT => sub { 1447 CFClient::SDL_ACTIVEEVENT => sub {
1432# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1448# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1433 }, 1449 },
1434 CFClient::SDL_KEYDOWN => sub { 1450 CFClient::SDL_KEYDOWN => sub {
1435 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1451 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1456 1472
1457############################################################################# 1473#############################################################################
1458 1474
1459$SIG{INT} = $SIG{TERM} = sub { exit }; 1475$SIG{INT} = $SIG{TERM} = sub { exit };
1460 1476
1461CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1462
1463$TILECACHE = CFClient::db_table "tilecache";
1464$FACEMAP = CFClient::db_table "facemap";
1465
1466my %DEF_CFG = (
1467 sdl_mode => 0,
1468 width => 640,
1469 height => 480,
1470 fullscreen => 0,
1471 fast => 0,
1472 map_scale => 0.5,
1473 fow_enable => 1,
1474 fow_intensity => 0.45,
1475 fow_smooth => 0,
1476 gui_fontsize => 1,
1477 log_fontsize => 1,
1478 gauge_fontsize => 1,
1479 gauge_size => 0.35,
1480 stat_fontsize => 1,
1481 mapsize => 100,
1482 host => "crossfire.schmorp.de",
1483 say_command => 'say',
1484 audio_enable => 1,
1485 bgm_enable => 1,
1486 bgm_volume => 0.25,
1487);
1488
1489while (my ($k, $v) = each %DEF_CFG) {
1490 $CFG->{$k} = $v unless exists $CFG->{$k};
1491}
1492
1493sdl_init;
1494
1495@SDL_MODES = reverse
1496 grep $_->[0] >= 640 && $_->[1] >= 480,
1497 CFClient::SDL_ListModes;
1498
1499@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1500
1501$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1502
1503{ 1477{
1478 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1479
1480 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1481
1482 $TILECACHE = CFClient::db_table "tilecache";
1483 $FACEMAP = CFClient::db_table "facemap";
1484
1485 my %DEF_CFG = (
1486 sdl_mode => 0,
1487 width => 640,
1488 height => 480,
1489 fullscreen => 0,
1490 fast => 0,
1491 map_scale => 0.5,
1492 fow_enable => 1,
1493 fow_intensity => 0.45,
1494 fow_smooth => 0,
1495 gui_fontsize => 1,
1496 log_fontsize => 1,
1497 gauge_fontsize=> 1,
1498 gauge_size => 0.35,
1499 stat_fontsize => 1,
1500 mapsize => 100,
1501 host => "crossfire.schmorp.de",
1502 say_command => 'say',
1503 audio_enable => 1,
1504 bgm_enable => 1,
1505 bgm_volume => 0.25,
1506 );
1507
1508 while (my ($k, $v) = each %DEF_CFG) {
1509 $CFG->{$k} = $v unless exists $CFG->{$k};
1510 }
1511
1512 sdl_init;
1513
1514 @SDL_MODES = reverse
1515 grep $_->[0] >= 640 && $_->[1] >= 480,
1516 CFClient::SDL_ListModes;
1517
1518 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1519
1520 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1521
1522 {
1504 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1523 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1505 DejaVuSans.ttf 1524 DejaVuSans.ttf
1506 DejaVuSansMono.ttf 1525 DejaVuSansMono.ttf
1507 DejaVuSans-Bold.ttf 1526 DejaVuSans-Bold.ttf
1508 DejaVuSansMono-Bold.ttf 1527 DejaVuSansMono-Bold.ttf
1509 DejaVuSans-Oblique.ttf 1528 DejaVuSans-Oblique.ttf
1510 DejaVuSansMono-Oblique.ttf 1529 DejaVuSansMono-Oblique.ttf
1511 DejaVuSans-BoldOblique.ttf 1530 DejaVuSans-BoldOblique.ttf
1512 DejaVuSansMono-BoldOblique.ttf 1531 DejaVuSansMono-BoldOblique.ttf
1513 ); 1532 );
1514 1533
1515 CFClient::add_font $_ for @fonts; 1534 CFClient::add_font $_ for @fonts;
1516 1535
1517 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1536 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1518 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1537 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1519 1538
1520 $FONT_PROP->make_default; 1539 $FONT_PROP->make_default;
1521} 1540 }
1522 1541
1523video_init; 1542 video_init;
1524audio_init; 1543 audio_init;
1544}
1525 1545
1526Event::loop; 1546Event::loop;
1527 1547
1528END { CFClient::SDL_Quit } 1548END { CFClient::SDL_Quit }
1529 1549

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines