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.138 by elmex, Tue Apr 18 21:37:48 2006 UTC vs.
Revision 1.148 by root, Wed Apr 19 23:37:50 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
110} 99}
111 100
112sub client_setup { 101sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 102 my $dialog = new CFClient::UI::FancyFrame
114 child => (my $vbox = new CFClient::UI::VBox); 103 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 104 $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 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 height => $FONTSIZE * 0.8); 111 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
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;
128 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 117 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
129 }); 118 });
130 $mode_slider->emit (changed => $mode_slider->{range}[0]); 119 $mode_slider->emit (changed => $mode_slider->{range}[0]);
131 120
132 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 121 $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 { 122 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
134 my ($self, $value) = @_; 123 my ($self, $value) = @_;
135 $CFG->{fullscreen} = $value; 124 $CFG->{fullscreen} = $value;
136 }); 125 });
137 126
138 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 127 $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 { 128 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
140 my ($self, $value) = @_; 129 my ($self, $value) = @_;
141 $CFG->{fast} = $value; 130 $CFG->{fast} = $value;
142 }); 131 });
143 132
144 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 133 $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 { 134 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
146 my ($self, $value) = @_; 135 my ($self, $value) = @_;
147 $CFG->{fow_enable} = $value; 136 $CFG->{fow_enable} = $value;
148 }); 137 });
149 138
150 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 139 $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 { 140 $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) = @_; 141 my ($self, $value) = @_;
153 $CFG->{fow_intensity} = $value; 142 $CFG->{fow_intensity} = $value;
154 }); 143 });
155 144
156 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 145 $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 { 146 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
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 align => 1, text => "Log Fontsize"); 152 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
153 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
154 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
155# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
156 });
157
158 $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 { 159 $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); 160 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
167 }); 161 });
168 162
169 $table->add (1, 7, 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 {
170 video_shutdown (); 164 video_shutdown ();
171 video_init (); 165 video_init ();
172 }); 166 });
173 167
174 $table->add (0, 8, new CFClient::UI::Label align => 1, text => "Sound"); 168 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
175 $table->add (1, 8, new CFClient::UI::CheckBox state => $CFG->{sound}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{sound} = $value;
178 });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music");
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bg_music_enable}, connect_changed => sub { 169 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bg_music_enable} = $value; 170 $CFG->{audio_enable} = $_[1];
171 });
172# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
173# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
174# $CFG->{effects_volume} = $_[1];
183 }); 175# });
176 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
177 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
178 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
179 $CFG->{bgm_enable} = $_[1];
180 });
181 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
182 $CFG->{bgm_volume} = $_[1];
183 CFClient::Mix_VolumeMusic ($_[1]);
184 });
185
184 $table->add (1, 10, 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 {
185 audio_shutdown (); 187 audio_shutdown ();
186 audio_init (); 188 audio_init ();
187 }); 189 });
188 190
189 $dialog 191 $dialog
255 $HOST->set_text ($CFG->{host} = $host); 257 $HOST->set_text ($CFG->{host} = $host);
256 }), 258 }),
257 (new CFClient::UI::Empty expand => 1), 259 (new CFClient::UI::Empty expand => 1),
258 ]); 260 ]);
259 261
260 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 262 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
261 for 0 .. $#$m; 263 for 0 .. $#$m;
262 } 264 }
263 } 265 }
264 }); 266 });
265} 267}
266 268
267sub server_setup { 269sub server_setup {
268 my $dialog = new CFClient::UI::FancyFrame 270 my $dialog = new CFClient::UI::FancyFrame
269 child => (my $vbox = new CFClient::UI::VBox); 271 child => (my $vbox = new CFClient::UI::VBox);
270 272
271 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 273 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
272 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 274 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
273 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 275 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
274 276
275 { 277 {
276 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 278 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
277 279
278 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 280 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
279 my ($self, $value) = @_; 281 my ($self, $value) = @_;
280 $CFG->{host} = $value; 282 $CFG->{host} = $value;
281 }); 283 });
282 284
283 $METASERVER = metaserver_dialog; 285 $METASERVER = metaserver_dialog;
284 286
285 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 287 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
286 update_metaserver $HOST; 288 update_metaserver $HOST;
287 }); 289 });
288 } 290 }
289 291
290 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 292 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
291 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 293 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
292 my ($self, $value) = @_; 294 my ($self, $value) = @_;
293 $CFG->{user} = $value; 295 $CFG->{user} = $value;
294 }); 296 });
295 297
296 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 298 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
297 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 299 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
298 my ($self, $value) = @_; 300 my ($self, $value) = @_;
299 $CFG->{password} = $value; 301 $CFG->{password} = $value;
300 }); 302 });
301 303
302 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 304 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
303 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 305 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
304 my ($self, $value) = @_; 306 my ($self, $value) = @_;
305 $CFG->{say_command} = $value; 307 $CFG->{say_command} = $value;
306 }); 308 });
307 309
308 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 310 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
309 $table->add (1, 7, new CFClient::UI::Slider 311 $table->add (1, 7, new CFClient::UI::Slider
310 req_w => 100, 312 req_w => 100,
311 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 313 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
312 connect_changed => sub { 314 connect_changed => sub {
313 my ($self, $value) = @_; 315 my ($self, $value) = @_;
374 376
375 $window 377 $window
376} 378}
377 379
378sub sdl_init { 380sub sdl_init {
379 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 381 CFClient::SDL_Init
380 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
381 and die "SDL::Init failed!\n"; 382 and die "SDL::Init failed!\n";
382} 383}
383 384
384sub video_init { 385sub video_init {
385 sdl_init; 386 sdl_init;
386 387
387 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 388 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
388 $FULLSCREEN = $CFG->{fullscreen}; 389 $FULLSCREEN = $CFG->{fullscreen};
389 $FAST = $CFG->{fast}; 390 $FAST = $CFG->{fast};
390 391
391 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 392 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
392 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
393 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
394 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
395
396 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
397 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
398 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
399 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
400
401 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
402 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
403 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
404
405 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
406 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
407 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
408 or die "SDL::SetVideoMode failed!\n"; 393 or die "SDL_SetVideoMode failed!\n";
409
410 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
411
412 $SDL_EV = new SDL::Event;
413 $SDL_EV->set_unicode (1);
414 394
415 $SDL_ACTIVE = 1; 395 $SDL_ACTIVE = 1;
416 396
417 $LAST_REFRESH = time - 0.01; 397 $LAST_REFRESH = time - 0.01;
418 398
419 CFClient::gl_init; 399 CFClient::gl_init;
420 400
421 $FONTSIZE = int $HEIGHT / 40; 401 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
422 402
423 ############################################################################# 403 #############################################################################
424 404
425 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 405 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
426 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 406 $DEBUG_STATUS->show;
427 407
428 $STATUS_LINE = new CFClient::UI::Label 408 $STATUS_LINE = new CFClient::UI::Label
429 padding => 0, 409 padding => 0,
430 y => $HEIGHT * 44 / 45 - $FONTSIZE; 410 y => $HEIGHT - $FONTSIZE * 1.8;
431 $CFClient::UI::ROOT->add ($STATUS_LINE); 411 $STATUS_LINE->show;
432 412
433 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 413 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
434 padding => 0, 414 padding => 0,
435 y => $HEIGHT * 44 / 45,
436 fontsize => $HEIGHT / 45, 415 fontsize => 0.8,
437 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 416 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
438 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 417 $ALT_ENTER_MESSAGE->show;
418 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
439 419
440 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 420 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
441 $MAPWIDGET->focus_in; 421 $MAPWIDGET->focus_in;
442 $MAPWIDGET->connect (activate_console => sub { 422 $MAPWIDGET->connect (activate_console => sub {
443 my ($mapwidget, $preset) = @_; 423 my ($mapwidget, $preset) = @_;
444 424
445 if ($CONSOLE) { 425 if ($CONSOLE) {
478} 458}
479 459
480sub video_shutdown { 460sub video_shutdown {
481 $CFClient::UI::ROOT->{children} = []; 461 $CFClient::UI::ROOT->{children} = [];
482 undef $SDL_ACTIVE; 462 undef $SDL_ACTIVE;
483 undef $SDL_EV;
484} 463}
485 464
486my $bgmusic;#TODO#hack#d# 465my $bgmusic;#TODO#hack#d#
487 466
488sub audio_init { 467sub audio_init {
489 if ($CFG->{sound} || 1) { 468 if ($CFG->{audio_enable}) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 469 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer; 470
492 $SDL_MIXER->allocate_channels (8); 471 $SDL_MIXER = !CFClient::Mix_OpenAudio;
472 CFClient::Mix_AllocateChannels 8;
473 CFClient::MixMusic::volume $CFG->{bgm_volume};
493 474
475 # TODO: hack, do play loop and mood music
494 if ($CFG->{bg_music_enable}) { 476 if ($CFG->{bgm_enable}) {
495 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 477 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
496 $SDL_MIXER->play_music ($bgmusic, -1); 478 $bgmusic->play;
497 } 479 }
498 480
499 while (<$fh>) { 481 while (<$fh>) {
500 next if /^\s*#/; 482 next if /^\s*#/;
501 next if /^\s*$/; 483 next if /^\s*$/;
503 my ($file, $volume, $event) = split /\s+/, $_, 3; 485 my ($file, $volume, $event) = split /\s+/, $_, 3;
504 486
505 push @SOUNDS, "$volume,$file"; 487 push @SOUNDS, "$volume,$file";
506 488
507 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 489 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
508 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 490 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
509 $chunk->volume ($volume * 128 / 100); 491 $chunk->volume ($volume * 128 / 100);
510 $chunk 492 $chunk
511 }; 493 };
512 } 494 }
513 } else { 495 } else {
515 } 497 }
516 } 498 }
517} 499}
518 500
519sub audio_shutdown { 501sub audio_shutdown {
502 CFClient::Mix_CloseAudio if $SDL_MIXER;
520 undef $SDL_MIXER; 503 undef $SDL_MIXER;
521 @SOUNDS = (); 504 @SOUNDS = ();
522 %AUDIO_CHUNKS = (); 505 %AUDIO_CHUNKS = ();
523} 506}
524 507
537 $want_refresh = 0; 520 $want_refresh = 0;
538 $can_refresh = 0; 521 $can_refresh = 0;
539 522
540 $CFClient::UI::ROOT->draw; 523 $CFClient::UI::ROOT->draw;
541 524
542 SDL::GLSwapBuffers; 525 CFClient::SDL_GL_SwapBuffers;
543 526
544 $LAST_REFRESH = $NOW; 527 $LAST_REFRESH = $NOW;
545} 528}
546 529
547my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 530my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
548 $NOW = time; 531 $NOW = time;
549 532
550 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 533 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
551 while $SDL_EV->poll; 534 for CFClient::SDL_PollEvent;
552 535
553 if (%animate_object) { 536 if (%animate_object) {
554 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 537 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
555 $want_refresh++; 538 $want_refresh++;
556 } 539 }
773} 756}
774 757
775sub conn::sound_play { 758sub conn::sound_play {
776 my ($self, $x, $y, $soundnum, $type) = @_; 759 my ($self, $x, $y, $soundnum, $type) = @_;
777 760
761 $SDL_MIXER
762 or return;
763
778 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 764 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
779 or return; 765 or return;
780 766
781 $SDL_MIXER->play_channel (-1, $chunk); 767 $chunk->play;
782 warn "sound $x,$y,$soundnum,$type\n";#d# 768# warn "sound $x,$y,$soundnum,$type\n";#d#
783} 769}
784 770
785sub conn::query { 771sub conn::query {
786 my ($self, $flags, $prompt) = @_; 772 my ($self, $flags, $prompt) = @_;
787 773
788 #TODO 774 #TODO, display dialog with relevant information
789 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 775 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
790} 776}
791 777
792sub conn::drawinfo { 778sub conn::drawinfo {
793 my ($self, $color, $text) = @_; 779 my ($self, $color, $text) = @_;
809 ); 795 );
810 796
811 $LOGVIEW->add_paragraph ($color[$color], $text); 797 $LOGVIEW->add_paragraph ($color[$color], $text);
812} 798}
813 799
800sub conn::spell_add {
801 my ($self, $spell) = @_;
802
803 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
804 });
805 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
806 });
807}
808
809sub conn::spell_delete {
810 my ($self, $spell) = @_;
811}
812
813sub conn::addme_success {
814 my ($self) = @_;
815
816 for my $skill (values %{$self->{skill_info}}) {
817 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
818 });
819 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
820 });
821 }
822}
823
814%SDL_CB = ( 824%SDL_CB = (
815 SDL_QUIT() => sub { 825 CFClient::SDL_QUIT => sub {
816 Event::unloop -1; 826 Event::unloop -1;
817 }, 827 },
818 SDL_VIDEORESIZE() => sub { 828 CFClient::SDL_VIDEORESIZE => sub {
819 }, 829 },
820 SDL_VIDEOEXPOSE() => sub { 830 CFClient::SDL_VIDEOEXPOSE => sub {
821 refresh; 831 refresh;
822 }, 832 },
823 SDL_KEYDOWN() => sub { 833 CFClient::SDL_KEYDOWN => sub {
824 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 834 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
825 # alt-enter 835 # alt-enter
826 video_shutdown; 836 video_shutdown;
827 $CFG->{fullscreen} = !$CFG->{fullscreen}; 837 $CFG->{fullscreen} = !$CFG->{fullscreen};
828 video_init; 838 video_init;
829 } else { 839 } else {
830 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 840 CFClient::UI::feed_sdl_key_down_event ($_[0]);
831 } 841 }
832 }, 842 },
833 SDL_KEYUP() => sub { 843 CFClient::SDL_KEYUP => sub {
834 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 844 CFClient::UI::feed_sdl_key_up_event ($_[0]);
835 }, 845 },
836 SDL_MOUSEMOTION() => sub { 846 CFClient::SDL_MOUSEMOTION => sub {
837 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 847 CFClient::UI::feed_sdl_motion_event ($_[0]);
838 }, 848 },
839 SDL_MOUSEBUTTONDOWN() => sub { 849 CFClient::SDL_MOUSEBUTTONDOWN => sub {
840 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 850 CFClient::UI::feed_sdl_button_down_event ($_[0]);
841 }, 851 },
842 SDL_MOUSEBUTTONUP() => sub { 852 CFClient::SDL_MOUSEBUTTONUP => sub {
843 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 853 CFClient::UI::feed_sdl_button_up_event ($_[0]);
844 }, 854 },
845 SDL_ACTIVEEVENT() => sub { 855 CFClient::SDL_ACTIVEEVENT => sub {
846# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 856# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
847 }, 857 },
848); 858);
849 859
850############################################################################# 860#############################################################################
863 fullscreen => 0, 873 fullscreen => 0,
864 fast => 0, 874 fast => 0,
865 fow_enable => 1, 875 fow_enable => 1,
866 fow_intensity => 0.45, 876 fow_intensity => 0.45,
867 fow_smooth => 0, 877 fow_smooth => 0,
878 gui_fontsize => 1,
868 log_fontsize => 14, 879 log_fontsize => 14,
869 mapsize => 100, 880 mapsize => 100,
870 host => "crossfire.schmorp.de", 881 host => "crossfire.schmorp.de",
871 say_command => 'say', 882 say_command => 'say',
872 sound => 1, 883 audio_enable => 1,
873 bg_music_enable => 1, 884 bgm_enable => 1,
885 bgm_volume => 64,
874); 886);
875 887
876while (my ($k, $v) = each %DEF_CFG) { 888while (my ($k, $v) = each %DEF_CFG) {
877 $CFG->{$k} = $v unless exists $CFG->{$k}; 889 $CFG->{$k} = $v unless exists $CFG->{$k};
878} 890}
879 891
880sdl_init; 892sdl_init;
881 893
882@SDL_MODES = reverse 894@SDL_MODES = reverse
883 grep $_->[0] >= 640 && $_->[1] >= 480, 895 grep $_->[0] >= 640 && $_->[1] >= 480,
884 map [SDL::RectW ($_), SDL::RectH ($_)], 896 CFClient::SDL_ListModes;
885 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
886 897
887@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 898@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
888 899
889$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 900$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
890 901
898video_init; 909video_init;
899audio_init; 910audio_init;
900 911
901Event::loop; 912Event::loop;
902 913
903END { SDL::Quit } 914END { CFClient::SDL_Quit }
904 915
905 916

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines