ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.140 by root, Wed Apr 19 06:06:46 2006 UTC vs.
Revision 1.150 by root, Thu Apr 20 07:12:58 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13
14use SDL::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
18use SDL::OpenGL;
19
20use Crossfire; 9use Crossfire;
21use Crossfire::Protocol; 10use Crossfire::Protocol;
22 11
23use Compress::LZF; 12use Compress::LZF;
24 13
25use CFClient; 14use CFClient;
26use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
27 17
28our $VERSION = '0.1'; 18our $VERSION = '0.1';
29 19
30my $MAX_FPS = 60; 20my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
57our $METASERVER; 47our $METASERVER;
58 48
59our $GAUGES; 49our $GAUGES;
60 50
61our $SDL_ACTIVE; 51our $SDL_ACTIVE;
62our $SDL_EV;
63our %SDL_CB; 52our %SDL_CB;
64 53
65our $SDL_MIXER; 54our $SDL_MIXER;
66our @SOUNDS; # event => file mapping 55our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files 56our %AUDIO_CHUNKS; # audio files
109 undef $CONN; 98 undef $CONN;
110} 99}
111 100
112sub client_setup { 101sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 102 my $dialog = new CFClient::UI::FancyFrame
103 title => "Client Setup",
114 child => (my $vbox = new CFClient::UI::VBox); 104 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
116 $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]);
117 106
118 $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");
119 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 108 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
120 109
121 $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]);
122 $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");
123 112
124 $mode_slider->connect (changed => sub { 113 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 114 my ($self, $value) = @_;
126 115
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
158 my ($self, $value) = @_; 147 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 148 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 149 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
161 }); 150 });
162 151
163 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize"); 152 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.5, 1.5, 0.1], connect_changed => sub { 153 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
165 $CFG->{gui_fontsize} = 0.1 * int $_[0] * 10; 154 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
166# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; 155# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
167 }); 156 });
168 157
169 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Log Fontsize"); 158 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
170 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.5, 0.1], connect_changed => sub { 159 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
171 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[0] * 10); 160 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
172 }); 161 });
173 162
174 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 163 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
175 video_shutdown (); 164 video_shutdown ();
176 video_init (); 165 video_init ();
182 }); 171 });
183# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); 172# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
184# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { 173# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
185# $CFG->{effects_volume} = $_[1]; 174# $CFG->{effects_volume} = $_[1];
186# }); 175# });
187 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Bg. Music"); 176 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
188 $table->add (1, 10, my $hbox = new CFClient::UI::HBox); 177 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
189 $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 {
190 $CFG->{bgm_enable} = $_[1]; 179 $CFG->{bgm_enable} = $_[1];
191 }); 180 });
192 $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 {
193 $CFG->{bgm_volume} = $_[1]; 182 $CFG->{bgm_volume} = $_[1];
194 $SDL_MIXER->music_volume ($_[1]); 183 CFClient::MixMusic::volume $_[1] * 128;
195 }); 184 });
196 185
197 $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 {
198 audio_shutdown (); 187 audio_shutdown ();
199 audio_init (); 188 audio_init ();
202 $dialog 191 $dialog
203} 192}
204 193
205sub metaserver_dialog { 194sub metaserver_dialog {
206 my $dialog = new CFClient::UI::FancyFrame 195 my $dialog = new CFClient::UI::FancyFrame
196 title => "Metaserver",
207 child => (my $vbox = new CFClient::UI::VBox); 197 child => (my $vbox = new CFClient::UI::VBox);
208 198
209 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 199 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
210 200
211 $dialog 201 $dialog
277 }); 267 });
278} 268}
279 269
280sub server_setup { 270sub server_setup {
281 my $dialog = new CFClient::UI::FancyFrame 271 my $dialog = new CFClient::UI::FancyFrame
272 title => "Server Setup",
282 child => (my $vbox = new CFClient::UI::VBox); 273 child => (my $vbox = new CFClient::UI::VBox);
283 274
284 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
285 $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]);
286 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 276 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
287 277
288 { 278 {
289 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 279 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
290 280
291 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 281 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
292 my ($self, $value) = @_; 282 my ($self, $value) = @_;
293 $CFG->{host} = $value; 283 $CFG->{host} = $value;
294 }); 284 });
295 285
296 $METASERVER = metaserver_dialog; 286 $METASERVER = metaserver_dialog;
297 287
298 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 288 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
299 update_metaserver $HOST; 289 update_metaserver $HOST;
300 }); 290 });
301 } 291 }
302 292
303 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 293 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
304 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 294 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
305 my ($self, $value) = @_; 295 my ($self, $value) = @_;
306 $CFG->{user} = $value; 296 $CFG->{user} = $value;
307 }); 297 });
308 298
309 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 299 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
310 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 300 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
311 my ($self, $value) = @_; 301 my ($self, $value) = @_;
312 $CFG->{password} = $value; 302 $CFG->{password} = $value;
313 }); 303 });
314 304
315 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 305 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
316 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 306 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
317 my ($self, $value) = @_; 307 my ($self, $value) = @_;
318 $CFG->{say_command} = $value; 308 $CFG->{say_command} = $value;
319 }); 309 });
320 310
321 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 311 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
322 $table->add (1, 7, new CFClient::UI::Slider 312 $table->add (1, 7, new CFClient::UI::Slider
323 req_w => 100, 313 req_w => 100,
324 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 314 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
325 connect_changed => sub { 315 connect_changed => sub {
326 my ($self, $value) = @_; 316 my ($self, $value) = @_;
336 $dialog 326 $dialog
337} 327}
338 328
339sub message_window { 329sub message_window {
340 my $window = new CFClient::UI::FancyFrame 330 my $window = new CFClient::UI::FancyFrame
331 title => "Messages",
341 border_bg => [1, 1, 1, 0.5], 332 border_bg => [1, 1, 1, 0.5],
342 bg => [0.3, 0.3, 0.3, 0.8], 333 bg => [0.3, 0.3, 0.3, 0.8],
343 user_w => int $::WIDTH / 3, 334 user_w => int $::WIDTH / 3,
344 user_h => int $::HEIGHT / 5, 335 user_h => int $::HEIGHT / 5,
345 child => (my $vbox = new CFClient::UI::VBox); 336 child => (my $vbox = new CFClient::UI::VBox);
387 378
388 $window 379 $window
389} 380}
390 381
391sub sdl_init { 382sub sdl_init {
392 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 383 CFClient::SDL_Init
393 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
394 and die "SDL::Init failed!\n"; 384 and die "SDL::Init failed!\n";
395} 385}
396 386
397sub video_init { 387sub video_init {
398 sdl_init; 388 sdl_init;
399 389
400 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 390 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
401 $FULLSCREEN = $CFG->{fullscreen}; 391 $FULLSCREEN = $CFG->{fullscreen};
402 $FAST = $CFG->{fast}; 392 $FAST = $CFG->{fast};
403 393
404 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 394 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
405 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
406 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
407 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
408
409 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
410 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
411 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
412 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
413
414 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
415 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
416 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
417
418 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
419 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
420 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
421 or die "SDL::SetVideoMode failed!\n"; 395 or die "SDL_SetVideoMode failed!\n";
422
423 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
424
425 $SDL_EV = new SDL::Event;
426 $SDL_EV->set_unicode (1);
427 396
428 $SDL_ACTIVE = 1; 397 $SDL_ACTIVE = 1;
429 398
430 $LAST_REFRESH = time - 0.01; 399 $LAST_REFRESH = time - 0.01;
431 400
448 fontsize => 0.8, 417 fontsize => 0.8,
449 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 418 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
450 $ALT_ENTER_MESSAGE->show; 419 $ALT_ENTER_MESSAGE->show;
451 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); 420 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
452 421
453 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 422 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
454 $MAPWIDGET->focus_in; 423 $MAPWIDGET->focus_in;
455 $MAPWIDGET->connect (activate_console => sub { 424 $MAPWIDGET->connect (activate_console => sub {
456 my ($mapwidget, $preset) = @_; 425 my ($mapwidget, $preset) = @_;
457 426
458 if ($CONSOLE) { 427 if ($CONSOLE) {
476 status "Configuration Saved"; 445 status "Configuration Saved";
477 }); 446 });
478 447
479 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 448 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
480 449
481 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");
482 $tgw->add (my $hbox = new CFClient::UI::HBox ()); 451 $tgw->add (my $hbox = new CFClient::UI::HBox ());
483 452
484 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); 453 $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
485 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); 454 $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
486 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); 455 $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
487 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); 456 $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
488 457
489 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 458 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
490 $CFClient::UI::ROOT->add ($tgw); 459 $CFClient::UI::ROOT->add ($tgw);
491} 460}
492 461
493sub video_shutdown { 462sub video_shutdown {
494 $CFClient::UI::ROOT->{children} = []; 463 $CFClient::UI::ROOT->{children} = [];
495 undef $SDL_ACTIVE; 464 undef $SDL_ACTIVE;
496 undef $SDL_EV;
497} 465}
498 466
499my $bgmusic;#TODO#hack#d# 467my $bgmusic;#TODO#hack#d#
500 468
501sub audio_init { 469sub audio_init {
502 if ($CFG->{audio_enable}) { 470 if ($CFG->{audio_enable}) {
503 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 471 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
504 $SDL_MIXER = new SDL::Mixer; 472
505 $SDL_MIXER->allocate_channels (8); 473 $SDL_MIXER = !CFClient::Mix_OpenAudio;
474 CFClient::Mix_AllocateChannels 8;
475 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
506 476
507 # TODO: hack, do play loop and mood music 477 # TODO: hack, do play loop and mood music
508 if ($CFG->{bgm_enable}) { 478 if ($CFG->{bgm_enable}) {
509 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 479 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
510 $SDL_MIXER->play_music ($bgmusic, -1); 480 $bgmusic->play;
511 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
512 } 481 }
513 482
514 while (<$fh>) { 483 while (<$fh>) {
515 next if /^\s*#/; 484 next if /^\s*#/;
516 next if /^\s*$/; 485 next if /^\s*$/;
518 my ($file, $volume, $event) = split /\s+/, $_, 3; 487 my ($file, $volume, $event) = split /\s+/, $_, 3;
519 488
520 push @SOUNDS, "$volume,$file"; 489 push @SOUNDS, "$volume,$file";
521 490
522 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 491 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
523 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 492 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
524 $chunk->volume ($volume * 128 / 100); 493 $chunk->volume ($volume * 128 / 100);
525 $chunk 494 $chunk
526 }; 495 };
527 } 496 }
528 } else { 497 } else {
530 } 499 }
531 } 500 }
532} 501}
533 502
534sub audio_shutdown { 503sub audio_shutdown {
504 CFClient::Mix_CloseAudio if $SDL_MIXER;
535 undef $SDL_MIXER; 505 undef $SDL_MIXER;
536 @SOUNDS = (); 506 @SOUNDS = ();
537 %AUDIO_CHUNKS = (); 507 %AUDIO_CHUNKS = ();
538} 508}
539 509
552 $want_refresh = 0; 522 $want_refresh = 0;
553 $can_refresh = 0; 523 $can_refresh = 0;
554 524
555 $CFClient::UI::ROOT->draw; 525 $CFClient::UI::ROOT->draw;
556 526
557 SDL::GLSwapBuffers; 527 CFClient::SDL_GL_SwapBuffers;
558 528
559 $LAST_REFRESH = $NOW; 529 $LAST_REFRESH = $NOW;
560} 530}
561 531
562my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 532my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
563 $NOW = time; 533 $NOW = time;
564 534
565 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 535 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
566 while $SDL_EV->poll; 536 for CFClient::SDL_PollEvent;
567 537
568 if (%animate_object) { 538 if (%animate_object) {
569 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 539 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
570 $want_refresh++; 540 $want_refresh++;
571 } 541 }
601 my $hp = $stats->{1}; 571 my $hp = $stats->{1};
602 my $hp_m = $stats->{2}; 572 my $hp_m = $stats->{2};
603 my $sp = $stats->{3}; 573 my $sp = $stats->{3};
604 my $sp_m = $stats->{4}; 574 my $sp_m = $stats->{4};
605 my $fo = $stats->{18}; 575 my $fo = $stats->{18};
606 my $fo_m = 1000; 576 my $fo_m = 999;
607 my $gr = $stats->{23}; 577 my $gr = $stats->{23};
608 my $gr_m = $stats->{24}; 578 my $gr_m = $stats->{24};
609 579
610 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 580 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
611 $GAUGES->{hp}->set_value ($hp, $hp_m); 581 $GAUGES->{hp} ->set_value ($hp, $hp_m);
612 $GAUGES->{mana}->set_value ($sp, $sp_m); 582 $GAUGES->{mana} ->set_value ($sp, $sp_m);
613 $GAUGES->{food}->set_value ($fo, $fo_m); 583 $GAUGES->{food} ->set_value ($fo, $fo_m);
614 $GAUGES->{grace}->set_value ($gr, $gr_m); 584 $GAUGES->{grace}->set_value ($gr, $gr_m);
615} 585}
616 586
617sub conn::user_send { 587sub conn::user_send {
618 my ($self, $command) = @_; 588 my ($self, $command) = @_;
653 623
654sub conn::map_clear { 624sub conn::map_clear {
655 my ($self) = @_; 625 my ($self) = @_;
656 626
657 $self->flush_map; 627 $self->flush_map;
658 delete $self->{neigh}; 628 delete $self->{neigh_map};
659 629
660 $MAP->clear; 630 $MAP->clear;
661} 631}
662 632
663 633
675 } 645 }
676 } 646 }
677} 647}
678 648
679sub conn::flood_fill { 649sub conn::flood_fill {
680 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 650 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
681 651
682 # the server does not allow map paths > 6 652 # the server does not allow map paths > 6
683 return if 6 <= length $path; 653 return if 6 <= length $path;
684 654
685 for my $tile (1..4) { 655 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
686 next if $self->{neigh}{$hash}[$tile]; 656
657 for (
658 [1, 0, -1],
659 [2, 1, 0],
660 [3, 0, 1],
661 [4, -1, 0],
662 ) {
663 my ($tile, $dx, $dy) = @$_;
664
665 my $gx = $gx + $dx;
666 my $gy = $gy + $dy;
667
687 next unless $flags & (1 << ($tile - 1)); 668 next unless $flags & (1 << ($tile - 1));
669 next if $self->{neigh_grid}{$gx, $gy}++;
688 670
689 my $neigh = $self->{neigh}{$hash} ||= []; 671 my $neigh = $self->{neigh_map}{$hash} ||= [];
690 672 if (my $info = $neigh->[$tile]) {
691 $self->send_mapinfo ("spatial $path$tile", sub {
692 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 673 my ($flags, $x, $y, $w, $h, $hash) = @$info;
693 674
694 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
695 return if $mode ne "spatial";
696
697 $x += $MAP->ox;
698 $y += $MAP->oy;
699
700 $self->load_map ($hash, $x, $y)
701 unless $self->{neigh}{$hash}[5]++;#d#
702
703 $neigh->[$tile] = [$x, $y, $w, $h];
704
705 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 675 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
706 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 676 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
677
678 } else {
679 $self->send_mapinfo ("spatial $path$tile", sub {
680 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
681
682 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
683 return if $mode ne "spatial";
684
685 $x += $MAP->ox;
686 $y += $MAP->oy;
687
688 $self->load_map ($hash, $x, $y)
689 unless $self->{neigh_map}{$hash}[5]++;#d#
690
691 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
692
693 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
694 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
695 });
707 }); 696 }
708 } 697 }
709} 698}
710 699
711sub conn::map_change { 700sub conn::map_change {
712 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 701 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
715 704
716 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 705 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
717 706
718 my $mapmapw = 250; 707 my $mapmapw = 250;
719 my $mapmaph = 250; 708 my $mapmaph = 250;
709
710 $self->{neigh_rect} = [
711 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
712 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5,
713 ];
720 714
715 delete $self->{neigh_grid};
721 $self->flood_fill ("", $hash, $flags, 716 $self->flood_fill (0, 0, "", $hash, $flags);
722 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
723 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
724 717
725 $x += $ox; 718 $x += $ox;
726 $y += $oy; 719 $y += $oy;
727 720
728 $self->{map_info} = [$hash, $x, $y, $w, $h]; 721 $self->{map_info} = [$hash, $x, $y, $w, $h];
794 or return; 787 or return;
795 788
796 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 789 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
797 or return; 790 or return;
798 791
799 $SDL_MIXER->play_channel (-1, $chunk); 792 $chunk->play;
800 warn "sound $x,$y,$soundnum,$type\n";#d# 793# warn "sound $x,$y,$soundnum,$type\n";#d#
801} 794}
802 795
803sub conn::query { 796sub conn::query {
804 my ($self, $flags, $prompt) = @_; 797 my ($self, $flags, $prompt) = @_;
805 798
806 #TODO 799 #TODO, display dialog with relevant information
807 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 800 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
808} 801}
809 802
810sub conn::drawinfo { 803sub conn::drawinfo {
811 my ($self, $color, $text) = @_; 804 my ($self, $color, $text) = @_;
827 ); 820 );
828 821
829 $LOGVIEW->add_paragraph ($color[$color], $text); 822 $LOGVIEW->add_paragraph ($color[$color], $text);
830} 823}
831 824
825sub conn::spell_add {
826 my ($self, $spell) = @_;
827
828 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
829 });
830 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
831 });
832}
833
834sub conn::spell_delete {
835 my ($self, $spell) = @_;
836}
837
838sub conn::addme_success {
839 my ($self) = @_;
840
841 for my $skill (values %{$self->{skill_info}}) {
842 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
843 });
844 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
845 });
846 }
847}
848
832%SDL_CB = ( 849%SDL_CB = (
833 SDL_QUIT() => sub { 850 CFClient::SDL_QUIT => sub {
834 Event::unloop -1; 851 Event::unloop -1;
835 }, 852 },
836 SDL_VIDEORESIZE() => sub { 853 CFClient::SDL_VIDEORESIZE => sub {
837 }, 854 },
838 SDL_VIDEOEXPOSE() => sub { 855 CFClient::SDL_VIDEOEXPOSE => sub {
839 refresh; 856 refresh;
840 }, 857 },
841 SDL_KEYDOWN() => sub { 858 CFClient::SDL_KEYDOWN => sub {
842 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 859 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
843 # alt-enter 860 # alt-enter
844 video_shutdown; 861 video_shutdown;
845 $CFG->{fullscreen} = !$CFG->{fullscreen}; 862 $CFG->{fullscreen} = !$CFG->{fullscreen};
846 video_init; 863 video_init;
847 } else { 864 } else {
848 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 865 CFClient::UI::feed_sdl_key_down_event ($_[0]);
849 } 866 }
850 }, 867 },
851 SDL_KEYUP() => sub { 868 CFClient::SDL_KEYUP => sub {
852 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 869 CFClient::UI::feed_sdl_key_up_event ($_[0]);
853 }, 870 },
854 SDL_MOUSEMOTION() => sub { 871 CFClient::SDL_MOUSEMOTION => sub {
855 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 872 CFClient::UI::feed_sdl_motion_event ($_[0]);
856 }, 873 },
857 SDL_MOUSEBUTTONDOWN() => sub { 874 CFClient::SDL_MOUSEBUTTONDOWN => sub {
858 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 875 CFClient::UI::feed_sdl_button_down_event ($_[0]);
859 }, 876 },
860 SDL_MOUSEBUTTONUP() => sub { 877 CFClient::SDL_MOUSEBUTTONUP => sub {
861 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 878 CFClient::UI::feed_sdl_button_up_event ($_[0]);
862 }, 879 },
863 SDL_ACTIVEEVENT() => sub { 880 CFClient::SDL_ACTIVEEVENT => sub {
864# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 881# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
865 }, 882 },
866); 883);
867 884
868############################################################################# 885#############################################################################
888 mapsize => 100, 905 mapsize => 100,
889 host => "crossfire.schmorp.de", 906 host => "crossfire.schmorp.de",
890 say_command => 'say', 907 say_command => 'say',
891 audio_enable => 1, 908 audio_enable => 1,
892 bgm_enable => 1, 909 bgm_enable => 1,
893 bgm_volume => 64, 910 bgm_volume => 0.25,
894); 911);
895 912
896while (my ($k, $v) = each %DEF_CFG) { 913while (my ($k, $v) = each %DEF_CFG) {
897 $CFG->{$k} = $v unless exists $CFG->{$k}; 914 $CFG->{$k} = $v unless exists $CFG->{$k};
898} 915}
899 916
900sdl_init; 917sdl_init;
901 918
902@SDL_MODES = reverse 919@SDL_MODES = reverse
903 grep $_->[0] >= 640 && $_->[1] >= 480, 920 grep $_->[0] >= 640 && $_->[1] >= 480,
904 map [SDL::RectW ($_), SDL::RectH ($_)], 921 CFClient::SDL_ListModes;
905 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
906 922
907@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 923@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
908 924
909$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 925$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
910 926
918video_init; 934video_init;
919audio_init; 935audio_init;
920 936
921Event::loop; 937Event::loop;
922 938
923END { SDL::Quit } 939END { CFClient::SDL_Quit }
924 940
925 941

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines