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.136 by root, Tue Apr 18 06:34:30 2006 UTC vs.
Revision 1.147 by root, Wed Apr 19 21:38:05 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; 9use SDL::OpenGL;
19 10
20use Crossfire; 11use Crossfire;
21use Crossfire::Protocol; 12use Crossfire::Protocol;
22 13
23use Compress::LZF; 14use Compress::LZF;
24 15
25use CFClient; 16use CFClient;
26use CFClient::UI; 17use CFClient::UI;
18use CFClient::MapWidget;
27 19
28our $VERSION = '0.1'; 20our $VERSION = '0.1';
29 21
30my $MAX_FPS = 60; 22my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 23my $MIN_FPS = 5; # unused as of yet
57our $METASERVER; 49our $METASERVER;
58 50
59our $GAUGES; 51our $GAUGES;
60 52
61our $SDL_ACTIVE; 53our $SDL_ACTIVE;
62our $SDL_EV;
63our %SDL_CB; 54our %SDL_CB;
64 55
65our $SDL_MIXER; 56our $SDL_MIXER;
66our @SOUNDS; # event => file mapping 57our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files 58our %AUDIO_CHUNKS; # audio files
110} 101}
111 102
112sub client_setup { 103sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 104 my $dialog = new CFClient::UI::FancyFrame
114 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 106 $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]); 107 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
117 108
118 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 109 $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); 110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
120 111
121 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 112 $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 height => $FONTSIZE * 0.8); 113 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
123 114
124 $mode_slider->connect (changed => sub { 115 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 116 my ($self, $value) = @_;
126 117
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
129 }); 120 });
130 $mode_slider->emit (changed => $mode_slider->{range}[0]); 121 $mode_slider->emit (changed => $mode_slider->{range}[0]);
131 122
132 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 123 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
133 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 124 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
134 my ($self, $value) = @_; 125 my ($self, $value) = @_;
135 $CFG->{fullscreen} = $value; 126 $CFG->{fullscreen} = $value;
136 }); 127 });
137 128
138 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 129 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
139 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 130 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
140 my ($self, $value) = @_; 131 my ($self, $value) = @_;
141 $CFG->{fast} = $value; 132 $CFG->{fast} = $value;
142 }); 133 });
143 134
144 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 135 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
145 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 136 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
146 my ($self, $value) = @_; 137 my ($self, $value) = @_;
147 $CFG->{fow_enable} = $value; 138 $CFG->{fow_enable} = $value;
148 }); 139 });
149 140
150 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 141 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
151 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 142 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
152 my ($self, $value) = @_; 143 my ($self, $value) = @_;
153 $CFG->{fow_intensity} = $value; 144 $CFG->{fow_intensity} = $value;
154 }); 145 });
155 146
156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 147 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
157 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 148 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
158 my ($self, $value) = @_; 149 my ($self, $value) = @_;
159 $CFG->{fow_smooth} = $value; 150 $CFG->{fow_smooth} = $value;
160 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; 151 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
161 }); 152 });
162 153
163 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 154 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
155 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
156 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
157# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
158 });
159
160 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
164 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 161 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
165 my ($self, $value) = @_;
166 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 162 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
167 }); 163 });
168 164
169 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 165 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
170 video_shutdown (); 166 video_shutdown ();
171 video_init (); 167 video_init ();
168 });
169
170 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
171 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
172 $CFG->{audio_enable} = $_[1];
173 });
174# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
175# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
176# $CFG->{effects_volume} = $_[1];
177# });
178 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
179 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
180 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
181 $CFG->{bgm_enable} = $_[1];
182 });
183 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
184 $CFG->{bgm_volume} = $_[1];
185 CFClient::Mix_VolumeMusic ($_[1]);
186 });
187
188 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
189 audio_shutdown ();
190 audio_init ();
172 }); 191 });
173 192
174 $dialog 193 $dialog
175} 194}
176 195
240 $HOST->set_text ($CFG->{host} = $host); 259 $HOST->set_text ($CFG->{host} = $host);
241 }), 260 }),
242 (new CFClient::UI::Empty expand => 1), 261 (new CFClient::UI::Empty expand => 1),
243 ]); 262 ]);
244 263
245 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 264 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
246 for 0 .. $#$m; 265 for 0 .. $#$m;
247 } 266 }
248 } 267 }
249 }); 268 });
250} 269}
251 270
252sub server_setup { 271sub server_setup {
253 my $dialog = new CFClient::UI::FancyFrame 272 my $dialog = new CFClient::UI::FancyFrame
254 child => (my $vbox = new CFClient::UI::VBox); 273 child => (my $vbox = new CFClient::UI::VBox);
255 274
256 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 275 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
257 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 276 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
258 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 277 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
259 278
260 { 279 {
261 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 280 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
262 281
263 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 282 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
264 my ($self, $value) = @_; 283 my ($self, $value) = @_;
265 $CFG->{host} = $value; 284 $CFG->{host} = $value;
266 }); 285 });
267 286
268 $METASERVER = metaserver_dialog; 287 $METASERVER = metaserver_dialog;
269 288
270 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 289 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
271 update_metaserver $HOST; 290 update_metaserver $HOST;
272 }); 291 });
273 } 292 }
274 293
275 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 294 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
276 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 295 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
277 my ($self, $value) = @_; 296 my ($self, $value) = @_;
278 $CFG->{user} = $value; 297 $CFG->{user} = $value;
279 }); 298 });
280 299
281 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 300 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
282 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 301 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
283 my ($self, $value) = @_; 302 my ($self, $value) = @_;
284 $CFG->{password} = $value; 303 $CFG->{password} = $value;
285 }); 304 });
286 305
287 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 306 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
288 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 307 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
289 my ($self, $value) = @_; 308 my ($self, $value) = @_;
290 $CFG->{say_command} = $value; 309 $CFG->{say_command} = $value;
291 }); 310 });
292 311
293 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 312 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
294 $table->add (1, 7, new CFClient::UI::Slider 313 $table->add (1, 7, new CFClient::UI::Slider
295 req_w => 100, 314 req_w => 100,
296 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 315 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
297 connect_changed => sub { 316 connect_changed => sub {
298 my ($self, $value) = @_; 317 my ($self, $value) = @_;
359 378
360 $window 379 $window
361} 380}
362 381
363sub sdl_init { 382sub sdl_init {
364 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 383 CFClient::SDL_Init
365 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
366 and die "SDL::Init failed!\n"; 384 and die "SDL::Init failed!\n";
367} 385}
368 386
369sub video_init { 387sub video_init {
370 sdl_init; 388 sdl_init;
371 389
372 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 390 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
373 $FULLSCREEN = $CFG->{fullscreen}; 391 $FULLSCREEN = $CFG->{fullscreen};
374 $FAST = $CFG->{fast}; 392 $FAST = $CFG->{fast};
375 393
376 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 394 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
377 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
378 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
379 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
380
381 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
382 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
383 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
384 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
385
386 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
387 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
388 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
389
390 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
391 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
392 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
393 or die "SDL::SetVideoMode failed!\n"; 395 or die "SDL_SetVideoMode failed!\n";
394
395 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
396
397 $SDL_EV = new SDL::Event;
398 $SDL_EV->set_unicode (1);
399 396
400 $SDL_ACTIVE = 1; 397 $SDL_ACTIVE = 1;
401 398
402 $LAST_REFRESH = time - 0.01; 399 $LAST_REFRESH = time - 0.01;
403 400
404 CFClient::gl_init; 401 CFClient::gl_init;
405 402
406 $FONTSIZE = int $HEIGHT / 40; 403 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
407 404
408 ############################################################################# 405 #############################################################################
409 406
410 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 407 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
411 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 408 $DEBUG_STATUS->show;
412 409
413 $STATUS_LINE = new CFClient::UI::Label 410 $STATUS_LINE = new CFClient::UI::Label
414 padding => 0, 411 padding => 0,
415 y => $HEIGHT * 44 / 45 - $FONTSIZE; 412 y => $HEIGHT - $FONTSIZE * 1.8;
416 $CFClient::UI::ROOT->add ($STATUS_LINE); 413 $STATUS_LINE->show;
417 414
418 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 415 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
419 padding => 0, 416 padding => 0,
420 y => $HEIGHT * 44 / 45,
421 fontsize => $HEIGHT / 45, 417 fontsize => 0.8,
422 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 418 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
423 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 419 $ALT_ENTER_MESSAGE->show;
420 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
424 421
425 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 422 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
426 $MAPWIDGET->focus_in; 423 $MAPWIDGET->focus_in;
427 $MAPWIDGET->connect (activate_console => sub { 424 $MAPWIDGET->connect (activate_console => sub {
428 my ($mapwidget, $preset) = @_; 425 my ($mapwidget, $preset) = @_;
429 426
430 if ($CONSOLE) { 427 if ($CONSOLE) {
463} 460}
464 461
465sub video_shutdown { 462sub video_shutdown {
466 $CFClient::UI::ROOT->{children} = []; 463 $CFClient::UI::ROOT->{children} = [];
467 undef $SDL_ACTIVE; 464 undef $SDL_ACTIVE;
468 undef $SDL_EV;
469} 465}
470 466
471my $bgmusic;#TODO#hack#d# 467my $bgmusic;#TODO#hack#d#
472 468
473sub audio_init { 469sub audio_init {
474 if ($CFG->{sound} || 1) { 470 if ($CFG->{audio_enable}) {
475 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 471 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
476 $SDL_MIXER = new SDL::Mixer; 472
477 $SDL_MIXER->allocate_channels (8); 473 $SDL_MIXER = !CFClient::Mix_OpenAudio;
474 CFClient::Mix_AllocateChannels 8;
475 CFClient::MixMusic::volume $CFG->{bgm_volume};
478 476
477 # TODO: hack, do play loop and mood music
478 if ($CFG->{bgm_enable}) {
479 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 479 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
480 $SDL_MIXER->play_music ($bgmusic, -1); 480 $bgmusic->play;
481 }
481 482
482 while (<$fh>) { 483 while (<$fh>) {
483 next if /^\s*#/; 484 next if /^\s*#/;
484 next if /^\s*$/; 485 next if /^\s*$/;
485 486
486 my ($file, $volume, $event) = split /\s+/, $_, 3; 487 my ($file, $volume, $event) = split /\s+/, $_, 3;
487 488
488 push @SOUNDS, "$volume,$file"; 489 push @SOUNDS, "$volume,$file";
489 490
490 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 491 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
491 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 492 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
492 $chunk->volume ($volume * 128 / 100); 493 $chunk->volume ($volume * 128 / 100);
493 $chunk 494 $chunk
494 }; 495 };
495 } 496 }
496 } else { 497 } else {
498 } 499 }
499 } 500 }
500} 501}
501 502
502sub audio_shutdown { 503sub audio_shutdown {
504 CFClient::Mix_CloseAudio if $SDL_MIXER;
503 undef $SDL_MIXER; 505 undef $SDL_MIXER;
504 @SOUNDS = (); 506 @SOUNDS = ();
505 %AUDIO_CHUNKS = (); 507 %AUDIO_CHUNKS = ();
506} 508}
507 509
528} 530}
529 531
530my $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 {
531 $NOW = time; 533 $NOW = time;
532 534
533 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 535 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
534 while $SDL_EV->poll; 536 for CFClient::SDL_PollEvent;
535 537
536 if (%animate_object) { 538 if (%animate_object) {
537 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 539 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
538 $want_refresh++; 540 $want_refresh++;
539 } 541 }
756} 758}
757 759
758sub conn::sound_play { 760sub conn::sound_play {
759 my ($self, $x, $y, $soundnum, $type) = @_; 761 my ($self, $x, $y, $soundnum, $type) = @_;
760 762
763 $SDL_MIXER
764 or return;
765
761 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 766 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
762 or return; 767 or return;
763 768
764 $SDL_MIXER->play_channel (-1, $chunk); 769 $chunk->play;
765 warn "sound $x,$y,$soundnum,$type\n";#d# 770# warn "sound $x,$y,$soundnum,$type\n";#d#
766} 771}
767 772
768sub conn::query { 773sub conn::query {
769 my ($self, $flags, $prompt) = @_; 774 my ($self, $flags, $prompt) = @_;
770 775
771 #TODO 776 #TODO, display dialog with relevant information
772 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 777 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
773} 778}
774 779
775sub conn::drawinfo { 780sub conn::drawinfo {
776 my ($self, $color, $text) = @_; 781 my ($self, $color, $text) = @_;
792 ); 797 );
793 798
794 $LOGVIEW->add_paragraph ($color[$color], $text); 799 $LOGVIEW->add_paragraph ($color[$color], $text);
795} 800}
796 801
802sub conn::spell_add {
803 my ($self, $spell) = @_;
804
805 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
806 });
807 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
808 });
809}
810
811sub conn::spell_delete {
812 my ($self, $spell) = @_;
813}
814
815sub conn::addme_success {
816 my ($self) = @_;
817
818 for my $skill (values %{$self->{skill_info}}) {
819 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
820 });
821 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
822 });
823 }
824}
825
797%SDL_CB = ( 826%SDL_CB = (
798 SDL_QUIT() => sub { 827 CFClient::SDL_QUIT => sub {
799 Event::unloop -1; 828 Event::unloop -1;
800 }, 829 },
801 SDL_VIDEORESIZE() => sub { 830 CFClient::SDL_VIDEORESIZE => sub {
802 }, 831 },
803 SDL_VIDEOEXPOSE() => sub { 832 CFClient::SDL_VIDEOEXPOSE => sub {
804 refresh; 833 refresh;
805 }, 834 },
806 SDL_KEYDOWN() => sub { 835 CFClient::SDL_KEYDOWN => sub {
807 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 836 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
808 # alt-enter 837 # alt-enter
809 video_shutdown; 838 video_shutdown;
810 $CFG->{fullscreen} = !$CFG->{fullscreen}; 839 $CFG->{fullscreen} = !$CFG->{fullscreen};
811 video_init; 840 video_init;
812 } else { 841 } else {
813 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 842 CFClient::UI::feed_sdl_key_down_event ($_[0]);
814 } 843 }
815 }, 844 },
816 SDL_KEYUP() => sub { 845 CFClient::SDL_KEYUP => sub {
817 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 846 CFClient::UI::feed_sdl_key_up_event ($_[0]);
818 }, 847 },
819 SDL_MOUSEMOTION() => sub { 848 CFClient::SDL_MOUSEMOTION => sub {
820 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 849 CFClient::UI::feed_sdl_motion_event ($_[0]);
821 }, 850 },
822 SDL_MOUSEBUTTONDOWN() => sub { 851 CFClient::SDL_MOUSEBUTTONDOWN => sub {
823 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 852 CFClient::UI::feed_sdl_button_down_event ($_[0]);
824 }, 853 },
825 SDL_MOUSEBUTTONUP() => sub { 854 CFClient::SDL_MOUSEBUTTONUP => sub {
826 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 855 CFClient::UI::feed_sdl_button_up_event ($_[0]);
827 }, 856 },
828 SDL_ACTIVEEVENT() => sub { 857 CFClient::SDL_ACTIVEEVENT => sub {
829# 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#
830 }, 859 },
831); 860);
832 861
833############################################################################# 862#############################################################################
846 fullscreen => 0, 875 fullscreen => 0,
847 fast => 0, 876 fast => 0,
848 fow_enable => 1, 877 fow_enable => 1,
849 fow_intensity => 0.45, 878 fow_intensity => 0.45,
850 fow_smooth => 0, 879 fow_smooth => 0,
880 gui_fontsize => 1,
851 log_fontsize => 14, 881 log_fontsize => 14,
852 mapsize => 100, 882 mapsize => 100,
853 host => "crossfire.schmorp.de", 883 host => "crossfire.schmorp.de",
854 say_command => 'say', 884 say_command => 'say',
885 audio_enable => 1,
886 bgm_enable => 1,
887 bgm_volume => 64,
855); 888);
856 889
857while (my ($k, $v) = each %DEF_CFG) { 890while (my ($k, $v) = each %DEF_CFG) {
858 $CFG->{$k} = $v unless exists $CFG->{$k}; 891 $CFG->{$k} = $v unless exists $CFG->{$k};
859} 892}
860 893
861sdl_init; 894sdl_init;
862 895
863@SDL_MODES = reverse 896@SDL_MODES = reverse
864 grep $_->[0] >= 640 && $_->[1] >= 480, 897 grep $_->[0] >= 640 && $_->[1] >= 480,
865 map [SDL::RectW ($_), SDL::RectH ($_)], 898 CFClient::SDL_ListModes;
866 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
867 899
868@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 900@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
869 901
870$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 902$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
871 903

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines