… | |
… | |
46 | our $TOPLEVEL; |
46 | our $TOPLEVEL; |
47 | |
47 | |
48 | our $tw; # Test widget #d# |
48 | our $tw; # Test widget #d# |
49 | |
49 | |
50 | my $last_refresh; |
50 | my $last_refresh; |
|
|
51 | my %ANIMATE; |
|
|
52 | my $refresh_handler; |
51 | |
53 | |
52 | sub init_screen { |
54 | sub init_screen { |
53 | $SDL_APP = new SDL::App |
55 | $SDL_APP = new SDL::App |
54 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
56 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
55 | -title => "Crossfire+ Client", |
57 | -title => "Crossfire+ Client", |
… | |
… | |
115 | |
117 | |
116 | $_->() for @GL_INIT; |
118 | $_->() for @GL_INIT; |
117 | } |
119 | } |
118 | |
120 | |
119 | sub start_game { |
121 | sub start_game { |
120 | $SDL_TIMER = add Glib::Timeout 1000/100, sub { |
122 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
121 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
123 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
122 | while $SDL_EV->poll; |
124 | while $SDL_EV->poll; |
123 | |
125 | |
124 | 1 |
126 | 1 |
125 | }; |
127 | }; |
… | |
… | |
127 | $WIDTH = $CFG->{width}; |
129 | $WIDTH = $CFG->{width}; |
128 | $HEIGHT = $CFG->{height}; |
130 | $HEIGHT = $CFG->{height}; |
129 | $FULLSCREEN = 0; |
131 | $FULLSCREEN = 0; |
130 | |
132 | |
131 | init_screen; |
133 | init_screen; |
|
|
134 | |
|
|
135 | my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; |
132 | |
136 | |
133 | $CONN = new conn |
137 | $CONN = new conn |
134 | host => $CFG->{host}, |
138 | host => $CFG->{host}, |
135 | port => $CFG->{port}, |
139 | port => $CFG->{port}, |
136 | user => $CFG->{user}, |
140 | user => $CFG->{user}, |
137 | pass => $CFG->{password}, |
141 | pass => $CFG->{password}, |
138 | mapw => 50, |
142 | mapw => $mapsize, |
139 | maph => 37, |
143 | maph => $mapsize, |
140 | ; |
144 | ; |
141 | |
145 | |
142 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
146 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
143 | } |
147 | } |
144 | |
148 | |
145 | sub stop_game { |
149 | sub stop_game { |
146 | remove Glib::Source $SDL_TIMER; |
150 | remove Glib::Source $SDL_TIMER; |
|
|
151 | remove Glib::Source $refresh_handler; |
|
|
152 | undef $refresh_handler; |
147 | |
153 | |
148 | undef $SDL_APP; |
154 | undef $SDL_APP; |
|
|
155 | undef $CONN; |
149 | SDL::Quit; |
156 | SDL::Quit; |
150 | } |
157 | } |
151 | |
158 | |
152 | |
159 | |
153 | sub force_refresh { |
160 | sub force_refresh { |
… | |
… | |
163 | $TOPLEVEL->draw; |
170 | $TOPLEVEL->draw; |
164 | |
171 | |
165 | SDL::GLSwapBuffers; |
172 | SDL::GLSwapBuffers; |
166 | } |
173 | } |
167 | |
174 | |
168 | my %ANIMATE; |
|
|
169 | |
|
|
170 | my $refresh_handler; |
|
|
171 | |
|
|
172 | sub refresh { |
175 | sub refresh { |
173 | $refresh_handler ||= add Glib::Idle sub { |
176 | $refresh_handler ||= add Glib::Idle sub { |
|
|
177 | return unless $SDL_APP; |
|
|
178 | |
174 | my $next_refresh = SDL::GetTicks; |
179 | my $next_refresh = SDL::GetTicks; |
175 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
180 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
176 | $last_refresh = $next_refresh; |
181 | $last_refresh = $next_refresh; |
177 | |
182 | |
178 | force_refresh; |
183 | force_refresh; |
… | |
… | |
360 | my $cb = $events{login} || sub {}; |
365 | my $cb = $events{login} || sub {}; |
361 | $cb->($::CFG->{user}, $::CFG->{password}); |
366 | $cb->($::CFG->{user}, $::CFG->{password}); |
362 | }); |
367 | }); |
363 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
368 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
364 | $cb->signal_connect (clicked => sub { |
369 | $cb->signal_connect (clicked => sub { |
365 | my $cb = $events{login} || sub {}; |
370 | my $cb = $events{logout} || sub {}; |
366 | $cb->(); |
371 | $cb->(); |
367 | }); |
372 | }); |
368 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
373 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
369 | $cb->signal_connect (clicked => sub { $w->destroy }); |
374 | $cb->signal_connect (clicked => sub { $w->destroy }); |
370 | |
375 | |