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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines