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 Glib; |
6 | use Crossfire::Protocol; |
7 | use Gtk2 -init; |
7 | |
|
|
8 | package Crossfire::Client; # uh, yeah |
|
|
9 | |
|
|
10 | use strict; |
|
|
11 | |
8 | |
12 | use SDL; |
9 | use SDL; |
13 | use SDL::App; |
10 | use SDL::App; |
14 | use SDL::Event; |
11 | use SDL::Event; |
15 | use SDL::Surface; |
12 | use SDL::Surface; |
16 | use SDL::OpenGL; |
13 | use SDL::OpenGL; |
17 | use SDL::OpenGL::Constants; |
14 | use SDL::OpenGL::Constants; |
18 | |
15 | |
19 | my $conn; |
16 | use Crossfire; |
20 | my $app; |
17 | use Crossfire::Protocol; |
21 | |
18 | |
22 | my $WIDTH = 640; |
19 | use CFClient; |
23 | my $HEIGHT = 480; |
20 | use CFClient::UI; |
24 | |
21 | |
25 | sub glinit { |
22 | our $VERSION = '0.1'; |
26 | # nuke all gl context data |
23 | |
27 | |
24 | my $MAX_FPS = 30; |
|
|
25 | my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame |
|
|
26 | |
|
|
27 | our $FACECACHE; |
|
|
28 | |
|
|
29 | our $CFG; |
|
|
30 | our $CONN; |
|
|
31 | |
|
|
32 | our $WIDTH; |
|
|
33 | our $HEIGHT; |
|
|
34 | our $FULLSCREEN; |
|
|
35 | |
|
|
36 | our $NOW; |
|
|
37 | |
|
|
38 | our $MAPWIDGET; |
|
|
39 | our $FONTSIZE; |
|
|
40 | |
|
|
41 | our $SDL_TIMER; |
|
|
42 | our $SDL_APP; |
|
|
43 | our $SDL_EV; |
|
|
44 | our %SDL_CB; |
|
|
45 | |
|
|
46 | our $ALT_ENTER_MESSAGE; |
|
|
47 | our $STATUS_LINE; |
|
|
48 | our $DEBUG_STATUS; |
|
|
49 | |
|
|
50 | my $last_refresh; |
|
|
51 | my %ANIMATE; |
|
|
52 | my $refresh_handler; |
|
|
53 | |
|
|
54 | our ($tw, $te); # Test widget #d# |
|
|
55 | |
|
|
56 | sub init_screen { |
28 | $app = new SDL::App |
57 | $SDL_APP = new SDL::App |
29 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
58 | -flags => SDL_ANYFORMAT | SDL_HWSURFACE, |
30 | -title => "Crossfire+ Client", |
59 | -title => "Crossfire+ Client", |
31 | -width => $WIDTH, |
60 | -width => $WIDTH, |
32 | -height => $HEIGHT, |
61 | -height => $HEIGHT, |
33 | -opengl => 1, |
62 | -opengl => 1, |
34 | -red_size => 8, |
63 | -red_size => 5, |
35 | -green_size => 8, |
64 | -green_size => 5, |
36 | -blue_size => 8, |
65 | -blue_size => 5, |
|
|
66 | -alpha_size => 0, |
37 | -double_buffer => 1, |
67 | -double_buffer => 1, |
|
|
68 | -fullscreen => $FULLSCREEN, |
38 | -resizeable => 0; |
69 | -resizeable => 0; |
39 | |
70 | |
|
|
71 | $SDL_EV = new SDL::Event; |
|
|
72 | $SDL_EV->set_unicode (1); |
|
|
73 | |
|
|
74 | $SDL_TIMER = add Glib::Timeout 1000/50, sub { |
|
|
75 | ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() |
|
|
76 | while $SDL_EV->poll; |
|
|
77 | |
|
|
78 | 1 |
|
|
79 | }; |
|
|
80 | |
|
|
81 | $last_refresh = SDL::GetTicks; |
|
|
82 | |
|
|
83 | CFClient::gl_init; |
|
|
84 | |
|
|
85 | $FONTSIZE = int $HEIGHT / 50; |
|
|
86 | |
|
|
87 | ############################################################################# |
|
|
88 | |
|
|
89 | glClearColor 0.45, 0.45, 0.45, 1; |
|
|
90 | |
40 | glEnable GL_TEXTURE_2D; |
91 | glEnable GL_TEXTURE_2D; |
41 | glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; |
92 | glEnable GL_COLOR_MATERIAL; |
42 | glShadeModel GL_FLAT; |
93 | glShadeModel GL_FLAT; |
43 | glDisable GL_DEPTH_TEST; |
94 | glDisable GL_DEPTH_TEST; |
44 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
95 | glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; |
45 | glEnable GL_BLEND; |
96 | |
|
|
97 | ############################################################################# |
|
|
98 | |
|
|
99 | $DEBUG_STATUS = new CFClient::UI::Label; |
|
|
100 | $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS); |
|
|
101 | |
|
|
102 | $STATUS_LINE = new CFClient::UI::Label |
|
|
103 | y => $HEIGHT * 59 / 60 - $FONTSIZE; |
|
|
104 | $CFClient::UI::TOPLEVEL->add ($STATUS_LINE); |
|
|
105 | |
|
|
106 | $ALT_ENTER_MESSAGE = new CFClient::UI::Label |
|
|
107 | y => $HEIGHT * 59 / 60, |
|
|
108 | height => $HEIGHT / 60, |
|
|
109 | text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; |
|
|
110 | $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE); |
|
|
111 | |
|
|
112 | $MAPWIDGET = new CFClient::UI::MapWidget; |
|
|
113 | $CFClient::UI::TOPLEVEL->add ($MAPWIDGET); |
|
|
114 | $MAPWIDGET->focus_in; |
|
|
115 | |
|
|
116 | # Test code #d# |
|
|
117 | unless ($tw) { # haha... |
|
|
118 | my $w = new CFClient::UI::Window |
|
|
119 | w => 300, h => 300, |
|
|
120 | child => (my $frame = new CFClient::UI::FancyFrame); |
|
|
121 | $CFClient::UI::TOPLEVEL->add ($w); |
|
|
122 | |
|
|
123 | $frame->add (my $vbox = new CFClient::UI::VBox); |
|
|
124 | |
|
|
125 | $vbox->add (new CFClient::UI::Entry text => "hallo"); |
|
|
126 | $vbox->add (new CFClient::UI::Slider); |
|
|
127 | |
|
|
128 | $tw = new CFClient::UI::Animator x => $WIDTH - 200, w => 600, h => 300; |
|
|
129 | my $lbl1 = new CFClient::UI::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; |
|
|
130 | my $lbl2 = new CFClient::UI::Label text => "LBL2"; |
|
|
131 | my $vb = new CFClient::UI::VBox; |
|
|
132 | my $f = new CFClient::UI::FancyFrame; |
|
|
133 | my $f2 = new CFClient::UI::FancyFrame; |
|
|
134 | $f->add ($lbl1); |
|
|
135 | $f2->add ($lbl2); |
|
|
136 | $vb->add ($f); |
|
|
137 | $vb->add ($f2, 1); |
|
|
138 | |
|
|
139 | $tw->add ($vb); |
|
|
140 | $tw->moveto (0, 0); |
|
|
141 | $CFClient::UI::TOPLEVEL->add ($tw); |
|
|
142 | |
|
|
143 | # $f->move ($WIDTH - 200, 0); |
|
|
144 | # $CFClient::UI::TOPLEVEL->add ($f); |
|
|
145 | } |
|
|
146 | } |
|
|
147 | |
|
|
148 | sub destroy_screen { |
|
|
149 | remove Glib::Source $SDL_TIMER; |
|
|
150 | undef $SDL_APP; |
|
|
151 | undef $SDL_EV; |
|
|
152 | SDL::Quit; |
|
|
153 | } |
|
|
154 | |
|
|
155 | sub config_dialog { |
|
|
156 | my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100, |
|
|
157 | child => (my $vbox = new CFClient::UI::VBox); |
|
|
158 | $vbox->add (new CFClient::UI::Label align => 0, text => "Setup"); |
|
|
159 | |
|
|
160 | $CFClient::UI::TOPLEVEL->add ($dialog); |
|
|
161 | } |
|
|
162 | |
|
|
163 | sub start_game { |
|
|
164 | $WIDTH = $CFG->{width}; |
|
|
165 | $HEIGHT = $CFG->{height}; |
|
|
166 | $FULLSCREEN = 0; |
|
|
167 | |
|
|
168 | init_screen; |
|
|
169 | |
|
|
170 | config_dialog; |
|
|
171 | |
|
|
172 | my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; |
|
|
173 | |
|
|
174 | $CONN = new conn |
|
|
175 | host => $CFG->{host}, |
|
|
176 | port => $CFG->{port}, |
|
|
177 | user => $CFG->{user}, |
|
|
178 | pass => $CFG->{password}, |
|
|
179 | mapw => $mapsize, |
|
|
180 | maph => $mapsize, |
|
|
181 | ; |
|
|
182 | |
|
|
183 | CFClient::lowdelay fileno $CONN->{fh}; |
|
|
184 | } |
|
|
185 | |
|
|
186 | sub stop_game { |
|
|
187 | remove Glib::Source $refresh_handler if $refresh_handler; |
|
|
188 | undef $refresh_handler; |
|
|
189 | |
|
|
190 | undef $CONN; |
|
|
191 | destroy_screen; |
|
|
192 | } |
|
|
193 | |
|
|
194 | sub force_refresh { |
|
|
195 | glViewport 0, 0, $WIDTH, $HEIGHT; |
46 | |
196 | |
47 | glMatrixMode GL_PROJECTION; |
197 | glMatrixMode GL_PROJECTION; |
48 | glLoadIdentity; |
198 | glLoadIdentity; |
49 | glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1; |
199 | glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; |
|
|
200 | glMatrixMode GL_MODELVIEW; |
50 | |
201 | |
51 | # re-bind all textures |
202 | glClear GL_COLOR_BUFFER_BIT; |
|
|
203 | |
|
|
204 | $CFClient::UI::TOPLEVEL->draw; |
|
|
205 | |
|
|
206 | SDL::GLSwapBuffers; |
52 | } |
207 | } |
|
|
208 | |
|
|
209 | sub debug { |
|
|
210 | $DEBUG_STATUS->set_text ($_[0]); |
|
|
211 | $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); |
|
|
212 | $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); |
|
|
213 | } |
|
|
214 | |
|
|
215 | my $FPS; |
53 | |
216 | |
54 | sub refresh { |
217 | sub refresh { |
55 | glClearColor 0, 0, 0, 0; |
218 | $refresh_handler ||= add Glib::Idle sub { |
56 | glClear GL_COLOR_BUFFER_BIT; |
219 | if ($SDL_APP) { |
|
|
220 | $NOW = SDL::GetTicks; |
57 | |
221 | |
58 | my $map = $conn->{map}; |
222 | if ($NOW - $last_refresh < $TICKS_PER_FRAME) { |
59 | |
223 | SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh); |
60 | for my $x (0 .. $conn->{mapw} - 1) { |
224 | $NOW = SDL::GetTicks; |
61 | for my $y (0 .. $conn->{maph} - 1) { |
|
|
62 | |
|
|
63 | my $cell = $map->[$x][$y] |
|
|
64 | or next; |
|
|
65 | |
|
|
66 | my $darkness = $cell->[3] * (1 / 255); |
|
|
67 | my $darkness = 0.8 + 0.2*rand; |
|
|
68 | glColor $darkness, $darkness, $darkness; |
|
|
69 | |
|
|
70 | for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) { |
|
|
71 | my $tex = $conn->{face}[$num]{texture} || 0; |
|
|
72 | |
|
|
73 | glBindTexture GL_TEXTURE_2D, $tex; |
|
|
74 | |
|
|
75 | glBegin GL_QUADS; |
|
|
76 | glTexCoord 0, 0; glVertex $x, $y; |
|
|
77 | glTexCoord 0, 1; glVertex $x, $y + 1; |
|
|
78 | glTexCoord 1, 1; glVertex $x + 1, $y + 1; |
|
|
79 | glTexCoord 1, 0; glVertex $x + 1, $y; |
|
|
80 | glEnd; |
|
|
81 | } |
225 | } |
|
|
226 | |
|
|
227 | my $interval = ($NOW - $last_refresh) * 0.001; |
|
|
228 | $last_refresh = $NOW; |
|
|
229 | |
|
|
230 | if ($interval) { |
|
|
231 | $FPS ||= 1 / $interval; |
|
|
232 | $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; |
|
|
233 | debug sprintf "%5.02f", $FPS; |
|
|
234 | } |
|
|
235 | |
|
|
236 | force_refresh; |
|
|
237 | $_->animate ($interval) for grep $_, values %ANIMATE; |
|
|
238 | |
|
|
239 | if (%ANIMATE) { |
|
|
240 | 1 |
|
|
241 | } else { |
|
|
242 | undef $refresh_handler; |
|
|
243 | 0 |
|
|
244 | } |
|
|
245 | } else { |
|
|
246 | undef $refresh_handler; |
|
|
247 | 0 |
82 | } |
248 | } |
83 | } |
249 | }; |
84 | |
|
|
85 | SDL::GLSwapBuffers; |
|
|
86 | } |
250 | } |
87 | |
251 | |
88 | my $ev = new SDL::Event; |
252 | sub animation_start { |
89 | my %ev_cb; |
253 | my ($widget) = @_; |
|
|
254 | $ANIMATE{$widget} = $widget; |
|
|
255 | Scalar::Util::weaken $ANIMATE{$widget}; |
90 | |
256 | |
91 | sub event(&$) { |
|
|
92 | $ev_cb{$_[0]->()} = $_[1]; |
|
|
93 | } |
|
|
94 | |
|
|
95 | sub does(&) { shift } |
|
|
96 | |
|
|
97 | event {SDL_QUIT} does { |
|
|
98 | exit; |
|
|
99 | }; |
|
|
100 | |
|
|
101 | event {SDL_VIDEORESIZE} does { |
|
|
102 | print "resize\n"; |
|
|
103 | }; |
|
|
104 | |
|
|
105 | event {SDL_VIDEOEXPOSE} does { |
|
|
106 | refresh; |
257 | refresh; |
107 | }; |
258 | } |
108 | |
259 | |
109 | event {SDL_KEYDOWN} does { |
260 | sub animation_stop { |
110 | print "keypress\n"; |
261 | my ($widget) = @_; |
111 | }; |
262 | delete $ANIMATE{$widget}; |
|
|
263 | } |
112 | |
264 | |
113 | event {SDL_KEYUP} does { |
265 | %SDL_CB = ( |
114 | print "keyup\n";#d# |
266 | SDL_QUIT() => sub { |
115 | }; |
267 | main_quit Gtk2; |
116 | |
268 | }, |
117 | event {SDL_MOUSEMOTION} does { |
269 | SDL_VIDEORESIZE() => sub { |
118 | print "motion\n"; |
270 | }, |
119 | }; |
271 | SDL_VIDEOEXPOSE() => sub { |
120 | |
272 | refresh; |
121 | event {SDL_MOUSEBUTTONDOWN} does { |
273 | }, |
122 | print "button\n"; |
274 | SDL_KEYDOWN() => sub { |
123 | }; |
275 | if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { |
124 | |
276 | # alt-enter |
125 | event {SDL_MOUSEBUTTONUP} does { |
277 | $FULLSCREEN = !$FULLSCREEN; |
126 | print "buttup\n"; |
278 | init_screen; |
127 | }; |
279 | } else { |
128 | |
280 | CFClient::UI::feed_sdl_key_down_event ($SDL_EV); |
129 | event {SDL_ACTIVEEVENT} does { |
281 | } |
130 | print "active\n"; |
282 | }, |
131 | }; |
283 | SDL_KEYUP() => sub { |
132 | |
284 | CFClient::UI::feed_sdl_key_up_event ($SDL_EV); |
133 | package Crossfire::Client; |
285 | }, |
|
|
286 | SDL_MOUSEMOTION() => sub { |
|
|
287 | CFClient::UI::feed_sdl_motion_event ($SDL_EV); |
|
|
288 | }, |
|
|
289 | SDL_MOUSEBUTTONDOWN() => sub { |
|
|
290 | CFClient::UI::feed_sdl_button_down_event ($SDL_EV); |
|
|
291 | }, |
|
|
292 | SDL_MOUSEBUTTONUP() => sub { |
|
|
293 | CFClient::UI::feed_sdl_button_up_event ($SDL_EV); |
|
|
294 | }, |
|
|
295 | SDL_ACTIVEEVENT() => sub { |
|
|
296 | # printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# |
|
|
297 | }, |
|
|
298 | ); |
134 | |
299 | |
135 | @conn::ISA = Crossfire::Protocol::; |
300 | @conn::ISA = Crossfire::Protocol::; |
136 | |
301 | |
137 | sub conn::map_update { |
302 | sub conn::map_update { |
138 | my ($self, $dirty) = @_; |
303 | my ($self, $dirty) = @_; |
139 | |
304 | |
140 | refresh; |
305 | $MAPWIDGET->update; |
141 | } |
306 | } |
142 | |
307 | |
143 | sub conn::map_scroll { |
308 | sub conn::map_scroll { |
144 | my ($self, $dx, $dy) = @_; |
309 | my ($self, $dx, $dy) = @_; |
145 | |
310 | |
146 | refresh; |
311 | # refresh; |
147 | } |
312 | } |
148 | |
313 | |
149 | sub conn::map_clear { |
314 | sub conn::map_clear { |
150 | my ($self) = @_; |
315 | my ($self) = @_; |
151 | |
316 | |
152 | refresh; |
317 | # refresh; |
|
|
318 | } |
|
|
319 | |
|
|
320 | sub conn::face_find { |
|
|
321 | my ($self, $face) = @_; |
|
|
322 | |
|
|
323 | $FACECACHE->{"$face->{chksum},$face->{name}"} |
153 | } |
324 | } |
154 | |
325 | |
155 | sub conn::face_update { |
326 | sub conn::face_update { |
156 | my ($self, $num, $face) = @_; |
327 | my ($self, $face) = @_; |
157 | |
328 | |
158 | warn "up face $self,$num,$face\n";#d# |
329 | $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; |
159 | use Gtk2; |
|
|
160 | |
330 | |
161 | my $pb = new Gtk2::Gdk::PixbufLoader; |
331 | $face->{texture} = new_from_image CFClient::Texture delete $face->{image}; |
162 | $pb->write ($face->{image}); |
332 | } |
163 | $pb->close; |
|
|
164 | |
333 | |
165 | $pb = $pb->get_pixbuf; |
334 | sub conn::query { |
166 | $pb = $pb->add_alpha (0, 0, 0, 0); |
335 | my ($self, $flags, $prompt) = @_; |
167 | |
336 | |
168 | glGetError(); |
337 | warn "<<<<QUERY:$flags:$prompt>>>\n";#d# |
169 | my ($tex) = @{glGenTextures 1}; |
338 | } |
170 | |
339 | |
171 | $face->{texture} = $tex; |
340 | sub gtk_add_cfg_field { |
|
|
341 | my ($tbl, $cfg, $klbl, $key, $value) = @_; |
|
|
342 | my $i = $cfg->{_i}++; |
|
|
343 | $tbl->attach_defaults (my $lbl = Gtk2::Label->new ($klbl), 0, 1, $i, $i + 1); |
|
|
344 | $tbl->attach_defaults (my $ent = Gtk2::Entry->new, 1, 2, $i, $i + 1); |
|
|
345 | if ($key eq 'password') { |
|
|
346 | $ent->set_invisible_char ("*"); |
|
|
347 | $ent->set (visibility => 0) |
|
|
348 | } |
|
|
349 | $ent->set_text ($value); |
|
|
350 | $ent->signal_connect (changed => sub { |
|
|
351 | my ($ent) = @_; |
|
|
352 | $cfg->{$key} = $ent->get_text; |
|
|
353 | # TODO: Mapsize should be a slider in the game gui |
|
|
354 | if ($key eq 'mapsize' and $cfg->{$key} > 100) { |
|
|
355 | $cfg->{$key} = 100; |
|
|
356 | } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) { |
|
|
357 | $cfg->{$key} = 50; |
|
|
358 | } |
|
|
359 | }); |
|
|
360 | } |
|
|
361 | |
|
|
362 | sub run_config_dialog { |
|
|
363 | my (%events) = @_; |
|
|
364 | |
|
|
365 | my $w = Gtk2::Window->new; |
|
|
366 | |
|
|
367 | my @cfg = ( |
|
|
368 | [qw/Host host/], |
|
|
369 | [qw/Port port/], |
|
|
370 | [qw/Mapsize% mapsize/], |
|
|
371 | [qw/Username user/], |
|
|
372 | [qw/Password password/], |
172 | |
373 | ); |
173 | glBindTexture GL_TEXTURE_2D, $tex; |
374 | |
174 | my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr; |
375 | my $cfg = {}; |
|
|
376 | |
|
|
377 | my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE); |
|
|
378 | my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a; |
|
|
379 | |
|
|
380 | $w->add (my $vb = Gtk2::VBox->new); |
|
|
381 | $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); |
|
|
382 | my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; |
|
|
383 | $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); |
|
|
384 | $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); |
|
|
385 | my $i = 0; |
|
|
386 | my $act = 0; |
|
|
387 | for (map { "$_->[0]x$_->[1]" } reverse @modes) { |
|
|
388 | if ($_ eq $selmode) { $act = $i } |
|
|
389 | $cb->append_text ($_); |
|
|
390 | $i++; |
|
|
391 | } |
|
|
392 | $cb->set_active ($act); |
|
|
393 | $cb->signal_connect (changed => sub { |
|
|
394 | my ($cb) = @_; |
|
|
395 | my $txt = $cb->get_active_text; |
|
|
396 | if ($txt =~ m/(\d+)x(\d+)/) { |
|
|
397 | $::CFG->{width} = $1; |
|
|
398 | $::CFG->{height} = $2; |
175 | |
399 | } |
176 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR; |
400 | }); |
177 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR; |
401 | |
178 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP; |
402 | $cfg->{_i} = 1; |
179 | glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP; |
403 | for (@cfg) { |
180 | |
404 | gtk_add_cfg_field ($t, $cfg, $_->[0], $_->[1], $::CFG->{$_->[1]}); |
181 | glTexImage2D GL_TEXTURE_2D, 0, |
405 | } |
182 | GL_RGBA8, |
406 | |
183 | $pb->get_width, $pb->get_height, |
407 | $vb->pack_start (my $hb = Gtk2::HBox->new, 0, 0, 0); |
|
|
408 | $hb->pack_start (my $cb = Gtk2::Button->new ("save"), 1, 1, 5); |
|
|
409 | $cb->signal_connect (clicked => sub { |
|
|
410 | for (keys %$cfg) { |
|
|
411 | $::CFG->{$_} = $cfg->{$_} |
|
|
412 | if $_ ne '_i'; |
184 | 0, |
413 | } |
|
|
414 | CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc"; |
|
|
415 | }); |
|
|
416 | $hb->pack_start (my $cb = Gtk2::Button->new ("login"), 1, 1, 5); |
|
|
417 | $cb->signal_connect (clicked => sub { |
|
|
418 | for (keys %$cfg) { |
|
|
419 | $::CFG->{$_} = $cfg->{$_} |
|
|
420 | if $_ ne '_i'; |
185 | GL_RGBA, |
421 | } |
186 | GL_UNSIGNED_BYTE, |
422 | my $cb = $events{login} || sub {}; |
187 | $pb->get_pixels; |
423 | $cb->($::CFG->{user}, $::CFG->{password}); |
188 | my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr; |
424 | }); |
|
|
425 | $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); |
|
|
426 | $cb->signal_connect (clicked => sub { |
|
|
427 | my $cb = $events{logout} || sub {}; |
|
|
428 | $cb->(); |
|
|
429 | }); |
|
|
430 | $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); |
|
|
431 | $cb->signal_connect (clicked => sub { $w->destroy }); |
|
|
432 | |
|
|
433 | $w->show_all; |
|
|
434 | |
|
|
435 | $w->signal_connect (destroy => sub { Gtk2->main_quit }); |
189 | } |
436 | } |
|
|
437 | |
190 | |
438 | |
191 | ############################################################################# |
439 | ############################################################################# |
192 | |
440 | |
193 | use Event; |
441 | SDL::Init SDL_INIT_EVERYTHING; |
194 | |
442 | |
195 | glinit; |
443 | CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; |
196 | |
444 | |
197 | $conn = new conn |
445 | $CFG ||= { |
|
|
446 | width => 640, |
|
|
447 | height => 480, |
|
|
448 | mapsize => 100, |
|
|
449 | fullscreen => 0, |
198 | host => "cf.schmorp.de", |
450 | host => "crossfire.schmorp.de", |
199 | port => 13327; |
451 | port => 13327, |
200 | |
|
|
201 | Event->timer (after => 0, interval => 1/20, hard => 1, cb => sub { |
|
|
202 | while ($ev->poll) { |
|
|
203 | ($ev_cb{$ev->type} || sub { warn "unhandled event ", $ev->type })->(); |
|
|
204 | } |
|
|
205 | }); |
452 | }; |
206 | |
453 | |
207 | Event::loop; |
454 | { |
|
|
455 | my @fonts = map CFClient::find_rcfile $_, qw(uifont.ttf uifontb.ttf uifonti.ttf uifontbi.ttf); |
208 | |
456 | |
|
|
457 | CFClient::add_font $_ for @fonts; |
|
|
458 | CFClient::set_font $fonts[0]; |
|
|
459 | } |
209 | |
460 | |
|
|
461 | $FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; |
|
|
462 | |
|
|
463 | run_config_dialog |
|
|
464 | login => sub { start_game }, |
|
|
465 | logout => sub { stop_game }; |
|
|
466 | |
|
|
467 | main Gtk2; |
|
|
468 | |
|
|
469 | Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; |