--- deliantra/Deliantra-Client/bin/cfplus 2007/07/29 03:58:26 1.188
+++ deliantra/Deliantra-Client/bin/cfplus 2007/08/21 02:39:17 1.220
@@ -73,6 +73,7 @@
use Time::HiRes 'time';
use Event;
+use List::Util qw(max min);
use Crossfire;
use Crossfire::Protocol::Constants;
@@ -114,7 +115,6 @@
our $FAST; # fast, low-quality mode, possibly useful for software-rendering
our $WANT_REFRESH;
-our $CAN_REFRESH;
our @SDL_MODES;
our $WIDTH;
@@ -145,6 +145,9 @@
our $PL_NOTEBOOK;
our $PL_WINDOW;
+our $MUSIC_PLAYING_WIDGET;
+our $LICENSE_WIDGET;
+
our $INVENTORY_PAGE;
our $STATS_PAGE;
our $SKILL_PAGE;
@@ -160,25 +163,15 @@
our $SDL_ACTIVE;
our %SDL_CB;
-our $SDL_MIXER;
-our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
-our @MUSIC_WANT;
-our $MUSIC_START;
-our $MUSIC_PLAYING;
-our $MUSIC_PLAYER;
-our $MUSIC_RESUME = 30; # resume music when players less than these many seconds before
-our @SOUNDS; # event => file mapping
-our %AUDIO_CHUNKS; # audio files
-
our $ALT_ENTER_MESSAGE;
our $STATUSBOX;
our $DEBUG_STATUS;
our $INV;
our $INVR;
-our $INV_RIGHT_HB;
+our $INVR_HB;
-our $PICKUP_CFG;
+#############################################################################
sub status {
$STATUSBOX->add (CFPlus::asxml $_[0], pri => -10, group => "status", timeout => 10, fg => [1, 1, 0, 1]);
@@ -193,6 +186,250 @@
$MESSAGE_WINDOW->message ($para);
}
+#############################################################################
+#TODO: maybe move into own audio module...
+
+our $SDL_MIXER;
+
+our $MUSIC_DEFAULT = "in_a_heartbeat.ogg";
+our $MUSIC_WANT; # arryref of ambient music we want to play
+our @MUSIC_HAVE; # ambient music we have on disk
+our $MUSIC_START;
+our @MUSIC_JINGLE; # which jingles to play next
+our $MUSIC_PLAYING_DATA;
+our $MUSIC_PLAYING_META;
+our $MUSIC_PLAYER;
+our $MUSIC_RESUME = 30; # resume music when played less than these many seconds before
+
+our %AUDIO_CHUNK; # audio "files"
+our %AUDIO_PLAY; # which audio faces should be played
+
+sub audio_channel_finished {
+ my ($channel) = @_;
+
+# warn "channel $channel finished\n";#d#
+}
+
+sub audio_sound_push($) {
+ my ($face) = @_;
+
+ $CFG->{effects_enable}
+ or return;
+
+ $AUDIO_PLAY{$face}
+ or return;
+
+ if (my $chunk = $AUDIO_CHUNK{$face}) {
+ for (grep $_->[0] >= Event::time, @{(delete $AUDIO_PLAY{$face}) || []}) {
+ my (undef, $dx, $dy, $vol) = @$_;
+
+ my $channel = CFPlus::Channel::find;
+ $channel->volume ($vol * $CFG->{effects_volume} * 128 / 255);
+ $channel->set_position_r ($dx, $dy, 20);
+ $chunk->play ($channel);
+ }
+ } else {
+ # sound_meta not set means data is in flight either way
+ my $meta = $CONN->{face}[$face]
+ or return;
+
+ $meta->{data}
+ or return;
+
+ # if its a jingle, play it as ambient music
+ if ($meta->{data}{jingle}) {
+ if (delete $AUDIO_PLAY{$face}) { # take the jingle out of the sound queue
+ push @MUSIC_JINGLE, $meta; # push it oto the music/jingle queue
+ &audio_music_push ($face);
+ }
+ } else {
+ # fetch from database
+ CFPlus::DB::get res_data => $meta->{name}, sub {
+ my $rwops = new CFPlus::RW $_[0];
+ my $chunk = new CFPlus::MixChunk $rwops
+ or Carp::confess "sound face " . (JSON::XS::to_json $meta) . " unloadable: " . CFPlus::Mix_GetError;
+ $chunk->volume (($meta->{data}{volume} || 1) * 128);
+ $AUDIO_CHUNK{$face} = $chunk;
+
+ audio_sound_push ($face);
+ };
+ }
+ }
+}
+
+sub audio_sound_play {
+ my ($face, $dx, $dy, $vol) = @_;
+
+ $SDL_MIXER
+ or return;
+ $CFG->{effects_enable}
+ or return;
+
+ my $queue = $AUDIO_PLAY{$face} ||= [];
+ push @$queue, [Event::time + 0.6, $dx, $dy, $vol]; # do not play sound for outdated events
+ audio_sound_push $face
+ unless @$queue > 1;
+}
+
+sub audio_music_set_meta {
+ my ($meta) = @_;
+
+ $MUSIC_PLAYING_META = $meta;
+ $MUSIC_PLAYING_WIDGET->set_markup (
+ "Name: " . (CFPlus::asxml $meta->{data}{name}) . "\n"
+ . "Author: " . (CFPlus::asxml $meta->{data}{author}) . "\n"
+ . "Source: " . (CFPlus::asxml $meta->{data}{source}) . "\n"
+ . "License: " . (CFPlus::asxml $meta->{data}{license})
+ );
+}
+
+sub audio_music_update_volume {
+ return unless $MUSIC_PLAYING_META;
+ my $volume = $MUSIC_PLAYING_META->{data}{volume} || 1;
+ my $base = $MUSIC_PLAYING_META->{data}{jingle} ? 1 : $CFG->{bgm_volume};
+ CFPlus::MixMusic::volume $base * $volume * 128;
+}
+
+sub audio_music_start {
+ my $meta = $MUSIC_PLAYING_META;
+
+ CFPlus::DB::get res_data => $meta->{name}, sub {
+ return unless $SDL_MIXER;
+
+ # music might have changed...
+ $meta eq $MUSIC_PLAYING_META
+ or return &audio_music_start ();
+
+ audio_music_update_volume;
+
+ $MUSIC_PLAYING_DATA = \$_[0];
+
+ my $rwops = $meta->{path}
+ ? new_from_file CFPlus::RW $meta->{path}
+ : new CFPlus::RW $$MUSIC_PLAYING_DATA;
+
+ $MUSIC_PLAYER = new CFPlus::MixMusic $rwops
+ or Carp::confess "music face $meta->{face} unloadable: " . CFPlus::Mix_GetError;
+
+ my $NOW = time;
+
+ if ($MUSIC_PLAYING_META->{stop_time} > $NOW - $MUSIC_RESUME) {
+ my $pos = $MUSIC_PLAYING_META->{stop_pos};
+ $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
+ $MUSIC_START = time - $pos;
+ } else {
+ $MUSIC_PLAYER->play (0);
+ $MUSIC_START = time;
+ }
+
+ delete $meta->{stop_time};
+ delete $meta->{stop_pos};
+ }
+}
+
+sub audio_music_push {
+ return unless $SDL_MIXER;
+
+ my $fade_out;
+
+ if (@MUSIC_JINGLE) {
+ @MUSIC_HAVE = $MUSIC_JINGLE[0];
+ $fade_out = 333;
+ } else {
+ return unless $CFG->{bgm_enable};
+
+ my @have =
+ grep $_ && $_->{data},
+ map $CONN->{face}[$_],
+ @$MUSIC_WANT;
+
+ @MUSIC_HAVE = @have
+ if @have;
+
+ # default MUSIC_HAVE == MUSIC_DEFAULT
+ @MUSIC_HAVE = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_HAVE;
+ $fade_out = 1000;
+ }
+
+ # if the currently playing song is acceptable, let it continue
+ return if grep $MUSIC_PLAYING_META == $_, @MUSIC_HAVE;
+
+ my $NOW = time;
+
+ if ($MUSIC_PLAYING_META) {
+ $MUSIC_PLAYING_META->{stop_time} = $NOW;
+ $MUSIC_PLAYING_META->{stop_pos} = $NOW - $MUSIC_START;
+ CFPlus::MixMusic::fade_out $fade_out;
+ } else {
+ # sort by stop time, oldest first
+ @MUSIC_HAVE = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_HAVE;
+
+ # if the most recently-played piece played very recently,
+ # resume it, else choose the oldest piece for rotation.
+ audio_music_set_meta
+ $MUSIC_HAVE[-1]{stop_time} > $NOW - $MUSIC_RESUME
+ ? $MUSIC_HAVE[-1]
+ : $MUSIC_HAVE[0];
+
+ audio_music_start;
+ }
+}
+
+sub audio_music_set_ambient {
+ my ($songs) = @_;
+
+ $MUSIC_WANT = $songs;
+ audio_music_push;
+}
+
+sub audio_music_finished {
+ # we compress multiple jingles of the same type
+ shift @MUSIC_JINGLE
+ while @MUSIC_JINGLE && $MUSIC_PLAYING_META == $MUSIC_JINGLE[0];
+
+ $MUSIC_PLAYING_WIDGET->clear;
+
+ undef $MUSIC_PLAYER;
+ undef $MUSIC_PLAYING_META;
+ undef $MUSIC_PLAYING_DATA;
+
+ audio_music_push;
+}
+
+sub audio_init {
+ if ($CFG->{audio_enable}) {
+ $ENV{MIX_EFFECTSMAXSPEED} = 1;
+ $SDL_MIXER = !CFPlus::Mix_OpenAudio;
+
+ unless ($SDL_MIXER) {
+ status "Unable to open sound device: there will be no sound";
+ return;
+ }
+
+ CFPlus::Mix_AllocateChannels 16;
+
+ audio_music_finished;
+ } else {
+ undef $SDL_MIXER;
+ }
+}
+
+sub audio_shutdown {
+ undef $MUSIC_PLAYER;
+ undef $MUSIC_PLAYING_META;
+ undef $MUSIC_PLAYING_DATA;
+
+ $MUSIC_WANT = [];
+ @MUSIC_JINGLE = ();
+ %AUDIO_PLAY = ();
+ %AUDIO_CHUNK = ();
+
+ CFPlus::Mix_CloseAudio if $SDL_MIXER;
+ undef $SDL_MIXER;
+}
+
+#############################################################################
+
sub destroy_query_dialog {
(delete $_[0]{query_dialog})->destroy
if $_[0]{query_dialog};
@@ -461,18 +698,6 @@
setup_req => {
smoothing => $CFG->{map_smoothing}*1,
},
-
- sound_play => sub {
- my ($x, $y, $soundnum, $type) = @_;
-
- $SDL_MIXER
- or return;
-
- my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
- or return;
-
- $chunk->play;
- },
};
if ($CONN) {
@@ -493,7 +718,7 @@
$SPELL_LIST->clear_spells;
$CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
- &audio_music_set ([]);
+ &audio_music_set_ambient ([]);
return unless $CONN;
@@ -547,6 +772,28 @@
on_changed => sub { my ($self, $value) = @_; $CFG->{fullscreen} = $value; 0 }
);
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Force OpenGL 1.1");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
+ state => $CFG->{force_opengl11},
+ tooltip => "Limit CFPlus to use OpenGL 1.1 features only. This will normally result in "
+ . "higher memory usage and slower performance. It will, however, help tremendously on "
+ . "cards that claim to support a feature but fall back to software rendering. "
+ . "Nvidia Geforce FX cards are known to claim features the hardware doesn't support, "
+ . "but cards and drivers from other vendors (ATI) are often just as bad. If you "
+ . "experience extremely low framerates and your card should do better, try this option.",
+ on_changed => sub { my ($self, $value) = @_; $CFG->{force_opengl11} = $value; 0 }
+ );
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Compress Textures");
+ $table->add_at (1, $row++, new CFPlus::UI::CheckBox
+ state => $CFG->{texture_compression},
+ tooltip => "Use texture compression. Normally this will not reduce visual quality noticable but "
+ . "will save a lot of memory and increase performance. The compression algorithm "
+ . "can differ form card to card, so your mileage may vary. This setting is ignored in "
+ . "forced OpenGL 1.1 mode.",
+ on_changed => sub { my ($self, $value) = @_; $CFG->{texture_compression} = $value; 0 }
+ );
+
$table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
$table->add_at (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{fast},
@@ -582,8 +829,8 @@
$table->add_at (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{map_smoothing},
tooltip => "Map Smoothing tries to make tile borders less square. "
- . "This increases load on the graphics subsystem and works only with 2.x servers. "
- . "Changes take effect at next connection only.",
+ . "This increases load on the graphics subsystem and works only with TRT servers. "
+ . "Changes take effect at next login only.",
on_changed => sub { my ($self, $value) = @_; $CFG->{map_smoothing} = $value; 0 }
);
@@ -604,7 +851,8 @@
$table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
$table->add_at (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
- tooltip => "The font size used by the message/server log window only. Changes are instant.",
+ tooltip => "The font size used by the message/server log window only. Changes are instant, "
+ . "but you still need to press apply to correctly re-layout the widget.",
on_changed => sub { $MESSAGE_WINDOW->set_fontsize ($CFG->{log_fontsize} = $_[1]); 0 },
);
@@ -636,7 +884,7 @@
sub audio_setup {
my $vbox = new CFPlus::UI::VBox;
- $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 1]);
+ $vbox->add (my $table = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1]);
my $row = 0;
@@ -650,21 +898,43 @@
# $table->add_at (1, 8, new CFPlus::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], on_changed => sub {
# $CFG->{effects_volume} = $_[1];
# });
+
+ $table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Sound Effects");
+ $table->add_at (1, $row, new CFPlus::UI::CheckBox
+ expand => 1, state => $CFG->{effects_enable},
+ tooltip => "If enabled, sound effects are enabled. If disabled, no sound effects will be played.",
+ on_changed => sub {
+ $CFG->{effects_enable} = $_[1];
+ $CONN->update_fx_want if $CONN;
+ 0
+ }
+ );
+ $table->add_at (2, $row++, new CFPlus::UI::Slider
+ expand => 1, range => [$CFG->{effects_volume}, 0, 1, 0, 1/128],
+ tooltip => "The relative volume of sound effects. Best audio quality is achieved if this "
+ . "is set highest (rightmost) and you use your operating system volume setting. Changes are instant.",
+ on_changed => sub { $CFG->{effects_volume} = $_[1]; 0 }
+ );
+
$table->add_at (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Background Music");
- $table->add_at (1, $row++, my $hbox = new CFPlus::UI::HBox);
- $hbox->add (new CFPlus::UI::CheckBox
+ $table->add_at (1, $row, new CFPlus::UI::CheckBox
expand => 1, state => $CFG->{bgm_enable},
tooltip => "If enabled, playing of background music is enabled. If disabled, no background music will be played.",
- on_changed => sub { $CFG->{bgm_enable} = $_[1]; 0 }
+ on_changed => sub {
+ $CFG->{bgm_enable} = $_[1];
+ $CONN->update_fx_want if $CONN;
+ audio_music_push;
+ 0
+ }
);
- $hbox->add (new CFPlus::UI::Slider
+ $table->add_at (2, $row++, new CFPlus::UI::Slider
expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0, 1/128],
tooltip => "The volume of the background music. Changes are instant.",
- on_changed => sub { $CFG->{bgm_volume} = $_[1]; CFPlus::MixMusic::volume $_[1] * 128; 0 }
+ on_changed => sub { $CFG->{bgm_volume} = $_[1]; audio_music_update_volume; 0 }
);
$table->add_at (1, $row++, new CFPlus::UI::Button
- expand => 1, align => 0, text => "Apply",
+ c_colspan => 2, expand => 1, align => 0, text => "Apply",
tooltip => "Apply the audio settings",
on_activate => sub {
audio_shutdown ();
@@ -717,10 +987,11 @@
$hb->add (my $fg = new CFPlus::UI::Gauge type => 'food', tooltip => "#stat_food");
$vbox->add (my $exp = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_exp");
+ $vbox->add (my $prg = new CFPlus::UI::ExperienceProgress);
$vbox->add (my $rng = new CFPlus::UI::Label valign => 0, align => 1, can_hover => 1, can_events => 1, tooltip => "#stat_ranged");
$GAUGES = {
- exp => $exp, win => $win, range => $rng,
+ exp => $exp, prg => $prg, win => $win, range => $rng,
food => $fg, mana => $mg, hp => $hg, grace => $gg
};
@@ -745,10 +1016,10 @@
$table->add_at (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
$table->add_at (7,7, my $t = new CFPlus::UI::Table expand => 0);
- $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", rowspan => 1, colspan => 2);
- $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", rowspan => 2, colspan => 1);
- $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", rowspan => 1, colspan => 2);
- $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", rowspan => 2, colspan => 1);
+ $t->add_at (0,0, new CFPlus::UI::Label text => "a a a a", c_rowspan => 1, c_colspan => 2);
+ $t->add_at (2,0, new CFPlus::UI::Label text => "b\nb", c_rowspan => 2, c_colspan => 1);
+ $t->add_at (1,2, new CFPlus::UI::Label text => "c c c c", c_rowspan => 1, c_colspan => 2);
+ $t->add_at (0,1, new CFPlus::UI::Label text => "d\nd", c_rowspan => 2, c_colspan => 1);
$t->add_at (1,1, new CFPlus::UI::Label text => "e");
$table->add_at (7, 6, my $c = new CFPlus::UI::Canvas);
@@ -932,7 +1203,9 @@
sub skill_window {
my $sw = new CFPlus::UI::ScrolledWindow (expand => 1);
- $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, 0, 0, 1]);
+
+ $sw->add ($STATWIDS->{skill_tbl} = new CFPlus::UI::Table expand => 1, col_expand => [0, 0, 1, .1, 0, 0, 1, .1]);
+
$sw
}
@@ -1083,7 +1356,7 @@
on_changed => sub {
my ($self, $value) = @_;
$CFG->{profile}{default}{host} = $value;
- 0
+ 1
}
);
@@ -1093,7 +1366,7 @@
other => $METASERVER,
tooltip => "Show a list of available crossfire servers",
on_activate => sub { $METASERVER->toggle_visibility; 0 },
- on_visibility_change => sub { $METASERVER->hide unless $_[1]; 0 },
+ on_visibility_change => sub { $METASERVER->hide unless $_[1]; 1 },
);
}
@@ -1101,7 +1374,7 @@
$table->add_at (1, 4, new CFPlus::UI::Entry
text => $CFG->{profile}{default}{user},
tooltip => "The name of your character on the server",
- on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value }
+ on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{user} = $value; 1 }
);
$table->add_at (0, 5, new CFPlus::UI::Label valign => 0, align => 1, text => "Password");
@@ -1109,7 +1382,7 @@
text => $CFG->{profile}{default}{password},
hidden => 1,
tooltip => "The password for your character",
- on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value }
+ on_changed => sub { my ($self, $value) = @_; $CFG->{profile}{default}{password} = $value; 1 }
);
$table->add_at (0, 7, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Size");
@@ -1120,53 +1393,41 @@
. "If you set this to a high value you will be able to see further, "
. "but you also increase bandwidth requirements and latency. "
. "This option is only used once at log-in.",
- on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 0 },
- );
-
- $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Face Prefetch");
- $table->add_at (1, 8, new CFPlus::UI::CheckBox
- state => $CFG->{face_prefetch},
- tooltip => "Background Image Prefetch\n\n"
- . "If enabled, the client automatically pre-fetches images from the server. "
- . "This might increase or create lag, but increases the chances "
- . "of faces being ready for display when you encounter them. "
- . "It also uses up server bandwidth on every connect, "
- . "so only set it if you really need to prefetch images. "
- . "This option can be set and unset any time.",
- on_changed => sub { $CFG->{face_prefetch} = $_[1]; 0 },
+ on_changed => sub { my ($self, $value) = @_; $CFG->{mapsize} = $self->{range}[0] = $value = int $value; 1 },
);
- $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
- $table->add_at (1, 9, new CFPlus::UI::Entry
+ $table->add_at (0, 8, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Rate");
+ $table->add_at (1, 8, new CFPlus::UI::Entry
text => $CFG->{output_rate},
- tooltip => "The approximate bandwidth in bytes per second that the server should not exceed "
- . "when sending images, to ensure interactiveness. When 0 or unset, the server "
- . "default will be used, which is usually around 100kb/s.",
- on_changed => sub { $CFG->{output_rate} = $_[1]; 0 },
+ tooltip => "The maximum bandwidth in bytes per second that the server should not exceed "
+ . "when sending data. When 0 or unset, the server "
+ . "default will be used, which is usually around 100kb/s. Most servers will "
+ . "dynamically find an optimal rate, so adjust this only when necessary.",
+ on_changed => sub { $CFG->{output_rate} = $_[1]; 1 },
);
- $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
- $table->add_at (1, 10, new CFPlus::UI::Entry
+ $table->add_at (0, 9, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Count");
+ $table->add_at (1, 9, new CFPlus::UI::Entry
text => $CFG->{output_count},
tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
- on_changed => sub { $CFG->{output_count} = $_[1]; 0 },
+ on_changed => sub { $CFG->{output_count} = $_[1]; 1 },
);
- $table->add_at (0, 11, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
- $table->add_at (1, 11, new CFPlus::UI::Entry
+ $table->add_at (0, 10, new CFPlus::UI::Label valign => 0, align => 1, text => "Output-Sync");
+ $table->add_at (1, 10, new CFPlus::UI::Entry
text => $CFG->{output_sync},
tooltip => "Should be set to 1 unless you know what you are doing. This option is only used once at log-in.",
- on_changed => sub { $CFG->{output_sync} = $_[1]; 0 },
+ on_changed => sub { $CFG->{output_sync} = $_[1]; 1 },
);
- $table->add_at (1, 12, $LOGIN_BUTTON = new CFPlus::UI::Button
+ $table->add_at (1, 11, $LOGIN_BUTTON = new CFPlus::UI::Button
expand => 1,
align => 0,
text => "Login",
on_activate => sub {
$CONN ? stop_game
: start_game;
- 0
+ 1
},
);
@@ -1366,7 +1627,7 @@
$hb->add (my $vb2 = new CFPlus::UI::VBox);
- $vb2->add ($INV_RIGHT_HB = new CFPlus::UI::HBox);
+ $vb2->add ($INVR_HB = new CFPlus::UI::HBox);
$vb2->add (my $sw2 = new CFPlus::UI::ScrolledWindow expand => 1, scroll_y => 1);
$sw2->add ($INVR = new CFPlus::UI::Inventory);
@@ -1377,6 +1638,46 @@
$hb
}
+sub media_window {
+ my $vb = new CFPlus::UI::VBox;
+
+ $vb->add (new CFPlus::UI::FancyFrame
+ label => "Currently playing music",
+ child => new CFPlus::UI::ScrolledWindow scroll_x => 1, scroll_y => 0,
+ child => ($MUSIC_PLAYING_WIDGET = new CFPlus::UI::Label ellipsise => 0, fontsize => 0.8),
+ );
+
+ $vb->add (new CFPlus::UI::FancyFrame
+ label => "Other media used in this session",
+ expand => 1,
+ child => ($LICENSE_WIDGET = new CFPlus::UI::TextScroller
+ expand => 1, fontsize => 0.8, padding_x => 4, padding_y => 4),
+ );
+
+ $vb
+}
+
+sub add_license {
+ my ($meta) = @_;
+
+ $meta = $meta->{data}
+ or return;
+
+ $meta->{license} || $meta->{author} || $meta->{source}
+ or return;
+
+ $LICENSE_WIDGET->add_paragraph ({
+ fg => [1, 1, 1, 1],
+ markup => ""
+ . "Name: " . (CFPlus::asxml $meta->{name}) . "\n"
+ . "Author: " . (CFPlus::asxml $meta->{author}) . "\n"
+ . "Source: " . (CFPlus::asxml $meta->{source}) . "\n"
+ . "License: " . (CFPlus::asxml $meta->{license}) . "\n"
+ . "",
+ });
+ $LICENSE_WIDGET->scroll_to_bottom;
+}
+
sub toggle_player_page {
my ($widget) = @_;
@@ -1423,9 +1724,12 @@
"Toggles the inventory window, where you can manage your loot (or treasures :). "
. "You can also hit the Tab-key to show/hide the Inventory."
);
- $ntb->add_tab (Pickup => autopickup_setup,
+ $ntb->add_tab (Pickup => autopickup_setup,
"Configure autopickup settings, i.e. which items you will pick up automatically when walking (or running) over them.");
+ $ntb->add_tab (Media => media_window,
+ "License, Author and Source info for media sent by the server.");
+
$ntb->set_current_page ($INVENTORY_PAGE);
$plwin->add ($ntb);
@@ -1588,7 +1892,7 @@
$hb->add (new CFPlus::UI::Button
text => "Quit anyway",
expand => 1,
- on_activate => sub { exit },
+ on_activate => sub { Event::unloop_all },
);
}
@@ -1792,7 +2096,7 @@
if ($CONN) {
open_quit_dialog;
} else {
- exit;
+ Event::unloop_all;
}
0
},
@@ -1800,6 +2104,7 @@
$BUTTONBAR->show;
$SETUP_DIALOG->show;
+ $MESSAGE_WINDOW->show;
}
$STATUSBOX->add ("Set video mode $WIDTH×$HEIGHT", timeout => 10, fg => [1, 1, 1, 0.5]);
@@ -1811,163 +2116,26 @@
undef $SDL_ACTIVE;
}
-sub audio_channel_finished {
- my ($channel) = @_;
-
- #warn "channel $channel finished\n";#d#
-}
-
-sub audio_music_set {
- my ($songs) = @_;
-
- my @want =
- grep $_,
- map $CONN->{music_meta}{$_},
- @$songs;
-
- if (@want) {
- @MUSIC_WANT = @want;
- &audio_music_changed ();
- }
-}
-
-sub audio_music_start {
- my $path = $MUSIC_PLAYING->{path}
- or return;
-
- CFPlus::DB::prefetch_file $path, 1024_000, sub {
- return unless $SDL_MIXER;
-
- # music might have changed...
- $path eq $MUSIC_PLAYING->{path}
- or return &audio_music_start ();
-
- my $rwops = new_from_file CFPlus::RW $path;
- $MUSIC_PLAYER = new CFPlus::MixMusic $rwops;
-
- my $NOW = time;
-
- if ($MUSIC_PLAYING->{stop_time} > $NOW - $MUSIC_RESUME) {
- my $pos = $MUSIC_PLAYING->{stop_pos};
- $MUSIC_PLAYER->fade_in_pos (0, 1000, $pos);
- $MUSIC_START = time - $pos;
- } else {
- $MUSIC_PLAYER->play (0);
- $MUSIC_START = time;
- }
-
- delete $MUSIC_PLAYING->{stop_time};
- delete $MUSIC_PLAYING->{stop_pos};
- }
-}
-
-sub audio_music_changed {
- return unless $CFG->{bgm_enable};
- return unless $SDL_MIXER;
-
- # default MUSIC_WANT == MUSIC_DEFAULT
- @MUSIC_WANT = { path => CFPlus::find_rcfile "music/$MUSIC_DEFAULT" } unless @MUSIC_WANT;
-
- # if the currently playing song is acceptable, let it continue
- return if $MUSIC_PLAYING
- && grep $MUSIC_PLAYING->{path} eq $_->{path}, @MUSIC_WANT;
-
- my $NOW = time;
-
- if ($MUSIC_PLAYING) {
- $MUSIC_PLAYING->{stop_time} = $NOW;
- $MUSIC_PLAYING->{stop_pos} = $NOW - $MUSIC_START;
- CFPlus::MixMusic::fade_out 1000;
- } else {
- # sort by stop time, oldest first
- @MUSIC_WANT = sort { $a->{stop_time} <=> $b->{stop_time} } @MUSIC_WANT;
-
- # if the most recently-played piece played very recently,
- # resume it, else choose the oldest piece for rotation.
- $MUSIC_PLAYING =
- $MUSIC_WANT[-1]{stop_time} > $NOW - $MUSIC_RESUME
- ? $MUSIC_WANT[-1]
- : $MUSIC_WANT[0];
-
- audio_music_start;
- }
-}
-
-sub audio_music_finished {
- $MUSIC_PLAYING = undef;
- undef $MUSIC_PLAYER;
-
- audio_music_changed;
-}
-
-sub audio_init {
- if ($CFG->{audio_enable}) {
- if (open my $fh, "<", CFPlus::find_rcfile "sounds/config") {
- $ENV{MIX_EFFECTSMAXSPEED} = 1;
- $SDL_MIXER = !CFPlus::Mix_OpenAudio;
-
- unless ($SDL_MIXER) {
- status "Unable to open sound device: there will be no sound";
- return;
- }
-
- CFPlus::Mix_AllocateChannels 8;
- CFPlus::MixMusic::volume $CFG->{bgm_volume} * 128;
-
- audio_music_finished;
-
- local $_;
- while (<$fh>) {
- next if /^\s*#/;
- next if /^\s*$/;
-
- my ($file, $volume, $event) = split /\s+/, $_, 3;
-
- push @SOUNDS, "$volume,$file";
-
- $AUDIO_CHUNKS{"$volume,$file"} ||= do {
- my $rwops = new_from_file CFPlus::RW CFPlus::find_rcfile "sounds/$file";
- my $chunk = new CFPlus::MixChunk $rwops;
- $chunk->volume ($volume * 128 / 100);
- $chunk
- };
- }
- } else {
- status "unable to open sound config: $!";
- }
- } else {
- undef $SDL_MIXER;
- }
-}
-
-sub audio_shutdown {
- CFPlus::Mix_CloseAudio if $SDL_MIXER;
- undef $SDL_MIXER;
- @SOUNDS = ();
- %AUDIO_CHUNKS = ();
-}
-
my %animate_object;
my $animate_timer;
my $fps = 9;
-my %demo;#d#
-
sub force_refresh {
- $fps = $fps * 0.95 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.05;
- debug sprintf "%3.2f", $fps if $ENV{CFPLUS_DEBUG} & 4;
+ if ($ENV{CFPLUS_DEBUG} & 4) {
+ $fps = $fps * 0.98 + 1 / (($NOW - $LAST_REFRESH) || 0.1) * 0.02;
+ debug sprintf "%3.2f", $fps;
+ }
$CFPlus::UI::ROOT->draw;
-
- $WANT_REFRESH = 0;
- $CAN_REFRESH = 0;
- $LAST_REFRESH = $NOW;
-
CFPlus::SDL_GL_SwapBuffers;
+ $LAST_REFRESH = $NOW;
+ $WANT_REFRESH->stop;
}
-my $refresh_watcher = Event->timer (after => 0, hard => 0, interval => 1 / $MAX_FPS, cb => sub {
+$WANT_REFRESH = Event->idle (min => 0.001, max => 0.06, parked => 1, cb => \&force_refresh);
+
+my $input = Event->timer (after => 0, hard => 0, interval => 1 / 50, cb => sub {
$NOW = time;
($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
@@ -1975,13 +2143,7 @@
if (%animate_object) {
$_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
- ++$WANT_REFRESH;
- }
-
- if ($WANT_REFRESH) {
- force_refresh;
- } else {
- $CAN_REFRESH = 1;
+ $WANT_REFRESH->start;
}
});
@@ -1995,15 +2157,6 @@
delete $animate_object{$widget};
}
-# check once/second for faces that need to be prefetched
-# this should, of course, only run on demand, but
-# SDL forces worse things on us....
-
-Event->timer (after => 1, interval => 0.25, cb => sub {
- $CONN->face_prefetch
- if $CONN;
-});
-
%SDL_CB = (
CFPlus::SDL_QUIT => sub {
exit;
@@ -2055,33 +2208,34 @@
CFPlus::UI::set_layout ($::CFG->{layout});
my %DEF_CFG = (
- sdl_mode => 0,
- width => 640,
- height => 480,
- fullscreen => 0,
- fast => 0,
- map_scale => 1,
- fow_enable => 1,
- fow_intensity => 0,
- map_smoothing => 1,
- gui_fontsize => 1,
- log_fontsize => 0.7,
- gauge_fontsize => 1,
- gauge_size => 0.35,
- stat_fontsize => 0.7,
- mapsize => 100,
- audio_enable => 1,
- bgm_enable => 1,
- bgm_volume => 0.25,
- face_prefetch => 0,
- output_sync => 1,
- output_count => 1,
- output_rate => "",
- pickup => 0,
- inv_sort => "mtime",
- default => "profile", # default profile
- show_tips => 1,
- logview_max_par => 1000,
+ sdl_mode => 0,
+ fullscreen => 0,
+ fast => 0,
+ force_opengl11 => undef,
+ texture_compression => 1,
+ map_scale => 1,
+ fow_enable => 1,
+ fow_intensity => 0,
+ map_smoothing => 1,
+ gui_fontsize => 1,
+ log_fontsize => 0.7,
+ gauge_fontsize => 1,
+ gauge_size => 0.35,
+ stat_fontsize => 0.7,
+ mapsize => 100,
+ audio_enable => 1,
+ effects_enable => 1,
+ effects_volume => 1,
+ bgm_enable => 1,
+ bgm_volume => 0.5,
+ output_sync => 1,
+ output_count => 1,
+ output_rate => "",
+ pickup => 0,
+ inv_sort => "mtime",
+ default => "profile", # default profile
+ show_tips => 1,
+ logview_max_par => 1000,
);
while (my ($k, $v) = each %DEF_CFG) {
@@ -2157,17 +2311,15 @@
show_tip_of_the_day if $CFG->{show_tips};
Event::loop;
-#CFPlus::SDL_Quit;
-#CFPlus::_exit 0;
-END {
- CFPlus::SDL_Quit;
- CFPlus::DB::Server::stop;
-}
+#video_shutdown;
+#audio_shutdown;
+CFPlus::SDL_Quit;
+CFPlus::DB::Server::stop;
=head1 NAME
-cfplus - A Crossfire+ and Crossfire game client
+cfplus - A Crossfire TRT and Crossfire game client
=head1 SYNOPSIS
@@ -2175,8 +2327,8 @@
=head1 USAGE
-cfplus utilises OpenGL for all UI elements and the game. It is supposed to be used
-fullscreen and interactively.
+cfplus utilises OpenGL for all UI elements and the game. It is supposed to
+be used in fullscreen mode and interactively.
=head1 DEBUGGING