--- deliantra/Deliantra-Client/bin/cfplus 2007/05/12 08:13:34 1.155
+++ deliantra/Deliantra-Client/bin/cfplus 2007/07/19 15:43:14 1.177
@@ -1,6 +1,7 @@
#!/opt/bin/perl
my $startup_done = sub { };
+our $PANGO = "1.5.0";
# do splash-screen thingy on win32
BEGIN {
@@ -45,8 +46,8 @@
# relocatable
} else {
# unix, need to patch pango rc file
- open my $fh, "<:perlio", "$tmp/usr/lib/pango/1.5.0/module-files.d/libpango1.0-0.modules"
- or die "$tmp/usr/lib/1.5.0/module-files.d/libpango1.0-0.modules: $!";
+ open my $fh, "<:perlio", "$tmp/usr/lib/pango/$PANGO/module-files.d/libpango1.0-0.modules"
+ or die "$tmp/usr/lib/$PANGO/module-files.d/libpango1.0-0.modules: $!";
local $/;
my $rc = <$fh>;
$rc =~ s/^\//$tmp\//gm; # replace abs paths by relative ones
@@ -160,6 +161,12 @@
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
@@ -320,9 +327,6 @@
return;
}
- $STATS_PAGE->show;
- $MESSAGE_WINDOW->hide;
-
unshift @dialog, new CFPlus::UI::Label
max_w => $::WIDTH * 0.4,
ellipsise => 0,
@@ -497,6 +501,9 @@
$SETUP_DIALOG->show;
$PL_WINDOW->hide;
$SPELL_LIST->clear_spells;
+ $CFPlus::UI::ROOT->emit (stop_game => ! ! $CONN);
+
+ &audio_music_set ([]);
return unless $CONN;
@@ -521,17 +528,25 @@
can_events => 1,
tooltip => "" . (CFPlus::OpenGL::gl_extensions) . "");
+ my $vidmode_tooltip =
+ "Video Mode. The video mode to use for fullscreen (and the window size for windowed operation). "
+ . "The format is width x height \@ depth-per-channel + alpha-channel.";
+
$table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Video Mode");
$table->add (1, $row++, my $hbox = new CFPlus::UI::HBox);
- $hbox->add (my $mode_slider = new CFPlus::UI::Slider force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1]);
- $hbox->add (my $mode_label = new CFPlus::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
+ $hbox->add (my $mode_slider = new CFPlus::UI::Slider
+ force_w => $WIDTH * 0.1, expand => 1, range => [$CFG->{sdl_mode}, 0, $#SDL_MODES, 0, 1],
+ tooltip => $vidmode_tooltip);
+ $hbox->add (my $mode_label = new CFPlus::UI::Label
+ align => 0, valign => 0, height => 0.8, template => "9999x9999@9+9",
+ can_events => 1, tooltip => $vidmode_tooltip);
$mode_slider->connect (changed => sub {
my ($self, $value) = @_;
$CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
- $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
+ $mode_label->set_text (sprintf '%dx%d@%d+%d', @{$SDL_MODES[$value]});
});
$mode_slider->emit (changed => $mode_slider->{range}[0]);
@@ -573,7 +588,7 @@
on_changed => sub { my ($self, $value) = @_; $CFG->{map_scale} = 2 ** $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Smoothing");
+ $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Map Smoothing");
$table->add (1, $row++, new CFPlus::UI::CheckBox
state => $CFG->{map_smoothing},
tooltip => "Map Smoothing tries to make tile borders less square. "
@@ -596,18 +611,6 @@
on_changed => sub { my ($self, $value) = @_; $CFG->{fow_intensity} = $value; 0 }
);
- $table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "FoW Smooth");
- $table->add (1, $row++, new CFPlus::UI::CheckBox
- state => $CFG->{fow_smooth},
- tooltip => "Smooth the Fog-of-War a bit to make it more realistic. Changes are instant.",
- on_changed => sub {
- my ($self, $value) = @_;
- $CFG->{fow_smooth} = $value;
- status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFPlus::OpenGL::GL_VERSION < 1.2;
- 0
- }
- );
-
$table->add (0, $row, new CFPlus::UI::Label valign => 0, align => 1, text => "Message Fontsize");
$table->add (1, $row++, new CFPlus::UI::Slider
range => [$CFG->{log_fontsize}, 0.5, 2, 0, 0.1],
@@ -747,19 +750,7 @@
$table->add (1, 2, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 4; 0 });
$table->add (0, 3, new CFPlus::UI::Label text => "Suppress Tooltips");
$table->add (1, 3, new CFPlus::UI::CheckBox on_changed => sub { $ENV{CFPLUS_DEBUG} ^= 8; 0 });
- $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { die "violator" } );
-
- my @default_smooth = (0.05, 0.13, 0.05, 0.13, 0.30, 0.13, 0.05, 0.13, 0.05);
-
- for my $x (0..2) {
- for my $y (0 .. 2) {
- $table->add ($x + 3, $y,
- new CFPlus::UI::Entry
- text => $default_smooth[$x * 3 + $y],
- on_changed => sub { $MAP->{smooth_matrix}[$x * 3 + $y] = $_[1] if $MAP; 0 },
- );
- }
- }
+ $table->add (0, 4, new CFPlus::UI::Button text => "die on click(tm)", on_activate => sub { &CFPlus::debug() } );
$table->add (0, 5, new CFPlus::UI::TextEdit text => "line1\0152\0153");#d#
@@ -1272,7 +1263,14 @@
}
sub autopickup_setup {
- my $table = new CFPlus::UI::Table;
+ my $r = new CFPlus::UI::ScrolledWindow (
+ expand => 1,
+ scroll_y => 1
+ );
+ $r->add (my $table = new CFPlus::UI::Table
+ row_expand => [0],
+ col_expand => [0, 1, 0, 1],
+ );
for (
["General", 0, 0,
@@ -1366,7 +1364,7 @@
0
});
- $table
+ $r
}
my %SORT_ORDER = (
@@ -1455,7 +1453,7 @@
my $ntb =
$PL_NOTEBOOK =
- new CFPlus::UI::Notebook expand => 1, debug => 1;
+ new CFPlus::UI::Notebook expand => 1;
$ntb->add (
"Statistics (F2)" => $STATS_PAGE = stats_window,
@@ -1710,17 +1708,15 @@
}
sub video_init {
- sdl_init;
-
$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} >= @SDL_MODES;
my ($old_w, $old_h) = ($WIDTH, $HEIGHT);
- ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
+ ($WIDTH, $HEIGHT, my ($rgb, $alpha)) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
$FULLSCREEN = $CFG->{fullscreen};
$FAST = $CFG->{fast};
- CFPlus::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
+ CFPlus::SDL_SetVideoMode $WIDTH, $HEIGHT, $rgb, $alpha, $FULLSCREEN
or die "SDL_SetVideoMode failed: " . (CFPlus::SDL_GetError) . "\n";
$SDL_ACTIVE = 1;
@@ -2002,23 +1998,89 @@
undef $SDL_ACTIVE;
}
-my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
-my $bgmusic;#TODO#hack#d#
-
sub audio_channel_finished {
my ($channel) = @_;
#warn "channel $channel finished\n";#d#
}
-sub audio_music_finished {
+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 {
+ # music might have changed...
+ $path eq $MUSIC_PLAYING->{path}
+ or return &audio_music_start ();
+
+ $MUSIC_PLAYER = new_from_file CFPlus::MixMusic $path;
+
+ 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};
- # TODO: hack, do play loop and mood music
- $bgmusic = new_from_file CFPlus::MixMusic CFPlus::find_rcfile "music/$bgmusic[0]";
- $bgmusic->play (0);
+ # 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];
- push @bgmusic, shift @bgmusic;
+ audio_music_start;
+ }
+}
+
+sub audio_music_finished {
+ $MUSIC_PLAYING = undef;
+ undef $MUSIC_PLAYER;
+
+ audio_music_changed;
}
sub audio_init {
@@ -2078,7 +2140,7 @@
$CFPlus::UI::ROOT->draw;
$WANT_REFRESH = 0;
- $CAN_REFRESH = 0;
+ $CAN_REFRESH = 0;
$LAST_REFRESH = $NOW;
CFPlus::SDL_GL_SwapBuffers;
@@ -2088,11 +2150,11 @@
$NOW = time;
($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
- for CFPlus::SDL_PollEvent;
+ for CFPlus::poll_events;
if (%animate_object) {
$_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
- $WANT_REFRESH++;
+ ++$WANT_REFRESH;
}
if ($WANT_REFRESH) {
@@ -2132,7 +2194,8 @@
},
CFPlus::SDL_ACTIVEEVENT => sub {
# not useful, as APPACTIVE include sonly iconified state, not unmapped
-# printf "active %x %x\n", $_[0]{gain}, $_[0]{state};#d#
+# printf "active %x %x %x\n", $_[0]{gain}, $_[0]{state}, CFPlus::SDL_GetAppState;#d#
+# printf "a %x\n", CFPlus::SDL_GetAppState & CFPlus::SDL_APPACTIVE;#d#
# printf "A\n" if $_[0]{state} & CFPlus::SDL_APPACTIVE;
# printf "K\n" if $_[0]{state} & CFPlus::SDL_APPINPUTFOCUS;
# printf "M\n" if $_[0]{state} & CFPlus::SDL_APPMOUSEFOCUS;
@@ -2178,8 +2241,7 @@
fast => 0,
map_scale => 1,
fow_enable => 1,
- fow_intensity => 0.45,
- fow_smooth => 0,
+ fow_intensity => 0,
map_smoothing => 1,
gui_fontsize => 1,
log_fontsize => 0.7,
@@ -2223,12 +2285,12 @@
sdl_init;
- @SDL_MODES = reverse
- grep $_->[0] >= 640 && $_->[1] >= 480,
- CFPlus::SDL_ListModes;
-
+ @SDL_MODES = CFPlus::SDL_ListModes 8, 8;
+ @SDL_MODES = CFPlus::SDL_ListModes 5, 0 unless @SDL_MODES;
@SDL_MODES or CFPlus::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
+ @SDL_MODES = sort { $a->[0] * $a->[1] <=> $b->[0] * $b->[1] } @SDL_MODES;
+
$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
{