… | |
… | |
59 | our $NOW; |
59 | our $NOW; |
60 | |
60 | |
61 | our $CFG; |
61 | our $CFG; |
62 | our $CONN; |
62 | our $CONN; |
63 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
63 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
|
|
64 | |
|
|
65 | our $WANT_REFRESH; |
|
|
66 | our $CAN_REFRESH; |
64 | |
67 | |
65 | our @SDL_MODES; |
68 | our @SDL_MODES; |
66 | our $WIDTH; |
69 | our $WIDTH; |
67 | our $HEIGHT; |
70 | our $HEIGHT; |
68 | our $FULLSCREEN; |
71 | our $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 | |
106 | sub debug { |
109 | sub 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 | |
111 | sub start_game { |
115 | sub 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 | |
909 | sub video_shutdown { |
917 | sub video_shutdown { |
910 | undef $SDL_ACTIVE; |
918 | undef $SDL_ACTIVE; |
… | |
… | |
966 | } |
974 | } |
967 | |
975 | |
968 | my %animate_object; |
976 | my %animate_object; |
969 | my $animate_timer; |
977 | my $animate_timer; |
970 | |
978 | |
971 | my $want_refresh; |
|
|
972 | my $can_refresh; |
|
|
973 | |
|
|
974 | my $fps = 9; |
979 | my $fps = 9; |
975 | |
980 | |
976 | sub force_refresh { |
981 | sub 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 | |
990 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
993 | my $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 | |
|
|
1008 | sub refresh { |
|
|
1009 | $want_refresh++; |
|
|
1010 | } |
|
|
1011 | |
1010 | |
1012 | sub animation_start { |
1011 | sub animation_start { |
1013 | my ($widget) = @_; |
1012 | my ($widget) = @_; |
1014 | $animate_object{$widget} = $widget; |
1013 | $animate_object{$widget} = $widget; |
1015 | } |
1014 | } |
… | |
… | |
1374 | $FLOORBOX->add ( |
1373 | $FLOORBOX->add ( |
1375 | map +(new CFClient::UI::InventoryItem item => $_), |
1374 | map +(new CFClient::UI::InventoryItem item => $_), |
1376 | @{ $CONN->{container}{0} } |
1375 | @{ $CONN->{container}{0} } |
1377 | ); |
1376 | ); |
1378 | }); |
1377 | }); |
1379 | refresh; |
1378 | |
|
|
1379 | $WANT_REFRESH++; |
1380 | } |
1380 | } |
1381 | |
1381 | |
1382 | sub conn::container_add { |
1382 | sub conn::container_add { |
1383 | my ($self, $tag, $items) = @_; |
1383 | my ($self, $tag, $items) = @_; |
1384 | |
1384 | |
… | |
… | |
1426 | CFClient::SDL_QUIT => sub { |
1426 | CFClient::SDL_QUIT => sub { |
1427 | Event::unloop -1; |
1427 | Event::unloop -1; |
1428 | }, |
1428 | }, |
1429 | CFClient::SDL_VIDEORESIZE => sub { |
1429 | CFClient::SDL_VIDEORESIZE => sub { |
1430 | }, |
1430 | }, |
1431 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
1431 | CFClient::SDL_VIDEOEXPOSE => sub { |
|
|
1432 | $WANT_REFRESH++; |
|
|
1433 | }, |
1432 | CFClient::SDL_ACTIVEEVENT => sub { |
1434 | CFClient::SDL_ACTIVEEVENT => sub { |
1433 | # 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# |
1434 | }, |
1436 | }, |
1435 | CFClient::SDL_KEYDOWN => sub { |
1437 | CFClient::SDL_KEYDOWN => sub { |
1436 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
1438 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
… | |
… | |
1477 | fow_enable => 1, |
1479 | fow_enable => 1, |
1478 | fow_intensity => 0.45, |
1480 | fow_intensity => 0.45, |
1479 | fow_smooth => 0, |
1481 | fow_smooth => 0, |
1480 | gui_fontsize => 1, |
1482 | gui_fontsize => 1, |
1481 | log_fontsize => 1, |
1483 | log_fontsize => 1, |
1482 | gauge_fontsize => 1, |
1484 | gauge_fontsize=> 1, |
1483 | gauge_size => 0.35, |
1485 | gauge_size => 0.35, |
1484 | stat_fontsize => 1, |
1486 | stat_fontsize => 1, |
1485 | mapsize => 100, |
1487 | mapsize => 100, |
1486 | host => "crossfire.schmorp.de", |
1488 | host => "crossfire.schmorp.de", |
1487 | say_command => 'say', |
1489 | say_command => 'say', |
1488 | audio_enable => 1, |
1490 | audio_enable => 1, |