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.82 by root, Wed Apr 12 12:16:59 2006 UTC vs.
Revision 1.153 by root, Thu Apr 20 09:13:32 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3use strict; 3use strict;
4use utf8; 4use utf8;
5 5
6use Glib; 6use Time::HiRes 'time';
7use Gtk2 -init;
8
9use SDL;
10use SDL::App;
11use SDL::Event; 7use Event;
12use SDL::Surface;
13use SDL::OpenGL;
14use SDL::OpenGL::Constants;
15 8
16use Crossfire; 9use Crossfire;
17use Crossfire::Protocol; 10use Crossfire::Protocol;
18 11
12use Compress::LZF;
13
19use CFClient; 14use CFClient;
20use CFClient::UI; 15use CFClient::UI;
16use CFClient::MapWidget;
21 17
22our $VERSION = '0.1'; 18our $VERSION = '0.1';
23 19
24my $MAX_FPS = 60; 20my $MAX_FPS = 60;
25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame 21my $MIN_FPS = 5; # unused as of yet
26 22
23our $META_SERVER = "crossfire.real-time.com:13326";
24
25our $FACEMAP;
26our $TILECACHE;
27our $FACECACHE; 27our $MAPCACHE;
28
29our $LAST_REFRESH;
30our $NOW;
28 31
29our $CFG; 32our $CFG;
30our $CONN; 33our $CONN;
31our $FAST; # fast, low-quality mode 34our $FAST; # fast, low-quality mode, possibly useful for software-rendering
32 35
33our @SDL_MODES; 36our @SDL_MODES;
34our $WIDTH; 37our $WIDTH;
35our $HEIGHT; 38our $HEIGHT;
36our $FULLSCREEN; 39our $FULLSCREEN;
40our $FONTSIZE;
37 41
38our $NOW; 42our $MAP;
39
40our $MAPWIDGET; 43our $MAPWIDGET;
41our $FONTSIZE; 44our $BUTTONBAR;
45our $LOGVIEW;
46our $CONSOLE;
47our $METASERVER;
42 48
49our $GAUGES;
50
43our $SDL_TIMER; 51our $SDL_ACTIVE;
44our $SDL_APP;
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;
51 61
52my $last_refresh;
53my %ANIMATE;
54my $refresh_handler;
55
56sub status { 62sub status {
57 $STATUS_LINE->set_text ($_[0]); 63 $STATUS_LINE->set_text ($_[0]);
58 my ($w, $h) = $STATUS_LINE->size_request;
59 $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});
60} 65}
61 66
62sub debug { 67sub debug {
63 $DEBUG_STATUS->set_text ($_[0]); 68 $DEBUG_STATUS->set_text ($_[0]);
64 my ($w, $h) = $DEBUG_STATUS->size_request; 69 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0, $DEBUG_STATUS->{w}, $DEBUG_STATUS->{h});
65 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
66} 70}
67 71
68sub config_dialog { 72sub start_game {
69 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, 73 status "logging in...";
70 child => (my $vbox = new CFClient::UI::VBox);
71 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
72 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
73 74
74 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode"); 75 my $mapsize = List::Util::min 32, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
75 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
76 76
77 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]); 77 $MAPCACHE = CFClient::db_table "mapcache_$CFG->{host}";
78 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
79 78
80 $mode_slider->connect (changed => sub { 79 $MAP = new CFClient::Map $mapsize, $mapsize;
81 my ($self, $value) = @_;
82 80
83 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; 81 my ($host, $port) = split /:/, $CFG->{host};
84 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
85 });
86 $mode_slider->emit (changed => $mode_slider->{range}[0]);
87
88 $table->add (1, 1, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
89 warn "apply\n";
90 });
91 82
92 $vbox->add (new CFClient::UI::Label align => 0, text => "Server");
93 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
94 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
95 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host});
96
97 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port");
98 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port});
99
100 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
101 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user});
102
103 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
104 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
105
106 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size");
107 $table->add (1, 6, new CFClient::UI::Slider
108 req_w => 100,
109 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
110 connect_changed => sub {
111 my ($self, $value) = @_;
112
113 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
114 },
115 );
116
117 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
118 warn "login\n";
119 });
120
121 $vbox->add (my $hbox = new CFClient::UI::HBox);
122
123 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
124 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
125 status "Configuration Saved";
126 });
127 $CFClient::UI::TOPLEVEL->add ($dialog);
128}
129
130sub init_screen {
131 $SDL_APP = new SDL::App
132 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
133 -title => "Crossfire+ Client",
134 -width => $WIDTH,
135 -height => $HEIGHT,
136 -opengl => 1,
137 -red_size => 5,
138 -green_size => 5,
139 -blue_size => 5,
140 -alpha_size => 0,
141 -double_buffer => 1,
142 -fullscreen => $FULLSCREEN,
143 -resizeable => 0;
144
145 $SDL_EV = new SDL::Event;
146 $SDL_EV->set_unicode (1);
147
148 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub {
149 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
150 while $SDL_EV->poll;
151
152 1
153 };
154
155 $last_refresh = SDL::GetTicks;
156
157 CFClient::gl_init;
158
159 $FONTSIZE = int $HEIGHT / 40;
160
161 #############################################################################
162
163 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
164 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
165
166 $STATUS_LINE = new CFClient::UI::Label
167 padding => 0,
168 y => $HEIGHT * 49 / 50 - $FONTSIZE;
169 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
170
171 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
172 padding => 0,
173 y => $HEIGHT * 49 / 50,
174 height => $HEIGHT / 50,
175 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
176 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
177
178 $MAPWIDGET = new CFClient::UI::MapWidget;
179 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
180 $MAPWIDGET->focus_in;
181
182 config_dialog;
183}
184
185sub destroy_screen {
186 $CFClient::UI::TOPLEVEL->{children} = [];
187 remove Glib::Source $SDL_TIMER;
188 undef $SDL_APP;
189 undef $SDL_EV;
190 SDL::Quit;
191}
192
193sub start_game {
194 $WIDTH = $CFG->{width};
195 $HEIGHT = $CFG->{height};
196 $FULLSCREEN = 0;
197
198 init_screen;
199
200 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
201
202 $CONN = new conn 83 $CONN = new conn
203 host => $CFG->{host}, 84 host => $host,
204 port => $CFG->{port}, 85 port => $port || 13327,
205 user => $CFG->{user}, 86 user => $CFG->{user},
206 pass => $CFG->{password}, 87 pass => $CFG->{password},
207 mapw => $mapsize, 88 mapw => $mapsize,
208 maph => $mapsize, 89 maph => $mapsize,
209 ; 90 ;
210 91
92 status "login successful";
93
211 CFClient::lowdelay fileno $CONN->{fh}; 94 CFClient::lowdelay fileno $CONN->{fh};
212} 95}
213 96
214sub stop_game { 97sub stop_game {
215 remove Glib::Source $refresh_handler if $refresh_handler;
216 undef $refresh_handler;
217
218 undef $CONN; 98 undef $CONN;
219 destroy_screen;
220} 99}
221 100
222sub force_refresh { 101sub client_setup {
223 glViewport 0, 0, $WIDTH, $HEIGHT; 102 my $dialog = new CFClient::UI::FancyFrame
103 title => "Client Setup",
104 child => (my $vbox = new CFClient::UI::VBox);
105 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
224 106
225 glMatrixMode GL_PROJECTION; 107 $table->add (0, 0, new CFClient::UI::Label valign => 0, align => 1, text => "Video Mode");
226 glLoadIdentity; 108 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
227 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
228 glMatrixMode GL_MODELVIEW;
229 glLoadIdentity;
230 109
231 glClear GL_COLOR_BUFFER_BIT; 110 $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_label = new CFClient::UI::Label align => 0, valign => 0, height => 0.8, template => "9999x9999");
232 112
233 $CFClient::UI::TOPLEVEL->draw; 113 $mode_slider->connect (changed => sub {
114 my ($self, $value) = @_;
234 115
235 SDL::GLSwapBuffers; 116 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
236} 117 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
118 });
119 $mode_slider->emit (changed => $mode_slider->{range}[0]);
237 120
238my $FPS; 121 $table->add (0, 1, new CFClient::UI::Label valign => 0, align => 1, text => "Fullscreen");
122 $table->add (1, 1, new CFClient::UI::CheckBox state => $CFG->{fullscreen}, connect_changed => sub {
123 my ($self, $value) = @_;
124 $CFG->{fullscreen} = $value;
125 });
239 126
240sub refresh { 127 $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Fast & Ugly");
241 $refresh_handler ||= add Glib::Idle sub { 128 $table->add (1, 2, new CFClient::UI::CheckBox state => $CFG->{fast}, connect_changed => sub {
242 if ($SDL_APP) { 129 my ($self, $value) = @_;
243 $NOW = SDL::GetTicks; 130 $CFG->{fast} = $value;
131 });
244 132
245 if ($NOW - $last_refresh < $TICKS_PER_FRAME) { 133 $table->add (0, 3, new CFClient::UI::Label valign => 0, align => 1, text => "Fog of War");
246 SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); 134 $table->add (1, 3, new CFClient::UI::CheckBox state => $CFG->{fow_enable}, connect_changed => sub {
247 $NOW = SDL::GetTicks; 135 my ($self, $value) = @_;
136 $CFG->{fow_enable} = $value;
137 });
138
139 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Intensity");
140 $table->add (1, 4, new CFClient::UI::Slider range => [$CFG->{fow_intensity}, 0, 1 + 0.001, 0.001], connect_changed => sub {
141 my ($self, $value) = @_;
142 $CFG->{fow_intensity} = $value;
143 });
144
145 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "FoW Smooth");
146 $table->add (1, 5, new CFClient::UI::CheckBox state => $CFG->{fow_smooth}, connect_changed => sub {
147 my ($self, $value) = @_;
148 $CFG->{fow_smooth} = $value;
149 status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2;
150 });
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
163 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
164 video_shutdown ();
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 ();
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;
248 } 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);
274
275 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
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
281 $vbox->add (my $HOST = new CFClient::UI::Entry expand => 1, text => $CFG->{host}, connect_changed => sub {
282 my ($self, $value) = @_;
283 $CFG->{host} = $value;
284 });
285
286 $METASERVER = metaserver_dialog;
287
288 $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub {
289 update_metaserver $HOST;
290 });
291 }
292
293 $table->add (0, 4, new CFClient::UI::Label valign => 0, align => 1, text => "Username");
294 $table->add (1, 4, new CFClient::UI::Entry text => $CFG->{user}, connect_changed => sub {
295 my ($self, $value) = @_;
296 $CFG->{user} = $value;
297 });
298
299 $table->add (0, 5, new CFClient::UI::Label valign => 0, align => 1, text => "Password");
300 $table->add (1, 5, new CFClient::UI::Entry text => $CFG->{password}, hidden => 1, connect_changed => sub {
301 my ($self, $value) = @_;
302 $CFG->{password} = $value;
303 });
304
305 $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "Def. say cmd");
306 $table->add (1, 6, my $saycmd = new CFClient::UI::Entry text => $CFG->{say_command}, connect_changed => sub {
307 my ($self, $value) = @_;
308 $CFG->{say_command} = $value;
309 });
310
311 $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Map Size");
312 $table->add (1, 7, new CFClient::UI::Slider
313 req_w => 100,
314 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
315 connect_changed => sub {
316 my ($self, $value) = @_;
317
318 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
319 },
320 );
321
322 $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
323 start_game;
324 });
325
326 $dialog
327}
328
329sub message_window {
330 my $window = new CFClient::UI::FancyFrame
331 title => "Messages",
332 border_bg => [1, 1, 1, 0.5],
333 bg => [0.3, 0.3, 0.3, 0.8],
334 user_w => int $::WIDTH / 3,
335 user_h => int $::HEIGHT / 5,
336 child => (my $vbox = new CFClient::UI::VBox);
337
338 $vbox->add ($LOGVIEW = new CFClient::UI::TextView
339 expand => 1,
340 fontsize => $::CFG->{log_fontsize},
341 );
342
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 },
354 connect_activate => sub {
355 my ($input, $text) = @_;
356 $input->set_text ('');
357
358 if ($text =~ /^\/(.*)/) {
359 $::CONN->user_send ($1);
360 } else {
361 my $say_cmd = $::CFG->{say_command} || 'say';
362 $::CONN->user_send ("$say_cmd $text");
363 }
364 if ($input->{refocus_map}) {
365 delete $input->{refocus_map};
366 $MAPWIDGET->focus_in
367 }
368 },
369 connect_escape => sub {
370 $MAPWIDGET->focus_in
371 },
372 );
373
374 $CONSOLE = {
375 window => $window,
376 input => $input
377 };
378
379 $window
380}
381
382sub sdl_init {
383 CFClient::SDL_Init
384 and die "SDL::Init failed!\n";
385}
386
387sub video_init {
388 sdl_init;
389
390 ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] };
391 $FULLSCREEN = $CFG->{fullscreen};
392 $FAST = $CFG->{fast};
393
394 CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN
395 or die "SDL_SetVideoMode failed!\n";
396
397 $SDL_ACTIVE = 1;
398
399 $LAST_REFRESH = time - 0.01;
400
401 CFClient::gl_init;
402
403 $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize};
404
405 #############################################################################
406
407 $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100;
408 $DEBUG_STATUS->show;
409
410 $STATUS_LINE = new CFClient::UI::Label
411 padding => 0,
412 y => $HEIGHT - $FONTSIZE * 1.8;
413 $STATUS_LINE->show;
414
415 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
416 padding => 0,
417 fontsize => 0.8,
418 markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
419 $ALT_ENTER_MESSAGE->show;
420 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h});
421
422 $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget);
423 $MAPWIDGET->focus_in;
424 $MAPWIDGET->connect (activate_console => sub {
425 my ($mapwidget, $preset) = @_;
426
427 if ($CONSOLE) {
428 $CONSOLE->{input}->{auto_activated} = 1;
429 $CONSOLE->{input}->focus_in;
430
431 if ($preset && $CONSOLE->{input}->get_text eq '') {
432 $CONSOLE->{input}->set_text ($preset);
433 }
434 }
435 });
436
437 $CFClient::UI::ROOT->add ($BUTTONBAR = new CFClient::UI::HBox);
438
439 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Client Setup", other => client_setup);
440 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Server Setup", other => server_setup);
441 $BUTTONBAR->add (new CFClient::UI::Flopper text => "Message Window", other => message_window);
442
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 {
463 $CFClient::UI::ROOT->{children} = [];
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") {
249 483
250 my $interval = ($NOW - $last_refresh) * 0.001; 484 $SDL_MIXER = !CFClient::Mix_OpenAudio;
251 $last_refresh = $NOW; 485 CFClient::Mix_AllocateChannels 8;
486 CFClient::MixMusic::volume $CFG->{bgm_volume} * 128;
252 487
253 if ($interval) { 488 audio_music_finished;
254 $FPS ||= 1 / $interval;
255 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
256 debug sprintf "%5.02f", $FPS;
257 }
258 489
259 force_refresh; 490 while (<$fh>) {
260 $_->animate ($interval) for grep $_, values %ANIMATE; 491 next if /^\s*#/;
492 next if /^\s*$/;
261 493
262 if (%ANIMATE) { 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
263 1 502 };
264 } else {
265 undef $refresh_handler;
266 0
267 } 503 }
268 } else { 504 } else {
269 undef $refresh_handler; 505 status "unable to open sound config: $!";
270 0
271 } 506 }
272 }; 507 }
508}
509
510sub audio_shutdown {
511 CFClient::Mix_CloseAudio if $SDL_MIXER;
512 undef $SDL_MIXER;
513 @SOUNDS = ();
514 %AUDIO_CHUNKS = ();
515}
516
517my %animate_object;
518my $animate_timer;
519
520my $want_refresh;
521my $can_refresh;
522
523my $fps = 9;
524
525sub force_refresh {
526 $fps = $fps * 0.95 + 1 / ($NOW - $LAST_REFRESH) * 0.05;
527 debug sprintf "%3.2f", $fps;
528
529 $want_refresh = 0;
530 $can_refresh = 0;
531
532 $CFClient::UI::ROOT->draw;
533
534 CFClient::SDL_GL_SwapBuffers;
535
536 $LAST_REFRESH = $NOW;
537}
538
539my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub {
540 $NOW = time;
541
542 ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_)
543 for CFClient::SDL_PollEvent;
544
545 if (%animate_object) {
546 $_->animate ($LAST_REFRESH - $NOW) for values %animate_object;
547 $want_refresh++;
548 }
549
550 if ($want_refresh) {
551 force_refresh;
552 } else {
553 $can_refresh = 1;
554 }
555});
556
557sub refresh {
558 $want_refresh++;
273} 559}
274 560
275sub animation_start { 561sub animation_start {
276 my ($widget) = @_; 562 my ($widget) = @_;
277 $ANIMATE{$widget} = $widget; 563 $animate_object{$widget} = $widget;
278 Scalar::Util::weaken $ANIMATE{$widget};
279
280 refresh;
281} 564}
282 565
283sub animation_stop { 566sub animation_stop {
284 my ($widget) = @_; 567 my ($widget) = @_;
285 delete $ANIMATE{$widget}; 568 delete $animate_object{$widget};
569}
570
571@conn::ISA = Crossfire::Protocol::;
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
594sub conn::user_send {
595 my ($self, $command) = @_;
596
597 $self->send_command ($command);
598 status $command;
599}
600
601sub conn::map_scroll {
602 my ($self, $dx, $dy) = @_;
603
604 $MAP->scroll ($dx, $dy);
605}
606
607sub conn::feed_map1a {
608 my ($self, $data) = @_;
609
610# $self->Crossfire::Protocol::feed_map1a ($data);
611
612 $MAP->map1a_update ($data);
613 $MAPWIDGET->update;
614}
615
616sub conn::flush_map {
617 my ($self) = @_;
618
619 my $map_info = delete $self->{map_info}
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}
628
629sub conn::map_clear {
630 my ($self) = @_;
631
632 $self->flush_map;
633 delete $self->{neigh_map};
634
635 $MAP->clear;
636}
637
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);
733}
734
735sub conn::face_find {
736 my ($self, $facenum, $face) = @_;
737
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)
767}
768
769sub conn::face_update {
770 my ($self, $facenum, $face) = @_;
771
772 $TILECACHE->put ($face->{id} => $face->{image}); #TODO: try to avoid duplicate writes
773
774 $self->set_texture ($face->{id} => delete $face->{image});
775}
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
785 $MAP->set_texture ($id, @$tex{qw(name w h s t)}, @{$tex->{minified}});
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#
803}
804
805sub conn::query {
806 my ($self, $flags, $prompt) = @_;
807
808 #TODO, display dialog with relevant information
809 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
810}
811
812sub conn::drawinfo {
813 my ($self, $color, $text) = @_;
814
815 my @color = (
816 [1.00, 1.00, 1.00], #[0.00, 0.00, 0.00],
817 [1.00, 1.00, 1.00],
818 [0.50, 0.50, 1.00], #[0.00, 0.00, 0.55]
819 [1.00, 0.00, 0.00],
820 [1.00, 0.54, 0.00],
821 [0.11, 0.56, 1.00],
822 [0.93, 0.46, 0.00],
823 [0.18, 0.54, 0.34],
824 [0.56, 0.73, 0.56],
825 [0.80, 0.80, 0.80],
826 [0.55, 0.41, 0.13],
827 [0.99, 0.77, 0.26],
828 [0.74, 0.65, 0.41],
829 );
830
831 $LOGVIEW->add_paragraph ($color[$color], $text);
832}
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 }
286} 856}
287 857
288%SDL_CB = ( 858%SDL_CB = (
289 SDL_QUIT() => sub { 859 CFClient::SDL_QUIT => sub {
290 main_quit Gtk2; 860 Event::unloop -1;
291 }, 861 },
292 SDL_VIDEORESIZE() => sub { 862 CFClient::SDL_VIDEORESIZE => sub {
293 }, 863 },
294 SDL_VIDEOEXPOSE() => sub { 864 CFClient::SDL_VIDEOEXPOSE => \&refresh,
295 refresh; 865 CFClient::SDL_ACTIVEEVENT => sub {
866# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
296 }, 867 },
297 SDL_KEYDOWN() => sub { 868 CFClient::SDL_KEYDOWN => sub {
298 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 869 if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) {
299 # alt-enter 870 # alt-enter
300 $FULLSCREEN = !$FULLSCREEN; 871 video_shutdown;
301 destroy_screen; 872 $CFG->{fullscreen} = !$CFG->{fullscreen};
302 init_screen; 873 video_init;
303 } else { 874 } else {
304 CFClient::UI::feed_sdl_key_down_event ($SDL_EV); 875 CFClient::UI::feed_sdl_key_down_event ($_[0]);
305 } 876 }
306 }, 877 },
307 SDL_KEYUP() => sub { 878 CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event,
308 CFClient::UI::feed_sdl_key_up_event ($SDL_EV); 879 CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event,
309 }, 880 CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event,
310 SDL_MOUSEMOTION() => sub { 881 CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event,
311 CFClient::UI::feed_sdl_motion_event ($SDL_EV); 882 CFClient::SDL_USEREVENT => \&audio_music_finished,
312 },
313 SDL_MOUSEBUTTONDOWN() => sub {
314 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
315 },
316 SDL_MOUSEBUTTONUP() => sub {
317 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
318 },
319 SDL_ACTIVEEVENT() => sub {
320# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
321 },
322); 883);
323 884
324@conn::ISA = Crossfire::Protocol::;
325
326sub conn::map_update {
327 my ($self, $dirty) = @_;
328
329 $MAPWIDGET->update;
330}
331
332sub conn::map_scroll {
333 my ($self, $dx, $dy) = @_;
334
335# refresh;
336}
337
338sub conn::map_clear {
339 my ($self) = @_;
340
341# refresh;
342}
343
344sub conn::face_find {
345 my ($self, $face) = @_;
346
347 $FACECACHE->{"$face->{chksum},$face->{name}"}
348}
349
350sub conn::face_update {
351 my ($self, $face) = @_;
352
353 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
354
355 $face->{texture} = new_from_image CFClient::Texture delete $face->{image};
356}
357
358sub conn::query {
359 my ($self, $flags, $prompt) = @_;
360
361 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
362}
363
364sub gtk_add_cfg_field {
365 my ($tbl, $cfg, $klbl, $key, $value) = @_;
366 my $i = $cfg->{_i}++;
367 $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1);
368 $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1);
369 if ($key eq 'password') {
370 $ent->set_invisible_char ("*");
371 $ent->set (visibility => 0)
372 }
373 $ent->set_text ($value);
374 $ent->signal_connect (changed => sub {
375 my ($ent) = @_;
376 $cfg->{$key} = $ent->get_text;
377 # TODO: Mapsize should be a slider in the game gui
378 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
379 $cfg->{$key} = 100;
380 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
381 $cfg->{$key} = 50;
382 }
383 });
384}
385
386sub run_config_dialog {
387 my (%events) = @_;
388
389 my $w = Gtk2::Window->new;
390
391 my @cfg = (
392 [qw/Host host/],
393 [qw/Port port/],
394 [qw/Mapsize% mapsize/],
395 [qw/Username user/],
396 [qw/Password password/],
397 );
398
399 my $cfg = {};
400
401 $w->add (my $vb = Gtk2::VBox->new);
402 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
403 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
404 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
405 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
406 my $i = 0;
407 my $act = 0;
408 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
409 if ($_ eq $selmode) { $act = $i }
410 $cb->append_text ($_);
411 $i++;
412 }
413 $cb->set_active ($act);
414 $cb->signal_connect (changed => sub {
415 my ($cb) = @_;
416 my $txt = $cb->get_active_text;
417 if ($txt =~ m/(\d+)x(\d+)/) {
418 $::CFG->{width} = $1;
419 $::CFG->{height} = $2;
420 }
421 });
422
423 $cfg->{_i} = 1;
424 for (@cfg) {
425 gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]});
426 }
427
428 $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0);
429 $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5);
430 $cb->signal_connect (clicked => sub {
431 for (keys %$cfg) {
432 $::CFG->{$_} = $cfg->{$_}
433 if $_ ne '_i';
434 }
435 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
436 });
437 $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5);
438 $cb->signal_connect (clicked => sub {
439 for (keys %$cfg) {
440 $::CFG->{$_} = $cfg->{$_}
441 if $_ ne '_i';
442 }
443 my $cb = $events{login} || sub {};
444 $cb->($::CFG->{user}, $::CFG->{password});
445 });
446 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
447 $cb->signal_connect (clicked => sub {
448 my $cb = $events{logout} || sub {};
449 $cb->();
450 });
451 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
452 $cb->signal_connect (clicked => sub { $w->destroy });
453
454 $w->show_all;
455
456 $w->signal_connect (destroy => sub { Gtk2->main_quit });
457}
458
459
460############################################################################# 885#############################################################################
461 886
462SDL::Init SDL_INIT_EVERYTHING; 887$SIG{INT} = $SIG{TERM} = sub { exit };
463 888
464@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)], 889$TILECACHE = CFClient::db_table "tilecache";
465 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE }; 890$FACEMAP = CFClient::db_table "facemap";
466 891
467CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 892CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
468 893
469$CFG ||= { 894my %DEF_CFG = (
895 sdl_mode => 0,
470 width => 640, 896 width => 640,
471 height => 480, 897 height => 480,
472 fullscreen => 0, 898 fullscreen => 0,
473 sdl_mode => 0, 899 fast => 0,
900 fow_enable => 1,
901 fow_intensity => 0.45,
902 fow_smooth => 0,
903 gui_fontsize => 1,
904 log_fontsize => 14,
474 mapsize => 100, 905 mapsize => 100,
475 host => "crossfire.schmorp.de", 906 host => "crossfire.schmorp.de",
476 port => 13327, 907 say_command => 'say',
477}; 908 audio_enable => 1,
909 bgm_enable => 1,
910 bgm_volume => 0.25,
911);
912
913while (my ($k, $v) = each %DEF_CFG) {
914 $CFG->{$k} = $v unless exists $CFG->{$k};
915}
916
917sdl_init;
918
919@SDL_MODES = reverse
920 grep $_->[0] >= 640 && $_->[1] >= 480,
921 CFClient::SDL_ListModes;
922
923@SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)";
924
925$CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES;
478 926
479{ 927{
480 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);
481 929
482 CFClient::add_font $_ for @fonts; 930 CFClient::add_font $_ for @fonts;
483 CFClient::set_font $fonts[0]; 931 CFClient::set_font $fonts[0];
484} 932}
485 933
486$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 934video_init;
935audio_init;
487 936
488run_config_dialog 937Event::loop;
489 login => sub { start_game },
490 logout => sub { stop_game };
491 938
492main Gtk2; 939END { CFClient::SDL_Quit }
493 940
494Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
495 941

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines