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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines