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.70 by root, Tue Apr 11 14:36:02 2006 UTC vs.
Revision 1.79 by root, Wed Apr 12 00:36:14 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;
31 31
32our @SDL_MODES;
32our $WIDTH; 33our $WIDTH;
33our $HEIGHT; 34our $HEIGHT;
34our $FULLSCREEN; 35our $FULLSCREEN;
36
37our $NOW;
35 38
36our $MAPWIDGET; 39our $MAPWIDGET;
37our $FONTSIZE; 40our $FONTSIZE;
38 41
39our $SDL_TIMER; 42our $SDL_TIMER;
67 -resizeable => 0; 70 -resizeable => 0;
68 71
69 $SDL_EV = new SDL::Event; 72 $SDL_EV = new SDL::Event;
70 $SDL_EV->set_unicode (1); 73 $SDL_EV->set_unicode (1);
71 74
72 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 75 $SDL_TIMER = add Glib::Timeout 1000 / $MAX_FPS, sub {
73 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 76 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
74 while $SDL_EV->poll; 77 while $SDL_EV->poll;
75 78
76 1 79 1
77 }; 80 };
78 81
79 $last_refresh = SDL::GetTicks; 82 $last_refresh = SDL::GetTicks;
80 83
81 CFClient::gl_init; 84 CFClient::gl_init;
82 85
83 $FONTSIZE = int $HEIGHT / 50; 86 $FONTSIZE = int $HEIGHT / 40;
84 87
85 ############################################################################# 88 #############################################################################
86 89
87 glClearColor 0.45, 0.45, 0.45, 1; 90 glClearColor 0.45, 0.45, 0.45, 1;
88 91
92 glDisable GL_DEPTH_TEST; 95 glDisable GL_DEPTH_TEST;
93 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 96 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
94 97
95 ############################################################################# 98 #############################################################################
96 99
97 $DEBUG_STATUS = new CFClient::Widget::Label; 100 $DEBUG_STATUS = new CFClient::UI::Label padding => 0;
98 $CFClient::Widget::TOPLEVEL->add ($DEBUG_STATUS); 101 $CFClient::UI::TOPLEVEL->add ($DEBUG_STATUS);
99 102
100 $STATUS_LINE = new CFClient::Widget::Label 103 $STATUS_LINE = new CFClient::UI::Label
104 padding => 0,
101 y => $HEIGHT * 59 / 60 - $FONTSIZE; 105 y => $HEIGHT * 49 / 50 - $FONTSIZE;
102 $CFClient::Widget::TOPLEVEL->add ($STATUS_LINE); 106 $CFClient::UI::TOPLEVEL->add ($STATUS_LINE);
103 107
104 $ALT_ENTER_MESSAGE = new CFClient::Widget::Label 108 $ALT_ENTER_MESSAGE = new CFClient::UI::Label
109 padding => 0,
105 y => $HEIGHT * 59 / 60, 110 y => $HEIGHT * 49 / 50,
106 height => $HEIGHT / 60, 111 height => $HEIGHT / 50,
107 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 112 text => "Use <b>Alt-Enter</b> to toggle fullscreen mode";
108 $CFClient::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE); 113 $CFClient::UI::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
109 114
110 $MAPWIDGET = new CFClient::Widget::MapWidget; 115 $MAPWIDGET = new CFClient::UI::MapWidget;
111 $CFClient::Widget::TOPLEVEL->add ($MAPWIDGET); 116 $CFClient::UI::TOPLEVEL->add ($MAPWIDGET);
112 $MAPWIDGET->focus_in; 117 $MAPWIDGET->focus_in;
113
114 # Test code #d#
115 unless ($tw) { # haha...
116 my $w = new CFClient::Widget::Window
117 w => 300, h => 300,
118 child => (my $te = new CFClient::Widget::FancyFrame);
119 $CFClient::Widget::TOPLEVEL->add ($w);
120 $te->add (new CFClient::Widget::Entry);
121
122 $tw = new CFClient::Widget::Animator x => $WIDTH - 200, w => 600, h => 300;
123 my $lbl1 = new CFClient::Widget::Label text => "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
124 my $lbl2 = new CFClient::Widget::Label text => "LBL2";
125 my $vb = new CFClient::Widget::VBox;
126 my $f = new CFClient::Widget::FancyFrame;
127 my $f2 = new CFClient::Widget::FancyFrame;
128 $f->add ($lbl1);
129 $f2->add ($lbl2);
130 $vb->add ($f);
131 $vb->add ($f2, 1);
132
133 $tw->add ($vb);
134 $tw->moveto (0, 0);
135 $CFClient::Widget::TOPLEVEL->add ($tw);
136
137# $f->move ($WIDTH - 200, 0);
138# $CFClient::Widget::TOPLEVEL->add ($f);
139 }
140} 118}
141 119
142sub destroy_screen { 120sub destroy_screen {
143 remove Glib::Source $SDL_TIMER; 121 remove Glib::Source $SDL_TIMER;
144 undef $SDL_APP; 122 undef $SDL_APP;
145 undef $SDL_EV; 123 undef $SDL_EV;
146 SDL::Quit; 124 SDL::Quit;
147} 125}
148 126
127sub config_dialog {
128 my $dialog = new CFClient::UI::FancyFrame x => 300, y => 100,
129 child => (my $vbox = new CFClient::UI::VBox);
130 $vbox->add (new CFClient::UI::Label align => 0, text => "Setup");
131 $vbox->add (my $table = new CFClient::UI::Table expand => 1, col_expand => [0, 1]);
132
133 $table->add (0, 0, new CFClient::UI::Label align => 1, text => "Video Mode");
134 $table->add (1, 0, my $hbox = new CFClient::UI::HBox);
135
136 $hbox->add (my $mode_slider = new CFClient::UI::Slider expand => 1, req_w => 100, range => [$CFG->{sdl_mode}, 0, scalar @SDL_MODES, 1]);
137 $hbox->add (my $mode_label = new CFClient::UI::Label height => $FONTSIZE * 0.8);
138
139 $mode_slider->connect (changed => sub {
140 my ($self, $value) = @_;
141
142 $CFG->{sdl_mode} = $self->{range}[0] = $value = int $value;
143 $mode_label->set_text (sprintf "%dx%d", @{$SDL_MODES[$value]});
144 });
145 $mode_slider->emit (changed => $mode_slider->{range}[0]);
146
147 $table->add (0, 1, new CFClient::UI::Label align => 1, text => "Host");
148 $table->add (1, 1, my $host = new CFClient::UI::Entry text => $CFG->{host});
149
150 $table->add (0, 2, new CFClient::UI::Label align => 1, text => "Port");
151 $table->add (1, 2, my $port = new CFClient::UI::Entry text => $CFG->{port});
152
153 $table->add (0, 3, new CFClient::UI::Label align => 1, text => "Username");
154 $table->add (1, 3, my $user = new CFClient::UI::Entry text => $CFG->{user});
155
156 $table->add (0, 4, new CFClient::UI::Label align => 1, text => "Password");
157 $table->add (1, 4, my $pass = new CFClient::UI::Entry text => $CFG->{password}, hidden => 1);
158
159 $table->add (0, 5, new CFClient::UI::Label align => 1, text => "Map Size");
160 $table->add (1, 5, new CFClient::UI::Slider
161 req_w => 100,
162 range => [$CFG->{mapsize}, 10, 100 + 1, 1],
163 connect_changed => sub {
164 my ($self, $value) = @_;
165
166 $CFG->{mapsize} = $self->{range}[0] = $value = int $value;
167 },
168 );
169
170 $vbox->add (my $hbox = new CFClient::UI::HBox);
171 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Save", connect_activate => sub {
172 warn "save\n";
173 });
174 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Login", connect_activate => sub {
175 warn "login\n";
176 });
177 $hbox->add (new CFClient::UI::Button expand => 1, align => 0, text => "Apply", connect_activate => sub {
178 warn "apply\n";
179 });
180
181 $CFClient::UI::TOPLEVEL->add ($dialog);
182}
183
149sub start_game { 184sub start_game {
150 $WIDTH = $CFG->{width}; 185 $WIDTH = $CFG->{width};
151 $HEIGHT = $CFG->{height}; 186 $HEIGHT = $CFG->{height};
152 $FULLSCREEN = 0; 187 $FULLSCREEN = 0;
153 188
154 init_screen; 189 init_screen;
190
191 config_dialog;
155 192
156 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32; 193 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
157 194
158 $CONN = new conn 195 $CONN = new conn
159 host => $CFG->{host}, 196 host => $CFG->{host},
180 217
181 glMatrixMode GL_PROJECTION; 218 glMatrixMode GL_PROJECTION;
182 glLoadIdentity; 219 glLoadIdentity;
183 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000; 220 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
184 glMatrixMode GL_MODELVIEW; 221 glMatrixMode GL_MODELVIEW;
222 glLoadIdentity;
185 223
186 glClear GL_COLOR_BUFFER_BIT; 224 glClear GL_COLOR_BUFFER_BIT;
187 225
188 $CFClient::Widget::TOPLEVEL->draw; 226 $CFClient::UI::TOPLEVEL->draw;
189 227
190 SDL::GLSwapBuffers; 228 SDL::GLSwapBuffers;
191} 229}
192 230
193sub debug { 231sub debug {
194 $DEBUG_STATUS->set_text ($_[0]); 232 $DEBUG_STATUS->set_text ($_[0]);
195 $DEBUG_STATUS->size_allocate ($DEBUG_STATUS->size_request); 233 my ($w, $h) = $DEBUG_STATUS->size_request;
196 $DEBUG_STATUS->move ($WIDTH - $DEBUG_STATUS->{w}, 0); 234 $DEBUG_STATUS->size_allocate ($WIDTH - $w, 0, $w, $h);
197} 235}
198 236
199my $FPS; 237my $FPS;
200 238
201sub refresh { 239sub refresh {
202 $refresh_handler ||= add Glib::Idle sub { 240 $refresh_handler ||= add Glib::Idle sub {
203 if ($SDL_APP) { 241 if ($SDL_APP) {
204 my $next_refresh = SDL::GetTicks; 242 $NOW = SDL::GetTicks;
205 243
206 if ($next_refresh - $last_refresh < $TICKS_PER_FRAME) { 244 if ($NOW - $last_refresh < $TICKS_PER_FRAME) {
207 SDL::Delay $TICKS_PER_FRAME - ($next_refresh - $last_refresh); 245 SDL::Delay $TICKS_PER_FRAME - ($NOW - $last_refresh);
208 $next_refresh = SDL::GetTicks; 246 $NOW = SDL::GetTicks;
209 } 247 }
210 248
211 my $interval = ($next_refresh - $last_refresh) * 0.001; 249 my $interval = ($NOW - $last_refresh) * 0.001;
212 $last_refresh = $next_refresh; 250 $last_refresh = $NOW;
213 251
214 if ($interval) { 252 if ($interval) {
215 $FPS ||= 1 / $interval; 253 $FPS ||= 1 / $interval;
216 $FPS = $FPS * 0.96 + (1 / $interval) * 0.04; 254 $FPS = $FPS * 0.9 + (1 / $interval) * 0.1;
217 debug sprintf "%5.02f", $FPS; 255 debug sprintf "%5.02f", $FPS;
218 } 256 }
219 257
220 force_refresh; 258 force_refresh;
221 $_->animate ($interval) for grep $_, values %ANIMATE; 259 $_->animate ($interval) for grep $_, values %ANIMATE;
259 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 297 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
260 # alt-enter 298 # alt-enter
261 $FULLSCREEN = !$FULLSCREEN; 299 $FULLSCREEN = !$FULLSCREEN;
262 init_screen; 300 init_screen;
263 } else { 301 } else {
264 CFClient::Widget::feed_sdl_key_down_event ($SDL_EV); 302 CFClient::UI::feed_sdl_key_down_event ($SDL_EV);
265 } 303 }
266 }, 304 },
267 SDL_KEYUP() => sub { 305 SDL_KEYUP() => sub {
268 CFClient::Widget::feed_sdl_key_up_event ($SDL_EV); 306 CFClient::UI::feed_sdl_key_up_event ($SDL_EV);
269 }, 307 },
270 SDL_MOUSEMOTION() => sub { 308 SDL_MOUSEMOTION() => sub {
271 CFClient::Widget::feed_sdl_motion_event ($SDL_EV); 309 CFClient::UI::feed_sdl_motion_event ($SDL_EV);
272 }, 310 },
273 SDL_MOUSEBUTTONDOWN() => sub { 311 SDL_MOUSEBUTTONDOWN() => sub {
274 CFClient::Widget::feed_sdl_button_down_event ($SDL_EV); 312 CFClient::UI::feed_sdl_button_down_event ($SDL_EV);
275 }, 313 },
276 SDL_MOUSEBUTTONUP() => sub { 314 SDL_MOUSEBUTTONUP() => sub {
277 CFClient::Widget::feed_sdl_button_up_event ($SDL_EV); 315 CFClient::UI::feed_sdl_button_up_event ($SDL_EV);
278 }, 316 },
279 SDL_ACTIVEEVENT() => sub { 317 SDL_ACTIVEEVENT() => sub {
280# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d# 318# printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
281 }, 319 },
282); 320);
356 [qw/Password password/], 394 [qw/Password password/],
357 ); 395 );
358 396
359 my $cfg = {}; 397 my $cfg = {};
360 398
361 my $a = SDL::ListModes (0, SDL_FULLSCREEN|SDL_HWSURFACE);
362 my @modes = map { [SDL::RectW ($_), SDL::RectH ($_)] } @$a;
363
364 $w->add (my $vb = Gtk2::VBox->new); 399 $w->add (my $vb = Gtk2::VBox->new);
365 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0); 400 $vb->pack_start (my $t = Gtk2::Table->new (2, scalar @cfg), 0, 0, 0);
366 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height}; 401 my $selmode = $::CFG->{width} . 'x' . $::CFG->{height};
367 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1); 402 $t->attach_defaults (Gtk2::Label->new ("Modes"), 0, 1, 0, 1);
368 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1); 403 $t->attach_defaults (my $cb = Gtk2::ComboBox->new_text, 1, 2, 0, 1);
369 my $i = 0; 404 my $i = 0;
370 my $act = 0; 405 my $act = 0;
371 for (map { "$_->[0]x$_->[1]" } reverse @modes) { 406 for (map { "$_->[0]x$_->[1]" } @SDL_MODES) {
372 if ($_ eq $selmode) { $act = $i } 407 if ($_ eq $selmode) { $act = $i }
373 $cb->append_text ($_); 408 $cb->append_text ($_);
374 $i++; 409 $i++;
375 } 410 }
376 $cb->set_active ($act); 411 $cb->set_active ($act);
422 457
423############################################################################# 458#############################################################################
424 459
425SDL::Init SDL_INIT_EVERYTHING; 460SDL::Init SDL_INIT_EVERYTHING;
426 461
462@SDL_MODES = reverse map [SDL::RectW ($_), SDL::RectH ($_)],
463 @{ SDL::ListModes 0, SDL_FULLSCREEN|SDL_HWSURFACE };
464
427CFClient::read_cfg "$Crossfire::VARDIR/pclientrc"; 465CFClient::read_cfg "$Crossfire::VARDIR/pclientrc";
428 466
429$CFG ||= { 467$CFG ||= {
430 width => 640, 468 width => 640,
431 height => 480, 469 height => 480,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines