… | |
… | |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Time::HiRes 'time'; |
6 | use Time::HiRes 'time'; |
7 | use Event; |
7 | use Event; |
8 | |
8 | |
9 | use SDL; |
|
|
10 | use SDL::App; |
|
|
11 | use SDL::Event; |
|
|
12 | use SDL::Surface; |
|
|
13 | |
|
|
14 | use SDL::Sound; |
|
|
15 | use SDL::Mixer; |
|
|
16 | |
|
|
17 | use SDL::OpenGL; |
|
|
18 | |
|
|
19 | use Crossfire; |
9 | use Crossfire; |
20 | use Crossfire::Protocol; |
10 | use Crossfire::Protocol; |
21 | |
11 | |
22 | use Compress::LZF; |
12 | use Compress::LZF; |
23 | |
13 | |
24 | use CFClient; |
14 | use CFClient; |
25 | use CFClient::UI; |
15 | use CFClient::UI; |
|
|
16 | use CFClient::MapWidget; |
26 | |
17 | |
27 | our $VERSION = '0.1'; |
18 | our $VERSION = '0.1'; |
28 | |
19 | |
29 | my $MAX_FPS = 60; |
20 | my $MAX_FPS = 60; |
30 | my $MIN_FPS = 5; # unused as of yet |
21 | my $MIN_FPS = 5; # unused as of yet |
… | |
… | |
56 | our $METASERVER; |
47 | our $METASERVER; |
57 | |
48 | |
58 | our $GAUGES; |
49 | our $GAUGES; |
59 | |
50 | |
60 | our $SDL_ACTIVE; |
51 | our $SDL_ACTIVE; |
61 | our $SDL_EV; |
|
|
62 | our %SDL_CB; |
52 | our %SDL_CB; |
63 | |
53 | |
64 | our $SDL_MIXER; |
54 | our $SDL_MIXER; |
65 | our @SOUNDS; # event => file mapping |
55 | our @SOUNDS; # event => file mapping |
66 | our %AUDIO_CHUNKS; # audio files |
56 | our %AUDIO_CHUNKS; # audio files |
… | |
… | |
108 | undef $CONN; |
98 | undef $CONN; |
109 | } |
99 | } |
110 | |
100 | |
111 | sub client_setup { |
101 | sub client_setup { |
112 | my $dialog = new CFClient::UI::FancyFrame |
102 | my $dialog = new CFClient::UI::FancyFrame |
|
|
103 | title => "Client Setup", |
113 | child => (my $vbox = new CFClient::UI::VBox); |
104 | child => (my $vbox = new CFClient::UI::VBox); |
114 | $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup"); |
|
|
115 | $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]); |
116 | |
106 | |
117 | $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"); |
118 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
108 | $table->add (1, 0, my $hbox = new CFClient::UI::HBox); |
119 | |
109 | |
120 | $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]); |
121 | $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"); |
122 | |
112 | |
123 | $mode_slider->connect (changed => sub { |
113 | $mode_slider->connect (changed => sub { |
124 | my ($self, $value) = @_; |
114 | my ($self, $value) = @_; |
125 | |
115 | |
126 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
116 | $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value; |
127 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
117 | $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]}); |
128 | }); |
118 | }); |
129 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
119 | $mode_slider->emit (changed => $mode_slider->{range}[0]); |
130 | |
120 | |
131 | $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"); |
132 | $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 { |
133 | my ($self, $value) = @_; |
123 | my ($self, $value) = @_; |
134 | $CFG->{fullscreen} = $value; |
124 | $CFG->{fullscreen} = $value; |
135 | }); |
125 | }); |
136 | |
126 | |
137 | $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"); |
138 | $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 { |
139 | my ($self, $value) = @_; |
129 | my ($self, $value) = @_; |
140 | $CFG->{fast} = $value; |
130 | $CFG->{fast} = $value; |
141 | }); |
131 | }); |
142 | |
132 | |
143 | $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"); |
144 | $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 { |
145 | my ($self, $value) = @_; |
135 | my ($self, $value) = @_; |
146 | $CFG->{fow_enable} = $value; |
136 | $CFG->{fow_enable} = $value; |
147 | }); |
137 | }); |
148 | |
138 | |
149 | $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"); |
150 | $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 { |
151 | my ($self, $value) = @_; |
141 | my ($self, $value) = @_; |
152 | $CFG->{fow_intensity} = $value; |
142 | $CFG->{fow_intensity} = $value; |
153 | }); |
143 | }); |
154 | |
144 | |
155 | $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"); |
156 | $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 { |
157 | my ($self, $value) = @_; |
147 | my ($self, $value) = @_; |
158 | $CFG->{fow_smooth} = $value; |
148 | $CFG->{fow_smooth} = $value; |
159 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
149 | status "Fog of War smoothing requires OpenGL 1.2 or higher" if $CFClient::GL_VERSION < 1.2; |
160 | }); |
150 | }); |
161 | |
151 | |
162 | $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Log Fontsize"); |
152 | $table->add (0, 6, new CFClient::UI::Label valign => 0, align => 1, text => "GUI Fontsize"); |
|
|
153 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{gui_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
|
|
154 | $CFG->{gui_fontsize} = 0.1 * int $_[1] * 10; |
|
|
155 | # $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
|
|
156 | }); |
|
|
157 | |
|
|
158 | $table->add (0, 7, new CFClient::UI::Label valign => 0, align => 1, text => "Server Log Fontsize"); |
163 | $table->add (1, 6, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 8, 30, 1], connect_changed => sub { |
159 | $table->add (1, 7, new CFClient::UI::Slider range => [$CFG->{log_fontsize}, 0.7, 1.7, 0.1], connect_changed => sub { |
164 | my ($self, $value) = @_; |
|
|
165 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = int $value); |
160 | $LOGVIEW->set_fontsize ($CFG->{log_fontsize} = 0.1 * int $_[1] * 10); |
166 | }); |
161 | }); |
167 | |
162 | |
168 | $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
163 | $table->add (1, 8, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
169 | video_shutdown (); |
164 | video_shutdown (); |
170 | video_init (); |
165 | video_init (); |
171 | }); |
166 | }); |
172 | |
167 | |
|
|
168 | $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Audio Enable"); |
|
|
169 | $table->add (1, 9, new CFClient::UI::CheckBox state => $CFG->{audio_enable}, connect_changed => sub { |
|
|
170 | $CFG->{audio_enable} = $_[1]; |
|
|
171 | }); |
|
|
172 | # $table->add (0, 9, new CFClient::UI::Label valign => 0, align => 1, text => "Effects Volume"); |
|
|
173 | # $table->add (1, 8, new CFClient::UI::Slider range => [$CFG->{effects_volume}, 0, 128, 1], connect_changed => sub { |
|
|
174 | # $CFG->{effects_volume} = $_[1]; |
|
|
175 | # }); |
|
|
176 | $table->add (0, 10, new CFClient::UI::Label valign => 0, align => 1, text => "Background Music"); |
|
|
177 | $table->add (1, 10, my $hbox = new CFClient::UI::HBox); |
|
|
178 | $hbox->add (new CFClient::UI::CheckBox expand => 1, state => $CFG->{bgm_enable}, connect_changed => sub { |
|
|
179 | $CFG->{bgm_enable} = $_[1]; |
|
|
180 | }); |
|
|
181 | $hbox->add (new CFClient::UI::Slider expand => 1, range => [$CFG->{bgm_volume}, 0, 1, 0.1], connect_changed => sub { |
|
|
182 | $CFG->{bgm_volume} = $_[1]; |
|
|
183 | CFClient::MixMusic::volume $_[1] * 128; |
|
|
184 | }); |
|
|
185 | |
|
|
186 | $table->add (1, 11, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub { |
|
|
187 | audio_shutdown (); |
|
|
188 | audio_init (); |
|
|
189 | }); |
|
|
190 | |
173 | $dialog |
191 | $dialog |
174 | } |
192 | } |
175 | |
193 | |
176 | sub metaserver_dialog { |
194 | sub metaserver_dialog { |
177 | my $dialog = new CFClient::UI::FancyFrame |
195 | my $dialog = new CFClient::UI::FancyFrame |
|
|
196 | title => "Metaserver", |
178 | child => (my $vbox = new CFClient::UI::VBox); |
197 | child => (my $vbox = new CFClient::UI::VBox); |
179 | |
198 | |
180 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
199 | $vbox->add ($dialog->{table} = new CFClient::UI::Table); |
181 | |
200 | |
182 | $dialog |
201 | $dialog |
… | |
… | |
239 | $HOST->set_text ($CFG->{host} = $host); |
258 | $HOST->set_text ($CFG->{host} = $host); |
240 | }), |
259 | }), |
241 | (new CFClient::UI::Empty expand => 1), |
260 | (new CFClient::UI::Empty expand => 1), |
242 | ]); |
261 | ]); |
243 | |
262 | |
244 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => $FONTSIZE * 0.8) |
263 | $table->add ($_ + 1, $y, new CFClient::UI::Label align => $align[$_], text => $m->[$_], fontsize => 0.8) |
245 | for 0 .. $#$m; |
264 | for 0 .. $#$m; |
246 | } |
265 | } |
247 | } |
266 | } |
248 | }); |
267 | }); |
249 | } |
268 | } |
250 | |
269 | |
251 | sub server_setup { |
270 | sub server_setup { |
252 | my $dialog = new CFClient::UI::FancyFrame |
271 | my $dialog = new CFClient::UI::FancyFrame |
|
|
272 | title => "Server Setup", |
253 | child => (my $vbox = new CFClient::UI::VBox); |
273 | child => (my $vbox = new CFClient::UI::VBox); |
254 | |
274 | |
255 | $vbox->add (new CFClient::UI::Label align => 0, text => "Server Setup"); |
|
|
256 | $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]); |
257 | $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host:Port"); |
276 | $table->add (0, 2, new CFClient::UI::Label valign => 0, align => 1, text => "Host:Port"); |
258 | |
277 | |
259 | { |
278 | { |
260 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
279 | $table->add (1, 2, my $vbox = new CFClient::UI::VBox); |
261 | |
280 | |
262 | $vbox->add (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 { |
263 | my ($self, $value) = @_; |
282 | my ($self, $value) = @_; |
264 | $CFG->{host} = $value; |
283 | $CFG->{host} = $value; |
265 | }); |
284 | }); |
266 | |
285 | |
267 | $METASERVER = metaserver_dialog; |
286 | $METASERVER = metaserver_dialog; |
268 | |
287 | |
269 | $vbox->add (new CFClient::UI::Flopper text => "Metaserver", other => $METASERVER, connect_open => sub { |
288 | $vbox->add (new CFClient::UI::Flopper expand => 1, text => "Metaserver", other => $METASERVER, connect_open => sub { |
270 | update_metaserver $HOST; |
289 | update_metaserver $HOST; |
271 | }); |
290 | }); |
272 | } |
291 | } |
273 | |
292 | |
274 | $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"); |
275 | $table->add (1, 4, 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 { |
276 | my ($self, $value) = @_; |
295 | my ($self, $value) = @_; |
277 | $CFG->{user} = $value; |
296 | $CFG->{user} = $value; |
278 | }); |
297 | }); |
279 | |
298 | |
280 | $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"); |
281 | $table->add (1, 5, 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 { |
282 | my ($self, $value) = @_; |
301 | my ($self, $value) = @_; |
283 | $CFG->{password} = $value; |
302 | $CFG->{password} = $value; |
284 | }); |
303 | }); |
285 | |
304 | |
286 | $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"); |
287 | $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 { |
288 | my ($self, $value) = @_; |
307 | my ($self, $value) = @_; |
289 | $CFG->{say_command} = $value; |
308 | $CFG->{say_command} = $value; |
290 | }); |
309 | }); |
291 | |
310 | |
292 | $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"); |
293 | $table->add (1, 7, new CFClient::UI::Slider |
312 | $table->add (1, 7, new CFClient::UI::Slider |
294 | req_w => 100, |
313 | req_w => 100, |
295 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
314 | range => [$CFG->{mapsize}, 10, 100 + 1, 1], |
296 | connect_changed => sub { |
315 | connect_changed => sub { |
297 | my ($self, $value) = @_; |
316 | my ($self, $value) = @_; |
… | |
… | |
307 | $dialog |
326 | $dialog |
308 | } |
327 | } |
309 | |
328 | |
310 | sub message_window { |
329 | sub message_window { |
311 | my $window = new CFClient::UI::FancyFrame |
330 | my $window = new CFClient::UI::FancyFrame |
|
|
331 | title => "Messages", |
312 | border_bg => [1, 1, 1, 0.5], |
332 | border_bg => [1, 1, 1, 0.5], |
313 | bg => [0.3, 0.3, 0.3, 0.8], |
333 | bg => [0.3, 0.3, 0.3, 0.8], |
314 | user_w => int $::WIDTH / 3, |
334 | user_w => int $::WIDTH / 3, |
315 | user_h => int $::HEIGHT / 5, |
335 | user_h => int $::HEIGHT / 5, |
316 | child => (my $vbox = new CFClient::UI::VBox); |
336 | child => (my $vbox = new CFClient::UI::VBox); |
… | |
… | |
358 | |
378 | |
359 | $window |
379 | $window |
360 | } |
380 | } |
361 | |
381 | |
362 | sub sdl_init { |
382 | sub sdl_init { |
363 | #SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE |
383 | CFClient::SDL_Init |
364 | SDL::Init SDL_INIT_AUDIO | SDL_INIT_VIDEO |
|
|
365 | and die "SDL::Init failed!\n"; |
384 | and die "SDL::Init failed!\n"; |
366 | } |
385 | } |
367 | |
386 | |
368 | sub video_init { |
387 | sub video_init { |
369 | sdl_init; |
388 | sdl_init; |
370 | |
389 | |
371 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
390 | ($WIDTH, $HEIGHT) = @{ $SDL_MODES[$CFG->{sdl_mode}] }; |
372 | $FULLSCREEN = $CFG->{fullscreen}; |
391 | $FULLSCREEN = $CFG->{fullscreen}; |
373 | $FAST = $CFG->{fast}; |
392 | $FAST = $CFG->{fast}; |
374 | |
393 | |
375 | SDL::GLSetAttribute SDL_GL_RED_SIZE, 5; |
394 | CFClient::SDL_SetVideoMode $WIDTH, $HEIGHT, $FULLSCREEN |
376 | SDL::GLSetAttribute SDL_GL_GREEN_SIZE, 5; |
|
|
377 | SDL::GLSetAttribute SDL_GL_BLUE_SIZE, 5; |
|
|
378 | SDL::GLSetAttribute SDL_GL_ALPHA_SIZE, 1; |
|
|
379 | |
|
|
380 | SDL::GLSetAttribute SDL_GL_ACCUM_RED_SIZE, 0; |
|
|
381 | SDL::GLSetAttribute SDL_GL_ACCUM_GREEN_SIZE, 0; |
|
|
382 | SDL::GLSetAttribute SDL_GL_ACCUM_BLUE_SIZE, 0; |
|
|
383 | SDL::GLSetAttribute SDL_GL_ACCUM_ALPHA_SIZE, 0; |
|
|
384 | |
|
|
385 | SDL::GLSetAttribute SDL_GL_DOUBLEBUFFER, 1; |
|
|
386 | SDL::GLSetAttribute SDL_GL_BUFFER_SIZE, 15; |
|
|
387 | SDL::GLSetAttribute SDL_GL_DEPTH_SIZE, 0; |
|
|
388 | |
|
|
389 | SDL::SetVideoMode $WIDTH, $HEIGHT, 0, |
|
|
390 | SDL_HWSURFACE | SDL_ANYFORMAT | SDL_OPENGL | SDL_DOUBLEBUF |
|
|
391 | | ($FULLSCREEN ? SDL_FULLSCREEN : 0) |
|
|
392 | or die "SDL::SetVideoMode failed!\n"; |
395 | or die "SDL_SetVideoMode failed!\n"; |
393 | |
|
|
394 | SDL::WMSetCaption "Crossfire+ Client", "Crossfire+"; |
|
|
395 | |
|
|
396 | $SDL_EV = new SDL::Event; |
|
|
397 | $SDL_EV->set_unicode (1); |
|
|
398 | |
396 | |
399 | $SDL_ACTIVE = 1; |
397 | $SDL_ACTIVE = 1; |
400 | |
398 | |
401 | $LAST_REFRESH = time - 0.01; |
399 | $LAST_REFRESH = time - 0.01; |
402 | |
400 | |
403 | CFClient::gl_init; |
401 | CFClient::gl_init; |
404 | |
402 | |
405 | $FONTSIZE = int $HEIGHT / 40; |
403 | $FONTSIZE = int $HEIGHT / 40 * $CFG->{gui_fontsize}; |
406 | |
404 | |
407 | ############################################################################# |
405 | ############################################################################# |
408 | |
406 | |
409 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
407 | $DEBUG_STATUS = new CFClient::UI::Label padding => 0, z => 100; |
410 | $CFClient::UI::ROOT->add ($DEBUG_STATUS); |
408 | $DEBUG_STATUS->show; |
411 | |
409 | |
412 | $STATUS_LINE = new CFClient::UI::Label |
410 | $STATUS_LINE = new CFClient::UI::Label |
413 | padding => 0, |
411 | padding => 0, |
414 | y => $HEIGHT * 44 / 45 - $FONTSIZE; |
412 | y => $HEIGHT - $FONTSIZE * 1.8; |
415 | $CFClient::UI::ROOT->add ($STATUS_LINE); |
413 | $STATUS_LINE->show; |
416 | |
414 | |
417 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
415 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
418 | padding => 0, |
416 | padding => 0, |
419 | y => $HEIGHT * 44 / 45, |
|
|
420 | fontsize => $HEIGHT / 45, |
417 | fontsize => 0.8, |
421 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
418 | markup => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
422 | $CFClient::UI::ROOT->add ($ALT_ENTER_MESSAGE); |
419 | $ALT_ENTER_MESSAGE->show; |
|
|
420 | $ALT_ENTER_MESSAGE->move (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h}); |
423 | |
421 | |
424 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::UI::MapWidget); |
422 | $CFClient::UI::ROOT->add ($MAPWIDGET = new CFClient::MapWidget); |
425 | $MAPWIDGET->focus_in; |
423 | $MAPWIDGET->focus_in; |
426 | $MAPWIDGET->connect (activate_console => sub { |
424 | $MAPWIDGET->connect (activate_console => sub { |
427 | my ($mapwidget, $preset) = @_; |
425 | my ($mapwidget, $preset) = @_; |
428 | |
426 | |
429 | if ($CONSOLE) { |
427 | if ($CONSOLE) { |
… | |
… | |
447 | status "Configuration Saved"; |
445 | status "Configuration Saved"; |
448 | }); |
446 | }); |
449 | |
447 | |
450 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
448 | $BUTTONBAR->{children}[1]->emit ("activate"); # pop up server setup |
451 | |
449 | |
452 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0); |
450 | my $tgw = new CFClient::UI::FancyFrame (x => $WIDTH - 300, y => 0, title => "Stats"); |
453 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
451 | $tgw->add (my $hbox = new CFClient::UI::HBox ()); |
454 | |
452 | |
455 | $hbox->add (my $hg = new CFClient::UI::VGauge (gauge => 'hp')); |
453 | $hbox->add (my $hg = new CFClient::UI::Gauge (type => 'hp')); |
456 | $hbox->add (my $mg = new CFClient::UI::VGauge (gauge => 'mana')); |
454 | $hbox->add (my $mg = new CFClient::UI::Gauge (type => 'mana')); |
457 | $hbox->add (my $gg = new CFClient::UI::VGauge (gauge => 'grace')); |
455 | $hbox->add (my $gg = new CFClient::UI::Gauge (type => 'grace')); |
458 | $hbox->add (my $fg = new CFClient::UI::VGauge (gauge => 'food')); |
456 | $hbox->add (my $fg = new CFClient::UI::Gauge (type => 'food')); |
459 | |
457 | |
460 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
458 | $GAUGES = { food => $fg, mana => $mg, hp => $hg, grace => $gg }; |
461 | $CFClient::UI::ROOT->add ($tgw); |
459 | $CFClient::UI::ROOT->add ($tgw); |
462 | } |
460 | } |
463 | |
461 | |
464 | sub video_shutdown { |
462 | sub video_shutdown { |
465 | $CFClient::UI::ROOT->{children} = []; |
463 | $CFClient::UI::ROOT->{children} = []; |
466 | undef $SDL_ACTIVE; |
464 | undef $SDL_ACTIVE; |
467 | undef $SDL_EV; |
465 | } |
|
|
466 | |
|
|
467 | my @bgmusic = qw(game1.ogg game2.ogg game3.ogg game5.ogg game6.ogg ross1.ogg ross2.ogg ross3.ogg ross4.ogg ross5.ogg); #d# |
|
|
468 | my $bgmusic;#TODO#hack#d# |
|
|
469 | |
|
|
470 | sub audio_music_finished { |
|
|
471 | return unless $CFG->{bgm_enable}; |
|
|
472 | |
|
|
473 | # TODO: hack, do play loop and mood music |
|
|
474 | $bgmusic = new_from_file CFClient::MixMusic CFClient::find_rcfile "music/$bgmusic[0]"; |
|
|
475 | $bgmusic->play (0); |
|
|
476 | |
|
|
477 | push @bgmusic, shift @bgmusic; |
468 | } |
478 | } |
469 | |
479 | |
470 | sub audio_init { |
480 | sub audio_init { |
471 | if ($CFG->{sound} || 1) { |
481 | if ($CFG->{audio_enable}) { |
472 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
482 | if (open my $fh, "<:utf8", CFClient::find_rcfile "sounds/config") { |
473 | $SDL_MIXER = new SDL::Mixer; |
483 | |
474 | $SDL_MIXER->allocate_channels (8); |
484 | $SDL_MIXER = !CFClient::Mix_OpenAudio; |
|
|
485 | CFClient::Mix_AllocateChannels 8; |
|
|
486 | CFClient::MixMusic::volume $CFG->{bgm_volume} * 128; |
|
|
487 | |
|
|
488 | audio_music_finished; |
475 | |
489 | |
476 | while (<$fh>) { |
490 | while (<$fh>) { |
477 | next if /^\s*#/; |
491 | next if /^\s*#/; |
478 | next if /^\s*$/; |
492 | next if /^\s*$/; |
479 | |
493 | |
480 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
494 | my ($file, $volume, $event) = split /\s+/, $_, 3; |
481 | |
495 | |
482 | push @SOUNDS, "$volume,$file"; |
496 | push @SOUNDS, "$volume,$file"; |
483 | |
497 | |
484 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
498 | $AUDIO_CHUNKS{"$volume,$file"} ||= do { |
485 | my $chunk = new SDL::Sound CFClient::find_rcfile "sounds/$file"; |
499 | my $chunk = new_from_file CFClient::MixChunk CFClient::find_rcfile "sounds/$file"; |
486 | $chunk->volume ($volume * 128 / 100); |
500 | $chunk->volume ($volume * 128 / 100); |
487 | $chunk |
501 | $chunk |
488 | }; |
502 | }; |
489 | } |
503 | } |
490 | } else { |
504 | } else { |
… | |
… | |
492 | } |
506 | } |
493 | } |
507 | } |
494 | } |
508 | } |
495 | |
509 | |
496 | sub audio_shutdown { |
510 | sub audio_shutdown { |
|
|
511 | CFClient::Mix_CloseAudio if $SDL_MIXER; |
497 | undef $SDL_MIXER; |
512 | undef $SDL_MIXER; |
498 | @SOUNDS = (); |
513 | @SOUNDS = (); |
499 | %AUDIO_CHUNKS = (); |
514 | %AUDIO_CHUNKS = (); |
500 | } |
515 | } |
501 | |
516 | |
… | |
… | |
514 | $want_refresh = 0; |
529 | $want_refresh = 0; |
515 | $can_refresh = 0; |
530 | $can_refresh = 0; |
516 | |
531 | |
517 | $CFClient::UI::ROOT->draw; |
532 | $CFClient::UI::ROOT->draw; |
518 | |
533 | |
519 | SDL::GLSwapBuffers; |
534 | CFClient::SDL_GL_SwapBuffers; |
520 | |
535 | |
521 | $LAST_REFRESH = $NOW; |
536 | $LAST_REFRESH = $NOW; |
522 | } |
537 | } |
523 | |
538 | |
524 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
539 | my $refresh_watcher = Event->timer (after => 0, hard => 1, interval => 1 / $MAX_FPS, cb => sub { |
525 | $NOW = time; |
540 | $NOW = time; |
526 | |
541 | |
527 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
542 | ($SDL_CB{$_->{type}} || sub { warn "unhandled event $_->{type}" })->($_) |
528 | while $SDL_EV->poll; |
543 | for CFClient::SDL_PollEvent; |
529 | |
544 | |
530 | if (%animate_object) { |
545 | if (%animate_object) { |
531 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
546 | $_->animate ($LAST_REFRESH - $NOW) for values %animate_object; |
532 | $want_refresh++; |
547 | $want_refresh++; |
533 | } |
548 | } |
… | |
… | |
563 | my $hp = $stats->{1}; |
578 | my $hp = $stats->{1}; |
564 | my $hp_m = $stats->{2}; |
579 | my $hp_m = $stats->{2}; |
565 | my $sp = $stats->{3}; |
580 | my $sp = $stats->{3}; |
566 | my $sp_m = $stats->{4}; |
581 | my $sp_m = $stats->{4}; |
567 | my $fo = $stats->{18}; |
582 | my $fo = $stats->{18}; |
568 | my $fo_m = 1000; |
583 | my $fo_m = 999; |
569 | my $gr = $stats->{23}; |
584 | my $gr = $stats->{23}; |
570 | my $gr_m = $stats->{24}; |
585 | my $gr_m = $stats->{24}; |
571 | |
586 | |
572 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
587 | #d# warn "DATA $hp $hp_m $sp $sp_m $fo $fo_m $gr $gr_m\n"; |
573 | $GAUGES->{hp}->set_value ($hp, $hp_m); |
588 | $GAUGES->{hp} ->set_value ($hp, $hp_m); |
574 | $GAUGES->{mana}->set_value ($sp, $sp_m); |
589 | $GAUGES->{mana} ->set_value ($sp, $sp_m); |
575 | $GAUGES->{food}->set_value ($fo, $fo_m); |
590 | $GAUGES->{food} ->set_value ($fo, $fo_m); |
576 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
591 | $GAUGES->{grace}->set_value ($gr, $gr_m); |
577 | } |
592 | } |
578 | |
593 | |
579 | sub conn::user_send { |
594 | sub conn::user_send { |
580 | my ($self, $command) = @_; |
595 | my ($self, $command) = @_; |
… | |
… | |
606 | |
621 | |
607 | my ($hash, $x, $y, $w, $h) = @$map_info; |
622 | my ($hash, $x, $y, $w, $h) = @$map_info; |
608 | |
623 | |
609 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
624 | my $data = $MAP->get_rect ($x, $y, $w, $h); |
610 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
625 | $MAPCACHE->put ($hash => Compress::LZF::compress $data); |
611 | |
|
|
612 | warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
626 | #warn sprintf "SAVEmap[%s] length %d\n", $hash, length $data;#d# |
613 | |
|
|
614 | } |
627 | } |
615 | |
628 | |
616 | sub conn::map_clear { |
629 | sub conn::map_clear { |
617 | my ($self) = @_; |
630 | my ($self) = @_; |
618 | |
631 | |
619 | $self->flush_map; |
632 | $self->flush_map; |
620 | delete $self->{neigh}; |
633 | delete $self->{neigh_map}; |
621 | |
634 | |
622 | $MAP->clear; |
635 | $MAP->clear; |
623 | } |
636 | } |
624 | |
637 | |
625 | |
638 | |
626 | sub conn::load_map($$$) { |
639 | sub conn::load_map($$$) { |
627 | my ($self, $hash, $x, $y) = @_; |
640 | my ($self, $hash, $x, $y) = @_; |
628 | |
641 | |
629 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
642 | if (defined (my $data = $MAPCACHE->get ($hash))) { |
630 | $data = Compress::LZF::decompress $data; |
643 | $data = Compress::LZF::decompress $data; |
631 | warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
644 | #warn sprintf "LOADmap[%s,%d,%d] length %d\n", $hash, $x, $y, length $data;#d# |
632 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
645 | for my $id ($MAP->set_rect ($x, $y, $data)) { |
633 | my $data = $TILECACHE->get ($id) |
646 | my $data = $TILECACHE->get ($id) |
634 | or next; |
647 | or next; |
635 | |
648 | |
636 | $self->set_texture ($id => $data); |
649 | $self->set_texture ($id => $data); |
637 | } |
650 | } |
638 | } |
651 | } |
639 | } |
652 | } |
640 | |
653 | |
|
|
654 | # this method does a "flood fill" into every tile direction |
|
|
655 | # it assumes that tiles are arranged in a rectangular grid, |
|
|
656 | # i.e. a map is the same as the left of the right map etc. |
|
|
657 | # failure to comply are harmless and result in display errors |
|
|
658 | # at worst. |
641 | sub conn::flood_fill { |
659 | sub conn::flood_fill { |
642 | my ($self, $path, $hash, $flags, $x0, $y0, $x1, $y1) = @_; |
660 | my ($self, $gx, $gy, $path, $hash, $flags) = @_; |
643 | |
661 | |
644 | # the server does not allow map paths > 6 |
662 | # the server does not allow map paths > 6 |
645 | return if 6 <= length $path; |
663 | return if 6 <= length $path; |
646 | |
664 | |
647 | for my $tile (1..4) { |
665 | my ($x0, $y0, $x1, $y1) = @{$self->{neigh_rect}}; |
648 | next if $self->{neigh}{$hash}[$tile]; |
666 | |
|
|
667 | for ( |
|
|
668 | [1, 0, -1], |
|
|
669 | [2, 1, 0], |
|
|
670 | [3, 0, 1], |
|
|
671 | [4, -1, 0], |
|
|
672 | ) { |
|
|
673 | my ($tile, $dx, $dy) = @$_; |
|
|
674 | |
|
|
675 | my $gx = $gx + $dx; |
|
|
676 | my $gy = $gy + $dy; |
|
|
677 | |
649 | next unless $flags & (1 << ($tile - 1)); |
678 | next unless $flags & (1 << ($tile - 1)); |
|
|
679 | next if $self->{neigh_grid}{$gx, $gy}++; |
650 | |
680 | |
651 | my $neigh = $self->{neigh}{$hash} ||= []; |
681 | my $neigh = $self->{neigh_map}{$hash} ||= []; |
652 | |
682 | if (my $info = $neigh->[$tile]) { |
653 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
654 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
683 | my ($flags, $x, $y, $w, $h, $hash) = @$info; |
655 | |
684 | |
656 | #warn "map<$path>_$tile=<$mode,$x,$y,$w,$h,$hash>\n";#d# |
|
|
657 | return if $mode ne "spatial"; |
|
|
658 | |
|
|
659 | $x += $MAP->ox; |
|
|
660 | $y += $MAP->oy; |
|
|
661 | |
|
|
662 | $self->load_map ($hash, $x, $y) |
|
|
663 | unless $self->{neigh}{$hash}[5]++;#d# |
|
|
664 | |
|
|
665 | $neigh->[$tile] = [$x, $y, $w, $h]; |
|
|
666 | |
|
|
667 | $self->flood_fill ("$path$tile", $hash, $flags, $x0, $y0, $x1, $y1) |
685 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
668 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
686 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
687 | |
|
|
688 | } else { |
|
|
689 | $self->send_mapinfo ("spatial $path$tile", sub { |
|
|
690 | my ($mode, $flags, $x, $y, $w, $h, $hash) = @_; |
|
|
691 | |
|
|
692 | return if $mode ne "spatial"; |
|
|
693 | |
|
|
694 | $x += $MAP->ox; |
|
|
695 | $y += $MAP->oy; |
|
|
696 | |
|
|
697 | $self->load_map ($hash, $x, $y) |
|
|
698 | unless $self->{neigh_map}{$hash}[5]++;#d# |
|
|
699 | |
|
|
700 | $neigh->[$tile] = [$flags, $x, $y, $w, $h, $hash]; |
|
|
701 | |
|
|
702 | $self->flood_fill ($gx, $gy, "$path$tile", $hash, $flags) |
|
|
703 | if $x >= $x0 && $x + $w < $x1 && $y >= $y0 && $y + $h < $y1; |
|
|
704 | }); |
669 | }); |
705 | } |
670 | } |
706 | } |
671 | } |
707 | } |
672 | |
708 | |
673 | sub conn::map_change { |
709 | sub conn::map_change { |
674 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
710 | my ($self, $mode, $flags, $x, $y, $w, $h, $hash) = @_; |
… | |
… | |
677 | |
713 | |
678 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
714 | my ($ox, $oy) = ($::MAP->ox, $::MAP->oy); |
679 | |
715 | |
680 | my $mapmapw = 250; |
716 | my $mapmapw = 250; |
681 | my $mapmaph = 250; |
717 | my $mapmaph = 250; |
|
|
718 | |
|
|
719 | $self->{neigh_rect} = [ |
|
|
720 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
721 | $ox + $mapmapw * 0.5 + $w, $oy + $mapmapw * 0.5 + $h, |
|
|
722 | ]; |
682 | |
723 | |
|
|
724 | delete $self->{neigh_grid}; |
683 | $self->flood_fill ("", $hash, $flags, |
725 | $self->flood_fill (0, 0, "", $hash, $flags); |
684 | $ox - $mapmapw * 0.5, $oy - $mapmapw * 0.5, |
|
|
685 | $ox + $mapmapw * 0.5, $oy + $mapmapw * 0.5); |
|
|
686 | |
726 | |
687 | $x += $ox; |
727 | $x += $ox; |
688 | $y += $oy; |
728 | $y += $oy; |
689 | |
729 | |
690 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
730 | $self->{map_info} = [$hash, $x, $y, $w, $h]; |
… | |
… | |
750 | } |
790 | } |
751 | |
791 | |
752 | sub conn::sound_play { |
792 | sub conn::sound_play { |
753 | my ($self, $x, $y, $soundnum, $type) = @_; |
793 | my ($self, $x, $y, $soundnum, $type) = @_; |
754 | |
794 | |
|
|
795 | $SDL_MIXER |
|
|
796 | or return; |
|
|
797 | |
755 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
798 | my $chunk = $AUDIO_CHUNKS{$SOUNDS[$soundnum]} |
756 | or return; |
799 | or return; |
757 | |
800 | |
758 | $SDL_MIXER->play_channel (-1, $chunk); |
801 | $chunk->play; |
759 | warn "sound $x,$y,$soundnum,$type\n";#d# |
802 | # warn "sound $x,$y,$soundnum,$type\n";#d# |
760 | } |
803 | } |
761 | |
804 | |
762 | sub conn::query { |
805 | sub conn::query { |
763 | my ($self, $flags, $prompt) = @_; |
806 | my ($self, $flags, $prompt) = @_; |
764 | |
807 | |
765 | #TODO |
808 | #TODO, display dialog with relevant information |
766 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
809 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
767 | } |
810 | } |
768 | |
811 | |
769 | sub conn::drawinfo { |
812 | sub conn::drawinfo { |
770 | my ($self, $color, $text) = @_; |
813 | my ($self, $color, $text) = @_; |
… | |
… | |
786 | ); |
829 | ); |
787 | |
830 | |
788 | $LOGVIEW->add_paragraph ($color[$color], $text); |
831 | $LOGVIEW->add_paragraph ($color[$color], $text); |
789 | } |
832 | } |
790 | |
833 | |
|
|
834 | sub conn::spell_add { |
|
|
835 | my ($self, $spell) = @_; |
|
|
836 | |
|
|
837 | $MAPWIDGET->add_command ("invoke $spell->{name}", $spell->{message}, sub { |
|
|
838 | }); |
|
|
839 | $MAPWIDGET->add_command ("cast $spell->{name}", $spell->{message}, sub { |
|
|
840 | }); |
|
|
841 | } |
|
|
842 | |
|
|
843 | sub conn::spell_delete { |
|
|
844 | my ($self, $spell) = @_; |
|
|
845 | } |
|
|
846 | |
|
|
847 | sub conn::addme_success { |
|
|
848 | my ($self) = @_; |
|
|
849 | |
|
|
850 | for my $skill (values %{$self->{skill_info}}) { |
|
|
851 | $MAPWIDGET->add_command ("ready_skill $skill", "", sub { |
|
|
852 | }); |
|
|
853 | $MAPWIDGET->add_command ("use_skill $skill", "", sub { |
|
|
854 | }); |
|
|
855 | } |
|
|
856 | } |
|
|
857 | |
791 | %SDL_CB = ( |
858 | %SDL_CB = ( |
792 | SDL_QUIT() => sub { |
859 | CFClient::SDL_QUIT => sub { |
793 | Event::unloop -1; |
860 | Event::unloop -1; |
794 | }, |
861 | }, |
795 | SDL_VIDEORESIZE() => sub { |
862 | CFClient::SDL_VIDEORESIZE => sub { |
796 | }, |
863 | }, |
797 | SDL_VIDEOEXPOSE() => sub { |
864 | CFClient::SDL_VIDEOEXPOSE => \&refresh, |
798 | refresh; |
865 | CFClient::SDL_ACTIVEEVENT => sub { |
|
|
866 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
799 | }, |
867 | }, |
800 | SDL_KEYDOWN() => sub { |
868 | CFClient::SDL_KEYDOWN => sub { |
801 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
869 | if ($_[0]{mod} & CFClient::KMOD_ALT && $_[0]{sym} == 13) { |
802 | # alt-enter |
870 | # alt-enter |
803 | video_shutdown; |
871 | video_shutdown; |
804 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
872 | $CFG->{fullscreen} = !$CFG->{fullscreen}; |
805 | video_init; |
873 | video_init; |
806 | } else { |
874 | } else { |
807 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
875 | CFClient::UI::feed_sdl_key_down_event ($_[0]); |
808 | } |
876 | } |
809 | }, |
877 | }, |
810 | SDL_KEYUP() => sub { |
878 | CFClient::SDL_KEYUP => \&CFClient::UI::feed_sdl_key_up_event, |
811 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
879 | CFClient::SDL_MOUSEMOTION => \&CFClient::UI::feed_sdl_motion_event, |
812 | }, |
880 | CFClient::SDL_MOUSEBUTTONDOWN => \&CFClient::UI::feed_sdl_button_down_event, |
813 | SDL_MOUSEMOTION() => sub { |
881 | CFClient::SDL_MOUSEBUTTONUP => \&CFClient::UI::feed_sdl_button_up_event, |
814 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
882 | CFClient::SDL_USEREVENT => \&audio_music_finished, |
815 | }, |
|
|
816 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
817 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
818 | }, |
|
|
819 | SDL_MOUSEBUTTONUP() => sub { |
|
|
820 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
821 | }, |
|
|
822 | SDL_ACTIVEEVENT() => sub { |
|
|
823 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
824 | }, |
|
|
825 | ); |
883 | ); |
826 | |
884 | |
827 | ############################################################################# |
885 | ############################################################################# |
828 | |
886 | |
829 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
887 | $SIG{INT} = $SIG{TERM} = sub { exit }; |
… | |
… | |
840 | fullscreen => 0, |
898 | fullscreen => 0, |
841 | fast => 0, |
899 | fast => 0, |
842 | fow_enable => 1, |
900 | fow_enable => 1, |
843 | fow_intensity => 0.45, |
901 | fow_intensity => 0.45, |
844 | fow_smooth => 0, |
902 | fow_smooth => 0, |
|
|
903 | gui_fontsize => 1, |
845 | log_fontsize => 14, |
904 | log_fontsize => 14, |
846 | mapsize => 100, |
905 | mapsize => 100, |
847 | host => "crossfire.schmorp.de", |
906 | host => "crossfire.schmorp.de", |
848 | say_command => 'say', |
907 | say_command => 'say', |
|
|
908 | audio_enable => 1, |
|
|
909 | bgm_enable => 1, |
|
|
910 | bgm_volume => 0.25, |
849 | ); |
911 | ); |
850 | |
912 | |
851 | while (my ($k, $v) = each %DEF_CFG) { |
913 | while (my ($k, $v) = each %DEF_CFG) { |
852 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
914 | $CFG->{$k} = $v unless exists $CFG->{$k}; |
853 | } |
915 | } |
854 | |
916 | |
855 | sdl_init; |
917 | sdl_init; |
856 | |
918 | |
857 | @SDL_MODES = reverse |
919 | @SDL_MODES = reverse |
858 | grep $_->[0] >= 640 && $_->[1] >= 480, |
920 | grep $_->[0] >= 640 && $_->[1] >= 480, |
859 | map [SDL::RectW ($_), SDL::RectH ($_)], |
921 | CFClient::SDL_ListModes; |
860 | @{ SDL::ListModes 0, SDL_FULLSCREEN | SDL_HWSURFACE | SDL_OPENGL }; |
|
|
861 | |
922 | |
862 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
923 | @SDL_MODES or CFClient::fatal "Unable to find a usable video mode\n(hardware accelerated opengl fullscreen)"; |
863 | |
924 | |
864 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
925 | $CFG->{sdl_mode} = 0 if $CFG->{sdl_mode} > @SDL_MODES; |
865 | |
926 | |
… | |
… | |
873 | video_init; |
934 | video_init; |
874 | audio_init; |
935 | audio_init; |
875 | |
936 | |
876 | Event::loop; |
937 | Event::loop; |
877 | |
938 | |
878 | END { SDL::Quit } |
939 | END { CFClient::SDL_Quit } |
879 | |
940 | |
880 | |
941 | |