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.142 by root, Wed Apr 19 07:30:33 2006 UTC vs.
Revision 1.157 by elmex, Fri Apr 21 15:03:47 2006 UTC

3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
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 8
20use Crossfire; 9use Crossfire;
21use Crossfire::Protocol; 10use Crossfire::Protocol;
22 11
23use Compress::LZF; 12use Compress::LZF;
56our $LOGVIEW; 45our $LOGVIEW;
57our $CONSOLE; 46our $CONSOLE;
58our $METASERVER; 47our $METASERVER;
59 48
60our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
61 51
62our $SDL_ACTIVE; 52our $SDL_ACTIVE;
63our $SDL_EV;
64our %SDL_CB; 53our %SDL_CB;
65 54
66our $SDL_MIXER; 55our $SDL_MIXER;
67our @SOUNDS; # event => file mapping 56our @SOUNDS; # event => file mapping
68our %AUDIO_CHUNKS; # audio files 57our %AUDIO_CHUNKS; # audio files
110 undef $CONN; 99 undef $CONN;
111} 100}
112 101
113sub client_setup { 102sub client_setup {
114 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
115 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
116 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Client Setup");
117 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 106 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
118 107
119 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode"); 108 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
120 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
121 110
122 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 111 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
123 $hbox->add (my $mode_label = new CFClient::UI::Label valign => 0, height => 0.8); 112 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
124 113
125 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
126 my ($self, $value) = @_; 115 my ($self, $value) = @_;
127 116
128 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
170 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); 159 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
171 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { 160 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
172 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); 161 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
173 }); 162 });
174 163
164 $table->add (0, 8, new CFClient::UI::Label valign => 0, align => 1, text => "Stats Fontsize");
165 $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{stat_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
166 $CFG->{stat_fontsize} = 0.1 * int $_[1] * 10;
167 &set_stats_window_fontsize;
168 });
169
170
175 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 171 $table->add (1, 9, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
176 video_shutdown (); 172 video_shutdown ();
177 video_init (); 173 video_init ();
178 }); 174 });
179 175
180 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); 176 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
181 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { 177 $table->add (1, 10, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
182 $CFG->{audio_enable} = $_[1]; 178 $CFG->{audio_enable} = $_[1];
183 }); 179 });
184# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); 180# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
185# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { 181# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
186# $CFG->{effects_volume} = $_[1]; 182# $CFG->{effects_volume} = $_[1];
187# }); 183# });
188 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); 184 $table->add (0, 11, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
189 $table->add (1, 10, my $hbox = new CFClient::UI::HBox); 185 $table->add (1, 11, my $hbox = new CFClient::UI::HBox);
190 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { 186 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
191 $CFG->{bgm_enable} = $_[1]; 187 $CFG->{bgm_enable} = $_[1];
192 }); 188 });
193 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 128, 1], connect_changed => sub { 189 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
194 $CFG->{bgm_volume} = $_[1]; 190 $CFG->{bgm_volume} = $_[1];
195 $SDL_MIXER->music_volume ($_[1]); 191 CFClient::MixMusic::volume $_[1] * 128;
196 }); 192 });
197 193
198 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 194 $table->add (1, 12, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
199 audio_shutdown (); 195 audio_shutdown ();
200 audio_init (); 196 audio_init ();
201 }); 197 });
202 198
203 $dialog 199 $dialog
204} 200}
205 201
202sub set_stats_window_fontsize {
203 for (values %{$STATWIDS}, values %{$GAUGES}) {
204 $_->set_fontsize ($::CFG->{stat_fontsize});
205 }
206}
207
208sub make_stats_window {
209 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/5, y => 0, title => "Stats");
210
211 $tgw->add (my $vb = new CFClient::UI::VBox);
212 $vb->add (my $uhb = new CFClient::UI::HBox);
213 $uhb->add ($STATWIDS->{title} = new CFClient::UI::Label valign => 0, align => -1, text => "Title:", expand => 1);
214 $uhb->add ($STATWIDS->{map} = new CFClient::UI::Label valign => 0, align => -1, text => "Map:", expand => 1);
215 $vb->add (my $dhb = new CFClient::UI::HBox);
216 $dhb->add ($STATWIDS->{exp} = new CFClient::UI::Label valign => 0, align => -1, text => "Exp:", expand => 1);
217 $dhb->add ($STATWIDS->{lvl} = new CFClient::UI::Label valign => 0, align => -1, text => "Level:", expand => 1);
218
219 $vb->add (my $hb = new CFClient::UI::HBox expand => 1);
220 $hb->add (my $hg = new CFClient::UI::Gauge type => 'hp', expand => 1);
221 $hb->add (my $mg = new CFClient::UI::Gauge type => 'mana', expand => 1);
222 $hb->add (my $gg = new CFClient::UI::Gauge type => 'grace', expand => 1);
223 $hb->add (my $fg = new CFClient::UI::Gauge type => 'food', expand => 1);
224 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
225
226 $hb->add (my $tbl = new CFClient::UI::Table expand => 1);
227
228 if (0) { # this code can vanish, just wanted to preserver it for a checkin
229 $tbl->add (0, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => "S");
230 $tbl->add (0, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => "D");
231 $tbl->add (0, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => "Co");
232 $tbl->add (0, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => "I");
233 $tbl->add (0, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => "W");
234 $tbl->add (0, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => "P");
235 $tbl->add (0, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => "Ch");
236
237 $tbl->add (1, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => "Wc");
238 $tbl->add (1, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => "Ac");
239 $tbl->add (1, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => "Dam");
240 $tbl->add (1, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => "Arm");
241 $tbl->add (1, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => "Sp");
242 $tbl->add (1, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => "WSp");
243 } else {
244 $tbl->add (0, 0, $STATWIDS->{st_str_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "S");
245 $tbl->add (0, 1, $STATWIDS->{st_dex_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "D");
246 $tbl->add (0, 2, $STATWIDS->{st_con_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Co");
247 $tbl->add (0, 3, $STATWIDS->{st_int_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "I");
248 $tbl->add (0, 4, $STATWIDS->{st_wis_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "W");
249 $tbl->add (0, 5, $STATWIDS->{st_pow_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "P");
250 $tbl->add (0, 6, $STATWIDS->{st_cha_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Ch");
251
252 $tbl->add (1, 0, $STATWIDS->{st_str} = new CFClient::UI::Label valign => 0, align => -1, text => "");
253 $tbl->add (1, 1, $STATWIDS->{st_dex} = new CFClient::UI::Label valign => 0, align => -1, text => "");
254 $tbl->add (1, 2, $STATWIDS->{st_con} = new CFClient::UI::Label valign => 0, align => -1, text => "");
255 $tbl->add (1, 3, $STATWIDS->{st_int} = new CFClient::UI::Label valign => 0, align => -1, text => "");
256 $tbl->add (1, 4, $STATWIDS->{st_wis} = new CFClient::UI::Label valign => 0, align => -1, text => "");
257 $tbl->add (1, 5, $STATWIDS->{st_pow} = new CFClient::UI::Label valign => 0, align => -1, text => "");
258 $tbl->add (1, 6, $STATWIDS->{st_cha} = new CFClient::UI::Label valign => 0, align => -1, text => "");
259
260 $tbl->add (2, 0, $STATWIDS->{st_wc_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Wc");
261 $tbl->add (2, 1, $STATWIDS->{st_ac_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Ac");
262 $tbl->add (2, 2, $STATWIDS->{st_dam_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Dam");
263 $tbl->add (2, 3, $STATWIDS->{st_arm_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Arm");
264 $tbl->add (2, 4, $STATWIDS->{st_spd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "Sp");
265 $tbl->add (2, 5, $STATWIDS->{st_wspd_lbl} = new CFClient::UI::Label valign => 0, align => +1, text => "WSp");
266
267 $tbl->add (3, 0, $STATWIDS->{st_wc} = new CFClient::UI::Label valign => 0, align => -1, text => "");
268 $tbl->add (3, 1, $STATWIDS->{st_ac} = new CFClient::UI::Label valign => 0, align => -1, text => "");
269 $tbl->add (3, 2, $STATWIDS->{st_dam} = new CFClient::UI::Label valign => 0, align => -1, text => "");
270 $tbl->add (3, 3, $STATWIDS->{st_arm} = new CFClient::UI::Label valign => 0, align => -1, text => "");
271 $tbl->add (3, 4, $STATWIDS->{st_spd} = new CFClient::UI::Label valign => 0, align => -1, text => "");
272 $tbl->add (3, 5, $STATWIDS->{st_wspd} = new CFClient::UI::Label valign => 0, align => -1, text => "");
273 }
274
275 $hb->add (my $tbl2 = new CFClient::UI::Table);
276
277 my $row = 0;
278 my $col = 0;
279
280 for (qw/slow holyw conf fire depl magic
281 drain acid pois para deat phys
282 blind fear tund elec cold ghit/)
283 {
284 $tbl2->add ($col, $row, new CFClient::UI::Image image => "ui/resist/resist_$_.png");
285 $tbl2->add ($col + 1, $row,
286 $STATWIDS->{"res_$_"} =
287 new CFClient::UI::Label text => "0", align => -1, valign => 0
288 );
289
290 $row++;
291 if ($row % 6 == 0) {
292 $col += 2;
293 $row = 0;
294 }
295 }
296
297 &set_stats_window_fontsize;
298 update_stats_window ({});
299
300 $tgw
301}
302
303sub update_stats_window {
304 my ($stats) = @_;
305
306 # i love text protocols!!!
307 my $hp = $stats->{1} * 1;
308 my $hp_m = $stats->{2} * 1;
309 my $sp = $stats->{3} * 1;
310 my $sp_m = $stats->{4} * 1;
311 my $fo = $stats->{18} * 1;
312 my $fo_m = 999;
313 my $gr = $stats->{23} * 1;
314 my $gr_m = $stats->{24} * 1;
315
316 $GAUGES->{hp} ->set_value ($hp, $hp_m);
317 $GAUGES->{mana} ->set_value ($sp, $sp_m);
318 $GAUGES->{food} ->set_value ($fo, $fo_m);
319 $GAUGES->{grace} ->set_value ($gr, $gr_m);
320 $STATWIDS->{title} ->set_text ("Title: " . $stats->{21});
321 $STATWIDS->{exp} ->set_text ("Exp.: " . ($stats->{11} || $stats->{28}));
322 $STATWIDS->{lvl} ->set_text ("Level: " . $stats->{12});
323
324 if (0) { # this code can vanish, just wanted to preserver it for a checkin
325 $STATWIDS->{st_str} ->set_text (sprintf "S%d", $stats->{5});
326 $STATWIDS->{st_dex} ->set_text (sprintf "D%d", $stats->{8});
327 $STATWIDS->{st_con} ->set_text (sprintf "Co%d", $stats->{9});
328 $STATWIDS->{st_int} ->set_text (sprintf "I%d", $stats->{6});
329 $STATWIDS->{st_wis} ->set_text (sprintf "W%d", $stats->{7});
330 $STATWIDS->{st_pow} ->set_text (sprintf "P%d", $stats->{22});
331 $STATWIDS->{st_cha} ->set_text (sprintf "Ch%d", $stats->{10});
332 $STATWIDS->{st_wc} ->set_text (sprintf "Wc%d", $stats->{13});
333 $STATWIDS->{st_ac} ->set_text (sprintf "Ac%d", $stats->{14});
334 $STATWIDS->{st_dam} ->set_text (sprintf "Dam%d", $stats->{15});
335 $STATWIDS->{st_arm} ->set_text (sprintf "Arm%d", $stats->{16});
336 $STATWIDS->{st_spd} ->set_text (sprintf "Sp%.1f", $stats->{17});
337 $STATWIDS->{st_wspd}->set_text (sprintf "WSp%.1f", $stats->{19});
338 } else {
339 $STATWIDS->{st_str} ->set_text (sprintf "%d", $stats->{5});
340 $STATWIDS->{st_dex} ->set_text (sprintf "%d", $stats->{8});
341 $STATWIDS->{st_con} ->set_text (sprintf "%d", $stats->{9});
342 $STATWIDS->{st_int} ->set_text (sprintf "%d", $stats->{6});
343 $STATWIDS->{st_wis} ->set_text (sprintf "%d", $stats->{7});
344 $STATWIDS->{st_pow} ->set_text (sprintf "%d", $stats->{22});
345 $STATWIDS->{st_cha} ->set_text (sprintf "%d", $stats->{10});
346 $STATWIDS->{st_wc} ->set_text (sprintf "%d", $stats->{13});
347 $STATWIDS->{st_ac} ->set_text (sprintf "%d", $stats->{14});
348 $STATWIDS->{st_dam} ->set_text (sprintf "%d", $stats->{15});
349 $STATWIDS->{st_arm} ->set_text (sprintf "%d", $stats->{16});
350 $STATWIDS->{st_spd} ->set_text (sprintf "%.1f", $stats->{17});
351 $STATWIDS->{st_wspd}->set_text (sprintf "%.1f", $stats->{19});
352 }
353
354 my %tbl = (
355 phys => 100,
356 magic => 101,
357 fire => 102,
358 elec => 103,
359 cold => 104,
360 conf => 105,
361 acid => 106,
362 drain => 107,
363 ghit => 108,
364 pois => 109,
365 slow => 110,
366 para => 111,
367 tund => 112,
368 fear => 113,
369 deat => 115,
370 holyw => 116,
371 blind => 117
372 );
373
374 for (keys %tbl) {
375 $STATWIDS->{"res_$_"}->set_text (sprintf "%d%", $stats->{$tbl{$_}});
376 }
377
378}
379
206sub metaserver_dialog { 380sub metaserver_dialog {
207 my $dialog = new CFClient::UI::FancyFrame 381 my $dialog = new CFClient::UI::FancyFrame
382 title => "Metaserver",
208 child => (my $vbox = new CFClient::UI::VBox); 383 child => (my $vbox = new CFClient::UI::VBox);
209 384
210 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 385 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
211 386
212 $dialog 387 $dialog
278 }); 453 });
279} 454}
280 455
281sub server_setup { 456sub server_setup {
282 my $dialog = new CFClient::UI::FancyFrame 457 my $dialog = new CFClient::UI::FancyFrame
458 title => "Server Setup",
283 child => (my $vbox = new CFClient::UI::VBox); 459 child => (my $vbox = new CFClient::UI::VBox);
284 460
285 $vbox->add (new CFClient::UI::Label valign => 0, align => 0, text => "Server Setup");
286 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 461 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
287 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); 462 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
288 463
289 { 464 {
290 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 465 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
337 $dialog 512 $dialog
338} 513}
339 514
340sub message_window { 515sub message_window {
341 my $window = new CFClient::UI::FancyFrame 516 my $window = new CFClient::UI::FancyFrame
517 title => "Messages",
342 border_bg => [1, 1, 1, 0.5], 518 border_bg => [1, 1, 1, 0.5],
343 bg => [0.3, 0.3, 0.3, 0.8], 519 bg => [0.3, 0.3, 0.3, 0.8],
344 user_w => int $::WIDTH / 3, 520 user_w => int $::WIDTH / 3,
345 user_h => int $::HEIGHT / 5, 521 user_h => int $::HEIGHT / 5,
346 child => (my $vbox = new CFClient::UI::VBox); 522 child => (my $vbox = new CFClient::UI::VBox);
388 564
389 $window 565 $window
390} 566}
391 567
392sub sdl_init { 568sub sdl_init {
393 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 569 CFClient::SDL_Init
394 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
395 and die "SDL::Init failed!\n"; 570 and die "SDL::Init failed!\n";
396} 571}
397 572
398sub video_init { 573sub video_init {
399 sdl_init; 574 sdl_init;
400 575
401 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 576 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
402 $FULLSCREEN = $CFG->{fullscreen}; 577 $FULLSCREEN = $CFG->{fullscreen};
403 $FAST = $CFG->{fast}; 578 $FAST = $CFG->{fast};
404 579
405 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 580 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
406 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
407 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
408 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
409
410 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
411 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
412 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
413 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
414
415 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
416 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
417 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
418
419 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
420 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
421 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
422 or die "SDL::SetVideoMode failed!\n"; 581 or die "SDL_SetVideoMode failed!\n";
423
424 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
425
426 $SDL_EV = new SDL::Event;
427 $SDL_EV->set_unicode (1);
428 582
429 $SDL_ACTIVE = 1; 583 $SDL_ACTIVE = 1;
430 584
431 $LAST_REFRESH = time - 0.01; 585 $LAST_REFRESH = time - 0.01;
432 586
477 status "Configuration Saved"; 631 status "Configuration Saved";
478 }); 632 });
479 633
480 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 634 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
481 635
482 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
483 $tgw->add (my $hbox = new CFClient::UI::HBox ());
484 636
485 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
486 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
487 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
488 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
489
490 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
491 $CFClient::UI::ROOT->add ($tgw); 637 $CFClient::UI::ROOT->add (make_stats_window);
492} 638}
493 639
494sub video_shutdown { 640sub video_shutdown {
495 $CFClient::UI::ROOT->{children} = []; 641 $CFClient::UI::ROOT->{children} = [];
496 undef $SDL_ACTIVE; 642 undef $SDL_ACTIVE;
497 undef $SDL_EV;
498} 643}
499 644
645my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
500my $bgmusic;#TODO#hack#d# 646my $bgmusic;#TODO#hack#d#
647
648sub audio_music_finished {
649 return unless $CFG->{bgm_enable};
650
651 # TODO: hack, do play loop and mood music
652 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
653 $bgmusic->play (0);
654
655 push @bgmusic, shift @bgmusic;
656}
501 657
502sub audio_init { 658sub audio_init {
503 if ($CFG->{audio_enable}) { 659 if ($CFG->{audio_enable}) {
504 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 660 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
505 661 $SDL_MIXER = !CFClient::Mix_OpenAudio;
506 $SDL_MIXER = new SDL::Mixer 662 CFClient::Mix_AllocateChannels 8;
507 -rate => 22050, 663 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
508 -channels => 1, # mono
509 -size => 512;
510 664
511 $SDL_MIXER->allocate_channels (8); 665 audio_music_finished;
512
513 # TODO: hack, do play loop and mood music
514 if ($CFG->{bgm_enable}) {
515 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg";
516 $SDL_MIXER->play_music ($bgmusic, -1);
517 $SDL_MIXER->music_volume ($CFG->{bgm_volume});
518 }
519 666
520 while (<$fh>) { 667 while (<$fh>) {
521 next if /^\s*#/; 668 next if /^\s*#/;
522 next if /^\s*$/; 669 next if /^\s*$/;
523 670
524 my ($file, $volume, $event) = split /\s+/, $_, 3; 671 my ($file, $volume, $event) = split /\s+/, $_, 3;
525 672
526 push @SOUNDS, "$volume,$file"; 673 push @SOUNDS, "$volume,$file";
527 674
528 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 675 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
529 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 676 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
530 $chunk->volume ($volume * 128 / 100); 677 $chunk->volume ($volume * 128 / 100);
531 $chunk 678 $chunk
532 }; 679 };
533 } 680 }
534 } else { 681 } else {
536 } 683 }
537 } 684 }
538} 685}
539 686
540sub audio_shutdown { 687sub audio_shutdown {
688 CFClient::Mix_CloseAudio if $SDL_MIXER;
541 undef $SDL_MIXER; 689 undef $SDL_MIXER;
542 @SOUNDS = (); 690 @SOUNDS = ();
543 %AUDIO_CHUNKS = (); 691 %AUDIO_CHUNKS = ();
544} 692}
545 693
558 $want_refresh = 0; 706 $want_refresh = 0;
559 $can_refresh = 0; 707 $can_refresh = 0;
560 708
561 $CFClient::UI::ROOT->draw; 709 $CFClient::UI::ROOT->draw;
562 710
563 SDL::GLSwapBuffers; 711 CFClient::SDL_GL_SwapBuffers;
564 712
565 $LAST_REFRESH = $NOW; 713 $LAST_REFRESH = $NOW;
566} 714}
567 715
568my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 716my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
569 $NOW = time; 717 $NOW = time;
570 718
571 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 719 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
572 while $SDL_EV->poll; 720 for CFClient::SDL_PollEvent;
573 721
574 if (%animate_object) { 722 if (%animate_object) {
575 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 723 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
576 $want_refresh++; 724 $want_refresh++;
577 } 725 }
600@conn::ISA = Crossfire::Protocol::; 748@conn::ISA = Crossfire::Protocol::;
601 749
602sub conn::stats_update { 750sub conn::stats_update {
603 my ($self, $stats) = @_; 751 my ($self, $stats) = @_;
604 752
605 # i love text protocols!!! 753 update_stats_window ($stats);
606 # FIXME: the stats are somehow weird
607 my $hp = $stats->{1};
608 my $hp_m = $stats->{2};
609 my $sp = $stats->{3};
610 my $sp_m = $stats->{4};
611 my $fo = $stats->{18};
612 my $fo_m = 1000;
613 my $gr = $stats->{23};
614 my $gr_m = $stats->{24};
615
616 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
617 $GAUGES->{hp}->set_value ($hp, $hp_m);
618 $GAUGES->{mana}->set_value ($sp, $sp_m);
619 $GAUGES->{food}->set_value ($fo, $fo_m);
620 $GAUGES->{grace}->set_value ($gr, $gr_m);
621} 754}
622 755
623sub conn::user_send { 756sub conn::user_send {
624 my ($self, $command) = @_; 757 my ($self, $command) = @_;
625 758
650 783
651 my ($hash, $x, $y, $w, $h) = @$map_info; 784 my ($hash, $x, $y, $w, $h) = @$map_info;
652 785
653 my $data = $MAP->get_rect ($x, $y, $w, $h); 786 my $data = $MAP->get_rect ($x, $y, $w, $h);
654 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 787 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
655
656 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 788 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
657
658} 789}
659 790
660sub conn::map_clear { 791sub conn::map_clear {
661 my ($self) = @_; 792 my ($self) = @_;
662 793
663 $self->flush_map; 794 $self->flush_map;
664 delete $self->{neigh}; 795 delete $self->{neigh_map};
665 796
666 $MAP->clear; 797 $MAP->clear;
667} 798}
668 799
669 800
670sub conn::load_map($$$) { 801sub conn::load_map($$$) {
671 my ($self, $hash, $x, $y) = @_; 802 my ($self, $hash, $x, $y) = @_;
672 803
673 if (defined (my $data = $MAPCACHE->get ($hash))) { 804 if (defined (my $data = $MAPCACHE->get ($hash))) {
674 $data = Compress::LZF::decompress $data; 805 $data = Compress::LZF::decompress $data;
675 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 806 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
676 for my $id ($MAP->set_rect ($x, $y, $data)) { 807 for my $id ($MAP->set_rect ($x, $y, $data)) {
677 my $data = $TILECACHE->get ($id) 808 my $data = $TILECACHE->get ($id)
678 or next; 809 or next;
679 810
680 $self->set_texture ($id => $data); 811 $self->set_texture ($id => $data);
681 } 812 }
682 } 813 }
683} 814}
684 815
816# this method does a "flood fill" into every tile direction
817# it assumes that tiles are arranged in a rectangular grid,
818# i.e. a map is the same as the left of the right map etc.
819# failure to comply are harmless and result in display errors
820# at worst.
685sub conn::flood_fill { 821sub conn::flood_fill {
686 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 822 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
687 823
688 # the server does not allow map paths > 6 824 # the server does not allow map paths > 6
689 return if 6 <= length $path; 825 return if 6 <= length $path;
690 826
691 for my $tile (1..4) { 827 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
692 next if $self->{neigh}{$hash}[$tile]; 828
829 for (
830 [1, 0, -1],
831 [2, 1, 0],
832 [3, 0, 1],
833 [4, -1, 0],
834 ) {
835 my ($tile, $dx, $dy) = @$_;
836
837 my $gx = $gx + $dx;
838 my $gy = $gy + $dy;
839
693 next unless $flags & (1 << ($tile - 1)); 840 next unless $flags & (1 << ($tile - 1));
841 next if $self->{neigh_grid}{$gx, $gy}++;
694 842
695 my $neigh = $self->{neigh}{$hash} ||= []; 843 my $neigh = $self->{neigh_map}{$hash} ||= [];
696 844 if (my $info = $neigh->[$tile]) {
697 $self->send_mapinfo ("spatial $path$tile", sub {
698 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 845 my ($flags, $x, $y, $w, $h, $hash) = @$info;
699 846
700 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
701 return if $mode ne "spatial";
702
703 $x += $MAP->ox;
704 $y += $MAP->oy;
705
706 $self->load_map ($hash, $x, $y)
707 unless $self->{neigh}{$hash}[5]++;#d#
708
709 $neigh->[$tile] = [$x, $y, $w, $h];
710
711 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 847 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
712 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 848 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
849
850 } else {
851 $self->send_mapinfo ("spatial $path$tile", sub {
852 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
853
854 return if $mode ne "spatial";
855
856 $x += $MAP->ox;
857 $y += $MAP->oy;
858
859 $self->load_map ($hash, $x, $y)
860 unless $self->{neigh_map}{$hash}[5]++;#d#
861
862 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
863
864 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
865 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
866 });
713 }); 867 }
714 } 868 }
715} 869}
716 870
717sub conn::map_change { 871sub conn::map_change {
718 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 872 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
721 875
722 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 876 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
723 877
724 my $mapmapw = 250; 878 my $mapmapw = 250;
725 my $mapmaph = 250; 879 my $mapmaph = 250;
880
881 $self->{neigh_rect} = [
882 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
883 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
884 ];
726 885
886 delete $self->{neigh_grid};
727 $self->flood_fill ("", $hash, $flags, 887 $self->flood_fill (0, 0, "", $hash, $flags);
728 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
729 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
730 888
731 $x += $ox; 889 $x += $ox;
732 $y += $oy; 890 $y += $oy;
733 891
734 $self->{map_info} = [$hash, $x, $y, $w, $h]; 892 $self->{map_info} = [$hash, $x, $y, $w, $h];
893
894 $STATWIDS->{map}->set_text ("Map: " . $self->{map_info}[0]);
735 895
736 $self->load_map ($hash, $x, $y); 896 $self->load_map ($hash, $x, $y);
737} 897}
738 898
739sub conn::face_find { 899sub conn::face_find {
800 or return; 960 or return;
801 961
802 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 962 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
803 or return; 963 or return;
804 964
805 $SDL_MIXER->play_channel (-1, $chunk, 0, -1); 965 $chunk->play;
806 warn "sound $x,$y,$soundnum,$type\n";#d# 966# warn "sound $x,$y,$soundnum,$type\n";#d#
807} 967}
808 968
809sub conn::query { 969sub conn::query {
810 my ($self, $flags, $prompt) = @_; 970 my ($self, $flags, $prompt) = @_;
811 971
812 #TODO 972 #TODO, display dialog with relevant information
813 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 973 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
814} 974}
815 975
816sub conn::drawinfo { 976sub conn::drawinfo {
817 my ($self, $color, $text) = @_; 977 my ($self, $color, $text) = @_;
833 ); 993 );
834 994
835 $LOGVIEW->add_paragraph ($color[$color], $text); 995 $LOGVIEW->add_paragraph ($color[$color], $text);
836} 996}
837 997
998sub conn::spell_add {
999 my ($self, $spell) = @_;
1000
1001 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
1002 });
1003 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
1004 });
1005}
1006
1007sub conn::spell_delete {
1008 my ($self, $spell) = @_;
1009}
1010
1011sub conn::addme_success {
1012 my ($self) = @_;
1013
1014 for my $skill (values %{$self->{skill_info}}) {
1015 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
1016 });
1017 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
1018 });
1019 }
1020}
1021
838%SDL_CB = ( 1022%SDL_CB = (
839 SDL_QUIT() => sub { 1023 CFClient::SDL_QUIT => sub {
840 Event::unloop -1; 1024 Event::unloop -1;
841 }, 1025 },
842 SDL_VIDEORESIZE() => sub { 1026 CFClient::SDL_VIDEORESIZE => sub {
843 }, 1027 },
844 SDL_VIDEOEXPOSE() => sub { 1028 CFClient::SDL_VIDEOEXPOSE => \&refresh,
845 refresh; 1029 CFClient::SDL_ACTIVEEVENT => sub {
1030# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
846 }, 1031 },
847 SDL_KEYDOWN() => sub { 1032 CFClient::SDL_KEYDOWN => sub {
848 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 1033 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
849 # alt-enter 1034 # alt-enter
850 video_shutdown; 1035 video_shutdown;
851 $CFG->{fullscreen} = !$CFG->{fullscreen}; 1036 $CFG->{fullscreen} = !$CFG->{fullscreen};
852 video_init; 1037 video_init;
853 } else { 1038 } else {
854 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 1039 CFClient::UI::feed_sdl_key_down_event ($_[0]);
855 } 1040 }
856 }, 1041 },
857 SDL_KEYUP() => sub { 1042 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
858 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 1043 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
859 }, 1044 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
860 SDL_MOUSEMOTION() => sub { 1045 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
861 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 1046 CFClient::SDL_USEREVENT => \&audio_music_finished,
862 },
863 SDL_MOUSEBUTTONDOWN() => sub {
864 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
865 },
866 SDL_MOUSEBUTTONUP() => sub {
867 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
868 },
869 SDL_ACTIVEEVENT() => sub {
870# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
871 },
872); 1047);
873 1048
874############################################################################# 1049#############################################################################
875 1050
876$SIG{INT} = $SIG{TERM} = sub { exit }; 1051$SIG{INT} = $SIG{TERM} = sub { exit };
888 fast => 0, 1063 fast => 0,
889 fow_enable => 1, 1064 fow_enable => 1,
890 fow_intensity => 0.45, 1065 fow_intensity => 0.45,
891 fow_smooth => 0, 1066 fow_smooth => 0,
892 gui_fontsize => 1, 1067 gui_fontsize => 1,
893 log_fontsize => 14, 1068 log_fontsize => 1,
1069 stat_fontsize => 1,
894 mapsize => 100, 1070 mapsize => 100,
895 host => "crossfire.schmorp.de", 1071 host => "crossfire.schmorp.de",
896 say_command => 'say', 1072 say_command => 'say',
897 audio_enable => 1, 1073 audio_enable => 1,
898 bgm_enable => 1, 1074 bgm_enable => 1,
899 bgm_volume => 64, 1075 bgm_volume => 0.25,
900); 1076);
901 1077
902while (my ($k, $v) = each %DEF_CFG) { 1078while (my ($k, $v) = each %DEF_CFG) {
903 $CFG->{$k} = $v unless exists $CFG->{$k}; 1079 $CFG->{$k} = $v unless exists $CFG->{$k};
904} 1080}
905 1081
906sdl_init; 1082sdl_init;
907 1083
908@SDL_MODES = reverse 1084@SDL_MODES = reverse
909 grep $_->[0] >= 640 && $_->[1] >= 480, 1085 grep $_->[0] >= 640 && $_->[1] >= 480,
910 map [SDL::RectW ($_), SDL::RectH ($_)], 1086 CFClient::SDL_ListModes;
911 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
912 1087
913@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 1088@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
914 1089
915$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 1090$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
916 1091
924video_init; 1099video_init;
925audio_init; 1100audio_init;
926 1101
927Event::loop; 1102Event::loop;
928 1103
929END { SDL::Quit } 1104END { CFClient::SDL_Quit }
930 1105
931 1106

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines