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