… | |
… | |
14 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
15 | |
15 | |
16 | use Crossfire; |
16 | use Crossfire; |
17 | use Crossfire::Protocol; |
17 | use Crossfire::Protocol; |
18 | |
18 | |
19 | use Crossfire::Client; |
19 | use CFClient; |
20 | use Crossfire::Client::Widget; |
20 | use CFClient::Widget; |
21 | |
21 | |
22 | our $VERSION = '0.1'; |
22 | our $VERSION = '0.1'; |
23 | |
23 | |
24 | my $MAX_FPS = 30; |
24 | my $MAX_FPS = 30; |
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
… | |
… | |
31 | |
31 | |
32 | our $WIDTH; |
32 | our $WIDTH; |
33 | our $HEIGHT; |
33 | our $HEIGHT; |
34 | our $FULLSCREEN; |
34 | our $FULLSCREEN; |
35 | |
35 | |
|
|
36 | our $NOW; |
|
|
37 | |
|
|
38 | our $MAPWIDGET; |
36 | our $FONTSIZE; |
39 | our $FONTSIZE; |
37 | |
40 | |
38 | our $SDL_TIMER; |
41 | our $SDL_TIMER; |
39 | our $SDL_APP; |
42 | our $SDL_APP; |
40 | our $SDL_EV; |
43 | our $SDL_EV; |
… | |
… | |
75 | 1 |
78 | 1 |
76 | }; |
79 | }; |
77 | |
80 | |
78 | $last_refresh = SDL::GetTicks; |
81 | $last_refresh = SDL::GetTicks; |
79 | |
82 | |
80 | Crossfire::Client::gl_init; |
83 | CFClient::gl_init; |
81 | |
84 | |
82 | $FONTSIZE = int $HEIGHT / 50; |
85 | $FONTSIZE = int $HEIGHT / 50; |
83 | |
86 | |
84 | ############################################################################# |
87 | ############################################################################# |
85 | |
88 | |
… | |
… | |
91 | glDisable GL_DEPTH_TEST; |
94 | glDisable GL_DEPTH_TEST; |
92 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
93 | |
96 | |
94 | ############################################################################# |
97 | ############################################################################# |
95 | |
98 | |
96 | $DEBUG_STATUS = new Crossfire::Client::Widget::Label 0, 0, 1, $FONTSIZE, ""; |
99 | $DEBUG_STATUS = new CFClient::Widget::Label; |
97 | $Crossfire::Client::Widget::TOPLEVEL->add ($DEBUG_STATUS); |
100 | $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); |
98 | |
101 | |
99 | $STATUS_LINE = new Crossfire::Client::Widget::Label |
102 | $STATUS_LINE = new CFClient::Widget::Label |
100 | 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, |
103 | y => $HEIGHT * 59 / 60 - $FONTSIZE; |
101 | ""; |
|
|
102 | $Crossfire::Client::Widget::TOPLEVEL->add ($STATUS_LINE); |
104 | $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); |
103 | |
105 | |
104 | $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label |
106 | $ALT_ENTER_MESSAGE = new CFClient::Widget::Label |
105 | 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, |
107 | y => $HEIGHT * 59 / 60, |
|
|
108 | height => $HEIGHT / 60, |
106 | "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
109 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
107 | $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
110 | $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
111 | |
|
|
112 | $MAPWIDGET = new CFClient::Widget::MapWidget; |
|
|
113 | $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); |
|
|
114 | $MAPWIDGET->focus_in; |
108 | |
115 | |
109 | # Test code #d# |
116 | # Test code #d# |
110 | unless ($tw) { # haha... |
117 | unless ($tw) { # haha... |
111 | $te = new Crossfire::Client::Widget::FancyFrame; |
118 | my $w = new CFClient::Widget::Window |
112 | $te->add (new Crossfire::Client::Widget::Entry); |
119 | w => 300, h => 300, |
113 | $te->move (300, 0, 2); |
120 | child => (my $frame = new CFClient::Widget::FancyFrame); |
114 | $Crossfire::Client::Widget::TOPLEVEL->add ($te); |
121 | $CFClient::Widget::TOPLEVEL->add ($w); |
|
|
122 | |
|
|
123 | $frame->add (my $vbox = new CFClient::Widget::VBox); |
|
|
124 | |
|
|
125 | $vbox->add (new CFClient::Widget::Entry text => "hallo"); |
|
|
126 | $vbox->add (new CFClient::Widget::Slider); |
115 | |
127 | |
116 | $tw = new Crossfire::Client::Widget::Animator; |
128 | $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 600, h => 300; |
117 | my $lbl1 = new Crossfire::Client::Widget::Label |
129 | my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
118 | 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
119 | my $lbl2 = new Crossfire::Client::Widget::Label |
130 | my $lbl2 = new CFClient::Widget::Label text => "LBL2"; |
120 | 0, 0, 10, $FONTSIZE, "LBL2"; |
|
|
121 | |
|
|
122 | my $vb = new Crossfire::Client::Widget::VBox; |
131 | my $vb = new CFClient::Widget::VBox; |
123 | my $f = new Crossfire::Client::Widget::FancyFrame; |
132 | my $f = new CFClient::Widget::FancyFrame; |
124 | my $f2 = new Crossfire::Client::Widget::FancyFrame; |
133 | my $f2 = new CFClient::Widget::FancyFrame; |
125 | $f->add ($lbl1); |
134 | $f->add ($lbl1); |
126 | $f2->add ($lbl2); |
135 | $f2->add ($lbl2); |
127 | $vb->add ($f); |
136 | $vb->add ($f); |
128 | $vb->add ($f2, 1); |
137 | $vb->add ($f2, 1); |
129 | |
138 | |
130 | $tw->add ($vb); |
139 | $tw->add ($vb); |
131 | $tw->w (400); |
|
|
132 | $tw->h (300); |
|
|
133 | $tw->move ($WIDTH - 200, 0); |
|
|
134 | $tw->moveto (0, 0); |
140 | $tw->moveto (0, 0); |
135 | $Crossfire::Client::Widget::TOPLEVEL->add ($tw); |
141 | $CFClient::Widget::TOPLEVEL->add ($tw); |
136 | |
142 | |
137 | # $f->move ($WIDTH - 200, 0); |
143 | # $f->move ($WIDTH - 200, 0); |
138 | # $Crossfire::Client::Widget::TOPLEVEL->add ($f); |
144 | # $CFClient::Widget::TOPLEVEL->add ($f); |
139 | } |
145 | } |
140 | } |
146 | } |
141 | |
147 | |
142 | sub destroy_screen { |
148 | sub destroy_screen { |
143 | remove Glib::Source $SDL_TIMER; |
149 | remove Glib::Source $SDL_TIMER; |
… | |
… | |
162 | pass => $CFG->{password}, |
168 | pass => $CFG->{password}, |
163 | mapw => $mapsize, |
169 | mapw => $mapsize, |
164 | maph => $mapsize, |
170 | maph => $mapsize, |
165 | ; |
171 | ; |
166 | |
172 | |
167 | Crossfire::Client::lowdelay fileno $CONN->{fh}; |
173 | CFClient::lowdelay fileno $CONN->{fh}; |
168 | } |
174 | } |
169 | |
175 | |
170 | sub stop_game { |
176 | sub stop_game { |
171 | remove Glib::Source $refresh_handler if $refresh_handler; |
177 | remove Glib::Source $refresh_handler if $refresh_handler; |
172 | undef $refresh_handler; |
178 | undef $refresh_handler; |
… | |
… | |
183 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
189 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
184 | glMatrixMode GL_MODELVIEW; |
190 | glMatrixMode GL_MODELVIEW; |
185 | |
191 | |
186 | glClear GL_COLOR_BUFFER_BIT; |
192 | glClear GL_COLOR_BUFFER_BIT; |
187 | |
193 | |
188 | $Crossfire::Client::Widget::TOPLEVEL->draw; |
194 | $CFClient::Widget::TOPLEVEL->draw; |
189 | |
195 | |
190 | SDL::GLSwapBuffers; |
196 | SDL::GLSwapBuffers; |
191 | } |
197 | } |
192 | |
198 | |
193 | sub debug { |
199 | sub debug { |
… | |
… | |
199 | my $FPS; |
205 | my $FPS; |
200 | |
206 | |
201 | sub refresh { |
207 | sub refresh { |
202 | $refresh_handler ||= add Glib::Idle sub { |
208 | $refresh_handler ||= add Glib::Idle sub { |
203 | if ($SDL_APP) { |
209 | if ($SDL_APP) { |
204 | my $next_refresh = SDL::GetTicks; |
210 | $NOW = SDL::GetTicks; |
205 | |
211 | |
206 | if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) { |
212 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
207 | SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh); |
213 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
208 | $next_refresh = SDL::GetTicks; |
214 | $NOW = SDL::GetTicks; |
209 | } |
215 | } |
210 | |
216 | |
211 | my $interval = ($next_refresh - $last_refresh) * 0.001; |
217 | my $interval = ($NOW - $last_refresh) * 0.001; |
212 | $last_refresh = $next_refresh; |
218 | $last_refresh = $NOW; |
213 | |
219 | |
214 | if ($interval) { |
220 | if ($interval) { |
215 | $FPS ||= 1 / $interval; |
221 | $FPS ||= 1 / $interval; |
216 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
222 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
217 | debug sprintf "%5.02f\n", $FPS; |
223 | debug sprintf "%5.02f", $FPS; |
218 | } |
224 | } |
219 | |
225 | |
220 | force_refresh; |
226 | force_refresh; |
221 | $_->animate ($interval) for grep $_, values %ANIMATE; |
227 | $_->animate ($interval) for grep $_, values %ANIMATE; |
222 | |
228 | |
… | |
… | |
259 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
265 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
260 | # alt-enter |
266 | # alt-enter |
261 | $FULLSCREEN = !$FULLSCREEN; |
267 | $FULLSCREEN = !$FULLSCREEN; |
262 | init_screen; |
268 | init_screen; |
263 | } else { |
269 | } else { |
264 | Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); |
270 | CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); |
265 | } |
271 | } |
266 | }, |
272 | }, |
267 | SDL_KEYUP() => sub { |
273 | SDL_KEYUP() => sub { |
268 | Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); |
274 | CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); |
269 | }, |
275 | }, |
270 | SDL_MOUSEMOTION() => sub { |
276 | SDL_MOUSEMOTION() => sub { |
271 | Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV); |
277 | CFClient::Widget::feed_sdl_motion_event ($SDL_EV); |
272 | }, |
278 | }, |
273 | SDL_MOUSEBUTTONDOWN() => sub { |
279 | SDL_MOUSEBUTTONDOWN() => sub { |
274 | Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); |
280 | CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); |
275 | }, |
281 | }, |
276 | SDL_MOUSEBUTTONUP() => sub { |
282 | SDL_MOUSEBUTTONUP() => sub { |
277 | Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); |
283 | CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); |
278 | }, |
284 | }, |
279 | SDL_ACTIVEEVENT() => sub { |
285 | SDL_ACTIVEEVENT() => sub { |
280 | printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
286 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
281 | }, |
287 | }, |
282 | ); |
288 | ); |
283 | |
289 | |
284 | @conn::ISA = Crossfire::Protocol::; |
290 | @conn::ISA = Crossfire::Protocol::; |
285 | |
291 | |
286 | sub conn::map_update { |
292 | sub conn::map_update { |
287 | my ($self, $dirty) = @_; |
293 | my ($self, $dirty) = @_; |
288 | |
294 | |
289 | refresh; |
295 | $MAPWIDGET->update; |
290 | } |
296 | } |
291 | |
297 | |
292 | sub conn::map_scroll { |
298 | sub conn::map_scroll { |
293 | my ($self, $dx, $dy) = @_; |
299 | my ($self, $dx, $dy) = @_; |
294 | |
300 | |
… | |
… | |
310 | sub conn::face_update { |
316 | sub conn::face_update { |
311 | my ($self, $face) = @_; |
317 | my ($self, $face) = @_; |
312 | |
318 | |
313 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
319 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
314 | |
320 | |
315 | $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; |
321 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
316 | } |
322 | } |
317 | |
323 | |
318 | sub conn::query { |
324 | sub conn::query { |
319 | my ($self, $flags, $prompt) = @_; |
325 | my ($self, $flags, $prompt) = @_; |
320 | |
326 | |
… | |
… | |
393 | $cb->signal_connect (clicked => sub { |
399 | $cb->signal_connect (clicked => sub { |
394 | for (keys %$cfg) { |
400 | for (keys %$cfg) { |
395 | $::CFG->{$_} = $cfg->{$_} |
401 | $::CFG->{$_} = $cfg->{$_} |
396 | if $_ ne '_i'; |
402 | if $_ ne '_i'; |
397 | } |
403 | } |
398 | Crossfire::Client::write_cfg "$Crossfire::VARDIR/pclientrc"; |
404 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
399 | }); |
405 | }); |
400 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
406 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
401 | $cb->signal_connect (clicked => sub { |
407 | $cb->signal_connect (clicked => sub { |
402 | for (keys %$cfg) { |
408 | for (keys %$cfg) { |
403 | $::CFG->{$_} = $cfg->{$_} |
409 | $::CFG->{$_} = $cfg->{$_} |
… | |
… | |
422 | |
428 | |
423 | ############################################################################# |
429 | ############################################################################# |
424 | |
430 | |
425 | SDL::Init SDL_INIT_EVERYTHING; |
431 | SDL::Init SDL_INIT_EVERYTHING; |
426 | |
432 | |
427 | my $mapwidget = Crossfire::Client::Widget::MapWidget->new; |
|
|
428 | |
|
|
429 | $Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget); |
|
|
430 | $mapwidget->focus_in; |
|
|
431 | |
|
|
432 | Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; |
433 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
433 | |
434 | |
434 | $CFG ||= { |
435 | $CFG ||= { |
435 | width => 640, |
436 | width => 640, |
436 | height => 480, |
437 | height => 480, |
437 | mapsize => 100, |
438 | mapsize => 100, |
… | |
… | |
439 | host => "crossfire.schmorp.de", |
440 | host => "crossfire.schmorp.de", |
440 | port => 13327, |
441 | port => 13327, |
441 | }; |
442 | }; |
442 | |
443 | |
443 | { |
444 | { |
444 | my @fonts = map Crossfire::Client::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
445 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
445 | |
446 | |
446 | Crossfire::Client::add_font $_ for @fonts; |
447 | CFClient::add_font $_ for @fonts; |
447 | Crossfire::Client::set_font $fonts[0]; |
448 | CFClient::set_font $fonts[0]; |
448 | } |
449 | } |
449 | |
450 | |
450 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
451 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
451 | |
452 | |
452 | run_config_dialog |
453 | run_config_dialog |