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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines