… | |
… | |
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]); |
… | |
… | |
226 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
223 | for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) { |
227 | my (undef, $dx, $dy, $vol) = @$_; |
224 | my (undef, $dx, $dy, $vol) = @$_; |
228 | |
225 | |
229 | my $channel = CFPlus::Channel::find; |
226 | my $channel = CFPlus::Channel::find; |
230 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
227 | $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255); |
231 | $dx = $dx / 10 * 255; |
|
|
232 | $channel->set_panning (255 - $dx, 255 + $dx); |
|
|
233 | |
|
|
234 | # my $angle = $dx ? : $dx < 0 ? |
|
|
235 | # my $distance = -$vol; |
|
|
236 | # $channel->set_position ($angle, $distance); |
228 | $channel->set_position_r ($dx, $dy, 20); |
237 | |
|
|
238 | $chunk->play ($channel); |
229 | $chunk->play ($channel); |
239 | } |
230 | } |
240 | } else { |
231 | } else { |
241 | # sound_meta not set means data is in flight either way |
232 | # sound_meta not set means data is in flight either way |
242 | my $meta = $CONN->{sound_meta}{$face} |
233 | my $meta = $CONN->{face}[$face] |
243 | or return; |
234 | or return; |
244 | |
235 | |
|
|
236 | $meta->{data} |
|
|
237 | or return; |
|
|
238 | |
245 | # if its a jingle, play it as ambient music |
239 | # if its a jingle, play it as ambient music |
246 | if ($meta->{meta}{jingle}) { |
240 | if ($meta->{data}{jingle}) { |
247 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
241 | if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue |
248 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
242 | push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue |
249 | &audio_music_push ($face); |
243 | &audio_music_push ($face); |
250 | } |
244 | } |
251 | } else { |
245 | } else { |
252 | # fetch from database |
246 | # fetch from database |
253 | CFPlus::DB::get res_data => $meta->{name}, sub { |
247 | CFPlus::DB::get res_data => $meta->{name}, sub { |
254 | my $rwops = new CFPlus::RW $_[0]; |
248 | my $rwops = new CFPlus::RW $_[0]; |
255 | my $chunk = new CFPlus::MixChunk $rwops |
249 | my $chunk = new CFPlus::MixChunk $rwops |
256 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
250 | or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError; |
257 | $chunk->volume (($meta->{meta}{volume} || 1) * 128); |
251 | $chunk->volume (($meta->{data}{volume} || 1) * 128); |
258 | $AUDIO_CHUNK{$face} = $chunk; |
252 | $AUDIO_CHUNK{$face} = $chunk; |
259 | |
253 | |
260 | audio_sound_push ($face); |
254 | audio_sound_push ($face); |
261 | }; |
255 | }; |
262 | } |
256 | } |
… | |
… | |
270 | or return; |
264 | or return; |
271 | $CFG->{effects_enable} |
265 | $CFG->{effects_enable} |
272 | or return; |
266 | or return; |
273 | |
267 | |
274 | my $queue = $AUDIO_PLAY{$face} ||= []; |
268 | my $queue = $AUDIO_PLAY{$face} ||= []; |
275 | push @$queue, [Event::time + 0.2, $dx, $dy, $vol]; # delay sound by max. 0.2s |
269 | push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events |
276 | audio_sound_push $face |
270 | audio_sound_push $face |
277 | unless @$queue > 1; |
271 | unless @$queue > 1; |
278 | } |
272 | } |
279 | |
273 | |
280 | sub audio_music_set_meta { |
274 | sub audio_music_set_meta { |
281 | my ($meta) = @_; |
275 | my ($meta) = @_; |
282 | |
276 | |
283 | $MUSIC_PLAYING_META = $meta; |
277 | $MUSIC_PLAYING_META = $meta; |
284 | $MUSIC_PLAYING_WIDGET->set_markup ( |
278 | $MUSIC_PLAYING_WIDGET->set_markup ( |
285 | "<b>Name</b>: " . (CFPlus::asxml $meta->{meta}{name}) . "\n" |
279 | "<b>Name</b>: " . (CFPlus::asxml $meta->{data}{name}) . "\n" |
286 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{meta}{author}) . "\n" |
280 | . "<b>Author</b>: " . (CFPlus::asxml $meta->{data}{author}) . "\n" |
287 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{meta}{source}) . "\n" |
281 | . "<b>Source</b>: " . (CFPlus::asxml $meta->{data}{source}) . "\n" |
288 | . "<b>License</b>: " . (CFPlus::asxml $meta->{meta}{license}) |
282 | . "<b>License</b>: " . (CFPlus::asxml $meta->{data}{license}) |
289 | ); |
283 | ); |
290 | } |
284 | } |
291 | |
285 | |
292 | sub audio_music_update_volume { |
286 | sub audio_music_update_volume { |
293 | return unless $MUSIC_PLAYING_META; |
287 | return unless $MUSIC_PLAYING_META; |
294 | my $volume = $MUSIC_PLAYING_META->{meta}{volume} || 1; |
288 | my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1; |
295 | my $base = $MUSIC_PLAYING_META->{meta}{jingle} ? 1 : $CFG->{bgm_volume}; |
289 | my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume}; |
296 | CFPlus::MixMusic::volume $base * $volume * 128; |
290 | CFPlus::MixMusic::volume $base * $volume * 128; |
297 | } |
291 | } |
298 | |
292 | |
299 | sub audio_music_start { |
293 | sub audio_music_start { |
300 | my $meta = $MUSIC_PLAYING_META; |
294 | my $meta = $MUSIC_PLAYING_META; |
… | |
… | |
343 | $fade_out = 333; |
337 | $fade_out = 333; |
344 | } else { |
338 | } else { |
345 | return unless $CFG->{bgm_enable}; |
339 | return unless $CFG->{bgm_enable}; |
346 | |
340 | |
347 | my @have = |
341 | my @have = |
348 | grep $_, |
342 | grep $_ && $_->{data}, |
349 | map $CONN->{music_meta}{$_}, |
343 | map $CONN->{face}[$_], |
350 | @$MUSIC_WANT; |
344 | @$MUSIC_WANT; |
351 | |
345 | |
352 | @MUSIC_HAVE = @have |
346 | @MUSIC_HAVE = @have |
353 | if @have; |
347 | if @have; |
354 | |
348 | |
… | |
… | |
776 | state => $CFG->{fullscreen}, |
770 | state => $CFG->{fullscreen}, |
777 | tooltip => "Bring the client into fullscreen mode.", |
771 | tooltip => "Bring the client into fullscreen mode.", |
778 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
772 | on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 } |
779 | ); |
773 | ); |
780 | |
774 | |
|
|
775 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1"); |
|
|
776 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
777 | state => $CFG->{force_opengl11}, |
|
|
778 | tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in " |
|
|
779 | . "higher memory usage and slower performance. It will, however, help tremendously on " |
|
|
780 | . "cards that claim to support a feature but fall back to software rendering. " |
|
|
781 | . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, " |
|
|
782 | . "but cards and drivers from other vendors (ATI) are often just as bad. <b>If you " |
|
|
783 | . "experience extremely low framerates and your card should do better, try this option.</b>", |
|
|
784 | on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 } |
|
|
785 | ); |
|
|
786 | |
|
|
787 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures"); |
|
|
788 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
|
|
789 | state => $CFG->{texture_compression}, |
|
|
790 | tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but " |
|
|
791 | . "will save a lot of memory and increase performance. The compression algorithm " |
|
|
792 | . "can differ form card to card, so your mileage may vary. This setting is ignored in " |
|
|
793 | . "forced OpenGL 1.1 mode.", |
|
|
794 | on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 } |
|
|
795 | ); |
|
|
796 | |
781 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
797 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly"); |
782 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
798 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
783 | state => $CFG->{fast}, |
799 | state => $CFG->{fast}, |
784 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
800 | tooltip => "Lower the visual quality considerably to speed up rendering.", |
785 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
801 | on_changed => sub { my ($self, $value) = @_; $CFG->{fast} = $value; 0 } |
… | |
… | |
811 | |
827 | |
812 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
828 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing"); |
813 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
829 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
814 | state => $CFG->{map_smoothing}, |
830 | state => $CFG->{map_smoothing}, |
815 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
831 | tooltip => "<b>Map Smoothing</b> tries to make tile borders less square. " |
816 | . "This increases load on the graphics subsystem and works only with 2.x servers. " |
832 | . "This increases load on the graphics subsystem and works only with TRT servers. " |
817 | . "Changes take effect at next connection only.", |
833 | . "Changes take effect at next login only.", |
818 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
834 | on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 } |
819 | ); |
835 | ); |
820 | |
836 | |
821 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
837 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fog of War"); |
822 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
838 | $table->add_at (1, $row++, new CFPlus::UI::CheckBox |
… | |
… | |
833 | ); |
849 | ); |
834 | |
850 | |
835 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
851 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize"); |
836 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
852 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
837 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
853 | range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1], |
838 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant.", |
854 | tooltip => "The font size used by the <b>message/server log</b> window only. Changes are instant, " |
|
|
855 | . "but you still need to press apply to correctly re-layout the widget.", |
839 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
856 | on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 }, |
840 | ); |
857 | ); |
841 | |
858 | |
842 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
859 | $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Gauge fontsize"); |
843 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
860 | $table->add_at (1, $row++, new CFPlus::UI::Slider |
… | |
… | |
904 | expand => 1, state => $CFG->{bgm_enable}, |
921 | expand => 1, state => $CFG->{bgm_enable}, |
905 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
922 | tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.", |
906 | on_changed => sub { |
923 | on_changed => sub { |
907 | $CFG->{bgm_enable} = $_[1]; |
924 | $CFG->{bgm_enable} = $_[1]; |
908 | $CONN->update_fx_want if $CONN; |
925 | $CONN->update_fx_want if $CONN; |
|
|
926 | audio_music_push; |
909 | 0 |
927 | 0 |
910 | } |
928 | } |
911 | ); |
929 | ); |
912 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
930 | $table->add_at (2, $row++, new CFPlus::UI::Slider |
913 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
931 | expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128], |
… | |
… | |
966 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
984 | $hb->add (my $hg = new CFPlus::UI::Gauge type => 'hp', tooltip => "#stat_health"); |
967 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
985 | $hb->add (my $mg = new CFPlus::UI::Gauge type => 'mana', tooltip => "#stat_mana"); |
968 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
986 | $hb->add (my $gg = new CFPlus::UI::Gauge type => 'grace', tooltip => "#stat_grace"); |
969 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
987 | $hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food"); |
970 | |
988 | |
971 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
989 | $vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp"); |
|
|
990 | $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress); |
|
|
991 | $vbox->add (my $sklprg = new CFPlus::UI::ExperienceProgress); |
972 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
992 | $vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged"); |
973 | |
993 | |
974 | $GAUGES = { |
994 | $GAUGES = { |
|
|
995 | exp => $exp, prg => $prg, sklprg => $sklprg, |
975 | exp => $exp, win => $win, range => $rng, |
996 | win => $win, range => $rng, |
976 | food => $fg, mana => $mg, hp => $hg, grace => $gg |
997 | hp => $hg, mana => $mg, grace => $gg, food => $fg, |
977 | }; |
998 | }; |
978 | |
999 | |
979 | &set_gauge_window_fontsize; |
1000 | &set_gauge_window_fontsize; |
980 | |
1001 | |
981 | $win |
1002 | $win |
… | |
… | |
1182 | $r |
1203 | $r |
1183 | } |
1204 | } |
1184 | |
1205 | |
1185 | sub skill_window { |
1206 | sub skill_window { |
1186 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
1207 | my $sw = new CFPlus::UI::ScrolledWindow (expand => 1); |
|
|
1208 | |
1187 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]); |
1209 | $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]); |
|
|
1210 | |
1188 | $sw |
1211 | $sw |
1189 | } |
1212 | } |
1190 | |
1213 | |
1191 | sub formsep($) { |
1214 | sub formsep($) { |
1192 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
1215 | scalar reverse join ",", unpack "(A3)*", reverse $_[0] * 1 |
… | |
… | |
1604 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1627 | $sw1->add ($INV = new CFPlus::UI::Inventory); |
1605 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1628 | $INV->set_sort_order ($SORT_ORDER{$::CFG->{inv_sort}}); |
1606 | |
1629 | |
1607 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1630 | $hb->add (my $vb2 = new CFPlus::UI::VBox); |
1608 | |
1631 | |
1609 | $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox); |
1632 | $vb2->add ($INVR_HB = new CFPlus::UI::HBox); |
1610 | |
1633 | |
1611 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1634 | $vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1); |
1612 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1635 | $sw2->add ($INVR = new CFPlus::UI::Inventory); |
1613 | |
1636 | |
1614 | # XXX: Call after $INVR = ... because set_opencont sets the items |
1637 | # XXX: Call after $INVR = ... because set_opencont sets the items |
… | |
… | |
1637 | } |
1660 | } |
1638 | |
1661 | |
1639 | sub add_license { |
1662 | sub add_license { |
1640 | my ($meta) = @_; |
1663 | my ($meta) = @_; |
1641 | |
1664 | |
1642 | $meta = $meta->{meta} |
1665 | $meta = $meta->{data} |
1643 | or return; |
1666 | or return; |
1644 | |
1667 | |
1645 | $meta->{license} || $meta->{author} || $meta->{source} |
1668 | $meta->{license} || $meta->{author} || $meta->{source} |
1646 | or return; |
1669 | or return; |
1647 | |
1670 | |
… | |
… | |
1869 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1892 | on_activate => sub { $QUIT_DIALOG->hide; 0 }, |
1870 | ); |
1893 | ); |
1871 | $hb->add (new CFPlus::UI::Button |
1894 | $hb->add (new CFPlus::UI::Button |
1872 | text => "Quit anyway", |
1895 | text => "Quit anyway", |
1873 | expand => 1, |
1896 | expand => 1, |
1874 | on_activate => sub { exit }, |
1897 | on_activate => sub { Event::unloop_all }, |
1875 | ); |
1898 | ); |
1876 | } |
1899 | } |
1877 | |
1900 | |
1878 | $QUIT_DIALOG->show; |
1901 | $QUIT_DIALOG->show; |
1879 | $QUIT_DIALOG->grab_focus; |
1902 | $QUIT_DIALOG->grab_focus; |
… | |
… | |
2073 | tooltip => "Terminates the program", |
2096 | tooltip => "Terminates the program", |
2074 | on_activate => sub { |
2097 | on_activate => sub { |
2075 | if ($CONN) { |
2098 | if ($CONN) { |
2076 | open_quit_dialog; |
2099 | open_quit_dialog; |
2077 | } else { |
2100 | } else { |
2078 | exit; |
2101 | Event::unloop_all; |
2079 | } |
2102 | } |
2080 | 0 |
2103 | 0 |
2081 | }, |
2104 | }, |
2082 | ); |
2105 | ); |
2083 | |
2106 | |
2084 | $BUTTONBAR->show; |
2107 | $BUTTONBAR->show; |
2085 | $SETUP_DIALOG->show; |
2108 | $SETUP_DIALOG->show; |
|
|
2109 | $MESSAGE_WINDOW->show; |
2086 | } |
2110 | } |
2087 | |
2111 | |
2088 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2112 | $STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]); |
2089 | } |
2113 | } |
2090 | |
2114 | |
… | |
… | |
2098 | my $animate_timer; |
2122 | my $animate_timer; |
2099 | |
2123 | |
2100 | my $fps = 9; |
2124 | my $fps = 9; |
2101 | |
2125 | |
2102 | sub force_refresh { |
2126 | sub force_refresh { |
|
|
2127 | if ($ENV{CFPLUS_DEBUG} & 4) { |
2103 | $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05; |
2128 | $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02; |
2104 | debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4; |
2129 | debug sprintf "%3.2f", $fps; |
|
|
2130 | } |
2105 | |
2131 | |
2106 | $CFPlus::UI::ROOT->draw; |
2132 | $CFPlus::UI::ROOT->draw; |
2107 | |
2133 | CFPlus::SDL_GL_SwapBuffers; |
2108 | $WANT_REFRESH = 0; |
|
|
2109 | $CAN_REFRESH = 0; |
|
|
2110 | $LAST_REFRESH = $NOW; |
2134 | $LAST_REFRESH = $NOW; |
2111 | |
2135 | $WANT_REFRESH->stop; |
2112 | CFPlus::SDL_GL_SwapBuffers; |
|
|
2113 | } |
2136 | } |
2114 | |
2137 | |
|
|
2138 | $WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh); |
|
|
2139 | |
2115 | my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub { |
2140 | my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub { |
2116 | $NOW = time; |
2141 | $NOW = time; |
2117 | |
2142 | |
2118 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2143 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
2119 | for CFPlus::poll_events; |
2144 | for CFPlus::poll_events; |
2120 | |
2145 | |
2121 | if (%animate_object) { |
2146 | if (%animate_object) { |
2122 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2147 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
2123 | ++$WANT_REFRESH; |
2148 | $WANT_REFRESH->start; |
2124 | } |
|
|
2125 | |
|
|
2126 | if ($WANT_REFRESH) { |
|
|
2127 | force_refresh; |
|
|
2128 | } else { |
|
|
2129 | $CAN_REFRESH = 1; |
|
|
2130 | } |
2149 | } |
2131 | }); |
2150 | }); |
2132 | |
2151 | |
2133 | sub animation_start { |
2152 | sub animation_start { |
2134 | my ($widget) = @_; |
2153 | my ($widget) = @_; |
… | |
… | |
2140 | delete $animate_object{$widget}; |
2159 | delete $animate_object{$widget}; |
2141 | } |
2160 | } |
2142 | |
2161 | |
2143 | %SDL_CB = ( |
2162 | %SDL_CB = ( |
2144 | CFPlus::SDL_QUIT => sub { |
2163 | CFPlus::SDL_QUIT => sub { |
2145 | exit; |
2164 | Event::unloop_all; |
2146 | }, |
2165 | }, |
2147 | CFPlus::SDL_VIDEORESIZE => sub { |
2166 | CFPlus::SDL_VIDEORESIZE => sub { |
2148 | }, |
2167 | }, |
2149 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2168 | CFPlus::SDL_VIDEOEXPOSE => sub { |
2150 | CFPlus::UI::full_refresh; |
2169 | CFPlus::UI::full_refresh; |
… | |
… | |
2189 | CFPlus::DB::Server::run; |
2208 | CFPlus::DB::Server::run; |
2190 | |
2209 | |
2191 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2210 | CFPlus::UI::set_layout ($::CFG->{layout}); |
2192 | |
2211 | |
2193 | my %DEF_CFG = ( |
2212 | my %DEF_CFG = ( |
2194 | sdl_mode => 0, |
2213 | sdl_mode => 0, |
2195 | fullscreen => 0, |
2214 | fullscreen => 0, |
2196 | fast => 0, |
2215 | fast => 0, |
|
|
2216 | force_opengl11 => undef, |
|
|
2217 | texture_compression => 1, |
2197 | map_scale => 1, |
2218 | map_scale => 1, |
2198 | fow_enable => 1, |
2219 | fow_enable => 1, |
2199 | fow_intensity => 0, |
2220 | fow_intensity => 0, |
2200 | map_smoothing => 1, |
2221 | map_smoothing => 1, |
2201 | gui_fontsize => 1, |
2222 | gui_fontsize => 1, |
2202 | log_fontsize => 0.7, |
2223 | log_fontsize => 0.7, |
2203 | gauge_fontsize => 1, |
2224 | gauge_fontsize => 1, |
2204 | gauge_size => 0.35, |
2225 | gauge_size => 0.35, |
2205 | stat_fontsize => 0.7, |
2226 | stat_fontsize => 0.7, |
2206 | mapsize => 100, |
2227 | mapsize => 100, |
2207 | audio_enable => 1, |
2228 | audio_enable => 1, |
2208 | effects_enable => 1, |
2229 | effects_enable => 1, |
2209 | effects_volume => 1, |
2230 | effects_volume => 1, |
2210 | bgm_enable => 1, |
2231 | bgm_enable => 1, |
2211 | bgm_volume => 0.5, |
2232 | bgm_volume => 0.5, |
2212 | output_sync => 1, |
2233 | output_sync => 1, |
2213 | output_count => 1, |
2234 | output_count => 1, |
2214 | output_rate => "", |
2235 | output_rate => "", |
2215 | pickup => 0, |
2236 | pickup => 0, |
2216 | inv_sort => "mtime", |
2237 | inv_sort => "mtime", |
2217 | default => "profile", # default profile |
2238 | default => "profile", # default profile |
2218 | show_tips => 1, |
2239 | show_tips => 1, |
2219 | logview_max_par => 1000, |
2240 | logview_max_par => 1000, |
2220 | ); |
2241 | ); |
2221 | |
2242 | |
2222 | while (my ($k, $v) = each %DEF_CFG) { |
2243 | while (my ($k, $v) = each %DEF_CFG) { |
2223 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2244 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
2224 | } |
2245 | } |
… | |
… | |
2281 | # } |
2302 | # } |
2282 | # my $t2 = Time::HiRes::time; |
2303 | # my $t2 = Time::HiRes::time; |
2283 | # warn $t2-$t1; |
2304 | # warn $t2-$t1; |
2284 | # } |
2305 | # } |
2285 | |
2306 | |
2286 | $startup_done->(); |
|
|
2287 | |
|
|
2288 | video_init; |
2307 | video_init; |
2289 | audio_init; |
2308 | audio_init; |
2290 | } |
2309 | } |
2291 | |
2310 | |
2292 | show_tip_of_the_day if $CFG->{show_tips}; |
2311 | show_tip_of_the_day if $CFG->{show_tips}; |
2293 | |
2312 | |
|
|
2313 | Event->idle (cb => sub { |
|
|
2314 | $_[0]->w->cancel; |
|
|
2315 | $startup_done->(); |
|
|
2316 | }); |
|
|
2317 | |
2294 | Event::loop; |
2318 | Event::loop; |
|
|
2319 | |
|
|
2320 | #video_shutdown; |
|
|
2321 | #audio_shutdown; |
2295 | #CFPlus::SDL_Quit; |
2322 | CFPlus::SDL_Quit; |
2296 | #CFPlus::_exit 0; |
|
|
2297 | |
|
|
2298 | END { |
|
|
2299 | video_shutdown; |
|
|
2300 | audio_shutdown; |
|
|
2301 | CFPlus::SDL_Quit; |
|
|
2302 | CFPlus::DB::Server::stop; |
2323 | CFPlus::DB::Server::stop; |
2303 | } |
|
|
2304 | |
2324 | |
2305 | =head1 NAME |
2325 | =head1 NAME |
2306 | |
2326 | |
2307 | cfplus - A Crossfire TRT and Crossfire game client |
2327 | cfplus - A Crossfire TRT and Crossfire game client |
2308 | |
2328 | |