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.126 by root, Mon Apr 17 20:59:20 2006 UTC vs.
Revision 1.146 by root, Wed Apr 19 21:17:16 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; 9use SDL::Event;
12use SDL::Surface; 10
13use SDL::OpenGL; 11use SDL::OpenGL;
14 12
15use Crossfire; 13use Crossfire;
16use Crossfire::Protocol; 14use Crossfire::Protocol;
17 15
18use Compress::LZF; 16use Compress::LZF;
19 17
20use CFClient; 18use CFClient;
21use CFClient::UI; 19use CFClient::UI;
20use CFClient::MapWidget;
22 21
23our $VERSION = '0.1'; 22our $VERSION = '0.1';
24 23
25my $MAX_FPS = 60; 24my $MAX_FPS = 60;
26my $MIN_FPS = 5; # unused as of yet 25my $MIN_FPS = 5; # unused as of yet
55 54
56our $SDL_ACTIVE; 55our $SDL_ACTIVE;
57our $SDL_EV; 56our $SDL_EV;
58our %SDL_CB; 57our %SDL_CB;
59 58
59our $SDL_MIXER;
60our @SOUNDS; # event => file mapping
61our %AUDIO_CHUNKS; # audio files
62
60our $ALT_ENTER_MESSAGE; 63our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 64our $STATUS_LINE;
62our $DEBUG_STATUS; 65our $DEBUG_STATUS;
63 66
64sub status { 67sub status {
65 $STATUS_LINE->set_text ($_[0]); 68 $STATUS_LINE->set_text ($_[0]);
66 my ($w, $h) = $STATUS_LINE->size_request;
67 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 69 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
68} 70}
69 71
70sub debug { 72sub debug {
71 $DEBUG_STATUS->set_text ($_[0]); 73 $DEBUG_STATUS->set_text ($_[0]);
72 my ($w, $h) = $DEBUG_STATUS->size_request; 74 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
73 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
74} 75}
75 76
76sub start_game { 77sub start_game {
77 status "logging in..."; 78 status "logging in...";
78 79
103} 104}
104 105
105sub client_setup { 106sub client_setup {
106 my $dialog = new CFClient::UI::FancyFrame 107 my $dialog = new CFClient::UI::FancyFrame
107 child => (my $vbox = new CFClient::UI::VBox); 108 child => (my $vbox = new CFClient::UI::VBox);
108 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); 109 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
109 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 110 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
110 111
111 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 112 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
112 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 113 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
113 114
114 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 115 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
115 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 116 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8);
116 117
117 $mode_slider->connect (changed => sub { 118 $mode_slider->connect (changed => sub {
118 my ($self, $value) = @_; 119 my ($self, $value) = @_;
119 120
120 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 121 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
121 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 122 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
122 }); 123 });
123 $mode_slider->emit (changed => $mode_slider->{range}[0]); 124 $mode_slider->emit (changed => $mode_slider->{range}[0]);
124 125
125 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 126 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
126 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 127 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
127 my ($self, $value) = @_; 128 my ($self, $value) = @_;
128 $CFG->{fullscreen} = $value; 129 $CFG->{fullscreen} = $value;
129 }); 130 });
130 131
131 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 132 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
132 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 133 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
133 my ($self, $value) = @_; 134 my ($self, $value) = @_;
134 $CFG->{fast} = $value; 135 $CFG->{fast} = $value;
135 }); 136 });
136 137
137 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 138 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
138 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 139 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
139 my ($self, $value) = @_; 140 my ($self, $value) = @_;
140 $CFG->{fow_enable} = $value; 141 $CFG->{fow_enable} = $value;
141 }); 142 });
142 143
143 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 144 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
144 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 145 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
145 my ($self, $value) = @_; 146 my ($self, $value) = @_;
146 $CFG->{fow_intensity} = $value; 147 $CFG->{fow_intensity} = $value;
147 }); 148 });
148 149
149 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 150 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
150 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 151 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
151 my ($self, $value) = @_; 152 my ($self, $value) = @_;
152 $CFG->{fow_smooth} = $value; 153 $CFG->{fow_smooth} = $value;
154 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
153 }); 155 });
154 156
155 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 157 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
158 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
159 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
160# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
161 });
162
163 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
156 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { 164 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
157 my ($self, $value) = @_;
158 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 165 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
159 }); 166 });
160 167
161 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 168 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
162 destroy_screen (); 169 video_shutdown ();
163 init_screen (); 170 video_init ();
171 });
172
173 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
174 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
175 $CFG->{audio_enable} = $_[1];
176 });
177# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
178# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
179# $CFG->{effects_volume} = $_[1];
180# });
181 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
182 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
183 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
184 $CFG->{bgm_enable} = $_[1];
185 });
186 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
187 $CFG->{bgm_volume} = $_[1];
188 CFClient::Mix_VolumeMusic ($_[1]);
189 });
190
191 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
192 audio_shutdown ();
193 audio_init ();
164 }); 194 });
165 195
166 $dialog 196 $dialog
167} 197}
168 198
232 $HOST->set_text ($CFG->{host} = $host); 262 $HOST->set_text ($CFG->{host} = $host);
233 }), 263 }),
234 (new CFClient::UI::Empty expand => 1), 264 (new CFClient::UI::Empty expand => 1),
235 ]); 265 ]);
236 266
237 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 267 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
238 for 0 .. $#$m; 268 for 0 .. $#$m;
239 } 269 }
240 } 270 }
241 }); 271 });
242} 272}
243 273
244sub server_setup { 274sub server_setup {
245 my $dialog = new CFClient::UI::FancyFrame 275 my $dialog = new CFClient::UI::FancyFrame
246 child => (my $vbox = new CFClient::UI::VBox); 276 child => (my $vbox = new CFClient::UI::VBox);
247 277
248 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); 278 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
249 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 279 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
250 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 280 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
251 281
252 { 282 {
253 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 283 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
254 284
255 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 285 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
256 my ($self, $value) = @_; 286 my ($self, $value) = @_;
257 $CFG->{host} = $value; 287 $CFG->{host} = $value;
258 }); 288 });
259 289
260 $METASERVER = metaserver_dialog; 290 $METASERVER = metaserver_dialog;
261 291
262 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 292 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
263 update_metaserver $HOST; 293 update_metaserver $HOST;
264 }); 294 });
265 } 295 }
266 296
267 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 297 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
268 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 298 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
269 my ($self, $value) = @_; 299 my ($self, $value) = @_;
270 $CFG->{user} = $value; 300 $CFG->{user} = $value;
271 }); 301 });
272 302
273 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 303 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
274 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 304 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
275 my ($self, $value) = @_; 305 my ($self, $value) = @_;
276 $CFG->{password} = $value; 306 $CFG->{password} = $value;
277 }); 307 });
278 308
279 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 309 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
280 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 310 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
281 my ($self, $value) = @_; 311 my ($self, $value) = @_;
282 $CFG->{say_command} = $value; 312 $CFG->{say_command} = $value;
283 }); 313 });
284 314
285 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 315 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
286 $table->add (1, 7, new CFClient::UI::Slider 316 $table->add (1, 7, new CFClient::UI::Slider
287 req_w => 100, 317 req_w => 100,
288 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 318 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
289 connect_changed => sub { 319 connect_changed => sub {
290 my ($self, $value) = @_; 320 my ($self, $value) = @_;
351 381
352 $window 382 $window
353} 383}
354 384
355sub sdl_init { 385sub sdl_init {
356 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 386 CFClient::SDL_Init
357 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
358 and die "SDL::Init failed!\n"; 387 and die "SDL::Init failed!\n";
359} 388}
360 389
361sub init_screen { 390sub video_init {
362 sdl_init; 391 sdl_init;
363 392
364 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 393 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
365 $FULLSCREEN = $CFG->{fullscreen}; 394 $FULLSCREEN = $CFG->{fullscreen};
366 $FAST = $CFG->{fast}; 395 $FAST = $CFG->{fast};
367 396
368 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 397 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
369 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
370 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
371 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
372
373 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
374 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
375 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
376 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
377
378 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
379 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
380 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
381
382 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
383 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
384 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
385 or die "SDL::SetVideoMode failed!\n"; 398 or die "SDL_SetVideoMode failed!\n";
386
387 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
388 399
389 $SDL_EV = new SDL::Event; 400 $SDL_EV = new SDL::Event;
390 $SDL_EV->set_unicode (1); 401 $SDL_EV->set_unicode (1);
391 402
392 $SDL_ACTIVE = 1; 403 $SDL_ACTIVE = 1;
393 404
394 $LAST_REFRESH = time - 0.01; 405 $LAST_REFRESH = time - 0.01;
395 406
396 CFClient::gl_init; 407 CFClient::gl_init;
397 408
398 $FONTSIZE = int $HEIGHT / 40; 409 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
399 410
400 ############################################################################# 411 #############################################################################
401 412
402 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 413 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
403 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 414 $DEBUG_STATUS->show;
404 415
405 $STATUS_LINE = new CFClient::UI::Label 416 $STATUS_LINE = new CFClient::UI::Label
406 padding => 0, 417 padding => 0,
407 y => $HEIGHT * 44 / 45 - $FONTSIZE; 418 y => $HEIGHT - $FONTSIZE * 1.8;
408 $CFClient::UI::ROOT->add ($STATUS_LINE); 419 $STATUS_LINE->show;
409 420
410 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 421 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
411 padding => 0, 422 padding => 0,
412 y => $HEIGHT * 44 / 45,
413 fontsize => $HEIGHT / 45, 423 fontsize => 0.8,
414 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 424 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
415 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 425 $ALT_ENTER_MESSAGE->show;
426 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
416 427
417 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 428 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
418 $MAPWIDGET->focus_in; 429 $MAPWIDGET->focus_in;
419 $MAPWIDGET->connect (activate_console => sub { 430 $MAPWIDGET->connect (activate_console => sub {
420 my ($mapwidget, $preset) = @_; 431 my ($mapwidget, $preset) = @_;
421 432
422 if ($CONSOLE) { 433 if ($CONSOLE) {
440 status "Configuration Saved"; 451 status "Configuration Saved";
441 }); 452 });
442 453
443 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 454 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
444 455
445 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 150, y => 0); 456 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
446 $tgw->add (my $hbox = new CFClient::UI::HBox (req_w => 60, req_h => 150)); 457 $tgw->add (my $hbox = new CFClient::UI::HBox ());
447 458
448 $hbox->add (my $fg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'food', expand => 1)); 459 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
449 $hbox->add (my $mg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'mana', expand => 1)); 460 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
450 $hbox->add (my $hg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'hp', expand => 1));
451 $hbox->add (my $gg = new CFClient::UI::VGauge (w => 30, h => 150, gauge => 'grace', expand => 1)); 461 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
462 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
452 463
453 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 464 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
454 $CFClient::UI::ROOT->add ($tgw); 465 $CFClient::UI::ROOT->add ($tgw);
455} 466}
456 467
457sub destroy_screen { 468sub video_shutdown {
458 $CFClient::UI::ROOT->{children} = []; 469 $CFClient::UI::ROOT->{children} = [];
459 undef $SDL_ACTIVE; 470 undef $SDL_ACTIVE;
460 undef $SDL_EV; 471 undef $SDL_EV;
461 SDL::Quit; 472}
473
474my $bgmusic;#TODO#hack#d#
475
476sub audio_init {
477 if ($CFG->{audio_enable}) {
478 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
479
480 $SDL_MIXER = !CFClient::Mix_OpenAudio;
481 CFClient::Mix_AllocateChannels 8;
482 CFClient::MixMusic::volume $CFG->{bgm_volume};
483
484 # TODO: hack, do play loop and mood music
485 if ($CFG->{bgm_enable}) {
486 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
487 $bgmusic->play;
488 }
489
490 while (<$fh>) {
491 next if /^\s*#/;
492 next if /^\s*$/;
493
494 my ($file, $volume, $event) = split /\s+/, $_, 3;
495
496 push @SOUNDS, "$volume,$file";
497
498 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
499 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
500 $chunk->volume ($volume * 128 / 100);
501 $chunk
502 };
503 }
504 } else {
505 status "unable to open sound config: $!";
506 }
507 }
508}
509
510sub audio_shutdown {
511 CFClient::Mix_CloseAudio if $SDL_MIXER;
512 undef $SDL_MIXER;
513 @SOUNDS = ();
514 %AUDIO_CHUNKS = ();
462} 515}
463 516
464my %animate_object; 517my %animate_object;
465my $animate_timer; 518my $animate_timer;
466 519
636 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 689 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
637 690
638 $self->flush_map; 691 $self->flush_map;
639 692
640 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 693 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
641
642 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
643 694
644 my $mapmapw = 250; 695 my $mapmapw = 250;
645 my $mapmaph = 250; 696 my $mapmaph = 250;
646 697
647 $self->flood_fill ("", $hash, $flags, 698 $self->flood_fill ("", $hash, $flags,
711 762
712 $tex 763 $tex
713 }; 764 };
714} 765}
715 766
767sub conn::sound_play {
768 my ($self, $x, $y, $soundnum, $type) = @_;
769
770 $SDL_MIXER
771 or return;
772
773 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
774 or return;
775
776 $chunk->play;
777# warn "sound $x,$y,$soundnum,$type\n";#d#
778}
779
716sub conn::query { 780sub conn::query {
717 my ($self, $flags, $prompt) = @_; 781 my ($self, $flags, $prompt) = @_;
718 782
719 #TODO 783 #TODO, display dialog with relevant information
720 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 784 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
721} 785}
722 786
723sub conn::drawinfo { 787sub conn::drawinfo {
724 my ($self, $color, $text) = @_; 788 my ($self, $color, $text) = @_;
740 ); 804 );
741 805
742 $LOGVIEW->add_paragraph ($color[$color], $text); 806 $LOGVIEW->add_paragraph ($color[$color], $text);
743} 807}
744 808
809sub conn::spell_add {
810 my ($self, $spell) = @_;
811
812 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
813 });
814 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
815 });
816}
817
818sub conn::spell_delete {
819 my ($self, $spell) = @_;
820}
821
822sub conn::addme_success {
823 my ($self) = @_;
824
825 for my $skill (values %{$self->{skill_info}}) {
826 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
827 });
828 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
829 });
830 }
831}
832
745%SDL_CB = ( 833%SDL_CB = (
746 SDL_QUIT() => sub { 834 CFClient::SDL_QUIT => sub {
747 Event::unloop -1; 835 Event::unloop -1;
748 }, 836 },
749 SDL_VIDEORESIZE() => sub { 837 CFClient::SDL_VIDEORESIZE => sub {
750 }, 838 },
751 SDL_VIDEOEXPOSE() => sub { 839 CFClient::SDL_VIDEOEXPOSE => sub {
752 refresh; 840 refresh;
753 }, 841 },
754 SDL_KEYDOWN() => sub { 842 CFClient::SDL_KEYDOWN => sub {
755 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 843 if ($SDL_EV->key_mod & CFClient::KMOD_ALT && $SDL_EV->key_sym == 13) {
756 # alt-enter 844 # alt-enter
757 destroy_screen; 845 video_shutdown;
758 $CFG->{fullscreen} = !$CFG->{fullscreen}; 846 $CFG->{fullscreen} = !$CFG->{fullscreen};
759 init_screen; 847 video_init;
760 } else { 848 } else {
761 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 849 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
762 } 850 }
763 }, 851 },
764 SDL_KEYUP() => sub { 852 CFClient::SDL_KEYUP => sub {
765 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 853 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
766 }, 854 },
767 SDL_MOUSEMOTION() => sub { 855 CFClient::SDL_MOUSEMOTION => sub {
768 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 856 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
769 }, 857 },
770 SDL_MOUSEBUTTONDOWN() => sub { 858 CFClient::SDL_MOUSEBUTTONDOWN => sub {
771 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 859 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
772 }, 860 },
773 SDL_MOUSEBUTTONUP() => sub { 861 CFClient::SDL_MOUSEBUTTONUP => sub {
774 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 862 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
775 }, 863 },
776 SDL_ACTIVEEVENT() => sub { 864 CFClient::SDL_ACTIVEEVENT => sub {
777# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 865# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
778 }, 866 },
779); 867);
780 868
781############################################################################# 869#############################################################################
870
871$SIG{INT} = $SIG{TERM} = sub { exit };
782 872
783$TILECACHE = CFClient::db_table "tilecache"; 873$TILECACHE = CFClient::db_table "tilecache";
784$FACEMAP = CFClient::db_table "facemap"; 874$FACEMAP = CFClient::db_table "facemap";
785 875
786CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 876CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
792 fullscreen => 0, 882 fullscreen => 0,
793 fast => 0, 883 fast => 0,
794 fow_enable => 1, 884 fow_enable => 1,
795 fow_intensity => 0.45, 885 fow_intensity => 0.45,
796 fow_smooth => 0, 886 fow_smooth => 0,
887 gui_fontsize => 1,
797 log_fontsize => 14, 888 log_fontsize => 14,
798 mapsize => 100, 889 mapsize => 100,
799 host => "crossfire.schmorp.de", 890 host => "crossfire.schmorp.de",
800 say_command => 'say', 891 say_command => 'say',
892 audio_enable => 1,
893 bgm_enable => 1,
894 bgm_volume => 64,
801); 895);
802 896
803while (my ($k, $v) = each %DEF_CFG) { 897while (my ($k, $v) = each %DEF_CFG) {
804 $CFG->{$k} = $v unless exists $CFG->{$k}; 898 $CFG->{$k} = $v unless exists $CFG->{$k};
805} 899}
806 900
807sdl_init; 901sdl_init;
808 902
809@SDL_MODES = reverse 903@SDL_MODES = reverse
810 grep $_->[0] >= 640 && $_->[1] >= 480, 904 grep $_->[0] >= 640 && $_->[1] >= 480,
811 map [SDL::RectW ($_), SDL::RectH ($_)], 905 CFClient::SDL_ListModes;
812 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
813 906
814@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 907@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
815 908
816$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 909$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
817 910
820 913
821 CFClient::add_font $_ for @fonts; 914 CFClient::add_font $_ for @fonts;
822 CFClient::set_font $fonts[0]; 915 CFClient::set_font $fonts[0];
823} 916}
824 917
825init_screen; 918video_init;
919audio_init;
826 920
827Event::loop; 921Event::loop;
828 922
923END { SDL::Quit }
829 924
925

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines