ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pclient (file contents):
Revision 1.47 by elmex, Sun Apr 9 18:28:23 2006 UTC vs.
Revision 1.59 by root, Mon Apr 10 11:55:16 2006 UTC

12use SDL::Surface; 12use SDL::Surface;
13use SDL::OpenGL; 13use SDL::OpenGL;
14use SDL::OpenGL::Constants; 14use SDL::OpenGL::Constants;
15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Protocol;
18
17use Crossfire::Client; 19use Crossfire::Client;
18use Crossfire::Protocol;
19
20use Crossfire::Client::Widget; 20use Crossfire::Client::Widget;
21 21
22our $FACECACHE; 22our $FACECACHE;
23 23
24our $VERSION = '0.1'; 24our $VERSION = '0.1';
34 34
35our $FONTSIZE; 35our $FONTSIZE;
36 36
37our $SDL_TIMER; 37our $SDL_TIMER;
38our $SDL_APP; 38our $SDL_APP;
39our $SDL_EV = new SDL::Event; 39our $SDL_EV;
40our %SDL_CB; 40our %SDL_CB;
41 41
42our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
43 43
44our $ALT_ENTER_MESSAGE; 44our $ALT_ENTER_MESSAGE;
45 45our $STATUS_LINE;
46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49 46
50my $last_refresh; 47my $last_refresh;
48my %ANIMATE;
49my $refresh_handler;
50
51our ($tw, $te); # Test widget #d#
51 52
52sub init_screen { 53sub init_screen {
53 $SDL_APP = new SDL::App 54 $SDL_APP = new SDL::App
54 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 55 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
55 -title => "Crossfire+ Client", 56 -title => "Crossfire+ Client",
56 -width => $WIDTH, 57 -width => $WIDTH,
57 -height => $HEIGHT, 58 -height => $HEIGHT,
58 -opengl => 1, 59 -opengl => 1,
59 -red_size => 8, 60 -red_size => 5,
60 -green_size => 8, 61 -green_size => 5,
61 -blue_size => 8, 62 -blue_size => 5,
63 -alpha_size => 0,
62 -double_buffer => 1, 64 -double_buffer => 1,
63 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
64 -resizeable => 0; 66 -resizeable => 0;
65 67
68 $SDL_EV = new SDL::Event;
69 $SDL_EV->set_unicode (1);
70
66 $last_refresh = SDL::GetTicks; 71 $last_refresh = SDL::GetTicks;
67 72
68 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 73 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
69 74
70 $GL_EXT{GL_ARB_texture_non_power_of_two} 75 $GL_EXT{GL_ARB_texture_non_power_of_two}
71 or warn "WARNING: non-power-of-two opengl extension required"; 76 or warn "WARNING: non-power-of-two opengl extension required";
72 77
73 $FONTSIZE = int $HEIGHT / 50; 78 $FONTSIZE = int $HEIGHT / 50;
74 79
80 #############################################################################
81
82 glClearColor 1, 1, 1, 1;
83
84 glEnable GL_TEXTURE_2D;
85 glEnable GL_COLOR_MATERIAL;
86 glShadeModel GL_FLAT;
87 glDisable GL_DEPTH_TEST;
88 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
89
90 $_->() for @GL_INIT;
91
92 #############################################################################
93
94 $STATUS_LINE = new Crossfire::Client::Widget::Label
95 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
96 "";
97 $Crossfire::Client::Widget::TOPLEVEL->add ($STATUS_LINE);
98
75 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 99 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
76 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, 100 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
77 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 101 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
78 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); 102 $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
79 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
80 103
81 # Test code #d# 104 # Test code #d#
82 unless ($tw) { # haha... 105 unless ($tw) { # haha...
106 $te = new Crossfire::Client::Widget::FancyFrame;
107 $te->add (new Crossfire::Client::Widget::Entry);
108 $te->move (300, 0, 2);
109 $Crossfire::Client::Widget::TOPLEVEL->add ($te);
110
83 $tw = new Crossfire::Client::Widget::Animator; 111 $tw = new Crossfire::Client::Widget::Animator;
84 my $lbl1 = new Crossfire::Client::Widget::Label 112 my $lbl1 = new Crossfire::Client::Widget::Label
85 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; 113 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
86 my $lbl2 = new Crossfire::Client::Widget::Label 114 my $lbl2 = new Crossfire::Client::Widget::Label
87 0, 0, 10, $FONTSIZE, "LBL2"; 115 0, 0, 10, $FONTSIZE, "LBL2";
97 $tw->add ($vb); 125 $tw->add ($vb);
98 $tw->w (400); 126 $tw->w (400);
99 $tw->h (300); 127 $tw->h (300);
100 $tw->move ($WIDTH - 200, 0); 128 $tw->move ($WIDTH - 200, 0);
101 $tw->moveto (0, 0); 129 $tw->moveto (0, 0);
102 $TOPLEVEL->add ($tw); 130 $Crossfire::Client::Widget::TOPLEVEL->add ($tw);
103 131
104# $f->move ($WIDTH - 200, 0); 132# $f->move ($WIDTH - 200, 0);
105# $TOPLEVEL->add ($f); 133# $Crossfire::Client::Widget::TOPLEVEL->add ($f);
106 } 134 }
107
108 glClearColor 0, 0, 0, 0;
109
110 glEnable GL_TEXTURE_2D;
111 glEnable GL_COLOR_MATERIAL;
112 glShadeModel GL_FLAT;
113 glDisable GL_DEPTH_TEST;
114 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
115
116 $_->() for @GL_INIT;
117} 135}
118 136
119sub start_game { 137sub start_game {
120 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 138 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
121 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 139 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
122 while $SDL_EV->poll; 140 while $SDL_EV->poll;
123 141
124 1 142 1
125 }; 143 };
127 $WIDTH = $CFG->{width}; 145 $WIDTH = $CFG->{width};
128 $HEIGHT = $CFG->{height}; 146 $HEIGHT = $CFG->{height};
129 $FULLSCREEN = 0; 147 $FULLSCREEN = 0;
130 148
131 init_screen; 149 init_screen;
150
151 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
132 152
133 $CONN = new conn 153 $CONN = new conn
134 host => $CFG->{host}, 154 host => $CFG->{host},
135 port => $CFG->{port}, 155 port => $CFG->{port},
136 user => $CFG->{user}, 156 user => $CFG->{user},
137 pass => $CFG->{password}, 157 pass => $CFG->{password},
138 mapw => 50, 158 mapw => $mapsize,
139 maph => 37, 159 maph => $mapsize,
140 ; 160 ;
141 161
142 Crossfire::Client::lowdelay fileno $CONN->{fh}; 162 Crossfire::Client::lowdelay fileno $CONN->{fh};
143} 163}
144 164
145sub stop_game { 165sub stop_game {
146 remove Glib::Source $SDL_TIMER; 166 remove Glib::Source $SDL_TIMER;
167 remove Glib::Source $refresh_handler if $refresh_handler;
168 undef $refresh_handler;
147 169
148 undef $SDL_APP; 170 undef $SDL_APP;
171 undef $CONN;
149 SDL::Quit; 172 SDL::Quit;
150} 173}
151
152 174
153sub force_refresh { 175sub force_refresh {
154 glViewport 0, 0, $WIDTH, $HEIGHT; 176 glViewport 0, 0, $WIDTH, $HEIGHT;
155 177
156 glMatrixMode GL_PROJECTION; 178 glMatrixMode GL_PROJECTION;
157 glLoadIdentity; 179 glLoadIdentity;
158 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; 180 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
159 glMatrixMode GL_MODELVIEW; 181 glMatrixMode GL_MODELVIEW;
160 182
161 glClear GL_COLOR_BUFFER_BIT; 183 glClear GL_COLOR_BUFFER_BIT;
162 184
163 $TOPLEVEL->draw; 185 $Crossfire::Client::Widget::TOPLEVEL->draw;
164 186
165 SDL::GLSwapBuffers; 187 SDL::GLSwapBuffers;
166} 188}
167
168my %ANIMATE;
169
170my $refresh_handler;
171 189
172sub refresh { 190sub refresh {
173 $refresh_handler ||= add Glib::Idle sub { 191 $refresh_handler ||= add Glib::Idle sub {
192 if ($SDL_APP) {
174 my $next_refresh = SDL::GetTicks; 193 my $next_refresh = SDL::GetTicks;
175 my $interval = ($next_refresh - $last_refresh) * 0.001; 194 my $interval = ($next_refresh - $last_refresh) * 0.001;
176 $last_refresh = $next_refresh; 195 $last_refresh = $next_refresh;
177 196
178 force_refresh; 197 force_refresh;
179 $_->animate ($interval) for grep $_, values %ANIMATE; 198 $_->animate ($interval) for grep $_, values %ANIMATE;
180 199
181 if (%ANIMATE) { 200 if (%ANIMATE) {
201 1
202 } else {
203 undef $refresh_handler;
204 0
182 1 205 }
183 } else { 206 } else {
184 undef $refresh_handler; 207 undef $refresh_handler;
185 0 208 0
186 } 209 }
187 }; 210 };
220 }, 243 },
221 SDL_KEYUP() => sub { 244 SDL_KEYUP() => sub {
222 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); 245 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
223 }, 246 },
224 SDL_MOUSEMOTION() => sub { 247 SDL_MOUSEMOTION() => sub {
225 warn "sdl motion\n";#d# 248 Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV);
226 }, 249 },
227 SDL_MOUSEBUTTONDOWN() => sub { 250 SDL_MOUSEBUTTONDOWN() => sub {
228 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); 251 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
229 }, 252 },
230 SDL_MOUSEBUTTONUP() => sub { 253 SDL_MOUSEBUTTONUP() => sub {
231 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); 254 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV);
232 }, 255 },
233 SDL_ACTIVEEVENT() => sub { 256 SDL_ACTIVEEVENT() => sub {
234 warn "active\n";#d# 257 printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
235 }, 258 },
236); 259);
237 260
238@conn::ISA = Crossfire::Protocol::; 261@conn::ISA = Crossfire::Protocol::;
239 262
286 } 309 }
287 $ent->set_text ($value); 310 $ent->set_text ($value);
288 $ent->signal_connect (changed => sub { 311 $ent->signal_connect (changed => sub {
289 my ($ent) = @_; 312 my ($ent) = @_;
290 $cfg->{$key} = $ent->get_text; 313 $cfg->{$key} = $ent->get_text;
314 # TODO: Mapsize should be a slider in the game gui
291 if ($key eq 'mapsize' and $cfg->{$key} > 100) { 315 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
292 $cfg->{$key} = 100; 316 $cfg->{$key} = 100;
293 $ent->set_text ('100');
294 } elsif ($key eq 'mapsize' and $cfg->{$key} < 0) { 317 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
295 $cfg->{$key} = 0; 318 $cfg->{$key} = 50;
296 $ent->set_text ('0');
297 } 319 }
298 }); 320 });
299} 321}
300 322
301sub run_config_dialog { 323sub run_config_dialog {
361 my $cb = $events{login} || sub {}; 383 my $cb = $events{login} || sub {};
362 $cb->($::CFG->{user}, $::CFG->{password}); 384 $cb->($::CFG->{user}, $::CFG->{password});
363 }); 385 });
364 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); 386 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
365 $cb->signal_connect (clicked => sub { 387 $cb->signal_connect (clicked => sub {
366 my $cb = $events{login} || sub {}; 388 my $cb = $events{logout} || sub {};
367 $cb->(); 389 $cb->();
368 }); 390 });
369 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); 391 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
370 $cb->signal_connect (clicked => sub { $w->destroy }); 392 $cb->signal_connect (clicked => sub { $w->destroy });
371 393
377 399
378############################################################################# 400#############################################################################
379 401
380SDL::Init SDL_INIT_EVERYTHING; 402SDL::Init SDL_INIT_EVERYTHING;
381 403
382$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
383
384my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 404my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
385 405
386$TOPLEVEL->add ($mapwidget); 406$Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget);
387$mapwidget->focus_in; 407$mapwidget->focus_in;
388 408
389Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 409Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
390 410
391$CFG ||= { 411$CFG ||= {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines