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.42 by root, Sun Apr 9 01:35:40 2006 UTC vs.
Revision 1.51 by root, Sun Apr 9 21:34:49 2006 UTC

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;
45our $STATUS_LINE;
45 46
46our $TOPLEVEL; 47our $TOPLEVEL;
47 48
48our $tw; # Test widget #d# 49our $tw; # Test widget #d#
50
51my $last_refresh;
52my %ANIMATE;
53my $refresh_handler;
49 54
50sub init_screen { 55sub init_screen {
51 $SDL_APP = new SDL::App 56 $SDL_APP = new SDL::App
52 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 57 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
53 -title => "Crossfire+ Client", 58 -title => "Crossfire+ Client",
54 -width => $WIDTH, 59 -width => $WIDTH,
55 -height => $HEIGHT, 60 -height => $HEIGHT,
56 -opengl => 1, 61 -opengl => 1,
57 -red_size => 8, 62 -red_size => 5,
58 -green_size => 8, 63 -green_size => 5,
59 -blue_size => 8, 64 -blue_size => 5,
65 -alpha_size => 0,
60 -double_buffer => 1, 66 -double_buffer => 1,
61 -fullscreen => $FULLSCREEN, 67 -fullscreen => $FULLSCREEN,
62 -resizeable => 0; 68 -resizeable => 0;
63 69
70 $last_refresh = SDL::GetTicks;
71
64 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 72 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
65 73
66 $GL_EXT{GL_ARB_texture_non_power_of_two} 74 $GL_EXT{GL_ARB_texture_non_power_of_two}
67 or warn "WARNING: non-power-of-two opengl extension required"; 75 or warn "WARNING: non-power-of-two opengl extension required";
68 76
69 $FONTSIZE = int $HEIGHT / 50; 77 $FONTSIZE = int $HEIGHT / 50;
70 78
79 $STATUS_LINE = new Crossfire::Client::Widget::Label
80 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
81 "";
82 $TOPLEVEL->add ($STATUS_LINE);
83
71 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 84 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
72 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, 85 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
73 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 86 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
74 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
75 $TOPLEVEL->add ($ALT_ENTER_MESSAGE); 87 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
76 88
77 # Test code #d# 89 # Test code #d#
78 { 90 unless ($tw) { # haha...
91 $tw = new Crossfire::Client::Widget::Animator;
92 my $lbl1 = new Crossfire::Client::Widget::Label
93 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
94 my $lbl2 = new Crossfire::Client::Widget::Label
95 0, 0, 10, $FONTSIZE, "LBL2";
96
97 my $vb = new Crossfire::Client::Widget::VBox;
79 my $frm = new Crossfire::Client::Widget::Frame; 98 my $f = new Crossfire::Client::Widget::FancyFrame;
80 $tw = new Crossfire::Client::Widget::Window; 99 my $f2 = new Crossfire::Client::Widget::FancyFrame;
81 $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!"); 100 $f->add ($lbl1);
101 $f2->add ($lbl2);
102 $vb->add ($f);
103 $vb->add ($f2, 1);
104
82 $tw->add ($frm); 105 $tw->add ($vb);
83 106 $tw->w (400);
107 $tw->h (300);
108 $tw->move ($WIDTH - 200, 0);
84 $tw->move (0, $HEIGHT - 120); 109 $tw->moveto (0, 0);
85 $TOPLEVEL->add ($tw); 110 $TOPLEVEL->add ($tw);
86# $te->focus_in; 111
112# $f->move ($WIDTH - 200, 0);
113# $TOPLEVEL->add ($f);
87 } 114 }
88 115
89 glClearColor 0, 0, 0, 0; 116 glClearColor 0, 0, 0, 0;
90 117
91 glEnable GL_TEXTURE_2D; 118 glEnable GL_TEXTURE_2D;
96 123
97 $_->() for @GL_INIT; 124 $_->() for @GL_INIT;
98} 125}
99 126
100sub start_game { 127sub start_game {
101 $SDL_TIMER = add Glib::Timeout 1000/100, sub { 128 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
102 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->() 129 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
103 while $SDL_EV->poll; 130 while $SDL_EV->poll;
104 131
105 1 132 1
106 }; 133 };
108 $WIDTH = $CFG->{width}; 135 $WIDTH = $CFG->{width};
109 $HEIGHT = $CFG->{height}; 136 $HEIGHT = $CFG->{height};
110 $FULLSCREEN = 0; 137 $FULLSCREEN = 0;
111 138
112 init_screen; 139 init_screen;
140
141 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32;
113 142
114 $CONN = new conn 143 $CONN = new conn
115 host => $CFG->{host}, 144 host => $CFG->{host},
116 port => $CFG->{port}, 145 port => $CFG->{port},
117 user => $CFG->{user}, 146 user => $CFG->{user},
118 pass => $CFG->{password}, 147 pass => $CFG->{password},
119 mapw => 50, 148 mapw => $mapsize,
120 maph => 37, 149 maph => $mapsize,
121 ; 150 ;
151
152 Crossfire::Client::lowdelay fileno $CONN->{fh};
122} 153}
123 154
124sub stop_game { 155sub stop_game {
125 remove Glib::Source $SDL_TIMER; 156 remove Glib::Source $SDL_TIMER;
157 remove Glib::Source $refresh_handler if $refresh_handler;
158 undef $refresh_handler;
126 159
127 undef $SDL_APP; 160 undef $SDL_APP;
161 undef $CONN;
128 SDL::Quit; 162 SDL::Quit;
129} 163}
130 164
131 165
132sub force_refresh { 166sub force_refresh {
133 glViewport 0, 0, $WIDTH, $HEIGHT; 167 glViewport 0, 0, $WIDTH, $HEIGHT;
134 168
135 glMatrixMode GL_PROJECTION; 169 glMatrixMode GL_PROJECTION;
136 glLoadIdentity; 170 glLoadIdentity;
137 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100; 171 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
138 glMatrixMode GL_MODELVIEW; 172 glMatrixMode GL_MODELVIEW;
139 173
140 glClear GL_COLOR_BUFFER_BIT; 174 glClear GL_COLOR_BUFFER_BIT;
141 175
142 $TOPLEVEL->draw; 176 $TOPLEVEL->draw;
143 177
144 SDL::GLSwapBuffers; 178 SDL::GLSwapBuffers;
145} 179}
146
147my $refresh_handler;
148 180
149sub refresh { 181sub refresh {
150 $refresh_handler ||= add Glib::Idle sub { 182 $refresh_handler ||= add Glib::Idle sub {
183 return unless $SDL_APP;
184
185 my $next_refresh = SDL::GetTicks;
186 my $interval = ($next_refresh - $last_refresh) * 0.001;
187 $last_refresh = $next_refresh;
188
151 force_refresh; 189 force_refresh;
190 $_->animate ($interval) for grep $_, values %ANIMATE;
191
192 if (%ANIMATE) {
193 1
194 } else {
152 undef $refresh_handler; 195 undef $refresh_handler;
196 0
153 0 197 }
154 }; 198 };
199}
200
201sub animation_start {
202 my ($widget) = @_;
203 $ANIMATE{$widget} = $widget;
204 Scalar::Util::weaken $ANIMATE{$widget};
205
206 refresh;
207}
208
209sub animation_stop {
210 my ($widget) = @_;
211 delete $ANIMATE{$widget};
155} 212}
156 213
157%SDL_CB = ( 214%SDL_CB = (
158 SDL_QUIT() => sub { 215 SDL_QUIT() => sub {
159 main_quit Gtk2; 216 main_quit Gtk2;
198} 255}
199 256
200sub conn::map_scroll { 257sub conn::map_scroll {
201 my ($self, $dx, $dy) = @_; 258 my ($self, $dx, $dy) = @_;
202 259
203 refresh; 260# refresh;
204} 261}
205 262
206sub conn::map_clear { 263sub conn::map_clear {
207 my ($self) = @_; 264 my ($self) = @_;
208 265
209 refresh; 266# refresh;
210} 267}
211 268
212sub conn::face_find { 269sub conn::face_find {
213 my ($self, $face) = @_; 270 my ($self, $face) = @_;
214 271
240 } 297 }
241 $ent->set_text ($value); 298 $ent->set_text ($value);
242 $ent->signal_connect (changed => sub { 299 $ent->signal_connect (changed => sub {
243 my ($ent) = @_; 300 my ($ent) = @_;
244 $cfg->{$key} = $ent->get_text; 301 $cfg->{$key} = $ent->get_text;
302 # TODO: Mapsize should be a slider in the game gui
303 if ($key eq 'mapsize' and $cfg->{$key} > 100) {
304 $cfg->{$key} = 100;
305 } elsif ($key eq 'mapsize' and $cfg->{$key} < 50) {
306 $cfg->{$key} = 50;
307 }
245 }); 308 });
246} 309}
247 310
248sub run_config_dialog { 311sub run_config_dialog {
249 my (%events) = @_; 312 my (%events) = @_;
251 my $w = Gtk2::Window->new; 314 my $w = Gtk2::Window->new;
252 315
253 my @cfg = ( 316 my @cfg = (
254 [qw/Host host/], 317 [qw/Host host/],
255 [qw/Port port/], 318 [qw/Port port/],
319 [qw/Mapsize% mapsize/],
256 [qw/Username user/], 320 [qw/Username user/],
257 [qw/Password password/], 321 [qw/Password password/],
258 ); 322 );
259 323
260 my $cfg = {}; 324 my $cfg = {};
307 my $cb = $events{login} || sub {}; 371 my $cb = $events{login} || sub {};
308 $cb->($::CFG->{user}, $::CFG->{password}); 372 $cb->($::CFG->{user}, $::CFG->{password});
309 }); 373 });
310 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5); 374 $hb->pack_start (my $cb = Gtk2::Button->new ("logout"), 1, 1, 5);
311 $cb->signal_connect (clicked => sub { 375 $cb->signal_connect (clicked => sub {
312 my $cb = $events{login} || sub {}; 376 my $cb = $events{logout} || sub {};
313 $cb->(); 377 $cb->();
314 }); 378 });
315 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5); 379 $hb->pack_start (my $cb = Gtk2::Button->new ("quit"), 1, 1, 5);
316 $cb->signal_connect (clicked => sub { $w->destroy }); 380 $cb->signal_connect (clicked => sub { $w->destroy });
317 381
335Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 399Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
336 400
337$CFG ||= { 401$CFG ||= {
338 width => 640, 402 width => 640,
339 height => 480, 403 height => 480,
404 mapsize => 100,
340 fullscreen => 0, 405 fullscreen => 0,
341 host => "crossfire.schmorp.de", 406 host => "crossfire.schmorp.de",
342 port => 13327, 407 port => 13327,
343}; 408};
344 409

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines