… | |
… | |
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 | |
8 | |
11 | use SDL::OpenGL; |
9 | use SDL::OpenGL; |
12 | |
10 | |
13 | use Crossfire; |
11 | use Crossfire; |
14 | use Crossfire::Protocol; |
12 | use Crossfire::Protocol; |
… | |
… | |
51 | our $METASERVER; |
49 | our $METASERVER; |
52 | |
50 | |
53 | our $GAUGES; |
51 | our $GAUGES; |
54 | |
52 | |
55 | our $SDL_ACTIVE; |
53 | our $SDL_ACTIVE; |
56 | our $SDL_EV; |
|
|
57 | our %SDL_CB; |
54 | our %SDL_CB; |
58 | |
55 | |
59 | our $SDL_MIXER; |
56 | our $SDL_MIXER; |
60 | our @SOUNDS; # event => file mapping |
57 | our @SOUNDS; # event => file mapping |
61 | our %AUDIO_CHUNKS; # audio files |
58 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
395 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
396 | |
393 | |
397 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
398 | or die "SDL_SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
399 | |
396 | |
400 | $SDL_EV = new SDL::Event; |
|
|
401 | $SDL_EV->set_unicode (1); |
|
|
402 | |
|
|
403 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
404 | |
398 | |
405 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
406 | |
400 | |
407 | CFClient::gl_init; |
401 | CFClient::gl_init; |
… | |
… | |
466 | } |
460 | } |
467 | |
461 | |
468 | sub video_shutdown { |
462 | sub video_shutdown { |
469 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
470 | undef $SDL_ACTIVE; |
464 | undef $SDL_ACTIVE; |
471 | undef $SDL_EV; |
|
|
472 | } |
465 | } |
473 | |
466 | |
474 | my $bgmusic;#TODO#hack#d# |
467 | my $bgmusic;#TODO#hack#d# |
475 | |
468 | |
476 | sub audio_init { |
469 | sub audio_init { |
… | |
… | |
537 | } |
530 | } |
538 | |
531 | |
539 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
532 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
540 | $NOW = time; |
533 | $NOW = time; |
541 | |
534 | |
542 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
535 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
543 | while $SDL_EV->poll; |
536 | for CFClient::SDL_PollEvent; |
544 | |
537 | |
545 | if (%animate_object) { |
538 | if (%animate_object) { |
546 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
539 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
547 | $want_refresh++; |
540 | $want_refresh++; |
548 | } |
541 | } |
… | |
… | |
838 | }, |
831 | }, |
839 | CFClient::SDL_VIDEOEXPOSE => sub { |
832 | CFClient::SDL_VIDEOEXPOSE => sub { |
840 | refresh; |
833 | refresh; |
841 | }, |
834 | }, |
842 | CFClient::SDL_KEYDOWN => sub { |
835 | CFClient::SDL_KEYDOWN => sub { |
843 | if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) { |
836 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
844 | # alt-enter |
837 | # alt-enter |
845 | video_shutdown; |
838 | video_shutdown; |
846 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
839 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
847 | video_init; |
840 | video_init; |
848 | } else { |
841 | } else { |
849 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
842 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
850 | } |
843 | } |
851 | }, |
844 | }, |
852 | CFClient::SDL_KEYUP => sub { |
845 | CFClient::SDL_KEYUP => sub { |
853 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
846 | CFClient::UI::feed_sdl_key_up_event ($_[0]); |
854 | }, |
847 | }, |
855 | CFClient::SDL_MOUSEMOTION => sub { |
848 | CFClient::SDL_MOUSEMOTION => sub { |
856 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
849 | CFClient::UI::feed_sdl_motion_event ($_[0]); |
857 | }, |
850 | }, |
858 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
851 | CFClient::SDL_MOUSEBUTTONDOWN => sub { |
859 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
852 | CFClient::UI::feed_sdl_button_down_event ($_[0]); |
860 | }, |
853 | }, |
861 | CFClient::SDL_MOUSEBUTTONUP => sub { |
854 | CFClient::SDL_MOUSEBUTTONUP => sub { |
862 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
855 | CFClient::UI::feed_sdl_button_up_event ($_[0]); |
863 | }, |
856 | }, |
864 | CFClient::SDL_ACTIVEEVENT => sub { |
857 | CFClient::SDL_ACTIVEEVENT => sub { |
865 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
858 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
866 | }, |
859 | }, |
867 | ); |
860 | ); |