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.69 by root, Tue Apr 11 14:04:27 2006 UTC vs.
Revision 1.82 by root, Wed Apr 12 12:16:59 2006 UTC

15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Protocol; 17use Crossfire::Protocol;
18 18
19use CFClient; 19use CFClient;
20use CFClient::Widget; 20use CFClient::UI;
21 21
22our $VERSION = '0.1'; 22our $VERSION = '0.1';
23 23
24my $MAX_FPS = 30; 24my $MAX_FPS = 60;
25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame 25my $TICKS_PER_FRAME = int 1000 / $MAX_FPS - 1; # min ticks per frame
26 26
27our $FACECACHE; 27our $FACECACHE;
28 28
29our $CFG; 29our $CFG;
30our $CONN; 30our $CONN;
31our $FAST; # fast, low-quality mode
31 32
33our @SDL_MODES;
32our $WIDTH; 34our $WIDTH;
33our $HEIGHT; 35our $HEIGHT;
34our $FULLSCREEN; 36our $FULLSCREEN;
37
38our $NOW;
35 39
36our $MAPWIDGET; 40our $MAPWIDGET;
37our $FONTSIZE; 41our $FONTSIZE;
38 42
39our $SDL_TIMER; 43our $SDL_TIMER;
47 51
48my $last_refresh; 52my $last_refresh;
49my %ANIMATE; 53my %ANIMATE;
50my $refresh_handler; 54my $refresh_handler;
51 55
52our ($tw, $te); # Test widget #d# 56sub status {
57 $STATUS_LINE->set_text ($_[0]);
58 my ($w, $h) = $STATUS_LINE->size_request;
59 $STATUS_LINE->size_allocate (0, $HEIGHT - $ALT_ENTER_MESSAGE->{h} - $h, $w, $h);
60}
61
62sub debug {
63 $DEBUG_STATUS->set_text ($_[0]);
64 my ($w, $h) = $DEBUG_STATUS->size_request;
65 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
66}
67
68sub config_dialog {
69 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
70 child => (my $vbox = new CFClient::UI::VBox);
71 $vbox->add (new CFClient::UI::Label align => 0, text => "Client Setup");
72 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
73
74 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
75 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
76
77 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
78 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
79
80 $mode_slider->connect (changed => sub {
81 my ($self, $value) = @_;
82
83 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
84 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
85 });
86 $mode_slider->emit (changed => $mode_slider->{range}[0]);
87
88 $table->add (1, 1, new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
89 warn "apply\n";
90 });
91
92 $vbox->add (new CFClient::UI::Label align => 0, text => "Server");
93 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
94 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Host");
95 $table->add (1, 2, my $host = new CFClient::UI::Entry text => $CFG->{host});
96
97 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Port");
98 $table->add (1, 3, my $port = new CFClient::UI::Entry text => $CFG->{port});
99
100 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Username");
101 $table->add (1, 4, my $user = new CFClient::UI::Entry text => $CFG->{user});
102
103 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Password");
104 $table->add (1, 5, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
105
106 $table->add (0, 6, new CFClient::UI::Label align => 1, text => "Map Size");
107 $table->add (1, 6, new CFClient::UI::Slider
108 req_w => 100,
109 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
110 connect_changed => sub {
111 my ($self, $value) = @_;
112
113 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
114 },
115 );
116
117 $table->add (1, 7, new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
118 warn "login\n";
119 });
120
121 $vbox->add (my $hbox = new CFClient::UI::HBox);
122
123 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
124 CFClient::write_cfg "$CFrossfire::VARDIR/pclientrc";
125 status "Configuration Saved";
126 });
127 $CFClient::UI::TOPLEVEL->add ($dialog);
128}
53 129
54sub init_screen { 130sub init_screen {
55 $SDL_APP = new SDL::App 131 $SDL_APP = new SDL::App
56 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 132 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
57 -title => "Crossfire+ Client", 133 -title => "Crossfire+ Client",
67 -resizeable => 0; 143 -resizeable => 0;
68 144
69 $SDL_EV = new SDL::Event; 145 $SDL_EV = new SDL::Event;
70 $SDL_EV->set_unicode (1); 146 $SDL_EV->set_unicode (1);
71 147
72 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 148 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub {
73 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 149 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
74 while $SDL_EV->poll; 150 while $SDL_EV->poll;
75 151
76 1 152 1
77 }; 153 };
78 154
79 $last_refresh = SDL::GetTicks; 155 $last_refresh = SDL::GetTicks;
80 156
81 CFClient::gl_init; 157 CFClient::gl_init;
82 158
83 $FONTSIZE = int $HEIGHT / 50; 159 $FONTSIZE = int $HEIGHT / 40;
84 160
85 ############################################################################# 161 #############################################################################
86 162
87 glClearColor 0.45, 0.45, 0.45, 1;
88
89 glEnable GL_TEXTURE_2D;
90 glEnable GL_COLOR_MATERIAL;
91 glShadeModel GL_FLAT;
92 glDisable GL_DEPTH_TEST;
93 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
94
95 #############################################################################
96
97 $DEBUG_STATUS = new CFClient::Widget::Label; 163 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
98 $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); 164 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
99 165
100 $STATUS_LINE = new CFClient::Widget::Label 166 $STATUS_LINE = new CFClient::UI::Label
167 padding => 0,
101 y => $HEIGHT * 59 / 60 - $FONTSIZE; 168 y => $HEIGHT * 49 / 50 - $FONTSIZE;
102 $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); 169 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
103 170
104 $ALT_ENTER_MESSAGE = new CFClient::Widget::Label 171 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
172 padding => 0,
105 y => $HEIGHT * 59 / 60, 173 y => $HEIGHT * 49 / 50,
106 height => $HEIGHT / 60, 174 height => $HEIGHT / 50,
107 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 175 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
108 $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 176 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
109 177
110 $MAPWIDGET = new CFClient::Widget::MapWidget; 178 $MAPWIDGET = new CFClient::UI::MapWidget;
111 $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); 179 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
112 $MAPWIDGET->focus_in; 180 $MAPWIDGET->focus_in;
113 181
114 # Test code #d# 182 config_dialog;
115 unless ($tw) { # haha...
116 $te = new CFClient::Widget::FancyFrame x => 300, z => 1;
117 $te->add (new CFClient::Widget::Entry);
118 $CFClient::Widget::TOPLEVEL->add ($te);
119
120 $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 600, h => 300;
121 my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
122 my $lbl2 = new CFClient::Widget::Label text => "LBL2";
123 my $vb = new CFClient::Widget::VBox;
124 my $f = new CFClient::Widget::FancyFrame;
125 my $f2 = new CFClient::Widget::FancyFrame;
126 $f->add ($lbl1);
127 $f2->add ($lbl2);
128 $vb->add ($f);
129 $vb->add ($f2, 1);
130
131 $tw->add ($vb);
132 $tw->moveto (0, 0);
133 $CFClient::Widget::TOPLEVEL->add ($tw);
134
135# $f->move ($WIDTH - 200, 0);
136# $CFClient::Widget::TOPLEVEL->add ($f);
137 }
138} 183}
139 184
140sub destroy_screen { 185sub destroy_screen {
186 $CFClient::UI::TOPLEVEL->{children} = [];
141 remove Glib::Source $SDL_TIMER; 187 remove Glib::Source $SDL_TIMER;
142 undef $SDL_APP; 188 undef $SDL_APP;
143 undef $SDL_EV; 189 undef $SDL_EV;
144 SDL::Quit; 190 SDL::Quit;
145} 191}
178 224
179 glMatrixMode GL_PROJECTION; 225 glMatrixMode GL_PROJECTION;
180 glLoadIdentity; 226 glLoadIdentity;
181 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; 227 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
182 glMatrixMode GL_MODELVIEW; 228 glMatrixMode GL_MODELVIEW;
229 glLoadIdentity;
183 230
184 glClear GL_COLOR_BUFFER_BIT; 231 glClear GL_COLOR_BUFFER_BIT;
185 232
186 $CFClient::Widget::TOPLEVEL->draw; 233 $CFClient::UI::TOPLEVEL->draw;
187 234
188 SDL::GLSwapBuffers; 235 SDL::GLSwapBuffers;
189}
190
191sub debug {
192 $DEBUG_STATUS->set_text ($_[0]);
193 $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request);
194 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0);
195} 236}
196 237
197my $FPS; 238my $FPS;
198 239
199sub refresh { 240sub refresh {
200 $refresh_handler ||= add Glib::Idle sub { 241 $refresh_handler ||= add Glib::Idle sub {
201 if ($SDL_APP) { 242 if ($SDL_APP) {
202 my $next_refresh = SDL::GetTicks; 243 $NOW = SDL::GetTicks;
203 244
204 if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) { 245 if ($NOW - $last_refresh < $TICKS_PER_FRAME) {
205 SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh); 246 SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh);
206 $next_refresh = SDL::GetTicks; 247 $NOW = SDL::GetTicks;
207 } 248 }
208 249
209 my $interval = ($next_refresh - $last_refresh) * 0.001; 250 my $interval = ($NOW - $last_refresh) * 0.001;
210 $last_refresh = $next_refresh; 251 $last_refresh = $NOW;
211 252
212 if ($interval) { 253 if ($interval) {
213 $FPS ||= 1 / $interval; 254 $FPS ||= 1 / $interval;
214 $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; 255 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
215 debug sprintf "%5.02f", $FPS; 256 debug sprintf "%5.02f", $FPS;
216 } 257 }
217 258
218 force_refresh; 259 force_refresh;
219 $_->animate ($interval) for grep $_, values %ANIMATE; 260 $_->animate ($interval) for grep $_, values %ANIMATE;
255 }, 296 },
256 SDL_KEYDOWN() => sub { 297 SDL_KEYDOWN() => sub {
257 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 298 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
258 # alt-enter 299 # alt-enter
259 $FULLSCREEN = !$FULLSCREEN; 300 $FULLSCREEN = !$FULLSCREEN;
301 destroy_screen;
260 init_screen; 302 init_screen;
261 } else { 303 } else {
262 CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); 304 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
263 } 305 }
264 }, 306 },
265 SDL_KEYUP() => sub { 307 SDL_KEYUP() => sub {
266 CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); 308 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
267 }, 309 },
268 SDL_MOUSEMOTION() => sub { 310 SDL_MOUSEMOTION() => sub {
269 CFClient::Widget::feed_sdl_motion_event ($SDL_EV); 311 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
270 }, 312 },
271 SDL_MOUSEBUTTONDOWN() => sub { 313 SDL_MOUSEBUTTONDOWN() => sub {
272 CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); 314 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
273 }, 315 },
274 SDL_MOUSEBUTTONUP() => sub { 316 SDL_MOUSEBUTTONUP() => sub {
275 CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); 317 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
276 }, 318 },
277 SDL_ACTIVEEVENT() => sub { 319 SDL_ACTIVEEVENT() => sub {
278 printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 320# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
279 }, 321 },
280); 322);
281 323
282@conn::ISA = Crossfire::Protocol::; 324@conn::ISA = Crossfire::Protocol::;
283 325
354 [qw/Password password/], 396 [qw/Password password/],
355 ); 397 );
356 398
357 my $cfg = {}; 399 my $cfg = {};
358 400
359 my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE);
360 my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a;
361
362 $w->add (my $vb = Gtk2::VBox->new); 401 $w->add (my $vb = Gtk2::VBox->new);
363 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); 402 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
364 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; 403 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
365 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); 404 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
366 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); 405 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
367 my $i = 0; 406 my $i = 0;
368 my $act = 0; 407 my $act = 0;
369 for (map { "$_->[0]x$_->[1]" } reverse @modes) { 408 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
370 if ($_ eq $selmode) { $act = $i } 409 if ($_ eq $selmode) { $act = $i }
371 $cb->append_text ($_); 410 $cb->append_text ($_);
372 $i++; 411 $i++;
373 } 412 }
374 $cb->set_active ($act); 413 $cb->set_active ($act);
420 459
421############################################################################# 460#############################################################################
422 461
423SDL::Init SDL_INIT_EVERYTHING; 462SDL::Init SDL_INIT_EVERYTHING;
424 463
464@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)],
465 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE };
466
425CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 467CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
426 468
427$CFG ||= { 469$CFG ||= {
428 width => 640, 470 width => 640,
429 height => 480, 471 height => 480,
472 fullscreen => 0,
473 sdl_mode => 0,
430 mapsize => 100, 474 mapsize => 100,
431 fullscreen => 0,
432 host => "crossfire.schmorp.de", 475 host => "crossfire.schmorp.de",
433 port => 13327, 476 port => 13327,
434}; 477};
435 478
436{ 479{
447 logout => sub { stop_game }; 490 logout => sub { stop_game };
448 491
449main Gtk2; 492main Gtk2;
450 493
451Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces"; 494Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";
495

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines