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.206 by root, Tue May 9 22:27:55 2006 UTC

59our $NOW; 59our $NOW;
60 60
61our $CFG; 61our $CFG;
62our $CONN; 62our $CONN;
63our $FAST; # fast, low-quality mode, possibly useful for software-rendering 63our $FAST; # fast, low-quality mode, possibly useful for software-rendering
64
65our $WANT_REFRESH;
66our $CAN_REFRESH;
64 67
65our @SDL_MODES; 68our @SDL_MODES;
66our $WIDTH; 69our $WIDTH;
67our $HEIGHT; 70our $HEIGHT;
68our $FULLSCREEN; 71our $FULLSCREEN;
103 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h}); 106 $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 status "logging in..."; 116 status "logging in...";
113 117
845 $CFClient::UI::ROOT->reconfigure; 849 $CFClient::UI::ROOT->reconfigure;
846 850
847 } else { 851 } else {
848 # create the widgets 852 # create the widgets
849 853
850 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 854 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100, text => "hulla", x => 100;#d#
851 $DEBUG_STATUS->show; 855 $DEBUG_STATUS->show;
852 856
853 $STATUS_LINE = new CFClient::UI::Label 857 $STATUS_LINE = new CFClient::UI::Label
854 padding => 0, 858 padding => 0,
855 y => $HEIGHT - $FONTSIZE * 1.8; 859 y => $HEIGHT - $FONTSIZE * 1.8;
900 status "Configuration Saved"; 904 status "Configuration Saved";
901 }); 905 });
902 906
903 $BUTTONBAR->show; 907 $BUTTONBAR->show;
904 908
909 # delay till geometry is constant
910 $CFClient::UI::ROOT->on_refresh (startup => sub {
905 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 911 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
912 });
913 force_refresh ();
906 } 914 }
907} 915}
908 916
909sub video_shutdown { 917sub video_shutdown {
910 undef $SDL_ACTIVE; 918 undef $SDL_ACTIVE;
966} 974}
967 975
968my %animate_object; 976my %animate_object;
969my $animate_timer; 977my $animate_timer;
970 978
971my $want_refresh;
972my $can_refresh;
973
974my $fps = 9; 979my $fps = 9;
975 980
976sub force_refresh { 981sub force_refresh {
977 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05; 982 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
978 debug sprintf "%3.2f", $fps; 983 debug sprintf "%3.2f", $fps;
979 984
980 $want_refresh = 0;
981 $can_refresh = 0;
982
983 $CFClient::UI::ROOT->draw; 985 $CFClient::UI::ROOT->draw;
984
985 CFClient::SDL_GL_SwapBuffers; 986 CFClient::SDL_GL_SwapBuffers;
986 987
988 $WANT_REFRESH = 0;
989 $CAN_REFRESH = 0;
987 $LAST_REFRESH = $NOW; 990 $LAST_REFRESH = $NOW;
988} 991}
989 992
990my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 993my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
991 $NOW = time; 994 $NOW = time;
993 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) 996 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
994 for CFClient::SDL_PollEvent; 997 for CFClient::SDL_PollEvent;
995 998
996 if (%animate_object) { 999 if (%animate_object) {
997 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 1000 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
998 $want_refresh++; 1001 $WANT_REFRESH++;
999 } 1002 }
1000 1003
1001 if ($want_refresh) { 1004 if ($WANT_REFRESH) {
1002 force_refresh; 1005 force_refresh;
1003 } else { 1006 } else {
1004 $can_refresh = 1; 1007 $CAN_REFRESH = 1;
1005 } 1008 }
1006}); 1009});
1007
1008sub refresh {
1009 $want_refresh++;
1010}
1011 1010
1012sub animation_start { 1011sub animation_start {
1013 my ($widget) = @_; 1012 my ($widget) = @_;
1014 $animate_object{$widget} = $widget; 1013 $animate_object{$widget} = $widget;
1015} 1014}
1369 1368
1370 $FLOORBOX->clear; 1369 $FLOORBOX->clear;
1371 $FLOORBOX->add (new CFClient::UI::Empty expand => 1); 1370 $FLOORBOX->add (new CFClient::UI::Empty expand => 1);
1372 1371
1373 # we basically have to use the same sorting as everybody else 1372 # we basically have to use the same sorting as everybody else
1374 for my $item (@{ $CONN->{container}{0} }) { 1373 $FLOORBOX->add (
1375 $FLOORBOX->add (new CFClient::UI::InventoryItem item => $item); 1374 map +(new CFClient::UI::InventoryItem item => $_),
1375 @{ $CONN->{container}{0} }
1376 } 1376 );
1377 }); 1377 });
1378 refresh; 1378
1379 $WANT_REFRESH++;
1379} 1380}
1380 1381
1381sub conn::container_add { 1382sub conn::container_add {
1382 my ($self, $tag, $items) = @_; 1383 my ($self, $tag, $items) = @_;
1383 1384
1416 my ($self, $item) = @_; 1417 my ($self, $item) = @_;
1417 1418
1418 update_floorbox if $item->{container} == 0; 1419 update_floorbox if $item->{container} == 0;
1419 1420
1420 $INV->set_items ($self->{container}{$item->{container}}) 1421 $INV->set_items ($self->{container}{$item->{container}})
1421 if $item->{container}; == $self->{player}{tag}; 1422 if $item->{container} == $self->{player}{tag};
1422} 1423}
1423 1424
1424%SDL_CB = ( 1425%SDL_CB = (
1425 CFClient::SDL_QUIT => sub { 1426 CFClient::SDL_QUIT => sub {
1426 Event::unloop -1; 1427 Event::unloop -1;
1427 }, 1428 },
1428 CFClient::SDL_VIDEORESIZE => sub { 1429 CFClient::SDL_VIDEORESIZE => sub {
1429 }, 1430 },
1430 CFClient::SDL_VIDEOEXPOSE => \&refresh, 1431 CFClient::SDL_VIDEOEXPOSE => sub {
1432 $WANT_REFRESH++;
1433 },
1431 CFClient::SDL_ACTIVEEVENT => sub { 1434 CFClient::SDL_ACTIVEEVENT => sub {
1432# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 1435# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
1433 }, 1436 },
1434 CFClient::SDL_KEYDOWN => sub { 1437 CFClient::SDL_KEYDOWN => sub {
1435 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { 1438 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
1456 1459
1457############################################################################# 1460#############################################################################
1458 1461
1459$SIG{INT} = $SIG{TERM} = sub { exit }; 1462$SIG{INT} = $SIG{TERM} = sub { exit };
1460 1463
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{ 1464{
1465 local $SIG{__DIE__} = sub { CFClient::fatal $_[0] };
1466
1467 CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
1468
1469 $TILECACHE = CFClient::db_table "tilecache";
1470 $FACEMAP = CFClient::db_table "facemap";
1471
1472 my %DEF_CFG = (
1473 sdl_mode => 0,
1474 width => 640,
1475 height => 480,
1476 fullscreen => 0,
1477 fast => 0,
1478 map_scale => 0.5,
1479 fow_enable => 1,
1480 fow_intensity => 0.45,
1481 fow_smooth => 0,
1482 gui_fontsize => 1,
1483 log_fontsize => 1,
1484 gauge_fontsize=> 1,
1485 gauge_size => 0.35,
1486 stat_fontsize => 1,
1487 mapsize => 100,
1488 host => "crossfire.schmorp.de",
1489 say_command => 'say',
1490 audio_enable => 1,
1491 bgm_enable => 1,
1492 bgm_volume => 0.25,
1493 );
1494
1495 while (my ($k, $v) = each %DEF_CFG) {
1496 $CFG->{$k} = $v unless exists $CFG->{$k};
1497 }
1498
1499 sdl_init;
1500
1501 @SDL_MODES = reverse
1502 grep $_->[0] >= 640 && $_->[1] >= 480,
1503 CFClient::SDL_ListModes;
1504
1505 @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
1506
1507 $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
1508
1509 {
1504 my @fonts = map CFClient::find_rcfile "fonts/$_", qw( 1510 my @fonts = map CFClient::find_rcfile "fonts/$_", qw(
1505 DejaVuSans.ttf 1511 DejaVuSans.ttf
1506 DejaVuSansMono.ttf 1512 DejaVuSansMono.ttf
1507 DejaVuSans-Bold.ttf 1513 DejaVuSans-Bold.ttf
1508 DejaVuSansMono-Bold.ttf 1514 DejaVuSansMono-Bold.ttf
1509 DejaVuSans-Oblique.ttf 1515 DejaVuSans-Oblique.ttf
1510 DejaVuSansMono-Oblique.ttf 1516 DejaVuSansMono-Oblique.ttf
1511 DejaVuSans-BoldOblique.ttf 1517 DejaVuSans-BoldOblique.ttf
1512 DejaVuSansMono-BoldOblique.ttf 1518 DejaVuSansMono-BoldOblique.ttf
1513 ); 1519 );
1514 1520
1515 CFClient::add_font $_ for @fonts; 1521 CFClient::add_font $_ for @fonts;
1516 1522
1517 $FONT_PROP = new_from_file CFClient::Font $fonts[0]; 1523 $FONT_PROP = new_from_file CFClient::Font $fonts[0];
1518 $FONT_FIXED = new_from_file CFClient::Font $fonts[1]; 1524 $FONT_FIXED = new_from_file CFClient::Font $fonts[1];
1519 1525
1520 $FONT_PROP->make_default; 1526 $FONT_PROP->make_default;
1521} 1527 }
1522 1528
1523video_init; 1529 video_init;
1524audio_init; 1530 audio_init;
1531}
1525 1532
1526Event::loop; 1533Event::loop;
1527 1534
1528END { CFClient::SDL_Quit } 1535END { CFClient::SDL_Quit }
1529 1536

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines