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.102 by elmex, Fri Apr 14 11:43:51 2006 UTC vs.
Revision 1.153 by root, Thu Apr 20 09:13:32 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
12use Compress::LZF;
13
18use CFClient; 14use CFClient;
19use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
20 17
21our $VERSION = '0.1'; 18our $VERSION = '0.1';
22 19
23my $MAX_FPS = 60; 20my $MAX_FPS = 60;
24my $MIN_FPS = 5; # unused as of yet 21my $MIN_FPS = 5; # unused as of yet
25 22
23our $META_SERVER = "crossfire.real-time.com:13326";
24
25our $FACEMAP;
26our $TILECACHE;
26our $FACECACHE; 27our $MAPCACHE;
27 28
28our $LAST_REFRESH; 29our $LAST_REFRESH;
29our $NOW; 30our $NOW;
30 31
31our $CFG; 32our $CFG;
38our $FULLSCREEN; 39our $FULLSCREEN;
39our $FONTSIZE; 40our $FONTSIZE;
40 41
41our $MAP; 42our $MAP;
42our $MAPWIDGET; 43our $MAPWIDGET;
44our $BUTTONBAR;
45our $LOGVIEW;
46our $CONSOLE;
47our $METASERVER;
48
49our $GAUGES;
43 50
44our $SDL_ACTIVE; 51our $SDL_ACTIVE;
45our $SDL_EV;
46our %SDL_CB; 52our %SDL_CB;
53
54our $SDL_MIXER;
55our @SOUNDS; # event => file mapping
56our %AUDIO_CHUNKS; # audio files
47 57
48our $ALT_ENTER_MESSAGE; 58our $ALT_ENTER_MESSAGE;
49our $STATUS_LINE; 59our $STATUS_LINE;
50our $DEBUG_STATUS; 60our $DEBUG_STATUS;
51our $BUTTONBAR;
52our $LOGVIEW;
53our $CONSOLE;
54 61
55sub status { 62sub status {
56 $STATUS_LINE->set_text ($_[0]); 63 $STATUS_LINE->set_text ($_[0]);
57 my ($w, $h) = $STATUS_LINE->size_request;
58 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h); 64 $STATUS_LINE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $STATUS_LINE->{h});
59} 65}
60 66
61sub debug { 67sub debug {
62 $DEBUG_STATUS->set_text ($_[0]); 68 $DEBUG_STATUS->set_text ($_[0]);
63 my ($w, $h) = $DEBUG_STATUS->size_request; 69 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
64 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
65} 70}
66 71
67sub start_game { 72sub start_game {
68 status "logging in..."; 73 status "logging in...";
69 74
70 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 75 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
76
77 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
71 78
72 $MAP = new CFClient::Map $mapsize, $mapsize; 79 $MAP = new CFClient::Map $mapsize, $mapsize;
80
81 my ($host, $port) = split /:/, $CFG->{host};
73 82
74 $CONN = new conn 83 $CONN = new conn
75 host => $CFG->{host}, 84 host => $host,
76 port => $CFG->{port}, 85 port => $port || 13327,
77 user => $CFG->{user}, 86 user => $CFG->{user},
78 pass => $CFG->{password}, 87 pass => $CFG->{password},
79 mapw => $mapsize, 88 mapw => $mapsize,
80 maph => $mapsize, 89 maph => $mapsize,
81 ; 90 ;
87 96
88sub stop_game { 97sub stop_game {
89 undef $CONN; 98 undef $CONN;
90} 99}
91 100
92sub config_dialog { 101sub client_setup {
93 my $dialog = new CFClient::UI::FancyFrame 102 my $dialog = new CFClient::UI::FancyFrame
103 title => "Client Setup",
94 child => (my $vbox = new CFClient::UI::VBox); 104 child => (my $vbox = new CFClient::UI::VBox);
95 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
96 $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]);
97 106
98 $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");
99 $table->add (1, 0, my $hbox = new CFClient::UI::HBox); 108 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
100 109
101 $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]);
102 $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");
103 112
104 $mode_slider->connect (changed => sub { 113 $mode_slider->connect (changed => sub {
105 my ($self, $value) = @_; 114 my ($self, $value) = @_;
106 115
107 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
108 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); 117 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
109 }); 118 });
110 $mode_slider->emit (changed => $mode_slider->{range}[0]); 119 $mode_slider->emit (changed => $mode_slider->{range}[0]);
111 120
112 $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");
113 $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 {
114 my ($self, $value) = @_; 123 my ($self, $value) = @_;
115 $CFG->{fullscreen} = $value; 124 $CFG->{fullscreen} = $value;
116 }); 125 });
117 126
118 $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");
119 $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 {
120 my ($self, $value) = @_; 129 my ($self, $value) = @_;
121 $CFG->{fast} = $value; 130 $CFG->{fast} = $value;
122 }); 131 });
123 132
124 $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");
125 $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 {
126 my ($self, $value) = @_; 135 my ($self, $value) = @_;
127 $CFG->{fow_enable} = $value; 136 $CFG->{fow_enable} = $value;
128 }); 137 });
129 138
130 $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");
131 $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 {
132 my ($self, $value) = @_; 141 my ($self, $value) = @_;
133 $CFG->{fow_intensity} = $value; 142 $CFG->{fow_intensity} = $value;
134 }); 143 });
135 144
136 $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");
137 $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 {
138 my ($self, $value) = @_; 147 my ($self, $value) = @_;
139 $CFG->{fow_smooth} = $value; 148 $CFG->{fow_smooth} = $value;
149 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
140 }); 150 });
141 151
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");
159 $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub {
160 $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10);
161 });
162
142 $table->add (1, 6, 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 {
143 destroy_screen (); 164 video_shutdown ();
144 init_screen (); 165 video_init ();
166 });
167
168 $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable");
169 $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub {
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];
145 }); 175# });
176 $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music");
177 $table->add (1, 10, my $hbox = new CFClient::UI::HBox);
178 $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub {
179 $CFG->{bgm_enable} = $_[1];
180 });
181 $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub {
182 $CFG->{bgm_volume} = $_[1];
183 CFClient::MixMusic::volume $_[1] * 128;
184 });
185
186 $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
187 audio_shutdown ();
188 audio_init ();
189 });
190
191 $dialog
192}
193
194sub metaserver_dialog {
195 my $dialog = new CFClient::UI::FancyFrame
196 title => "Metaserver",
197 child => (my $vbox = new CFClient::UI::VBox);
198
199 $vbox->add ($dialog->{table} = new CFClient::UI::Table);
200
201 $dialog
202}
203
204sub update_metaserver {
205 my ($HOST) = @_;
206
207 status "fetching metaserver list...";
208
209 my $buf;
210
211 my $fh = new IO::Socket::INET PeerHost => $META_SERVER, Blocking => 0;
212
213 Event->io (fd => $fh, poll => 'r', cb => sub {
214 my $res = sysread $fh, $buf, 8192, length $buf;
215
216 if (!defined $res) {
217 $_[0]->w->cancel;
218 status "metaserver: $!";
219 } elsif ($res == 0) {
220 $_[0]->w->cancel;
221 status "server list retrieved";
222
223 my $table = $METASERVER->{table};
224
225 $table->clear;
226
227 my @col = qw(Use #Users Host Uptime Version Description);
228 $table->add ($_, 0, new CFClient::UI::Label align => 0, fg => [1, 1, 0], text => $col[$_])
229 for 0 .. $#col;
230
231 my @align = qw(1 0 1 1 -1);
232
233 my $y = 0;
234 for my $m (sort { $b->[3] <=> $a->[3] } map [split /\|/], split /\015?\012/, $buf) {
235 my ($ip, $last, $host, $users, $version, $desc, $ibytes, $obytes, $uptime) = @$m;
236
237 for ($desc) {
238 s/<br>/\n/gi;
239 s/<li>/\n· /gi;
240 s/<.*?>//sgi;
241 s/&/&amp;/g;
242 s/</&lt;/g;
243 s/>/&gt;/g;
244 }
245
246 $uptime = sprintf "%dd %02d:%02d:%02d",
247 (int $m->[8] / 86400),
248 (int $m->[8] / 3600) % 24,
249 (int $m->[8] / 60) % 60,
250 $m->[8] % 60;
251
252 $m = [$users, $host, $uptime, $version, $desc];
253
254 $y++;
255
256 $table->add (0, $y, new CFClient::UI::VBox children => [
257 (new CFClient::UI::Button text => " ", connect_activate => sub {
258 $HOST->set_text ($CFG->{host} = $host);
259 }),
260 (new CFClient::UI::Empty expand => 1),
261 ]);
262
263 $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8)
264 for 0 .. $#$m;
265 }
266 }
267 });
268}
269
270sub server_setup {
271 my $dialog = new CFClient::UI::FancyFrame
272 title => "Server Setup",
273 child => (my $vbox = new CFClient::UI::VBox);
146 274
147 $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup");
148 $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]);
149 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host"); 276 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port");
277
278 {
279 $table->add (1, 2, my $vbox = new CFClient::UI::VBox);
280
150 $table->add (1, 2, 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 {
151 my ($self, $value) = @_; 282 my ($self, $value) = @_;
152 $CFG->{host} = $value; 283 $CFG->{host} = $value;
153 }); 284 });
154 285
155 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port"); 286 $METASERVER = metaserver_dialog;
156 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port}, connect_changed => sub { 287
157 my ($self, $value) = @_; 288 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
158 $CFG->{port} = $value; 289 update_metaserver $HOST;
159 }); 290 });
291 }
160 292
161 $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");
162 $table->add (1, 4, my $user = 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 {
163 my ($self, $value) = @_; 295 my ($self, $value) = @_;
164 $CFG->{user} = $value; 296 $CFG->{user} = $value;
165 }); 297 });
166 298
167 $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");
168 $table->add (1, 5, my $pass = 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 {
169 my ($self, $value) = @_; 301 my ($self, $value) = @_;
170 $CFG->{password} = $value; 302 $CFG->{password} = $value;
171 }); 303 });
172 304
173 $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");
174 $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 {
175 my ($self, $value) = @_; 307 my ($self, $value) = @_;
176 $CFG->{say_command} = $value; 308 $CFG->{say_command} = $value;
177 }); 309 });
178 310
179 $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");
180 $table->add (1, 7, new CFClient::UI::Slider 312 $table->add (1, 7, new CFClient::UI::Slider
181 req_w => 100, 313 req_w => 100,
182 range => [$CFG->{mapsize}, 10, 100 + 1, 1], 314 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
183 connect_changed => sub { 315 connect_changed => sub {
184 my ($self, $value) = @_; 316 my ($self, $value) = @_;
189 321
190 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub { 322 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
191 start_game; 323 start_game;
192 }); 324 });
193 325
194 $vbox->add (my $hbox = new CFClient::UI::HBox);
195
196 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
197 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
198 status "Configuration Saved";
199 });
200
201 $dialog 326 $dialog
202} 327}
203 328
204sub console_window { 329sub message_window {
205 my $window = new CFClient::UI::FancyFrame 330 my $window = new CFClient::UI::FancyFrame
331 title => "Messages",
206 border_bg => [1, 1, 1, 0.5], 332 border_bg => [1, 1, 1, 0.5],
207 bg => [0.3, 0.3, 0.3, 0.8], 333 bg => [0.3, 0.3, 0.3, 0.8],
334 user_w => int $::WIDTH / 3,
335 user_h => int $::HEIGHT / 5,
208 child => (my $vbox = new CFClient::UI::VBox); 336 child => (my $vbox = new CFClient::UI::VBox);
209 337
210 $vbox->add ($LOGVIEW = new CFClient::UI::TextView expand => 1); 338 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
339 expand => 1,
340 fontsize => $::CFG->{log_fontsize},
341 );
342
211 $vbox->add (my $input = new CFClient::UI::LineEntry); 343 $vbox->add (my $input = new CFClient::UI::Entry
344 connect_focus_in => sub {
345 my ($input, $prev_focus) = @_;
346
347 delete $input->{refocus_map};
348
349 if ($prev_focus == $MAPWIDGET && $input->{auto_activated}) {
350 $input->{refocus_map} = 1;
351 }
352 delete $input->{auto_activated};
353 },
212 $input->connect (activate => sub { 354 connect_activate => sub {
213 my ($input, $text) = @_; 355 my ($input, $text) = @_;
214 $input->set_text (''); 356 $input->set_text ('');
215 357
216 if ($text =~ /^\/(.*)/) { 358 if ($text =~ /^\/(.*)/) {
217 $::CONN->user_send ("command $1"); 359 $::CONN->user_send ($1);
218 } else { 360 } else {
219 my $say_cmd = $::CFG->{say_command} || 'say'; 361 my $say_cmd = $::CFG->{say_command} || 'say';
220 $::CONN->user_send ("command $say_cmd $text"); 362 $::CONN->user_send ("$say_cmd $text");
221 } 363 }
364 if ($input->{refocus_map}) {
365 delete $input->{refocus_map};
366 $MAPWIDGET->focus_in
222 1 367 }
223 }); 368 },
224 $input->connect (escape => sub { 369 connect_escape => sub {
225 $MAPWIDGET->focus_in 370 $MAPWIDGET->focus_in
226 }); 371 },
227 $input->focus_in; 372 );
228 373
229 $CONSOLE = { 374 $CONSOLE = {
230 window => $window, 375 window => $window,
231 input => $input 376 input => $input
232 }; 377 };
233 378
234 $window 379 $window
235} 380}
236 381
237sub sdl_init { 382sub sdl_init {
238 SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO 383 CFClient::SDL_Init
239 and die "SDL::Init failed!\n"; 384 and die "SDL::Init failed!\n";
240} 385}
241 386
242sub init_screen { 387sub video_init {
243 sdl_init; 388 sdl_init;
244 389
245 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; 390 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
246 $FULLSCREEN = $CFG->{fullscreen}; 391 $FULLSCREEN = $CFG->{fullscreen};
247 $FAST = $CFG->{fast}; 392 $FAST = $CFG->{fast};
248 393
249 SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; 394 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
250 SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5;
251 SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5;
252 SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 0;
253
254 SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0;
255 SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0;
256 SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0;
257 SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0;
258
259 SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1;
260 SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15;
261 SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0;
262
263 SDL::SetVideoMode $WIDTH, $HEIGHT, 0,
264 SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF
265 | ($FULLSCREEN ? SDL_FULLSCREEN : 0)
266 or die "SDL::SetVideoMode failed!\n"; 395 or die "SDL_SetVideoMode failed!\n";
267
268 SDL::WMSetCaption "Crossfire+ Client", "Crossfire+";
269
270 $SDL_EV = new SDL::Event;
271 $SDL_EV->set_unicode (1);
272 396
273 $SDL_ACTIVE = 1; 397 $SDL_ACTIVE = 1;
274 398
275 $LAST_REFRESH = time - 0.01; 399 $LAST_REFRESH = time - 0.01;
276 400
277 CFClient::gl_init; 401 CFClient::gl_init;
278 402
279 $FONTSIZE = int $HEIGHT / 40; 403 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
280 404
281 ############################################################################# 405 #############################################################################
282 406
283 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; 407 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
284 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); 408 $DEBUG_STATUS->show;
285 409
286 $STATUS_LINE = new CFClient::UI::Label 410 $STATUS_LINE = new CFClient::UI::Label
287 padding => 0, 411 padding => 0,
288 y => $HEIGHT * 44 / 45 - $FONTSIZE; 412 y => $HEIGHT - $FONTSIZE * 1.8;
289 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); 413 $STATUS_LINE->show;
290 414
291 $ALT_ENTER_MESSAGE = new CFClient::UI::Label 415 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
292 padding => 0, 416 padding => 0,
293 y => $HEIGHT * 44 / 45, 417 fontsize => 0.8,
294 height => $HEIGHT / 45,
295 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 418 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
296 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 419 $ALT_ENTER_MESSAGE->show;
420 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
297 421
298 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET = new CFClient::UI::MapWidget); 422 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
299 $MAPWIDGET->focus_in; 423 $MAPWIDGET->focus_in;
300 $MAPWIDGET->connect (activate_console => sub { 424 $MAPWIDGET->connect (activate_console => sub {
425 my ($mapwidget, $preset) = @_;
426
301 if ($CONSOLE) { 427 if ($CONSOLE) {
428 $CONSOLE->{input}->{auto_activated} = 1;
302 $CONSOLE->{input}->focus_in; 429 $CONSOLE->{input}->focus_in;
430
431 if ($preset && $CONSOLE->{input}->get_text eq '') {
432 $CONSOLE->{input}->set_text ($preset);
433 }
303 } 434 }
304 }); 435 });
305 436
306 $CFClient::UI::TOPLEVEL->add ($BUTTONBAR = new CFClient::UI::HBox); 437 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
307 438
308 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Setup", other => config_dialog, state => 1); 439 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
309 $BUTTONBAR->add (my $setup = new CFClient::UI::Flopper x => 0, y => 0, text => "Console", other => console_window); 440 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
310} 441 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
311 442
312sub destroy_screen { 443 $BUTTONBAR->add (new CFClient::UI::Button text => "Save Config", connect_activate => sub {
444 CFClient::write_cfg "$Crossfire::VARDIR/pclientrc";
445 status "Configuration Saved";
446 });
447
448 $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup
449
450 my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats");
451 $tgw->add (my $hbox = new CFClient::UI::HBox ());
452
453 $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp'));
454 $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana'));
455 $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace'));
456 $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food'));
457
458 $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg };
459 $CFClient::UI::ROOT->add ($tgw);
460}
461
462sub video_shutdown {
313 $CFClient::UI::TOPLEVEL->{children} = []; 463 $CFClient::UI::ROOT->{children} = [];
314 undef $SDL_ACTIVE; 464 undef $SDL_ACTIVE;
465}
466
467my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d#
468my $bgmusic;#TODO#hack#d#
469
470sub audio_music_finished {
471 return unless $CFG->{bgm_enable};
472
473 # TODO: hack, do play loop and mood music
474 $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]";
475 $bgmusic->play (0);
476
477 push @bgmusic, shift @bgmusic;
478}
479
480sub audio_init {
481 if ($CFG->{audio_enable}) {
482 if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") {
483
484 $SDL_MIXER = !CFClient::Mix_OpenAudio;
485 CFClient::Mix_AllocateChannels 8;
486 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
487
488 audio_music_finished;
489
490 while (<$fh>) {
491 next if /^\s*#/;
492 next if /^\s*$/;
493
494 my ($file, $volume, $event) = split /\s+/, $_, 3;
495
496 push @SOUNDS, "$volume,$file";
497
498 $AUDIO_CHUNKS{"$volume,$file"} ||= do {
499 my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file";
500 $chunk->volume ($volume * 128 / 100);
501 $chunk
502 };
503 }
504 } else {
505 status "unable to open sound config: $!";
506 }
507 }
508}
509
510sub audio_shutdown {
511 CFClient::Mix_CloseAudio if $SDL_MIXER;
315 undef $SDL_EV; 512 undef $SDL_MIXER;
316 SDL::Quit; 513 @SOUNDS = ();
514 %AUDIO_CHUNKS = ();
317} 515}
318 516
319my %animate_object; 517my %animate_object;
320my $animate_timer; 518my $animate_timer;
321 519
329 debug sprintf "%3.2f", $fps; 527 debug sprintf "%3.2f", $fps;
330 528
331 $want_refresh = 0; 529 $want_refresh = 0;
332 $can_refresh = 0; 530 $can_refresh = 0;
333 531
334 glViewport 0, 0, $WIDTH, $HEIGHT;
335
336 glMatrixMode GL_PROJECTION;
337 glLoadIdentity;
338 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
339 glMatrixMode GL_MODELVIEW;
340 glLoadIdentity;
341
342 glClearColor +($CFG->{fow_intensity}) x 3, 1;
343 glClear GL_COLOR_BUFFER_BIT;
344
345 $CFClient::UI::TOPLEVEL->draw; 532 $CFClient::UI::ROOT->draw;
346 533
347 SDL::GLSwapBuffers; 534 CFClient::SDL_GL_SwapBuffers;
348 535
349 $LAST_REFRESH = $NOW; 536 $LAST_REFRESH = $NOW;
350} 537}
351 538
352my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { 539my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
353 $NOW = time; 540 $NOW = time;
354 541
355 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 542 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
356 while $SDL_EV->poll; 543 for CFClient::SDL_PollEvent;
357 544
358 if (%animate_object) { 545 if (%animate_object) {
359 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; 546 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
360 $want_refresh++; 547 $want_refresh++;
361 } 548 }
381 delete $animate_object{$widget}; 568 delete $animate_object{$widget};
382} 569}
383 570
384@conn::ISA = Crossfire::Protocol::; 571@conn::ISA = Crossfire::Protocol::;
385 572
573sub conn::stats_update {
574 my ($self, $stats) = @_;
575
576 # i love text protocols!!!
577 # FIXME: the stats are somehow weird
578 my $hp = $stats->{1};
579 my $hp_m = $stats->{2};
580 my $sp = $stats->{3};
581 my $sp_m = $stats->{4};
582 my $fo = $stats->{18};
583 my $fo_m = 999;
584 my $gr = $stats->{23};
585 my $gr_m = $stats->{24};
586
587 #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n";
588 $GAUGES->{hp} ->set_value ($hp, $hp_m);
589 $GAUGES->{mana} ->set_value ($sp, $sp_m);
590 $GAUGES->{food} ->set_value ($fo, $fo_m);
591 $GAUGES->{grace}->set_value ($gr, $gr_m);
592}
593
386sub conn::user_send { 594sub conn::user_send {
387 my ($self, $command) = @_; 595 my ($self, $command) = @_;
388 596
389 $self->send ($command); 597 $self->send_command ($command);
390 status $command; 598 status $command;
599}
600
601sub conn::map_scroll {
602 my ($self, $dx, $dy) = @_;
603
604 $MAP->scroll ($dx, $dy);
391} 605}
392 606
393sub conn::feed_map1a { 607sub conn::feed_map1a {
394 my ($self, $data) = @_; 608 my ($self, $data) = @_;
395 609
396# $self->Crossfire::Protocol::feed_map1a ($data); 610# $self->Crossfire::Protocol::feed_map1a ($data);
397 611
398 $MAP->scroll (delete $self->{delayed_scroll_x}, delete $self->{delayed_scroll_y});
399 $MAP->map1a_update ($data); 612 $MAP->map1a_update ($data);
400 $MAPWIDGET->update; 613 $MAPWIDGET->update;
401} 614}
402 615
403#sub conn::map_update { 616sub conn::flush_map {
404# my ($self, $dirty) = @_; 617 my ($self) = @_;
405# 618
406# $MAPWIDGET->update; 619 my $map_info = delete $self->{map_info}
407#} 620 or return;
621
622 my ($hash, $x, $y, $w, $h) = @$map_info;
623
624 my $data = $MAP->get_rect ($x, $y, $w, $h);
625 $MAPCACHE->put ($hash => Compress::LZF::compress $data);
626 #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d#
627}
408 628
409sub conn::map_clear { 629sub conn::map_clear {
410 my ($self) = @_; 630 my ($self) = @_;
411 631
632 $self->flush_map;
633 delete $self->{neigh_map};
634
412 $MAP->clear; 635 $MAP->clear;
636}
413 637
414# refresh; 638
639sub conn::load_map($$$) {
640 my ($self, $hash, $x, $y) = @_;
641
642 if (defined (my $data = $MAPCACHE->get ($hash))) {
643 $data = Compress::LZF::decompress $data;
644 #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d#
645 for my $id ($MAP->set_rect ($x, $y, $data)) {
646 my $data = $TILECACHE->get ($id)
647 or next;
648
649 $self->set_texture ($id => $data);
650 }
651 }
652}
653
654# this method does a "flood fill" into every tile direction
655# it assumes that tiles are arranged in a rectangular grid,
656# i.e. a map is the same as the left of the right map etc.
657# failure to comply are harmless and result in display errors
658# at worst.
659sub conn::flood_fill {
660 my ($self, $gx, $gy, $path, $hash, $flags) = @_;
661
662 # the server does not allow map paths > 6
663 return if 6 <= length $path;
664
665 my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}};
666
667 for (
668 [1, 0, -1],
669 [2, 1, 0],
670 [3, 0, 1],
671 [4, -1, 0],
672 ) {
673 my ($tile, $dx, $dy) = @$_;
674
675 my $gx = $gx + $dx;
676 my $gy = $gy + $dy;
677
678 next unless $flags & (1 << ($tile - 1));
679 next if $self->{neigh_grid}{$gx, $gy}++;
680
681 my $neigh = $self->{neigh_map}{$hash} ||= [];
682 if (my $info = $neigh->[$tile]) {
683 my ($flags, $x, $y, $w, $h, $hash) = @$info;
684
685 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
686 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
687
688 } else {
689 $self->send_mapinfo ("spatial $path$tile", sub {
690 my ($mode, $flags, $x, $y, $w, $h, $hash) = @_;
691
692 return if $mode ne "spatial";
693
694 $x += $MAP->ox;
695 $y += $MAP->oy;
696
697 $self->load_map ($hash, $x, $y)
698 unless $self->{neigh_map}{$hash}[5]++;#d#
699
700 $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash];
701
702 $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags)
703 if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1;
704 });
705 }
706 }
707}
708
709sub conn::map_change {
710 my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_;
711
712 $self->flush_map;
713
714 my ($ox, $oy) = ($::MAP->ox, $::MAP->oy);
715
716 my $mapmapw = 250;
717 my $mapmaph = 250;
718
719 $self->{neigh_rect} = [
720 $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5,
721 $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h,
722 ];
723
724 delete $self->{neigh_grid};
725 $self->flood_fill (0, 0, "", $hash, $flags);
726
727 $x += $ox;
728 $y += $oy;
729
730 $self->{map_info} = [$hash, $x, $y, $w, $h];
731
732 $self->load_map ($hash, $x, $y);
415} 733}
416 734
417sub conn::face_find { 735sub conn::face_find {
418 my ($self, $face) = @_; 736 my ($self, $facenum, $face) = @_;
419 737
420 $FACECACHE->{"$face->{chksum},$face->{name}"} 738 my $hash = "$face->{chksum},$face->{name}";
739
740 my $id = $FACEMAP->get ($hash);
741
742 unless ($id) {
743 # create new id for face
744 # i love transactions
745 for (1..100) {
746 my $txn = $CFClient::DB_ENV->txn_begin;
747 my $status = $FACEMAP->db_get (id => $id, BerkeleyDB::DB_RMW);
748 if ($status == 0 || $status == BerkeleyDB::DB_NOTFOUND) {
749 $id++;
750 if ($FACEMAP->put (id => $id) == 0
751 && $FACEMAP->put ($hash => $id) == 0) {
752 $txn->txn_commit;
753
754 goto gotid;
755 }
756 }
757 $txn->abort;
758 }
759
760 CFClient::fatal "maximum number of transaction retries reached - database problems?";
761 }
762
763gotid:
764 $face->{id} = $id;
765 $MAP->set_face ($facenum => $id);
766 $TILECACHE->get ($id)
421} 767}
422 768
423sub conn::face_update { 769sub conn::face_update {
424 my ($self, $facenum, $face) = @_; 770 my ($self, $facenum, $face) = @_;
425 771
426 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 772 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
427 773
428 my $tex = $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; 774 $self->set_texture ($face->{id} => delete $face->{image});
775}
429 776
777sub conn::set_texture {
778 my ($self, $id, $data) = @_;
779
780 $self->{texture}[$id] ||= do {
781 my $tex =
782 new_from_image CFClient::Texture
783 $data, minify => 1;
784
430 $MAP->set_texture ($facenum, @$tex{qw(name w h s t)}); 785 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
431 $MAPWIDGET->update; 786 $MAPWIDGET->update;
787
788 $tex
789 };
790}
791
792sub conn::sound_play {
793 my ($self, $x, $y, $soundnum, $type) = @_;
794
795 $SDL_MIXER
796 or return;
797
798 my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]}
799 or return;
800
801 $chunk->play;
802# warn "sound $x,$y,$soundnum,$type\n";#d#
432} 803}
433 804
434sub conn::query { 805sub conn::query {
435 my ($self, $flags, $prompt) = @_; 806 my ($self, $flags, $prompt) = @_;
436 807
437 #TODO 808 #TODO, display dialog with relevant information
438 warn "<<<<QUERY:$flags:$prompt>>>\n";#d# 809 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
439} 810}
440 811
441sub conn::drawinfo { 812sub conn::drawinfo {
442 my ($self, $color, $text) = @_; 813 my ($self, $color, $text) = @_;
443 814
444 my @color = ( 815 my @color = (
445 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00], 816 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
446 [1.00, 1.00, 1.00], 817 [1.00, 1.00, 1.00],
447 [0.00, 0.00, 0.55], 818 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
448 [1.00, 0.00, 0.00], 819 [1.00, 0.00, 0.00],
449 [1.00, 0.54, 0.00], 820 [1.00, 0.54, 0.00],
450 [0.11, 0.56, 1.00], 821 [0.11, 0.56, 1.00],
451 [0.93, 0.46, 0.00], 822 [0.93, 0.46, 0.00],
452 [0.18, 0.54, 0.34], 823 [0.18, 0.54, 0.34],
458 ); 829 );
459 830
460 $LOGVIEW->add_paragraph ($color[$color], $text); 831 $LOGVIEW->add_paragraph ($color[$color], $text);
461} 832}
462 833
834sub conn::spell_add {
835 my ($self, $spell) = @_;
836
837 $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub {
838 });
839 $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub {
840 });
841}
842
843sub conn::spell_delete {
844 my ($self, $spell) = @_;
845}
846
847sub conn::addme_success {
848 my ($self) = @_;
849
850 for my $skill (values %{$self->{skill_info}}) {
851 $MAPWIDGET->add_command ("ready_skill $skill", "", sub {
852 });
853 $MAPWIDGET->add_command ("use_skill $skill", "", sub {
854 });
855 }
856}
857
463%SDL_CB = ( 858%SDL_CB = (
464 SDL_QUIT() => sub { 859 CFClient::SDL_QUIT => sub {
465 Event::unloop -1; 860 Event::unloop -1;
466 }, 861 },
467 SDL_VIDEORESIZE() => sub { 862 CFClient::SDL_VIDEORESIZE => sub {
468 }, 863 },
469 SDL_VIDEOEXPOSE() => sub { 864 CFClient::SDL_VIDEOEXPOSE => \&refresh,
470 refresh; 865 CFClient::SDL_ACTIVEEVENT => sub {
866# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
471 }, 867 },
472 SDL_KEYDOWN() => sub { 868 CFClient::SDL_KEYDOWN => sub {
473 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 869 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
474 # alt-enter 870 # alt-enter
475 destroy_screen; 871 video_shutdown;
476 $CFG->{fullscreen} = !$CFG->{fullscreen}; 872 $CFG->{fullscreen} = !$CFG->{fullscreen};
477 init_screen; 873 video_init;
478 } else { 874 } else {
479 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 875 CFClient::UI::feed_sdl_key_down_event ($_[0]);
480 } 876 }
481 }, 877 },
482 SDL_KEYUP() => sub { 878 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
483 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 879 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
484 }, 880 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
485 SDL_MOUSEMOTION() => sub { 881 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
486 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 882 CFClient::SDL_USEREVENT => \&audio_music_finished,
487 },
488 SDL_MOUSEBUTTONDOWN() => sub {
489 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
490 },
491 SDL_MOUSEBUTTONUP() => sub {
492 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
493 },
494 SDL_ACTIVEEVENT() => sub {
495# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
496 },
497); 883);
498 884
499############################################################################# 885#############################################################################
500 886
887$SIG{INT} = $SIG{TERM} = sub { exit };
888
889$TILECACHE = CFClient::db_table "tilecache";
890$FACEMAP = CFClient::db_table "facemap";
891
501CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 892CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
502 893
503my %DEF_CFG = ( 894my %DEF_CFG = (
895 sdl_mode => 0,
504 width => 640, 896 width => 640,
505 height => 480, 897 height => 480,
898 fullscreen => 0,
506 fast => 0, 899 fast => 0,
507 fow_enable => 1, 900 fow_enable => 1,
508 fow_intensity => 0.45, 901 fow_intensity => 0.45,
509 fow_smooth => 0, 902 fow_smooth => 0,
510 fullscreen => 0, 903 gui_fontsize => 1,
511 sdl_mode => 0, 904 log_fontsize => 14,
512 mapsize => 100, 905 mapsize => 100,
513 host => "crossfire.schmorp.de", 906 host => "crossfire.schmorp.de",
514 port => 13327,
515 say_command => 'say', 907 say_command => 'say',
908 audio_enable => 1,
909 bgm_enable => 1,
910 bgm_volume => 0.25,
516); 911);
517 912
518while (my ($k, $v) = each %DEF_CFG) { 913while (my ($k, $v) = each %DEF_CFG) {
519 $CFG->{$k} = $v unless exists $CFG->{$k}; 914 $CFG->{$k} = $v unless exists $CFG->{$k};
520} 915}
521 916
522sdl_init; 917sdl_init;
523 918
524@SDL_MODES = reverse 919@SDL_MODES = reverse
525 grep $_->[0] >= 640 && $_->[1] >= 480, 920 grep $_->[0] >= 640 && $_->[1] >= 480,
526 map [SDL::RectW ($_), SDL::RectH ($_)], 921 CFClient::SDL_ListModes;
527 @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL };
528 922
529@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; 923@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
530 924
531$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; 925$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
532
533init_screen;
534 926
535{ 927{
536 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); 928 my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf);
537 929
538 CFClient::add_font $_ for @fonts; 930 CFClient::add_font $_ for @fonts;
539 CFClient::set_font $fonts[0]; 931 CFClient::set_font $fonts[0];
540} 932}
541 933
542$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 934video_init;
935audio_init;
543 936
544Event::loop; 937Event::loop;
545 938
546Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 939END { CFClient::SDL_Quit }
547 940
941

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines