… | |
… | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
|
|
9 | use SDL::OpenGL; |
|
|
10 | |
8 | |
11 | use Crossfire; |
9 | use Crossfire; |
12 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
13 | |
11 | |
14 | use Compress::LZF; |
12 | use Compress::LZF; |
… | |
… | |
47 | our $LOGVIEW; |
45 | our $LOGVIEW; |
48 | our $CONSOLE; |
46 | our $CONSOLE; |
49 | our $METASERVER; |
47 | our $METASERVER; |
50 | |
48 | |
51 | our $GAUGES; |
49 | our $GAUGES; |
|
|
50 | our $STATWIDS; |
52 | |
51 | |
53 | our $SDL_ACTIVE; |
52 | our $SDL_ACTIVE; |
54 | our %SDL_CB; |
53 | our %SDL_CB; |
55 | |
54 | |
56 | our $SDL_MIXER; |
55 | our $SDL_MIXER; |
… | |
… | |
100 | undef $CONN; |
99 | undef $CONN; |
101 | } |
100 | } |
102 | |
101 | |
103 | sub client_setup { |
102 | sub client_setup { |
104 | my $dialog = new CFClient::UI::FancyFrame |
103 | my $dialog = new CFClient::UI::FancyFrame |
|
|
104 | title => "Client Setup", |
105 | child => (my $vbox = new CFClient::UI::VBox); |
105 | child => (my $vbox = new CFClient::UI::VBox); |
106 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); |
|
|
107 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
106 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
108 | |
107 | |
109 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
108 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
110 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
109 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
111 | |
110 | |
112 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
111 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
113 | $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); |
112 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
114 | |
113 | |
115 | $mode_slider->connect (changed => sub { |
114 | $mode_slider->connect (changed => sub { |
116 | my ($self, $value) = @_; |
115 | my ($self, $value) = @_; |
117 | |
116 | |
118 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
117 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
… | |
… | |
180 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
179 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
181 | $CFG->{bgm_enable} = $_[1]; |
180 | $CFG->{bgm_enable} = $_[1]; |
182 | }); |
181 | }); |
183 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
182 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
184 | $CFG->{bgm_volume} = $_[1]; |
183 | $CFG->{bgm_volume} = $_[1]; |
185 | CFClient::Mix_VolumeMusic ($_[1]); |
184 | CFClient::MixMusic::volume $_[1] * 128; |
186 | }); |
185 | }); |
187 | |
186 | |
188 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
187 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
189 | audio_shutdown (); |
188 | audio_shutdown (); |
190 | audio_init (); |
189 | audio_init (); |
191 | }); |
190 | }); |
192 | |
191 | |
193 | $dialog |
192 | $dialog |
194 | } |
193 | } |
195 | |
194 | |
|
|
195 | sub make_stats_window { |
|
|
196 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats"); |
|
|
197 | $tgw->add (my $vb = new CFClient::UI::VBox ()); |
|
|
198 | $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1); |
|
|
199 | $vb->add (my $hb2 = new CFClient::UI::HBox); |
|
|
200 | $hb2->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
|
|
201 | $hb2->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
|
|
202 | $hb2->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
|
|
203 | $hb2->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
|
|
204 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
205 | $tgw |
|
|
206 | } |
|
|
207 | |
|
|
208 | sub update_stats_window { |
|
|
209 | my ($stats) = @_; |
|
|
210 | |
|
|
211 | $STATWIDS->{stat}->set_text ( |
|
|
212 | "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28}) |
|
|
213 | . " Level: $stats->{12}\n" |
|
|
214 | . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n", |
|
|
215 | @$stats{5,8,9,6,7,22,10, 13, 14}) |
|
|
216 | . (sprintf "Dam %d Arm %d Speed %.2f/%.2f", |
|
|
217 | @$stats{15,16,17,19}) |
|
|
218 | ); |
|
|
219 | } |
|
|
220 | |
196 | sub metaserver_dialog { |
221 | sub metaserver_dialog { |
197 | my $dialog = new CFClient::UI::FancyFrame |
222 | my $dialog = new CFClient::UI::FancyFrame |
|
|
223 | title => "Metaserver", |
198 | child => (my $vbox = new CFClient::UI::VBox); |
224 | child => (my $vbox = new CFClient::UI::VBox); |
199 | |
225 | |
200 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
226 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
201 | |
227 | |
202 | $dialog |
228 | $dialog |
… | |
… | |
268 | }); |
294 | }); |
269 | } |
295 | } |
270 | |
296 | |
271 | sub server_setup { |
297 | sub server_setup { |
272 | my $dialog = new CFClient::UI::FancyFrame |
298 | my $dialog = new CFClient::UI::FancyFrame |
|
|
299 | title => "Server Setup", |
273 | child => (my $vbox = new CFClient::UI::VBox); |
300 | child => (my $vbox = new CFClient::UI::VBox); |
274 | |
301 | |
275 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); |
|
|
276 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
302 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
277 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
303 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
278 | |
304 | |
279 | { |
305 | { |
280 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
306 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
… | |
… | |
327 | $dialog |
353 | $dialog |
328 | } |
354 | } |
329 | |
355 | |
330 | sub message_window { |
356 | sub message_window { |
331 | my $window = new CFClient::UI::FancyFrame |
357 | my $window = new CFClient::UI::FancyFrame |
|
|
358 | title => "Messages", |
332 | border_bg => [1, 1, 1, 0.5], |
359 | border_bg => [1, 1, 1, 0.5], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
360 | bg => [0.3, 0.3, 0.3, 0.8], |
334 | user_w => int $::WIDTH / 3, |
361 | user_w => int $::WIDTH / 3, |
335 | user_h => int $::HEIGHT / 5, |
362 | user_h => int $::HEIGHT / 5, |
336 | child => (my $vbox = new CFClient::UI::VBox); |
363 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
445 | status "Configuration Saved"; |
472 | status "Configuration Saved"; |
446 | }); |
473 | }); |
447 | |
474 | |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
475 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
449 | |
476 | |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
|
|
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
|
|
452 | |
477 | |
453 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
|
|
454 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
|
|
455 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
|
|
456 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
|
|
457 | |
|
|
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
|
|
459 | $CFClient::UI::ROOT->add ($tgw); |
478 | $CFClient::UI::ROOT->add (make_stats_window); |
460 | } |
479 | } |
461 | |
480 | |
462 | sub video_shutdown { |
481 | sub video_shutdown { |
463 | $CFClient::UI::ROOT->{children} = []; |
482 | $CFClient::UI::ROOT->{children} = []; |
464 | undef $SDL_ACTIVE; |
483 | undef $SDL_ACTIVE; |
465 | } |
484 | } |
466 | |
485 | |
|
|
486 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
467 | my $bgmusic;#TODO#hack#d# |
487 | my $bgmusic;#TODO#hack#d# |
|
|
488 | |
|
|
489 | sub audio_music_finished { |
|
|
490 | return unless $CFG->{bgm_enable}; |
|
|
491 | |
|
|
492 | # TODO: hack, do play loop and mood music |
|
|
493 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
494 | $bgmusic->play (0); |
|
|
495 | |
|
|
496 | push @bgmusic, shift @bgmusic; |
|
|
497 | } |
468 | |
498 | |
469 | sub audio_init { |
499 | sub audio_init { |
470 | if ($CFG->{audio_enable}) { |
500 | if ($CFG->{audio_enable}) { |
471 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
501 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
472 | |
|
|
473 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
502 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
474 | CFClient::Mix_AllocateChannels 8; |
503 | CFClient::Mix_AllocateChannels 8; |
475 | CFClient::MixMusic::volume $CFG->{bgm_volume}; |
504 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
476 | |
505 | |
477 | # TODO: hack, do play loop and mood music |
506 | audio_music_finished; |
478 | if ($CFG->{bgm_enable}) { |
|
|
479 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg"; |
|
|
480 | $bgmusic->play; |
|
|
481 | } |
|
|
482 | |
507 | |
483 | while (<$fh>) { |
508 | while (<$fh>) { |
484 | next if /^\s*#/; |
509 | next if /^\s*#/; |
485 | next if /^\s*$/; |
510 | next if /^\s*$/; |
486 | |
511 | |
… | |
… | |
522 | $want_refresh = 0; |
547 | $want_refresh = 0; |
523 | $can_refresh = 0; |
548 | $can_refresh = 0; |
524 | |
549 | |
525 | $CFClient::UI::ROOT->draw; |
550 | $CFClient::UI::ROOT->draw; |
526 | |
551 | |
527 | SDL::GLSwapBuffers; |
552 | CFClient::SDL_GL_SwapBuffers; |
528 | |
553 | |
529 | $LAST_REFRESH = $NOW; |
554 | $LAST_REFRESH = $NOW; |
530 | } |
555 | } |
531 | |
556 | |
532 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
557 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
… | |
… | |
571 | my $hp = $stats->{1}; |
596 | my $hp = $stats->{1}; |
572 | my $hp_m = $stats->{2}; |
597 | my $hp_m = $stats->{2}; |
573 | my $sp = $stats->{3}; |
598 | my $sp = $stats->{3}; |
574 | my $sp_m = $stats->{4}; |
599 | my $sp_m = $stats->{4}; |
575 | my $fo = $stats->{18}; |
600 | my $fo = $stats->{18}; |
576 | my $fo_m = 1000; |
601 | my $fo_m = 999; |
577 | my $gr = $stats->{23}; |
602 | my $gr = $stats->{23}; |
578 | my $gr_m = $stats->{24}; |
603 | my $gr_m = $stats->{24}; |
579 | |
604 | |
580 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
605 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
581 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
606 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
582 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
607 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
583 | $GAUGES->{food}->set_value ($fo, $fo_m); |
608 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
584 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
609 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
|
|
610 | |
|
|
611 | update_stats_window ($stats); |
585 | } |
612 | } |
586 | |
613 | |
587 | sub conn::user_send { |
614 | sub conn::user_send { |
588 | my ($self, $command) = @_; |
615 | my ($self, $command) = @_; |
589 | |
616 | |
… | |
… | |
614 | |
641 | |
615 | my ($hash, $x, $y, $w, $h) = @$map_info; |
642 | my ($hash, $x, $y, $w, $h) = @$map_info; |
616 | |
643 | |
617 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
644 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
618 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
645 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
619 | |
|
|
620 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
646 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
621 | |
|
|
622 | } |
647 | } |
623 | |
648 | |
624 | sub conn::map_clear { |
649 | sub conn::map_clear { |
625 | my ($self) = @_; |
650 | my ($self) = @_; |
626 | |
651 | |
627 | $self->flush_map; |
652 | $self->flush_map; |
628 | delete $self->{neigh}; |
653 | delete $self->{neigh_map}; |
629 | |
654 | |
630 | $MAP->clear; |
655 | $MAP->clear; |
631 | } |
656 | } |
632 | |
657 | |
633 | |
658 | |
634 | sub conn::load_map($$$) { |
659 | sub conn::load_map($$$) { |
635 | my ($self, $hash, $x, $y) = @_; |
660 | my ($self, $hash, $x, $y) = @_; |
636 | |
661 | |
637 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
662 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
638 | $data = Compress::LZF::decompress $data; |
663 | $data = Compress::LZF::decompress $data; |
639 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
664 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
640 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
665 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
641 | my $data = $TILECACHE->get ($id) |
666 | my $data = $TILECACHE->get ($id) |
642 | or next; |
667 | or next; |
643 | |
668 | |
644 | $self->set_texture ($id => $data); |
669 | $self->set_texture ($id => $data); |
645 | } |
670 | } |
646 | } |
671 | } |
647 | } |
672 | } |
648 | |
673 | |
|
|
674 | # this method does a "flood fill" into every tile direction |
|
|
675 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
676 | # i.e. a map is the same as the left of the right map etc. |
|
|
677 | # failure to comply are harmless and result in display errors |
|
|
678 | # at worst. |
649 | sub conn::flood_fill { |
679 | sub conn::flood_fill { |
650 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
680 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
651 | |
681 | |
652 | # the server does not allow map paths > 6 |
682 | # the server does not allow map paths > 6 |
653 | return if 6 <= length $path; |
683 | return if 6 <= length $path; |
654 | |
684 | |
655 | for my $tile (1..4) { |
685 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
656 | next if $self->{neigh}{$hash}[$tile]; |
686 | |
|
|
687 | for ( |
|
|
688 | [1, 0, -1], |
|
|
689 | [2, 1, 0], |
|
|
690 | [3, 0, 1], |
|
|
691 | [4, -1, 0], |
|
|
692 | ) { |
|
|
693 | my ($tile, $dx, $dy) = @$_; |
|
|
694 | |
|
|
695 | my $gx = $gx + $dx; |
|
|
696 | my $gy = $gy + $dy; |
|
|
697 | |
657 | next unless $flags & (1 << ($tile - 1)); |
698 | next unless $flags & (1 << ($tile - 1)); |
|
|
699 | next if $self->{neigh_grid}{$gx, $gy}++; |
658 | |
700 | |
659 | my $neigh = $self->{neigh}{$hash} ||= []; |
701 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
660 | |
702 | if (my $info = $neigh->[$tile]) { |
661 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
662 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
703 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
663 | |
704 | |
664 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
665 | return if $mode ne "spatial"; |
|
|
666 | |
|
|
667 | $x += $MAP->ox; |
|
|
668 | $y += $MAP->oy; |
|
|
669 | |
|
|
670 | $self->load_map ($hash, $x, $y) |
|
|
671 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
672 | |
|
|
673 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
674 | |
|
|
675 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
705 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
676 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
706 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
707 | |
|
|
708 | } else { |
|
|
709 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
710 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
711 | |
|
|
712 | return if $mode ne "spatial"; |
|
|
713 | |
|
|
714 | $x += $MAP->ox; |
|
|
715 | $y += $MAP->oy; |
|
|
716 | |
|
|
717 | $self->load_map ($hash, $x, $y) |
|
|
718 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
719 | |
|
|
720 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
721 | |
|
|
722 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
723 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
724 | }); |
677 | }); |
725 | } |
678 | } |
726 | } |
679 | } |
727 | } |
680 | |
728 | |
681 | sub conn::map_change { |
729 | sub conn::map_change { |
682 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
730 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
685 | |
733 | |
686 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
734 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
687 | |
735 | |
688 | my $mapmapw = 250; |
736 | my $mapmapw = 250; |
689 | my $mapmaph = 250; |
737 | my $mapmaph = 250; |
|
|
738 | |
|
|
739 | $self->{neigh_rect} = [ |
|
|
740 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
741 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
742 | ]; |
690 | |
743 | |
|
|
744 | delete $self->{neigh_grid}; |
691 | $self->flood_fill ("", $hash, $flags, |
745 | $self->flood_fill (0, 0, "", $hash, $flags); |
692 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
693 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
694 | |
746 | |
695 | $x += $ox; |
747 | $x += $ox; |
696 | $y += $oy; |
748 | $y += $oy; |
697 | |
749 | |
698 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
750 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
827 | CFClient::SDL_QUIT => sub { |
879 | CFClient::SDL_QUIT => sub { |
828 | Event::unloop -1; |
880 | Event::unloop -1; |
829 | }, |
881 | }, |
830 | CFClient::SDL_VIDEORESIZE => sub { |
882 | CFClient::SDL_VIDEORESIZE => sub { |
831 | }, |
883 | }, |
832 | CFClient::SDL_VIDEOEXPOSE => sub { |
884 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
833 | refresh; |
885 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
886 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
834 | }, |
887 | }, |
835 | CFClient::SDL_KEYDOWN => sub { |
888 | CFClient::SDL_KEYDOWN => sub { |
836 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
889 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
837 | # alt-enter |
890 | # alt-enter |
838 | video_shutdown; |
891 | video_shutdown; |
… | |
… | |
840 | video_init; |
893 | video_init; |
841 | } else { |
894 | } else { |
842 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
895 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
843 | } |
896 | } |
844 | }, |
897 | }, |
845 | CFClient::SDL_KEYUP => sub { |
898 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
846 | CFClient::UI::feed_sdl_key_up_event ($_[0]); |
899 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
847 | }, |
900 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
848 | CFClient::SDL_MOUSEMOTION => sub { |
901 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
849 | CFClient::UI::feed_sdl_motion_event ($_[0]); |
902 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
850 | }, |
|
|
851 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
|
|
852 | CFClient::UI::feed_sdl_button_down_event ($_[0]); |
|
|
853 | }, |
|
|
854 | CFClient::SDL_MOUSEBUTTONUP => sub { |
|
|
855 | CFClient::UI::feed_sdl_button_up_event ($_[0]); |
|
|
856 | }, |
|
|
857 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
858 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
859 | }, |
|
|
860 | ); |
903 | ); |
861 | |
904 | |
862 | ############################################################################# |
905 | ############################################################################# |
863 | |
906 | |
864 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
907 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
882 | mapsize => 100, |
925 | mapsize => 100, |
883 | host => "crossfire.schmorp.de", |
926 | host => "crossfire.schmorp.de", |
884 | say_command => 'say', |
927 | say_command => 'say', |
885 | audio_enable => 1, |
928 | audio_enable => 1, |
886 | bgm_enable => 1, |
929 | bgm_enable => 1, |
887 | bgm_volume => 64, |
930 | bgm_volume => 0.25, |
888 | ); |
931 | ); |
889 | |
932 | |
890 | while (my ($k, $v) = each %DEF_CFG) { |
933 | while (my ($k, $v) = each %DEF_CFG) { |
891 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
934 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
892 | } |
935 | } |
… | |
… | |
911 | video_init; |
954 | video_init; |
912 | audio_init; |
955 | audio_init; |
913 | |
956 | |
914 | Event::loop; |
957 | Event::loop; |
915 | |
958 | |
916 | END { SDL::Quit } |
959 | END { CFClient::SDL_Quit } |
917 | |
960 | |
918 | |
961 | |