… | |
… | |
113 | our $CONN; |
113 | our $CONN; |
114 | our $PROFILE; # current profile |
114 | our $PROFILE; # current profile |
115 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
115 | our $FAST; # fast, low-quality mode, possibly useful for software-rendering |
116 | |
116 | |
117 | our $WANT_REFRESH; |
117 | our $WANT_REFRESH; |
118 | our $CAN_REFRESH; |
|
|
119 | |
118 | |
120 | our @SDL_MODES; |
119 | our @SDL_MODES; |
121 | our $WIDTH; |
120 | our $WIDTH; |
122 | our $HEIGHT; |
121 | our $HEIGHT; |
123 | our $FULLSCREEN; |
122 | our $FULLSCREEN; |
… | |
… | |
168 | our $STATUSBOX; |
167 | our $STATUSBOX; |
169 | our $DEBUG_STATUS; |
168 | our $DEBUG_STATUS; |
170 | |
169 | |
171 | our $INV; |
170 | our $INV; |
172 | our $INVR; |
171 | our $INVR; |
173 | our $INV_RIGHT_HB; |
172 | our $INVR_HB; |
174 | |
|
|
175 | our $PICKUP_CFG; |
|
|
176 | |
173 | |
177 | ############################################################################# |
174 | ############################################################################# |
178 | |
175 | |
179 | sub status { |
176 | sub status { |
180 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
177 | $STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]); |
… | |
… | |
264 | or return; |
261 | or return; |
265 | $CFG->{effects_enable} |
262 | $CFG->{effects_enable} |
266 | or return; |
263 | or return; |
267 | |
264 | |
268 | my $queue = $AUDIO_PLAY{$face} ||= []; |
265 | my $queue = $AUDIO_PLAY{$face} ||= []; |
269 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
266 | push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events |
270 | audio_sound_push $face |
267 | audio_sound_push $face |
271 | unless @$queue > 1; |
268 | unless @$queue > 1; |
272 | } |
269 | } |
273 | |
270 | |
274 | sub audio_music_set_meta { |
271 | sub audio_music_set_meta { |
… | |
… | |
770 | state => $CFG->{fullscreen}, |
767 | state => $CFG->{fullscreen}, |
771 | tooltip => "Bring the client into fullscreen mode.", |
768 | tooltip => "Bring the client into fullscreen mode.", |
772 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
769 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
773 | ); |
770 | ); |
774 | |
771 | |
|
|
772 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
|
|
773 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
774 | state => $CFG->{opengl11}, |
|
|
775 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
|
|
776 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
|
|
777 | . "cards that claim to support a feature but fall back to software rendering. " |
|
|
778 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
|
|
779 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
|
|
780 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
781 | on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 } |
|
|
782 | ); |
|
|
783 | |
775 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
784 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
776 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
785 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
777 | state => $CFG->{fast}, |
786 | state => $CFG->{fast}, |
778 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
787 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
779 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
788 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
… | |
… | |
805 | |
814 | |
806 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
815 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
807 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
816 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
808 | state => $CFG->{map_smoothing}, |
817 | state => $CFG->{map_smoothing}, |
809 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
818 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
810 | . "This increases load on the graphics subsystem and works only with 2.x servers. " |
819 | . "This increases load on the graphics subsystem and works only with TRT servers. " |
811 | . "Changes take effect at next connection only.", |
820 | . "Changes take effect at next login only.", |
812 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
821 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
813 | ); |
822 | ); |
814 | |
823 | |
815 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
824 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
816 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
825 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
827 | ); |
836 | ); |
828 | |
837 | |
829 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
838 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
830 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
839 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
831 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
840 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
832 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", |
841 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, " |
|
|
842 | . "but you still need to press apply to correctly re-layout the widget.", |
833 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
843 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
834 | ); |
844 | ); |
835 | |
845 | |
836 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
846 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
837 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
847 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
… | |
… | |
1598 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1608 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1599 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1609 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1600 | |
1610 | |
1601 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1611 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1602 | |
1612 | |
1603 | $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); |
1613 | $vb2->add ($INVR_HB = new CFPlus::UI::HBox); |
1604 | |
1614 | |
1605 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1615 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1606 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1616 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1607 | |
1617 | |
1608 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1618 | # XXX: Call after $INVR = ... because set_opencont sets the items |
… | |
… | |
1863 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1873 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1864 | ); |
1874 | ); |
1865 | $hb->add (new CFPlus::UI::Button |
1875 | $hb->add (new CFPlus::UI::Button |
1866 | text => "Quit anyway", |
1876 | text => "Quit anyway", |
1867 | expand => 1, |
1877 | expand => 1, |
1868 | on_activate => sub { exit }, |
1878 | on_activate => sub { Event::unloop_all }, |
1869 | ); |
1879 | ); |
1870 | } |
1880 | } |
1871 | |
1881 | |
1872 | $QUIT_DIALOG->show; |
1882 | $QUIT_DIALOG->show; |
1873 | $QUIT_DIALOG->grab_focus; |
1883 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2067 | tooltip => "Terminates the program", |
2077 | tooltip => "Terminates the program", |
2068 | on_activate => sub { |
2078 | on_activate => sub { |
2069 | if ($CONN) { |
2079 | if ($CONN) { |
2070 | open_quit_dialog; |
2080 | open_quit_dialog; |
2071 | } else { |
2081 | } else { |
2072 | exit; |
2082 | Event::unloop_all; |
2073 | } |
2083 | } |
2074 | 0 |
2084 | 0 |
2075 | }, |
2085 | }, |
2076 | ); |
2086 | ); |
2077 | |
2087 | |
2078 | $BUTTONBAR->show; |
2088 | $BUTTONBAR->show; |
2079 | $SETUP_DIALOG->show; |
2089 | $SETUP_DIALOG->show; |
|
|
2090 | $MESSAGE_WINDOW->show; |
2080 | } |
2091 | } |
2081 | |
2092 | |
2082 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2093 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2083 | } |
2094 | } |
2084 | |
2095 | |
… | |
… | |
2092 | my $animate_timer; |
2103 | my $animate_timer; |
2093 | |
2104 | |
2094 | my $fps = 9; |
2105 | my $fps = 9; |
2095 | |
2106 | |
2096 | sub force_refresh { |
2107 | sub force_refresh { |
|
|
2108 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2097 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
2109 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2098 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2110 | debug sprintf "%3.2f", $fps; |
|
|
2111 | } |
2099 | |
2112 | |
2100 | $CFPlus::UI::ROOT->draw; |
2113 | $CFPlus::UI::ROOT->draw; |
2101 | |
2114 | CFPlus::SDL_GL_SwapBuffers; |
2102 | $WANT_REFRESH = 0; |
|
|
2103 | $CAN_REFRESH = 0; |
|
|
2104 | $LAST_REFRESH = $NOW; |
2115 | $LAST_REFRESH = $NOW; |
2105 | |
2116 | $WANT_REFRESH->stop; |
2106 | CFPlus::SDL_GL_SwapBuffers; |
|
|
2107 | } |
2117 | } |
2108 | |
2118 | |
|
|
2119 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
|
|
2120 | |
2109 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2121 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2110 | $NOW = time; |
2122 | $NOW = time; |
2111 | |
2123 | |
2112 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2124 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2113 | for CFPlus::poll_events; |
2125 | for CFPlus::poll_events; |
2114 | |
2126 | |
2115 | if (%animate_object) { |
2127 | if (%animate_object) { |
2116 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2128 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2117 | ++$WANT_REFRESH; |
2129 | $WANT_REFRESH->start; |
2118 | } |
|
|
2119 | |
|
|
2120 | if ($WANT_REFRESH) { |
|
|
2121 | force_refresh; |
|
|
2122 | } else { |
|
|
2123 | $CAN_REFRESH = 1; |
|
|
2124 | } |
2130 | } |
2125 | }); |
2131 | }); |
2126 | |
2132 | |
2127 | sub animation_start { |
2133 | sub animation_start { |
2128 | my ($widget) = @_; |
2134 | my ($widget) = @_; |
… | |
… | |
2186 | |
2192 | |
2187 | my %DEF_CFG = ( |
2193 | my %DEF_CFG = ( |
2188 | sdl_mode => 0, |
2194 | sdl_mode => 0, |
2189 | fullscreen => 0, |
2195 | fullscreen => 0, |
2190 | fast => 0, |
2196 | fast => 0, |
|
|
2197 | opengl11 => 0, |
2191 | map_scale => 1, |
2198 | map_scale => 1, |
2192 | fow_enable => 1, |
2199 | fow_enable => 1, |
2193 | fow_intensity => 0, |
2200 | fow_intensity => 0, |
2194 | map_smoothing => 1, |
2201 | map_smoothing => 1, |
2195 | gui_fontsize => 1, |
2202 | gui_fontsize => 1, |
… | |
… | |
2284 | } |
2291 | } |
2285 | |
2292 | |
2286 | show_tip_of_the_day if $CFG->{show_tips}; |
2293 | show_tip_of_the_day if $CFG->{show_tips}; |
2287 | |
2294 | |
2288 | Event::loop; |
2295 | Event::loop; |
|
|
2296 | |
|
|
2297 | #video_shutdown; |
|
|
2298 | #audio_shutdown; |
2289 | #CFPlus::SDL_Quit; |
2299 | CFPlus::SDL_Quit; |
2290 | #CFPlus::_exit 0; |
|
|
2291 | |
|
|
2292 | END { |
|
|
2293 | video_shutdown; |
|
|
2294 | audio_shutdown; |
|
|
2295 | CFPlus::SDL_Quit; |
|
|
2296 | CFPlus::DB::Server::stop; |
2300 | CFPlus::DB::Server::stop; |
2297 | } |
|
|
2298 | |
2301 | |
2299 | =head1 NAME |
2302 | =head1 NAME |
2300 | |
2303 | |
2301 | cfplus - A Crossfire TRT and Crossfire game client |
2304 | cfplus - A Crossfire TRT and Crossfire game client |
2302 | |
2305 | |