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.105 by root, Fri Apr 14 20:27:36 2006 UTC vs.
Revision 1.151 by root, Thu Apr 20 07:27:11 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines