… | |
… | |
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; |
… | |
… | |
217 | my ($face) = @_; |
216 | my ($face) = @_; |
218 | |
217 | |
219 | $CFG->{effects_enable} |
218 | $CFG->{effects_enable} |
220 | or return; |
219 | or return; |
221 | |
220 | |
|
|
221 | $AUDIO_PLAY{$face} |
|
|
222 | or return; |
|
|
223 | |
222 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
224 | if (my $chunk = $AUDIO_CHUNK{$face}) { |
223 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
225 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
224 | my (undef, $dx, $dy, $vol) = @$_; |
226 | my (undef, $dx, $dy, $vol) = @$_; |
225 | |
227 | |
226 | my $channel = CFPlus::Channel::find; |
228 | my $channel = CFPlus::Channel::find; |
227 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
229 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
228 | $dx = $dx / 10 * 255; |
|
|
229 | $channel->set_panning (255 - $dx, 255 + $dx); |
|
|
230 | |
|
|
231 | # my $angle = $dx ? : $dx < 0 ? |
|
|
232 | # my $distance = -$vol; |
|
|
233 | # $channel->set_position ($angle, $distance); |
230 | $channel->set_position_r ($dx, $dy, 20); |
234 | |
|
|
235 | $chunk->play ($channel); |
231 | $chunk->play ($channel); |
236 | } |
232 | } |
237 | } else { |
233 | } else { |
238 | # sound_meta not set means data is in flight either way |
234 | # sound_meta not set means data is in flight either way |
239 | my $meta = $CONN->{sound_meta}{$face} |
235 | my $meta = $CONN->{sound_meta}{$face} |
… | |
… | |
248 | } else { |
244 | } else { |
249 | # fetch from database |
245 | # fetch from database |
250 | CFPlus::DB::get res_data => $meta->{name}, sub { |
246 | CFPlus::DB::get res_data => $meta->{name}, sub { |
251 | my $rwops = new CFPlus::RW $_[0]; |
247 | my $rwops = new CFPlus::RW $_[0]; |
252 | my $chunk = new CFPlus::MixChunk $rwops |
248 | my $chunk = new CFPlus::MixChunk $rwops |
253 | or Carp::confess "sound face $meta->{face} unloadable: " . CFPlus::Mix_GetError; |
249 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
254 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
250 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
255 | $AUDIO_CHUNK{$face} = $chunk; |
251 | $AUDIO_CHUNK{$face} = $chunk; |
256 | |
252 | |
257 | audio_sound_push ($face); |
253 | audio_sound_push ($face); |
258 | }; |
254 | }; |
… | |
… | |
267 | or return; |
263 | or return; |
268 | $CFG->{effects_enable} |
264 | $CFG->{effects_enable} |
269 | or return; |
265 | or return; |
270 | |
266 | |
271 | my $queue = $AUDIO_PLAY{$face} ||= []; |
267 | my $queue = $AUDIO_PLAY{$face} ||= []; |
272 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
268 | push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events |
273 | audio_sound_push $face |
269 | audio_sound_push $face |
274 | unless @$queue > 1; |
270 | unless @$queue > 1; |
275 | } |
271 | } |
276 | |
272 | |
277 | sub audio_music_set_meta { |
273 | sub audio_music_set_meta { |
… | |
… | |
419 | |
415 | |
420 | sub audio_shutdown { |
416 | sub audio_shutdown { |
421 | undef $MUSIC_PLAYER; |
417 | undef $MUSIC_PLAYER; |
422 | undef $MUSIC_PLAYING_META; |
418 | undef $MUSIC_PLAYING_META; |
423 | undef $MUSIC_PLAYING_DATA; |
419 | undef $MUSIC_PLAYING_DATA; |
424 | |
|
|
425 | audio_music_set_meta { }; |
|
|
426 | |
420 | |
427 | $MUSIC_WANT = []; |
421 | $MUSIC_WANT = []; |
428 | @MUSIC_JINGLE = (); |
422 | @MUSIC_JINGLE = (); |
429 | %AUDIO_PLAY = (); |
423 | %AUDIO_PLAY = (); |
430 | %AUDIO_CHUNK = (); |
424 | %AUDIO_CHUNK = (); |
… | |
… | |
775 | state => $CFG->{fullscreen}, |
769 | state => $CFG->{fullscreen}, |
776 | tooltip => "Bring the client into fullscreen mode.", |
770 | tooltip => "Bring the client into fullscreen mode.", |
777 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
771 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
778 | ); |
772 | ); |
779 | |
773 | |
|
|
774 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
|
|
775 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
776 | state => $CFG->{opengl11}, |
|
|
777 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
|
|
778 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
|
|
779 | . "cards that claim to support a feature but fall back to software rendering. " |
|
|
780 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
|
|
781 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
|
|
782 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
783 | on_changed => sub { my ($self, $value) = @_; $CFG->{opengl11} = $value; 0 } |
|
|
784 | ); |
|
|
785 | |
780 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
786 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
781 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
787 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
782 | state => $CFG->{fast}, |
788 | state => $CFG->{fast}, |
783 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
789 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
784 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
790 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
… | |
… | |
810 | |
816 | |
811 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
817 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
812 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
818 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
813 | state => $CFG->{map_smoothing}, |
819 | state => $CFG->{map_smoothing}, |
814 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
820 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
815 | . "This increases load on the graphics subsystem and works only with 2.x servers. " |
821 | . "This increases load on the graphics subsystem and works only with TRT servers. " |
816 | . "Changes take effect at next connection only.", |
822 | . "Changes take effect at next login only.", |
817 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
823 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
818 | ); |
824 | ); |
819 | |
825 | |
820 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
826 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
821 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
827 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
832 | ); |
838 | ); |
833 | |
839 | |
834 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
840 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
835 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
841 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
836 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
842 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
837 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", |
843 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, " |
|
|
844 | . "but you still need to press apply to correctly re-layout the widget.", |
838 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
845 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
839 | ); |
846 | ); |
840 | |
847 | |
841 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
848 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
842 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
849 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
… | |
… | |
879 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
886 | # $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
880 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
887 | # $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub { |
881 | # $CFG->{effects_volume} = $_[1]; |
888 | # $CFG->{effects_volume} = $_[1]; |
882 | # }); |
889 | # }); |
883 | |
890 | |
884 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
891 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects"); |
885 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
892 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
886 | expand => 1, state => $CFG->{effects_enable}, |
893 | expand => 1, state => $CFG->{effects_enable}, |
887 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
894 | tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.", |
|
|
895 | on_changed => sub { |
888 | on_changed => sub { $CFG->{effects_enable} = $_[1]; 0 } |
896 | $CFG->{effects_enable} = $_[1]; |
|
|
897 | $CONN->update_fx_want if $CONN; |
|
|
898 | 0 |
|
|
899 | } |
889 | ); |
900 | ); |
890 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
901 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
891 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
902 | expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128], |
892 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
903 | tooltip => "The relative volume of sound effects. Best audio quality is achieved if this " |
893 | . "is set highest and you use your operating system volume setting. Changes are instant.", |
904 | . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.", |
894 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
905 | on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 } |
895 | ); |
906 | ); |
896 | |
907 | |
897 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
908 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music"); |
898 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
909 | $table->add_at (1, $row, new CFPlus::UI::CheckBox |
899 | expand => 1, state => $CFG->{bgm_enable}, |
910 | expand => 1, state => $CFG->{bgm_enable}, |
900 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
911 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
901 | on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 } |
912 | on_changed => sub { |
|
|
913 | $CFG->{bgm_enable} = $_[1]; |
|
|
914 | $CONN->update_fx_want if $CONN; |
|
|
915 | 0 |
|
|
916 | } |
902 | ); |
917 | ); |
903 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
918 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
904 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
919 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
905 | tooltip => "The volume of the background music. Changes are instant.", |
920 | tooltip => "The volume of the background music. Changes are instant.", |
906 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
921 | on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 } |
… | |
… | |
2089 | my $animate_timer; |
2104 | my $animate_timer; |
2090 | |
2105 | |
2091 | my $fps = 9; |
2106 | my $fps = 9; |
2092 | |
2107 | |
2093 | sub force_refresh { |
2108 | sub force_refresh { |
|
|
2109 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2094 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
2110 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2095 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2111 | debug sprintf "%3.2f", $fps; |
|
|
2112 | } |
2096 | |
2113 | |
2097 | $CFPlus::UI::ROOT->draw; |
2114 | $CFPlus::UI::ROOT->draw; |
2098 | |
2115 | CFPlus::SDL_GL_SwapBuffers; |
2099 | $WANT_REFRESH = 0; |
|
|
2100 | $CAN_REFRESH = 0; |
|
|
2101 | $LAST_REFRESH = $NOW; |
2116 | $LAST_REFRESH = $NOW; |
2102 | |
2117 | $WANT_REFRESH->stop; |
2103 | CFPlus::SDL_GL_SwapBuffers; |
|
|
2104 | } |
2118 | } |
2105 | |
2119 | |
|
|
2120 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
|
|
2121 | |
2106 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2122 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2107 | $NOW = time; |
2123 | $NOW = time; |
2108 | |
2124 | |
2109 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2125 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2110 | for CFPlus::poll_events; |
2126 | for CFPlus::poll_events; |
2111 | |
2127 | |
2112 | if (%animate_object) { |
2128 | if (%animate_object) { |
2113 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2129 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2114 | ++$WANT_REFRESH; |
2130 | $WANT_REFRESH->start; |
2115 | } |
|
|
2116 | |
|
|
2117 | if ($WANT_REFRESH) { |
|
|
2118 | force_refresh; |
|
|
2119 | } else { |
|
|
2120 | $CAN_REFRESH = 1; |
|
|
2121 | } |
2131 | } |
2122 | }); |
2132 | }); |
2123 | |
2133 | |
2124 | sub animation_start { |
2134 | sub animation_start { |
2125 | my ($widget) = @_; |
2135 | my ($widget) = @_; |
… | |
… | |
2183 | |
2193 | |
2184 | my %DEF_CFG = ( |
2194 | my %DEF_CFG = ( |
2185 | sdl_mode => 0, |
2195 | sdl_mode => 0, |
2186 | fullscreen => 0, |
2196 | fullscreen => 0, |
2187 | fast => 0, |
2197 | fast => 0, |
|
|
2198 | opengl11 => 0, |
2188 | map_scale => 1, |
2199 | map_scale => 1, |
2189 | fow_enable => 1, |
2200 | fow_enable => 1, |
2190 | fow_intensity => 0, |
2201 | fow_intensity => 0, |
2191 | map_smoothing => 1, |
2202 | map_smoothing => 1, |
2192 | gui_fontsize => 1, |
2203 | gui_fontsize => 1, |
… | |
… | |
2285 | Event::loop; |
2296 | Event::loop; |
2286 | #CFPlus::SDL_Quit; |
2297 | #CFPlus::SDL_Quit; |
2287 | #CFPlus::_exit 0; |
2298 | #CFPlus::_exit 0; |
2288 | |
2299 | |
2289 | END { |
2300 | END { |
|
|
2301 | video_shutdown; |
|
|
2302 | audio_shutdown; |
2290 | CFPlus::SDL_Quit; |
2303 | CFPlus::SDL_Quit; |
2291 | CFPlus::DB::Server::stop; |
2304 | CFPlus::DB::Server::stop; |
2292 | } |
2305 | } |
2293 | |
2306 | |
2294 | =head1 NAME |
2307 | =head1 NAME |
2295 | |
2308 | |
2296 | cfplus - A Crossfire+ and Crossfire game client |
2309 | cfplus - A Crossfire TRT and Crossfire game client |
2297 | |
2310 | |
2298 | =head1 SYNOPSIS |
2311 | =head1 SYNOPSIS |
2299 | |
2312 | |
2300 | Just run it - no commandline arguments are supported. |
2313 | Just run it - no commandline arguments are supported. |
2301 | |
2314 | |
2302 | =head1 USAGE |
2315 | =head1 USAGE |
2303 | |
2316 | |
2304 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used |
2317 | cfplus utilises OpenGL for all UI elements and the game. It is supposed to |
2305 | fullscreen and interactively. |
2318 | be used in fullscreen mode and interactively. |
2306 | |
2319 | |
2307 | =head1 DEBUGGING |
2320 | =head1 DEBUGGING |
2308 | |
2321 | |
2309 | |
2322 | |
2310 | CFPLUS_DEBUG - environment variable |
2323 | CFPLUS_DEBUG - environment variable |