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.139 by root, Wed Apr 19 00:47:35 2006 UTC vs.
Revision 1.152 by root, Thu Apr 20 08:11:57 2006 UTC

4use utf8; 4use utf8;
5 5
6use Time::HiRes 'time'; 6use Time::HiRes 'time';
7use Event; 7use Event;
8 8
9use SDL;
10use SDL::App;
11use SDL::Event;
12use SDL::Surface;
13
14use SDL::Mixer;
15use SDL::Sound;
16use SDL::Music;
17
18use SDL::OpenGL;
19
20use Crossfire; 9use Crossfire;
21use Crossfire::Protocol; 10use Crossfire::Protocol;
22 11
23use Compress::LZF; 12use Compress::LZF;
24 13
25use CFClient; 14use CFClient;
26use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
27 17
28our $VERSION = '0.1'; 18our $VERSION = '0.1';
29 19
30my $MAX_FPS = 60; 20my $MAX_FPS = 60;
31my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
57our $METASERVER; 47our $METASERVER;
58 48
59our $GAUGES; 49our $GAUGES;
60 50
61our $SDL_ACTIVE; 51our $SDL_ACTIVE;
62our $SDL_EV;
63our %SDL_CB; 52our %SDL_CB;
64 53
65our $SDL_MIXER; 54our $SDL_MIXER;
66our @SOUNDS; # event => file mapping 55our @SOUNDS; # event => file mapping
67our %AUDIO_CHUNKS; # audio files 56our %AUDIO_CHUNKS; # audio files
109 undef $CONN; 98 undef $CONN;
110} 99}
111 100
112sub client_setup { 101sub client_setup {
113 my $dialog = new CFClient::UI::FancyFrame 102 my $dialog = new CFClient::UI::FancyFrame
103 title => "Client Setup",
114 child => (my $vbox = new CFClient::UI::VBox); 104 child => (my $vbox = new CFClient::UI::VBox);
115 $vbox->add (new CFClient::UI::Label 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 align => 0, valign => 0, height => 0.8, template => "9999x9999");
123 112
124 $mode_slider->connect (changed => sub { 113 $mode_slider->connect (changed => sub {
125 my ($self, $value) = @_; 114 my ($self, $value) = @_;
126 115
127 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
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->{audio_enable}, connect_changed => sub { 169 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
176 my ($self, $value) = @_;
177 $CFG->{audio_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];
178 }); 175# });
179 $table->add (0, 9, new CFClient::UI::Label align => 1, text => "Bg. Music"); 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);
180 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{bgm_enable}, connect_changed => sub { 178 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
181 my ($self, $value) = @_;
182 $CFG->{bgm_enable} = $value; 179 $CFG->{bgm_enable} = $_[1];
183 }); 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::MixMusic::volume $_[1] * 128;
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
190} 192}
191 193
192sub metaserver_dialog { 194sub metaserver_dialog {
193 my $dialog = new CFClient::UI::FancyFrame 195 my $dialog = new CFClient::UI::FancyFrame
196 title => "Metaserver",
194 child => (my $vbox = new CFClient::UI::VBox); 197 child => (my $vbox = new CFClient::UI::VBox);
195 198
196 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 199 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
197 200
198 $dialog 201 $dialog
255 $HOST->set_text ($CFG->{host} = $host); 258 $HOST->set_text ($CFG->{host} = $host);
256 }), 259 }),
257 (new CFClient::UI::Empty expand => 1), 260 (new CFClient::UI::Empty expand => 1),
258 ]); 261 ]);
259 262
260 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 263 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
261 for 0 .. $#$m; 264 for 0 .. $#$m;
262 } 265 }
263 } 266 }
264 }); 267 });
265} 268}
266 269
267sub server_setup { 270sub server_setup {
268 my $dialog = new CFClient::UI::FancyFrame 271 my $dialog = new CFClient::UI::FancyFrame
272 title => "Server Setup",
269 child => (my $vbox = new CFClient::UI::VBox); 273 child => (my $vbox = new CFClient::UI::VBox);
270 274
271 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
272 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 275 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
273 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 276 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
274 277
275 { 278 {
276 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 279 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
277 280
278 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 281 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
279 my ($self, $value) = @_; 282 my ($self, $value) = @_;
280 $CFG->{host} = $value; 283 $CFG->{host} = $value;
281 }); 284 });
282 285
283 $METASERVER = metaserver_dialog; 286 $METASERVER = metaserver_dialog;
284 287
285 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 288 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
286 update_metaserver $HOST; 289 update_metaserver $HOST;
287 }); 290 });
288 } 291 }
289 292
290 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 293 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
291 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 294 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
292 my ($self, $value) = @_; 295 my ($self, $value) = @_;
293 $CFG->{user} = $value; 296 $CFG->{user} = $value;
294 }); 297 });
295 298
296 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 299 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
297 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 300 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
298 my ($self, $value) = @_; 301 my ($self, $value) = @_;
299 $CFG->{password} = $value; 302 $CFG->{password} = $value;
300 }); 303 });
301 304
302 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 305 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
303 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 306 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
304 my ($self, $value) = @_; 307 my ($self, $value) = @_;
305 $CFG->{say_command} = $value; 308 $CFG->{say_command} = $value;
306 }); 309 });
307 310
308 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 311 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
309 $table->add (1, 7, new CFClient::UI::Slider 312 $table->add (1, 7, new CFClient::UI::Slider
310 req_w => 100, 313 req_w => 100,
311 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 314 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
312 connect_changed => sub { 315 connect_changed => sub {
313 my ($self, $value) = @_; 316 my ($self, $value) = @_;
323 $dialog 326 $dialog
324} 327}
325 328
326sub message_window { 329sub message_window {
327 my $window = new CFClient::UI::FancyFrame 330 my $window = new CFClient::UI::FancyFrame
331 title => "Messages",
328 border_bg => [1, 1, 1, 0.5], 332 border_bg => [1, 1, 1, 0.5],
329 bg => [0.3, 0.3, 0.3, 0.8], 333 bg => [0.3, 0.3, 0.3, 0.8],
330 user_w => int $::WIDTH / 3, 334 user_w => int $::WIDTH / 3,
331 user_h => int $::HEIGHT / 5, 335 user_h => int $::HEIGHT / 5,
332 child => (my $vbox = new CFClient::UI::VBox); 336 child => (my $vbox = new CFClient::UI::VBox);
374 378
375 $window 379 $window
376} 380}
377 381
378sub sdl_init { 382sub sdl_init {
379 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 383 CFClient::SDL_Init
380 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
381 and die "SDL::Init failed!\n"; 384 and die "SDL::Init failed!\n";
382} 385}
383 386
384sub video_init { 387sub video_init {
385 sdl_init; 388 sdl_init;
386 389
387 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 390 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
388 $FULLSCREEN = $CFG->{fullscreen}; 391 $FULLSCREEN = $CFG->{fullscreen};
389 $FAST = $CFG->{fast}; 392 $FAST = $CFG->{fast};
390 393
391 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 394 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"; 395 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 396
415 $SDL_ACTIVE = 1; 397 $SDL_ACTIVE = 1;
416 398
417 $LAST_REFRESH = time - 0.01; 399 $LAST_REFRESH = time - 0.01;
418 400
419 CFClient::gl_init; 401 CFClient::gl_init;
420 402
421 $FONTSIZE = int $HEIGHT / 40; 403 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
422 404
423 ############################################################################# 405 #############################################################################
424 406
425 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 407 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
426 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 408 $DEBUG_STATUS->show;
427 409
428 $STATUS_LINE = new CFClient::UI::Label 410 $STATUS_LINE = new CFClient::UI::Label
429 padding => 0, 411 padding => 0,
430 y => $HEIGHT * 44 / 45 - $FONTSIZE; 412 y => $HEIGHT - $FONTSIZE * 1.8;
431 $CFClient::UI::ROOT->add ($STATUS_LINE); 413 $STATUS_LINE->show;
432 414
433 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 415 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
434 padding => 0, 416 padding => 0,
435 y => $HEIGHT * 44 / 45,
436 fontsize => $HEIGHT / 45, 417 fontsize => 0.8,
437 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 418 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
438 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 419 $ALT_ENTER_MESSAGE->show;
420 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
439 421
440 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 422 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
441 $MAPWIDGET->focus_in; 423 $MAPWIDGET->focus_in;
442 $MAPWIDGET->connect (activate_console => sub { 424 $MAPWIDGET->connect (activate_console => sub {
443 my ($mapwidget, $preset) = @_; 425 my ($mapwidget, $preset) = @_;
444 426
445 if ($CONSOLE) { 427 if ($CONSOLE) {
463 status "Configuration Saved"; 445 status "Configuration Saved";
464 }); 446 });
465 447
466 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 448 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
467 449
468 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); 450 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats");
469 $tgw->add (my $hbox = new CFClient::UI::HBox ()); 451 $tgw->add (my $hbox = new CFClient::UI::HBox ());
470 452
471 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); 453 $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
472 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); 454 $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
473 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); 455 $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
474 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); 456 $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
475 457
476 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; 458 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
477 $CFClient::UI::ROOT->add ($tgw); 459 $CFClient::UI::ROOT->add ($tgw);
478} 460}
479 461
480sub video_shutdown { 462sub video_shutdown {
481 $CFClient::UI::ROOT->{children} = []; 463 $CFClient::UI::ROOT->{children} = [];
482 undef $SDL_ACTIVE; 464 undef $SDL_ACTIVE;
483 undef $SDL_EV;
484} 465}
485 466
486my $bgmusic;#TODO#hack#d# 467my $bgmusic;#TODO#hack#d#
487 468
488sub audio_init { 469sub audio_init {
489 if ($CFG->{audio_enable}) { 470 if ($CFG->{audio_enable}) {
490 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { 471 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
491 $SDL_MIXER = new SDL::Mixer; 472
492 $SDL_MIXER->allocate_channels (8); 473 $SDL_MIXER = !CFClient::Mix_OpenAudio;
474 CFClient::Mix_AllocateChannels 8;
475 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
493 476
494 # TODO: hack, do play loop and mood music 477 # TODO: hack, do play loop and mood music
495 if ($CFG->{bgm_enable}) { 478 if ($CFG->{bgm_enable}) {
496 $bgmusic = new SDL::Music CFClient::find_rcfile "music/game3.ogg"; 479 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/game3.ogg";
497 $SDL_MIXER->play_music ($bgmusic, -1); 480 $bgmusic->play;
498 } 481 }
499 482
500 while (<$fh>) { 483 while (<$fh>) {
501 next if /^\s*#/; 484 next if /^\s*#/;
502 next if /^\s*$/; 485 next if /^\s*$/;
504 my ($file, $volume, $event) = split /\s+/, $_, 3; 487 my ($file, $volume, $event) = split /\s+/, $_, 3;
505 488
506 push @SOUNDS, "$volume,$file"; 489 push @SOUNDS, "$volume,$file";
507 490
508 $AUDIO_CHUNKS{"$volume,$file"} ||= do { 491 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
509 my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; 492 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
510 $chunk->volume ($volume * 128 / 100); 493 $chunk->volume ($volume * 128 / 100);
511 $chunk 494 $chunk
512 }; 495 };
513 } 496 }
514 } else { 497 } else {
516 } 499 }
517 } 500 }
518} 501}
519 502
520sub audio_shutdown { 503sub audio_shutdown {
504 CFClient::Mix_CloseAudio if $SDL_MIXER;
521 undef $SDL_MIXER; 505 undef $SDL_MIXER;
522 @SOUNDS = (); 506 @SOUNDS = ();
523 %AUDIO_CHUNKS = (); 507 %AUDIO_CHUNKS = ();
524} 508}
525 509
538 $want_refresh = 0; 522 $want_refresh = 0;
539 $can_refresh = 0; 523 $can_refresh = 0;
540 524
541 $CFClient::UI::ROOT->draw; 525 $CFClient::UI::ROOT->draw;
542 526
543 SDL::GLSwapBuffers; 527 CFClient::SDL_GL_SwapBuffers;
544 528
545 $LAST_REFRESH = $NOW; 529 $LAST_REFRESH = $NOW;
546} 530}
547 531
548my $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 {
549 $NOW = time; 533 $NOW = time;
550 534
551 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 535 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
552 while $SDL_EV->poll; 536 for CFClient::SDL_PollEvent;
553 537
554 if (%animate_object) { 538 if (%animate_object) {
555 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 539 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
556 $want_refresh++; 540 $want_refresh++;
557 } 541 }
587 my $hp = $stats->{1}; 571 my $hp = $stats->{1};
588 my $hp_m = $stats->{2}; 572 my $hp_m = $stats->{2};
589 my $sp = $stats->{3}; 573 my $sp = $stats->{3};
590 my $sp_m = $stats->{4}; 574 my $sp_m = $stats->{4};
591 my $fo = $stats->{18}; 575 my $fo = $stats->{18};
592 my $fo_m = 1000; 576 my $fo_m = 999;
593 my $gr = $stats->{23}; 577 my $gr = $stats->{23};
594 my $gr_m = $stats->{24}; 578 my $gr_m = $stats->{24};
595 579
596 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 580 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
597 $GAUGES->{hp}->set_value ($hp, $hp_m); 581 $GAUGES->{hp} ->set_value ($hp, $hp_m);
598 $GAUGES->{mana}->set_value ($sp, $sp_m); 582 $GAUGES->{mana} ->set_value ($sp, $sp_m);
599 $GAUGES->{food}->set_value ($fo, $fo_m); 583 $GAUGES->{food} ->set_value ($fo, $fo_m);
600 $GAUGES->{grace}->set_value ($gr, $gr_m); 584 $GAUGES->{grace}->set_value ($gr, $gr_m);
601} 585}
602 586
603sub conn::user_send { 587sub conn::user_send {
604 my ($self, $command) = @_; 588 my ($self, $command) = @_;
630 614
631 my ($hash, $x, $y, $w, $h) = @$map_info; 615 my ($hash, $x, $y, $w, $h) = @$map_info;
632 616
633 my $data = $MAP->get_rect ($x, $y, $w, $h); 617 my $data = $MAP->get_rect ($x, $y, $w, $h);
634 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 618 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
635
636 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 619 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
637
638} 620}
639 621
640sub conn::map_clear { 622sub conn::map_clear {
641 my ($self) = @_; 623 my ($self) = @_;
642 624
643 $self->flush_map; 625 $self->flush_map;
644 delete $self->{neigh}; 626 delete $self->{neigh_map};
645 627
646 $MAP->clear; 628 $MAP->clear;
647} 629}
648 630
649 631
650sub conn::load_map($$$) { 632sub conn::load_map($$$) {
651 my ($self, $hash, $x, $y) = @_; 633 my ($self, $hash, $x, $y) = @_;
652 634
653 if (defined (my $data = $MAPCACHE->get ($hash))) { 635 if (defined (my $data = $MAPCACHE->get ($hash))) {
654 $data = Compress::LZF::decompress $data; 636 $data = Compress::LZF::decompress $data;
655 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 637 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
656 for my $id ($MAP->set_rect ($x, $y, $data)) { 638 for my $id ($MAP->set_rect ($x, $y, $data)) {
657 my $data = $TILECACHE->get ($id) 639 my $data = $TILECACHE->get ($id)
658 or next; 640 or next;
659 641
660 $self->set_texture ($id => $data); 642 $self->set_texture ($id => $data);
661 } 643 }
662 } 644 }
663} 645}
664 646
647# this method does a "flood fill" into every tile direction
648# it assumes that tiles are arranged in a rectangular grid,
649# i.e. a map is the same as the left of the right map etc.
650# failure to comply are harmless and result in display errors
651# at worst.
665sub conn::flood_fill { 652sub conn::flood_fill {
666 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 653 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
667 654
668 # the server does not allow map paths > 6 655 # the server does not allow map paths > 6
669 return if 6 <= length $path; 656 return if 6 <= length $path;
670 657
671 for my $tile (1..4) { 658 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
672 next if $self->{neigh}{$hash}[$tile]; 659
660 for (
661 [1, 0, -1],
662 [2, 1, 0],
663 [3, 0, 1],
664 [4, -1, 0],
665 ) {
666 my ($tile, $dx, $dy) = @$_;
667
668 my $gx = $gx + $dx;
669 my $gy = $gy + $dy;
670
673 next unless $flags & (1 << ($tile - 1)); 671 next unless $flags & (1 << ($tile - 1));
672 next if $self->{neigh_grid}{$gx, $gy}++;
674 673
675 my $neigh = $self->{neigh}{$hash} ||= []; 674 my $neigh = $self->{neigh_map}{$hash} ||= [];
676 675 if (my $info = $neigh->[$tile]) {
677 $self->send_mapinfo ("spatial $path$tile", sub {
678 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 676 my ($flags, $x, $y, $w, $h, $hash) = @$info;
679 677
680 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
681 return if $mode ne "spatial";
682
683 $x += $MAP->ox;
684 $y += $MAP->oy;
685
686 $self->load_map ($hash, $x, $y)
687 unless $self->{neigh}{$hash}[5]++;#d#
688
689 $neigh->[$tile] = [$x, $y, $w, $h];
690
691 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 678 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
692 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 679 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
680
681 } else {
682 $self->send_mapinfo ("spatial $path$tile", sub {
683 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
684
685 return if $mode ne "spatial";
686
687 $x += $MAP->ox;
688 $y += $MAP->oy;
689
690 $self->load_map ($hash, $x, $y)
691 unless $self->{neigh_map}{$hash}[5]++;#d#
692
693 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
694
695 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
696 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
697 });
693 }); 698 }
694 } 699 }
695} 700}
696 701
697sub conn::map_change { 702sub conn::map_change {
698 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 703 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
701 706
702 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 707 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
703 708
704 my $mapmapw = 250; 709 my $mapmapw = 250;
705 my $mapmaph = 250; 710 my $mapmaph = 250;
711
712 $self->{neigh_rect} = [
713 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
714 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
715 ];
706 716
717 delete $self->{neigh_grid};
707 $self->flood_fill ("", $hash, $flags, 718 $self->flood_fill (0, 0, "", $hash, $flags);
708 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
709 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
710 719
711 $x += $ox; 720 $x += $ox;
712 $y += $oy; 721 $y += $oy;
713 722
714 $self->{map_info} = [$hash, $x, $y, $w, $h]; 723 $self->{map_info} = [$hash, $x, $y, $w, $h];
780 or return; 789 or return;
781 790
782 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} 791 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
783 or return; 792 or return;
784 793
785 $SDL_MIXER->play_channel (-1, $chunk); 794 $chunk->play;
786 warn "sound $x,$y,$soundnum,$type\n";#d# 795# warn "sound $x,$y,$soundnum,$type\n";#d#
787} 796}
788 797
789sub conn::query { 798sub conn::query {
790 my ($self, $flags, $prompt) = @_; 799 my ($self, $flags, $prompt) = @_;
791 800
792 #TODO 801 #TODO, display dialog with relevant information
793 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 802 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
794} 803}
795 804
796sub conn::drawinfo { 805sub conn::drawinfo {
797 my ($self, $color, $text) = @_; 806 my ($self, $color, $text) = @_;
813 ); 822 );
814 823
815 $LOGVIEW->add_paragraph ($color[$color], $text); 824 $LOGVIEW->add_paragraph ($color[$color], $text);
816} 825}
817 826
827sub conn::spell_add {
828 my ($self, $spell) = @_;
829
830 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
831 });
832 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
833 });
834}
835
836sub conn::spell_delete {
837 my ($self, $spell) = @_;
838}
839
840sub conn::addme_success {
841 my ($self) = @_;
842
843 for my $skill (values %{$self->{skill_info}}) {
844 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
845 });
846 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
847 });
848 }
849}
850
818%SDL_CB = ( 851%SDL_CB = (
819 SDL_QUIT() => sub { 852 CFClient::SDL_QUIT => sub {
820 Event::unloop -1; 853 Event::unloop -1;
821 }, 854 },
822 SDL_VIDEORESIZE() => sub { 855 CFClient::SDL_VIDEORESIZE => sub {
823 }, 856 },
824 SDL_VIDEOEXPOSE() => sub { 857 CFClient::SDL_VIDEOEXPOSE => sub {
825 refresh; 858 refresh;
826 }, 859 },
827 SDL_KEYDOWN() => sub { 860 CFClient::SDL_KEYDOWN => sub {
828 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 861 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
829 # alt-enter 862 # alt-enter
830 video_shutdown; 863 video_shutdown;
831 $CFG->{fullscreen} = !$CFG->{fullscreen}; 864 $CFG->{fullscreen} = !$CFG->{fullscreen};
832 video_init; 865 video_init;
833 } else { 866 } else {
834 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 867 CFClient::UI::feed_sdl_key_down_event ($_[0]);
835 } 868 }
836 }, 869 },
837 SDL_KEYUP() => sub { 870 CFClient::SDL_KEYUP => sub {
838 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 871 CFClient::UI::feed_sdl_key_up_event ($_[0]);
839 }, 872 },
840 SDL_MOUSEMOTION() => sub { 873 CFClient::SDL_MOUSEMOTION => sub {
841 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 874 CFClient::UI::feed_sdl_motion_event ($_[0]);
842 }, 875 },
843 SDL_MOUSEBUTTONDOWN() => sub { 876 CFClient::SDL_MOUSEBUTTONDOWN => sub {
844 CFClient::UI::feed_sdl_button_down_event ($SDL_EV); 877 CFClient::UI::feed_sdl_button_down_event ($_[0]);
845 }, 878 },
846 SDL_MOUSEBUTTONUP() => sub { 879 CFClient::SDL_MOUSEBUTTONUP => sub {
847 CFClient::UI::feed_sdl_button_up_event ($SDL_EV); 880 CFClient::UI::feed_sdl_button_up_event ($_[0]);
848 }, 881 },
849 SDL_ACTIVEEVENT() => sub { 882 CFClient::SDL_ACTIVEEVENT => sub {
850# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 883# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
851 }, 884 },
852); 885);
853 886
854############################################################################# 887#############################################################################
867 fullscreen => 0, 900 fullscreen => 0,
868 fast => 0, 901 fast => 0,
869 fow_enable => 1, 902 fow_enable => 1,
870 fow_intensity => 0.45, 903 fow_intensity => 0.45,
871 fow_smooth => 0, 904 fow_smooth => 0,
905 gui_fontsize => 1,
872 log_fontsize => 14, 906 log_fontsize => 14,
873 mapsize => 100, 907 mapsize => 100,
874 host => "crossfire.schmorp.de", 908 host => "crossfire.schmorp.de",
875 say_command => 'say', 909 say_command => 'say',
876 audio_enable => 1, 910 audio_enable => 1,
877 bgm_enable => 1, 911 bgm_enable => 1,
912 bgm_volume => 0.25,
878); 913);
879 914
880while (my ($k, $v) = each %DEF_CFG) { 915while (my ($k, $v) = each %DEF_CFG) {
881 $CFG->{$k} = $v unless exists $CFG->{$k}; 916 $CFG->{$k} = $v unless exists $CFG->{$k};
882} 917}
883 918
884sdl_init; 919sdl_init;
885 920
886@SDL_MODES = reverse 921@SDL_MODES = reverse
887 grep $_->[0] >= 640 && $_->[1] >= 480, 922 grep $_->[0] >= 640 && $_->[1] >= 480,
888 map [SDL::RectW ($_), SDL::RectH ($_)], 923 CFClient::SDL_ListModes;
889 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
890 924
891@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 925@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
892 926
893$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 927$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
894 928
902video_init; 936video_init;
903audio_init; 937audio_init;
904 938
905Event::loop; 939Event::loop;
906 940
907END { SDL::Quit } 941END { CFClient::SDL_Quit }
908 942
909 943

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines