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.130 by root, Tue Apr 18 01:36:13 2006 UTC vs.
Revision 1.154 by elmex, Thu Apr 20 16:29:40 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;
13use SDL::OpenGL;
14
15use Crossfire; 9use Crossfire;
16use Crossfire::Protocol; 10use Crossfire::Protocol;
17 11
18use Compress::LZF; 12use Compress::LZF;
19 13
20use CFClient; 14use CFClient;
21use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
22 17
23our $VERSION = '0.1'; 18our $VERSION = '0.1';
24 19
25my $MAX_FPS = 60; 20my $MAX_FPS = 60;
26my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
50our $LOGVIEW; 45our $LOGVIEW;
51our $CONSOLE; 46our $CONSOLE;
52our $METASERVER; 47our $METASERVER;
53 48
54our $GAUGES; 49our $GAUGES;
50our $STATWIDS;
55 51
56our $SDL_ACTIVE; 52our $SDL_ACTIVE;
57our $SDL_EV;
58our %SDL_CB; 53our %SDL_CB;
54
55our $SDL_MIXER;
56our @SOUNDS; # event => file mapping
57our %AUDIO_CHUNKS; # audio files
59 58
60our $ALT_ENTER_MESSAGE; 59our $ALT_ENTER_MESSAGE;
61our $STATUS_LINE; 60our $STATUS_LINE;
62our $DEBUG_STATUS; 61our $DEBUG_STATUS;
63 62
100 undef $CONN; 99 undef $CONN;
101} 100}
102 101
103sub client_setup { 102sub client_setup {
104 my $dialog = new CFClient::UI::FancyFrame 103 my $dialog = new CFClient::UI::FancyFrame
104 title => "Client Setup",
105 child => (my $vbox = new CFClient::UI::VBox); 105 child => (my $vbox = new CFClient::UI::VBox);
106 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
107 $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]);
108 107
109 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 108 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
110 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 109 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
111 110
112 $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]);
113 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8); 112 $hbox->add (my $mode_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
114 113
115 $mode_slider->connect (changed => sub { 114 $mode_slider->connect (changed => sub {
116 my ($self, $value) = @_; 115 my ($self, $value) = @_;
117 116
118 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 117 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
119 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 118 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
120 }); 119 });
121 $mode_slider->emit (changed => $mode_slider->{range}[0]); 120 $mode_slider->emit (changed => $mode_slider->{range}[0]);
122 121
123 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Fullscreen"); 122 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
124 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub { 123 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
125 my ($self, $value) = @_; 124 my ($self, $value) = @_;
126 $CFG->{fullscreen} = $value; 125 $CFG->{fullscreen} = $value;
127 }); 126 });
128 127
129 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Fast & Ugly"); 128 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
130 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub { 129 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
131 my ($self, $value) = @_; 130 my ($self, $value) = @_;
132 $CFG->{fast} = $value; 131 $CFG->{fast} = $value;
133 }); 132 });
134 133
135 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Fog of War"); 134 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
136 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub { 135 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
137 my ($self, $value) = @_; 136 my ($self, $value) = @_;
138 $CFG->{fow_enable} = $value; 137 $CFG->{fow_enable} = $value;
139 }); 138 });
140 139
141 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "FoW Intensity"); 140 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
142 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub { 141 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
143 my ($self, $value) = @_; 142 my ($self, $value) = @_;
144 $CFG->{fow_intensity} = $value; 143 $CFG->{fow_intensity} = $value;
145 }); 144 });
146 145
147 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "FoW Smooth"); 146 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
148 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub { 147 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
149 my ($self, $value) = @_; 148 my ($self, $value) = @_;
150 $CFG->{fow_smooth} = $value; 149 $CFG->{fow_smooth} = $value;
150 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
151 }); 151 });
152 152
153 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); 153 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
155 $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10;
156# $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
157 });
158
159 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize");
154 $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 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 {
155 my ($self, $value) = @_;
156 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); 161 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
157 }); 162 });
158 163
159 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { 164 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
160 destroy_screen (); 165 video_shutdown ();
161 init_screen (); 166 video_init ();
167 });
168
169 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
170 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
171 $CFG->{audio_enable} = $_[1];
172 });
173# $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume");
174# $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub {
175# $CFG->{effects_volume} = $_[1];
176# });
177 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
178 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
179 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
180 $CFG->{bgm_enable} = $_[1];
181 });
182 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
183 $CFG->{bgm_volume} = $_[1];
184 CFClient::MixMusic::volume $_[1] * 128;
185 });
186
187 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
188 audio_shutdown ();
189 audio_init ();
162 }); 190 });
163 191
164 $dialog 192 $dialog
193}
194
195sub make_stats_window {
196 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH * 2/3, y => 0, title => "Stats");
197 $tgw->add (my $vb = new CFClient::UI::VBox ());
198 $vb->add ($STATWIDS->{stat} = new CFClient::UI::Label valign => 0, align => -1);
199 $vb->add (my $hb2 = new CFClient::UI::HBox);
200 $hb2->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
201 $hb2->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
202 $hb2->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
203 $hb2->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
204 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
205 $tgw
206}
207
208sub update_stats_window {
209 my ($stats) = @_;
210
211 $STATWIDS->{stat}->set_text (
212 "Title: $stats->{21}\nExp.: " . ($stats->{11} || $stats->{28})
213 . " Level: $stats->{12}\n"
214 . (sprintf "S%d D%d Co%d I%d W%d P%d Ch%2d, Wc%d Ac%d\n",
215 @$stats{5,8,9,6,7,22,10, 13, 14})
216 . (sprintf "Dam %d Arm %d Speed %.2f/%.2f",
217 @$stats{15,16,17,19})
218 );
165} 219}
166 220
167sub metaserver_dialog { 221sub metaserver_dialog {
168 my $dialog = new CFClient::UI::FancyFrame 222 my $dialog = new CFClient::UI::FancyFrame
223 title => "Metaserver",
169 child => (my $vbox = new CFClient::UI::VBox); 224 child => (my $vbox = new CFClient::UI::VBox);
170 225
171 $vbox->add ($dialog->{table} = new CFClient::UI::Table); 226 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
172 227
173 $dialog 228 $dialog
230 $HOST->set_text ($CFG->{host} = $host); 285 $HOST->set_text ($CFG->{host} = $host);
231 }), 286 }),
232 (new CFClient::UI::Empty expand => 1), 287 (new CFClient::UI::Empty expand => 1),
233 ]); 288 ]);
234 289
235 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) 290 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
236 for 0 .. $#$m; 291 for 0 .. $#$m;
237 } 292 }
238 } 293 }
239 }); 294 });
240} 295}
241 296
242sub server_setup { 297sub server_setup {
243 my $dialog = new CFClient::UI::FancyFrame 298 my $dialog = new CFClient::UI::FancyFrame
299 title => "Server Setup",
244 child => (my $vbox = new CFClient::UI::VBox); 300 child => (my $vbox = new CFClient::UI::VBox);
245 301
246 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
247 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]); 302 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
248 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); 303 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
249 304
250 { 305 {
251 $table->add (1, 2, my $vbox = new CFClient::UI::VBox); 306 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
252 307
253 $vbox->add (my $HOST = new CFClient::UI::Entry text => $CFG->{host}, connect_changed => sub { 308 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
254 my ($self, $value) = @_; 309 my ($self, $value) = @_;
255 $CFG->{host} = $value; 310 $CFG->{host} = $value;
256 }); 311 });
257 312
258 $METASERVER = metaserver_dialog; 313 $METASERVER = metaserver_dialog;
259 314
260 $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { 315 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
261 update_metaserver $HOST; 316 update_metaserver $HOST;
262 }); 317 });
263 } 318 }
264 319
265 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username"); 320 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
266 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub { 321 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
267 my ($self, $value) = @_; 322 my ($self, $value) = @_;
268 $CFG->{user} = $value; 323 $CFG->{user} = $value;
269 }); 324 });
270 325
271 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password"); 326 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
272 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub { 327 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
273 my ($self, $value) = @_; 328 my ($self, $value) = @_;
274 $CFG->{password} = $value; 329 $CFG->{password} = $value;
275 }); 330 });
276 331
277 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Def. say cmd"); 332 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
278 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub { 333 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
279 my ($self, $value) = @_; 334 my ($self, $value) = @_;
280 $CFG->{say_command} = $value; 335 $CFG->{say_command} = $value;
281 }); 336 });
282 337
283 $table->add (0, 7, new CFClient::UI::Label align => 1, text => "Map Size"); 338 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
284 $table->add (1, 7, new CFClient::UI::Slider 339 $table->add (1, 7, new CFClient::UI::Slider
285 req_w => 100, 340 req_w => 100,
286 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 341 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
287 connect_changed => sub { 342 connect_changed => sub {
288 my ($self, $value) = @_; 343 my ($self, $value) = @_;
298 $dialog 353 $dialog
299} 354}
300 355
301sub message_window { 356sub message_window {
302 my $window = new CFClient::UI::FancyFrame 357 my $window = new CFClient::UI::FancyFrame
358 title => "Messages",
303 border_bg => [1, 1, 1, 0.5], 359 border_bg => [1, 1, 1, 0.5],
304 bg => [0.3, 0.3, 0.3, 0.8], 360 bg => [0.3, 0.3, 0.3, 0.8],
305 user_w => int $::WIDTH / 3, 361 user_w => int $::WIDTH / 3,
306 user_h => int $::HEIGHT / 5, 362 user_h => int $::HEIGHT / 5,
307 child => (my $vbox = new CFClient::UI::VBox); 363 child => (my $vbox = new CFClient::UI::VBox);
349 405
350 $window 406 $window
351} 407}
352 408
353sub sdl_init { 409sub sdl_init {
354 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE 410 CFClient::SDL_Init
355 #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO
356 and die "SDL::Init failed!\n"; 411 and die "SDL::Init failed!\n";
357} 412}
358 413
359sub init_screen { 414sub video_init {
360 sdl_init; 415 sdl_init;
361 416
362 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 417 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
363 $FULLSCREEN = $CFG->{fullscreen}; 418 $FULLSCREEN = $CFG->{fullscreen};
364 $FAST = $CFG->{fast}; 419 $FAST = $CFG->{fast};
365 420
366 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 421 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
367 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
368 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
369 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1;
370
371 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
372 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
373 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
374 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
375
376 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
377 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
378 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
379
380 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
381 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
382 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
383 or die "SDL::SetVideoMode failed!\n"; 422 or die "SDL_SetVideoMode failed!\n";
384
385 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
386
387 $SDL_EV = new SDL::Event;
388 $SDL_EV->set_unicode (1);
389 423
390 $SDL_ACTIVE = 1; 424 $SDL_ACTIVE = 1;
391 425
392 $LAST_REFRESH = time - 0.01; 426 $LAST_REFRESH = time - 0.01;
393 427
394 CFClient::gl_init; 428 CFClient::gl_init;
395 429
396 $FONTSIZE = int $HEIGHT / 40; 430 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
397 431
398 ############################################################################# 432 #############################################################################
399 433
400 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 434 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
401 $CFClient::UI::ROOT->add ($DEBUG_STATUS); 435 $DEBUG_STATUS->show;
402 436
403 $STATUS_LINE = new CFClient::UI::Label 437 $STATUS_LINE = new CFClient::UI::Label
404 padding => 0, 438 padding => 0,
405 y => $HEIGHT * 44 / 45 - $FONTSIZE; 439 y => $HEIGHT - $FONTSIZE * 1.8;
406 $CFClient::UI::ROOT->add ($STATUS_LINE); 440 $STATUS_LINE->show;
407 441
408 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 442 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
409 padding => 0, 443 padding => 0,
410 y => $HEIGHT * 44 / 45,
411 fontsize => $HEIGHT / 45, 444 fontsize => 0.8,
412 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 445 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
413 $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); 446 $ALT_ENTER_MESSAGE->show;
447 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
414 448
415 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); 449 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
416 $MAPWIDGET->focus_in; 450 $MAPWIDGET->focus_in;
417 $MAPWIDGET->connect (activate_console => sub { 451 $MAPWIDGET->connect (activate_console => sub {
418 my ($mapwidget, $preset) = @_; 452 my ($mapwidget, $preset) = @_;
419 453
420 if ($CONSOLE) { 454 if ($CONSOLE) {
438 status "Configuration Saved"; 472 status "Configuration Saved";
439 }); 473 });
440 474
441 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup 475 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
442 476
443 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0);
444 $tgw->add (my $hbox = new CFClient::UI::HBox ());
445 477
446 $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp'));
447 $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana'));
448 $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace'));
449 $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food'));
450
451 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
452 $CFClient::UI::ROOT->add ($tgw); 478 $CFClient::UI::ROOT->add (make_stats_window);
453} 479}
454 480
455sub destroy_screen { 481sub video_shutdown {
456 $CFClient::UI::ROOT->{children} = []; 482 $CFClient::UI::ROOT->{children} = [];
457 undef $SDL_ACTIVE; 483 undef $SDL_ACTIVE;
484}
485
486my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
487my $bgmusic;#TODO#hack#d#
488
489sub audio_music_finished {
490 return unless $CFG->{bgm_enable};
491
492 # TODO: hack, do play loop and mood music
493 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
494 $bgmusic->play (0);
495
496 push @bgmusic, shift @bgmusic;
497}
498
499sub audio_init {
500 if ($CFG->{audio_enable}) {
501 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
502 $SDL_MIXER = !CFClient::Mix_OpenAudio;
503 CFClient::Mix_AllocateChannels 8;
504 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
505
506 audio_music_finished;
507
508 while (<$fh>) {
509 next if /^\s*#/;
510 next if /^\s*$/;
511
512 my ($file, $volume, $event) = split /\s+/, $_, 3;
513
514 push @SOUNDS, "$volume,$file";
515
516 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
517 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
518 $chunk->volume ($volume * 128 / 100);
519 $chunk
520 };
521 }
522 } else {
523 status "unable to open sound config: $!";
524 }
525 }
526}
527
528sub audio_shutdown {
529 CFClient::Mix_CloseAudio if $SDL_MIXER;
458 undef $SDL_EV; 530 undef $SDL_MIXER;
459 SDL::Quit; 531 @SOUNDS = ();
532 %AUDIO_CHUNKS = ();
460} 533}
461 534
462my %animate_object; 535my %animate_object;
463my $animate_timer; 536my $animate_timer;
464 537
474 $want_refresh = 0; 547 $want_refresh = 0;
475 $can_refresh = 0; 548 $can_refresh = 0;
476 549
477 $CFClient::UI::ROOT->draw; 550 $CFClient::UI::ROOT->draw;
478 551
479 SDL::GLSwapBuffers; 552 CFClient::SDL_GL_SwapBuffers;
480 553
481 $LAST_REFRESH = $NOW; 554 $LAST_REFRESH = $NOW;
482} 555}
483 556
484my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 557my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
485 $NOW = time; 558 $NOW = time;
486 559
487 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 560 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
488 while $SDL_EV->poll; 561 for CFClient::SDL_PollEvent;
489 562
490 if (%animate_object) { 563 if (%animate_object) {
491 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 564 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
492 $want_refresh++; 565 $want_refresh++;
493 } 566 }
523 my $hp = $stats->{1}; 596 my $hp = $stats->{1};
524 my $hp_m = $stats->{2}; 597 my $hp_m = $stats->{2};
525 my $sp = $stats->{3}; 598 my $sp = $stats->{3};
526 my $sp_m = $stats->{4}; 599 my $sp_m = $stats->{4};
527 my $fo = $stats->{18}; 600 my $fo = $stats->{18};
528 my $fo_m = 1000; 601 my $fo_m = 999;
529 my $gr = $stats->{23}; 602 my $gr = $stats->{23};
530 my $gr_m = $stats->{24}; 603 my $gr_m = $stats->{24};
531 604
532 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; 605 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
533 $GAUGES->{hp}->set_value ($hp, $hp_m); 606 $GAUGES->{hp} ->set_value ($hp, $hp_m);
534 $GAUGES->{mana}->set_value ($sp, $sp_m); 607 $GAUGES->{mana} ->set_value ($sp, $sp_m);
535 $GAUGES->{food}->set_value ($fo, $fo_m); 608 $GAUGES->{food} ->set_value ($fo, $fo_m);
536 $GAUGES->{grace}->set_value ($gr, $gr_m); 609 $GAUGES->{grace}->set_value ($gr, $gr_m);
610
611 update_stats_window ($stats);
537} 612}
538 613
539sub conn::user_send { 614sub conn::user_send {
540 my ($self, $command) = @_; 615 my ($self, $command) = @_;
541 616
566 641
567 my ($hash, $x, $y, $w, $h) = @$map_info; 642 my ($hash, $x, $y, $w, $h) = @$map_info;
568 643
569 my $data = $MAP->get_rect ($x, $y, $w, $h); 644 my $data = $MAP->get_rect ($x, $y, $w, $h);
570 $MAPCACHE->put ($hash => Compress::LZF::compress $data); 645 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
571
572 warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# 646 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
573
574} 647}
575 648
576sub conn::map_clear { 649sub conn::map_clear {
577 my ($self) = @_; 650 my ($self) = @_;
578 651
579 $self->flush_map; 652 $self->flush_map;
580 delete $self->{neigh}; 653 delete $self->{neigh_map};
581 654
582 $MAP->clear; 655 $MAP->clear;
583} 656}
584 657
585 658
586sub conn::load_map($$$) { 659sub conn::load_map($$$) {
587 my ($self, $hash, $x, $y) = @_; 660 my ($self, $hash, $x, $y) = @_;
588 661
589 if (defined (my $data = $MAPCACHE->get ($hash))) { 662 if (defined (my $data = $MAPCACHE->get ($hash))) {
590 $data = Compress::LZF::decompress $data; 663 $data = Compress::LZF::decompress $data;
591 warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# 664 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
592 for my $id ($MAP->set_rect ($x, $y, $data)) { 665 for my $id ($MAP->set_rect ($x, $y, $data)) {
593 my $data = $TILECACHE->get ($id) 666 my $data = $TILECACHE->get ($id)
594 or next; 667 or next;
595 668
596 $self->set_texture ($id => $data); 669 $self->set_texture ($id => $data);
597 } 670 }
598 } 671 }
599} 672}
600 673
674# this method does a "flood fill" into every tile direction
675# it assumes that tiles are arranged in a rectangular grid,
676# i.e. a map is the same as the left of the right map etc.
677# failure to comply are harmless and result in display errors
678# at worst.
601sub conn::flood_fill { 679sub conn::flood_fill {
602 my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; 680 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
603 681
604 # the server does not allow map paths > 6 682 # the server does not allow map paths > 6
605 return if 6 <= length $path; 683 return if 6 <= length $path;
606 684
607 for my $tile (1..4) { 685 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
608 next if $self->{neigh}{$hash}[$tile]; 686
687 for (
688 [1, 0, -1],
689 [2, 1, 0],
690 [3, 0, 1],
691 [4, -1, 0],
692 ) {
693 my ($tile, $dx, $dy) = @$_;
694
695 my $gx = $gx + $dx;
696 my $gy = $gy + $dy;
697
609 next unless $flags & (1 << ($tile - 1)); 698 next unless $flags & (1 << ($tile - 1));
699 next if $self->{neigh_grid}{$gx, $gy}++;
610 700
611 my $neigh = $self->{neigh}{$hash} ||= []; 701 my $neigh = $self->{neigh_map}{$hash} ||= [];
612 702 if (my $info = $neigh->[$tile]) {
613 $self->send_mapinfo ("spatial $path$tile", sub {
614 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; 703 my ($flags, $x, $y, $w, $h, $hash) = @$info;
615 704
616 #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d#
617 return if $mode ne "spatial";
618
619 $x += $MAP->ox;
620 $y += $MAP->oy;
621
622 $self->load_map ($hash, $x, $y)
623 unless $self->{neigh}{$hash}[5]++;#d#
624
625 $neigh->[$tile] = [$x, $y, $w, $h];
626
627 $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) 705 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
628 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; 706 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
707
708 } else {
709 $self->send_mapinfo ("spatial $path$tile", sub {
710 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
711
712 return if $mode ne "spatial";
713
714 $x += $MAP->ox;
715 $y += $MAP->oy;
716
717 $self->load_map ($hash, $x, $y)
718 unless $self->{neigh_map}{$hash}[5]++;#d#
719
720 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
721
722 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
723 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
724 });
629 }); 725 }
630 } 726 }
631} 727}
632 728
633sub conn::map_change { 729sub conn::map_change {
634 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; 730 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
635 731
636 $self->flush_map; 732 $self->flush_map;
637 733
638 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); 734 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
639 735
640 warn "$ox $oy map_info<$flags, $x, $y, $w, $h, $hash>\n";#d#
641
642 my $mapmapw = 250; 736 my $mapmapw = 250;
643 my $mapmaph = 250; 737 my $mapmaph = 250;
738
739 $self->{neigh_rect} = [
740 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
741 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
742 ];
644 743
744 delete $self->{neigh_grid};
645 $self->flood_fill ("", $hash, $flags, 745 $self->flood_fill (0, 0, "", $hash, $flags);
646 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
647 $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5);
648 746
649 $x += $ox; 747 $x += $ox;
650 $y += $oy; 748 $y += $oy;
651 749
652 $self->{map_info} = [$hash, $x, $y, $w, $h]; 750 $self->{map_info} = [$hash, $x, $y, $w, $h];
709 807
710 $tex 808 $tex
711 }; 809 };
712} 810}
713 811
812sub conn::sound_play {
813 my ($self, $x, $y, $soundnum, $type) = @_;
814
815 $SDL_MIXER
816 or return;
817
818 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
819 or return;
820
821 $chunk->play;
822# warn "sound $x,$y,$soundnum,$type\n";#d#
823}
824
714sub conn::query { 825sub conn::query {
715 my ($self, $flags, $prompt) = @_; 826 my ($self, $flags, $prompt) = @_;
716 827
717 #TODO 828 #TODO, display dialog with relevant information
718 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 829 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
719} 830}
720 831
721sub conn::drawinfo { 832sub conn::drawinfo {
722 my ($self, $color, $text) = @_; 833 my ($self, $color, $text) = @_;
738 ); 849 );
739 850
740 $LOGVIEW->add_paragraph ($color[$color], $text); 851 $LOGVIEW->add_paragraph ($color[$color], $text);
741} 852}
742 853
854sub conn::spell_add {
855 my ($self, $spell) = @_;
856
857 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
858 });
859 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
860 });
861}
862
863sub conn::spell_delete {
864 my ($self, $spell) = @_;
865}
866
867sub conn::addme_success {
868 my ($self) = @_;
869
870 for my $skill (values %{$self->{skill_info}}) {
871 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
872 });
873 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
874 });
875 }
876}
877
743%SDL_CB = ( 878%SDL_CB = (
744 SDL_QUIT() => sub { 879 CFClient::SDL_QUIT => sub {
745 Event::unloop -1; 880 Event::unloop -1;
746 }, 881 },
747 SDL_VIDEORESIZE() => sub { 882 CFClient::SDL_VIDEORESIZE => sub {
748 }, 883 },
749 SDL_VIDEOEXPOSE() => sub { 884 CFClient::SDL_VIDEOEXPOSE => \&refresh,
750 refresh; 885 CFClient::SDL_ACTIVEEVENT => sub {
886# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
751 }, 887 },
752 SDL_KEYDOWN() => sub { 888 CFClient::SDL_KEYDOWN => sub {
753 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 889 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
754 # alt-enter 890 # alt-enter
755 destroy_screen; 891 video_shutdown;
756 $CFG->{fullscreen} = !$CFG->{fullscreen}; 892 $CFG->{fullscreen} = !$CFG->{fullscreen};
757 init_screen; 893 video_init;
758 } else { 894 } else {
759 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 895 CFClient::UI::feed_sdl_key_down_event ($_[0]);
760 } 896 }
761 }, 897 },
762 SDL_KEYUP() => sub { 898 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
763 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 899 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
764 }, 900 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
765 SDL_MOUSEMOTION() => sub { 901 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
766 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 902 CFClient::SDL_USEREVENT => \&audio_music_finished,
767 },
768 SDL_MOUSEBUTTONDOWN() => sub {
769 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
770 },
771 SDL_MOUSEBUTTONUP() => sub {
772 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
773 },
774 SDL_ACTIVEEVENT() => sub {
775# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
776 },
777); 903);
778 904
779############################################################################# 905#############################################################################
906
907$SIG{INT} = $SIG{TERM} = sub { exit };
780 908
781$TILECACHE = CFClient::db_table "tilecache"; 909$TILECACHE = CFClient::db_table "tilecache";
782$FACEMAP = CFClient::db_table "facemap"; 910$FACEMAP = CFClient::db_table "facemap";
783 911
784CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 912CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
790 fullscreen => 0, 918 fullscreen => 0,
791 fast => 0, 919 fast => 0,
792 fow_enable => 1, 920 fow_enable => 1,
793 fow_intensity => 0.45, 921 fow_intensity => 0.45,
794 fow_smooth => 0, 922 fow_smooth => 0,
923 gui_fontsize => 1,
795 log_fontsize => 14, 924 log_fontsize => 14,
796 mapsize => 100, 925 mapsize => 100,
797 host => "crossfire.schmorp.de", 926 host => "crossfire.schmorp.de",
798 say_command => 'say', 927 say_command => 'say',
928 audio_enable => 1,
929 bgm_enable => 1,
930 bgm_volume => 0.25,
799); 931);
800 932
801while (my ($k, $v) = each %DEF_CFG) { 933while (my ($k, $v) = each %DEF_CFG) {
802 $CFG->{$k} = $v unless exists $CFG->{$k}; 934 $CFG->{$k} = $v unless exists $CFG->{$k};
803} 935}
804 936
805sdl_init; 937sdl_init;
806 938
807@SDL_MODES = reverse 939@SDL_MODES = reverse
808 grep $_->[0] >= 640 && $_->[1] >= 480, 940 grep $_->[0] >= 640 && $_->[1] >= 480,
809 map [SDL::RectW ($_), SDL::RectH ($_)], 941 CFClient::SDL_ListModes;
810 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
811 942
812@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 943@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
813 944
814$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 945$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
815 946
818 949
819 CFClient::add_font $_ for @fonts; 950 CFClient::add_font $_ for @fonts;
820 CFClient::set_font $fonts[0]; 951 CFClient::set_font $fonts[0];
821} 952}
822 953
823init_screen; 954video_init;
955audio_init;
824 956
825Event::loop; 957Event::loop;
826 958
959END { CFClient::SDL_Quit }
827 960
961

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines