… | |
… | |
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::Event; |
|
|
10 | |
|
|
11 | use SDL::Mixer; |
|
|
12 | use SDL::Sound; |
|
|
13 | use SDL::Music; |
|
|
14 | |
|
|
15 | use SDL::OpenGL; |
|
|
16 | |
8 | |
17 | use Crossfire; |
9 | use Crossfire; |
18 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
19 | |
11 | |
20 | use Compress::LZF; |
12 | use Compress::LZF; |
… | |
… | |
55 | our $METASERVER; |
47 | our $METASERVER; |
56 | |
48 | |
57 | our $GAUGES; |
49 | our $GAUGES; |
58 | |
50 | |
59 | our $SDL_ACTIVE; |
51 | our $SDL_ACTIVE; |
60 | our $SDL_EV; |
|
|
61 | our %SDL_CB; |
52 | our %SDL_CB; |
62 | |
53 | |
63 | our $SDL_MIXER; |
54 | our $SDL_MIXER; |
64 | our @SOUNDS; # event => file mapping |
55 | our @SOUNDS; # event => file mapping |
65 | our %AUDIO_CHUNKS; # audio files |
56 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
107 | undef $CONN; |
98 | undef $CONN; |
108 | } |
99 | } |
109 | |
100 | |
110 | sub client_setup { |
101 | sub client_setup { |
111 | my $dialog = new CFClient::UI::FancyFrame |
102 | my $dialog = new CFClient::UI::FancyFrame |
|
|
103 | title => "Client Setup", |
112 | child => (my $vbox = new CFClient::UI::VBox); |
104 | child => (my $vbox = new CFClient::UI::VBox); |
113 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup"); |
|
|
114 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
105 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
115 | |
106 | |
116 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
107 | $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); |
117 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
108 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
118 | |
109 | |
119 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
110 | $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); |
120 | $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); |
111 | $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999"); |
121 | |
112 | |
122 | $mode_slider->connect (changed => sub { |
113 | $mode_slider->connect (changed => sub { |
123 | my ($self, $value) = @_; |
114 | my ($self, $value) = @_; |
124 | |
115 | |
125 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
116 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
… | |
… | |
185 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
176 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
186 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
177 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
187 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
178 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
188 | $CFG->{bgm_enable} = $_[1]; |
179 | $CFG->{bgm_enable} = $_[1]; |
189 | }); |
180 | }); |
190 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { |
181 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
191 | $CFG->{bgm_volume} = $_[1]; |
182 | $CFG->{bgm_volume} = $_[1]; |
192 | $SDL_MIXER->music_volume ($_[1]); |
183 | CFClient::MixMusic::volume $_[1] * 128; |
193 | }); |
184 | }); |
194 | |
185 | |
195 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
186 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
196 | audio_shutdown (); |
187 | audio_shutdown (); |
197 | audio_init (); |
188 | audio_init (); |
… | |
… | |
200 | $dialog |
191 | $dialog |
201 | } |
192 | } |
202 | |
193 | |
203 | sub metaserver_dialog { |
194 | sub metaserver_dialog { |
204 | my $dialog = new CFClient::UI::FancyFrame |
195 | my $dialog = new CFClient::UI::FancyFrame |
|
|
196 | title => "Metaserver", |
205 | child => (my $vbox = new CFClient::UI::VBox); |
197 | child => (my $vbox = new CFClient::UI::VBox); |
206 | |
198 | |
207 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
199 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
208 | |
200 | |
209 | $dialog |
201 | $dialog |
… | |
… | |
275 | }); |
267 | }); |
276 | } |
268 | } |
277 | |
269 | |
278 | sub server_setup { |
270 | sub server_setup { |
279 | my $dialog = new CFClient::UI::FancyFrame |
271 | my $dialog = new CFClient::UI::FancyFrame |
|
|
272 | title => "Server Setup", |
280 | child => (my $vbox = new CFClient::UI::VBox); |
273 | child => (my $vbox = new CFClient::UI::VBox); |
281 | |
274 | |
282 | $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup"); |
|
|
283 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
275 | $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); |
284 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
276 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
285 | |
277 | |
286 | { |
278 | { |
287 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
279 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
… | |
… | |
334 | $dialog |
326 | $dialog |
335 | } |
327 | } |
336 | |
328 | |
337 | sub message_window { |
329 | sub message_window { |
338 | my $window = new CFClient::UI::FancyFrame |
330 | my $window = new CFClient::UI::FancyFrame |
|
|
331 | title => "Messages", |
339 | border_bg => [1, 1, 1, 0.5], |
332 | border_bg => [1, 1, 1, 0.5], |
340 | bg => [0.3, 0.3, 0.3, 0.8], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
341 | user_w => int $::WIDTH / 3, |
334 | user_w => int $::WIDTH / 3, |
342 | user_h => int $::HEIGHT / 5, |
335 | user_h => int $::HEIGHT / 5, |
343 | child => (my $vbox = new CFClient::UI::VBox); |
336 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
399 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
400 | |
393 | |
401 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
402 | or die "SDL_SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
403 | |
396 | |
404 | $SDL_EV = new SDL::Event; |
|
|
405 | $SDL_EV->set_unicode (1); |
|
|
406 | |
|
|
407 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
408 | |
398 | |
409 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
410 | |
400 | |
411 | CFClient::gl_init; |
401 | CFClient::gl_init; |
… | |
… | |
455 | status "Configuration Saved"; |
445 | status "Configuration Saved"; |
456 | }); |
446 | }); |
457 | |
447 | |
458 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
459 | |
449 | |
460 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats"); |
461 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
462 | |
452 | |
463 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
453 | $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
464 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
454 | $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
465 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
455 | $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
466 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
456 | $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
467 | |
457 | |
468 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
469 | $CFClient::UI::ROOT->add ($tgw); |
459 | $CFClient::UI::ROOT->add ($tgw); |
470 | } |
460 | } |
471 | |
461 | |
472 | sub video_shutdown { |
462 | sub video_shutdown { |
473 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
474 | undef $SDL_ACTIVE; |
464 | undef $SDL_ACTIVE; |
475 | undef $SDL_EV; |
|
|
476 | } |
465 | } |
477 | |
466 | |
|
|
467 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
478 | my $bgmusic;#TODO#hack#d# |
468 | my $bgmusic;#TODO#hack#d# |
|
|
469 | |
|
|
470 | sub audio_music_finished { |
|
|
471 | return unless $CFG->{bgm_enable}; |
|
|
472 | |
|
|
473 | # TODO: hack, do play loop and mood music |
|
|
474 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
475 | $bgmusic->play (0); |
|
|
476 | |
|
|
477 | push @bgmusic, shift @bgmusic; |
|
|
478 | } |
479 | |
479 | |
480 | sub audio_init { |
480 | sub audio_init { |
481 | if ($CFG->{audio_enable}) { |
481 | if ($CFG->{audio_enable}) { |
482 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
482 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
483 | |
483 | |
484 | $SDL_MIXER = new SDL::Mixer |
484 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
485 | -rate => 22050, |
485 | CFClient::Mix_AllocateChannels 8; |
486 | -channels => 1, # mono |
486 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
487 | -size => 512; |
|
|
488 | |
487 | |
489 | $SDL_MIXER->allocate_channels (8); |
488 | audio_music_finished; |
490 | |
|
|
491 | # TODO: hack, do play loop and mood music |
|
|
492 | if ($CFG->{bgm_enable}) { |
|
|
493 | $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; |
|
|
494 | $SDL_MIXER->play_music ($bgmusic, -1); |
|
|
495 | $SDL_MIXER->music_volume ($CFG->{bgm_volume}); |
|
|
496 | } |
|
|
497 | |
489 | |
498 | while (<$fh>) { |
490 | while (<$fh>) { |
499 | next if /^\s*#/; |
491 | next if /^\s*#/; |
500 | next if /^\s*$/; |
492 | next if /^\s*$/; |
501 | |
493 | |
502 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
494 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
503 | |
495 | |
504 | push @SOUNDS, "$volume,$file"; |
496 | push @SOUNDS, "$volume,$file"; |
505 | |
497 | |
506 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
498 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
507 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
499 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
508 | $chunk->volume ($volume * 128 / 100); |
500 | $chunk->volume ($volume * 128 / 100); |
509 | $chunk |
501 | $chunk |
510 | }; |
502 | }; |
511 | } |
503 | } |
512 | } else { |
504 | } else { |
… | |
… | |
514 | } |
506 | } |
515 | } |
507 | } |
516 | } |
508 | } |
517 | |
509 | |
518 | sub audio_shutdown { |
510 | sub audio_shutdown { |
|
|
511 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
519 | undef $SDL_MIXER; |
512 | undef $SDL_MIXER; |
520 | @SOUNDS = (); |
513 | @SOUNDS = (); |
521 | %AUDIO_CHUNKS = (); |
514 | %AUDIO_CHUNKS = (); |
522 | } |
515 | } |
523 | |
516 | |
… | |
… | |
536 | $want_refresh = 0; |
529 | $want_refresh = 0; |
537 | $can_refresh = 0; |
530 | $can_refresh = 0; |
538 | |
531 | |
539 | $CFClient::UI::ROOT->draw; |
532 | $CFClient::UI::ROOT->draw; |
540 | |
533 | |
541 | SDL::GLSwapBuffers; |
534 | CFClient::SDL_GL_SwapBuffers; |
542 | |
535 | |
543 | $LAST_REFRESH = $NOW; |
536 | $LAST_REFRESH = $NOW; |
544 | } |
537 | } |
545 | |
538 | |
546 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
539 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
547 | $NOW = time; |
540 | $NOW = time; |
548 | |
541 | |
549 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
542 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
550 | while $SDL_EV->poll; |
543 | for CFClient::SDL_PollEvent; |
551 | |
544 | |
552 | if (%animate_object) { |
545 | if (%animate_object) { |
553 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
546 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
554 | $want_refresh++; |
547 | $want_refresh++; |
555 | } |
548 | } |
… | |
… | |
585 | my $hp = $stats->{1}; |
578 | my $hp = $stats->{1}; |
586 | my $hp_m = $stats->{2}; |
579 | my $hp_m = $stats->{2}; |
587 | my $sp = $stats->{3}; |
580 | my $sp = $stats->{3}; |
588 | my $sp_m = $stats->{4}; |
581 | my $sp_m = $stats->{4}; |
589 | my $fo = $stats->{18}; |
582 | my $fo = $stats->{18}; |
590 | my $fo_m = 1000; |
583 | my $fo_m = 999; |
591 | my $gr = $stats->{23}; |
584 | my $gr = $stats->{23}; |
592 | my $gr_m = $stats->{24}; |
585 | my $gr_m = $stats->{24}; |
593 | |
586 | |
594 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
587 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
595 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
588 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
596 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
589 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
597 | $GAUGES->{food}->set_value ($fo, $fo_m); |
590 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
598 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
591 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
599 | } |
592 | } |
600 | |
593 | |
601 | sub conn::user_send { |
594 | sub conn::user_send { |
602 | my ($self, $command) = @_; |
595 | my ($self, $command) = @_; |
… | |
… | |
628 | |
621 | |
629 | my ($hash, $x, $y, $w, $h) = @$map_info; |
622 | my ($hash, $x, $y, $w, $h) = @$map_info; |
630 | |
623 | |
631 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
624 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
632 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
625 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
633 | |
|
|
634 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
626 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
635 | |
|
|
636 | } |
627 | } |
637 | |
628 | |
638 | sub conn::map_clear { |
629 | sub conn::map_clear { |
639 | my ($self) = @_; |
630 | my ($self) = @_; |
640 | |
631 | |
641 | $self->flush_map; |
632 | $self->flush_map; |
642 | delete $self->{neigh}; |
633 | delete $self->{neigh_map}; |
643 | |
634 | |
644 | $MAP->clear; |
635 | $MAP->clear; |
645 | } |
636 | } |
646 | |
637 | |
647 | |
638 | |
648 | sub conn::load_map($$$) { |
639 | sub conn::load_map($$$) { |
649 | my ($self, $hash, $x, $y) = @_; |
640 | my ($self, $hash, $x, $y) = @_; |
650 | |
641 | |
651 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
642 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
652 | $data = Compress::LZF::decompress $data; |
643 | $data = Compress::LZF::decompress $data; |
653 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
644 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
654 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
645 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
655 | my $data = $TILECACHE->get ($id) |
646 | my $data = $TILECACHE->get ($id) |
656 | or next; |
647 | or next; |
657 | |
648 | |
658 | $self->set_texture ($id => $data); |
649 | $self->set_texture ($id => $data); |
659 | } |
650 | } |
660 | } |
651 | } |
661 | } |
652 | } |
662 | |
653 | |
|
|
654 | # this method does a "flood fill" into every tile direction |
|
|
655 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
656 | # i.e. a map is the same as the left of the right map etc. |
|
|
657 | # failure to comply are harmless and result in display errors |
|
|
658 | # at worst. |
663 | sub conn::flood_fill { |
659 | sub conn::flood_fill { |
664 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
660 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
665 | |
661 | |
666 | # the server does not allow map paths > 6 |
662 | # the server does not allow map paths > 6 |
667 | return if 6 <= length $path; |
663 | return if 6 <= length $path; |
668 | |
664 | |
669 | for my $tile (1..4) { |
665 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
670 | next if $self->{neigh}{$hash}[$tile]; |
666 | |
|
|
667 | for ( |
|
|
668 | [1, 0, -1], |
|
|
669 | [2, 1, 0], |
|
|
670 | [3, 0, 1], |
|
|
671 | [4, -1, 0], |
|
|
672 | ) { |
|
|
673 | my ($tile, $dx, $dy) = @$_; |
|
|
674 | |
|
|
675 | my $gx = $gx + $dx; |
|
|
676 | my $gy = $gy + $dy; |
|
|
677 | |
671 | next unless $flags & (1 << ($tile - 1)); |
678 | next unless $flags & (1 << ($tile - 1)); |
|
|
679 | next if $self->{neigh_grid}{$gx, $gy}++; |
672 | |
680 | |
673 | my $neigh = $self->{neigh}{$hash} ||= []; |
681 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
674 | |
682 | if (my $info = $neigh->[$tile]) { |
675 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
676 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
683 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
677 | |
684 | |
678 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
679 | return if $mode ne "spatial"; |
|
|
680 | |
|
|
681 | $x += $MAP->ox; |
|
|
682 | $y += $MAP->oy; |
|
|
683 | |
|
|
684 | $self->load_map ($hash, $x, $y) |
|
|
685 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
686 | |
|
|
687 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
688 | |
|
|
689 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
685 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
690 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
686 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
687 | |
|
|
688 | } else { |
|
|
689 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
690 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
691 | |
|
|
692 | return if $mode ne "spatial"; |
|
|
693 | |
|
|
694 | $x += $MAP->ox; |
|
|
695 | $y += $MAP->oy; |
|
|
696 | |
|
|
697 | $self->load_map ($hash, $x, $y) |
|
|
698 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
699 | |
|
|
700 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
701 | |
|
|
702 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
703 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
704 | }); |
691 | }); |
705 | } |
692 | } |
706 | } |
693 | } |
707 | } |
694 | |
708 | |
695 | sub conn::map_change { |
709 | sub conn::map_change { |
696 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
710 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
699 | |
713 | |
700 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
714 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
701 | |
715 | |
702 | my $mapmapw = 250; |
716 | my $mapmapw = 250; |
703 | my $mapmaph = 250; |
717 | my $mapmaph = 250; |
|
|
718 | |
|
|
719 | $self->{neigh_rect} = [ |
|
|
720 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
721 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
722 | ]; |
704 | |
723 | |
|
|
724 | delete $self->{neigh_grid}; |
705 | $self->flood_fill ("", $hash, $flags, |
725 | $self->flood_fill (0, 0, "", $hash, $flags); |
706 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
707 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
708 | |
726 | |
709 | $x += $ox; |
727 | $x += $ox; |
710 | $y += $oy; |
728 | $y += $oy; |
711 | |
729 | |
712 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
730 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
778 | or return; |
796 | or return; |
779 | |
797 | |
780 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
798 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
781 | or return; |
799 | or return; |
782 | |
800 | |
783 | $SDL_MIXER->play_channel (-1, $chunk); |
801 | $chunk->play; |
784 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
802 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
785 | } |
803 | } |
786 | |
804 | |
787 | sub conn::query { |
805 | sub conn::query { |
788 | my ($self, $flags, $prompt) = @_; |
806 | my ($self, $flags, $prompt) = @_; |
… | |
… | |
841 | CFClient::SDL_QUIT => sub { |
859 | CFClient::SDL_QUIT => sub { |
842 | Event::unloop -1; |
860 | Event::unloop -1; |
843 | }, |
861 | }, |
844 | CFClient::SDL_VIDEORESIZE => sub { |
862 | CFClient::SDL_VIDEORESIZE => sub { |
845 | }, |
863 | }, |
846 | CFClient::SDL_VIDEOEXPOSE => sub { |
864 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
847 | refresh; |
865 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
866 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
848 | }, |
867 | }, |
849 | CFClient::SDL_KEYDOWN => sub { |
868 | CFClient::SDL_KEYDOWN => sub { |
850 | if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) { |
869 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
851 | # alt-enter |
870 | # alt-enter |
852 | video_shutdown; |
871 | video_shutdown; |
853 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
872 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
854 | video_init; |
873 | video_init; |
855 | } else { |
874 | } else { |
856 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
875 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
857 | } |
876 | } |
858 | }, |
877 | }, |
859 | CFClient::SDL_KEYUP => sub { |
878 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
860 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
879 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
861 | }, |
880 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
862 | CFClient::SDL_MOUSEMOTION => sub { |
881 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
863 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
882 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
864 | }, |
|
|
865 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
|
|
866 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
867 | }, |
|
|
868 | CFClient::SDL_MOUSEBUTTONUP => sub { |
|
|
869 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
870 | }, |
|
|
871 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
872 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
873 | }, |
|
|
874 | ); |
883 | ); |
875 | |
884 | |
876 | ############################################################################# |
885 | ############################################################################# |
877 | |
886 | |
878 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
887 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
896 | mapsize => 100, |
905 | mapsize => 100, |
897 | host => "crossfire.schmorp.de", |
906 | host => "crossfire.schmorp.de", |
898 | say_command => 'say', |
907 | say_command => 'say', |
899 | audio_enable => 1, |
908 | audio_enable => 1, |
900 | bgm_enable => 1, |
909 | bgm_enable => 1, |
901 | bgm_volume => 64, |
910 | bgm_volume => 0.25, |
902 | ); |
911 | ); |
903 | |
912 | |
904 | while (my ($k, $v) = each %DEF_CFG) { |
913 | while (my ($k, $v) = each %DEF_CFG) { |
905 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
914 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
906 | } |
915 | } |
… | |
… | |
925 | video_init; |
934 | video_init; |
926 | audio_init; |
935 | audio_init; |
927 | |
936 | |
928 | Event::loop; |
937 | Event::loop; |
929 | |
938 | |
930 | END { SDL::Quit } |
939 | END { CFClient::SDL_Quit } |
931 | |
940 | |
932 | |
941 | |