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.52 by root, Sun Apr 9 22:12:12 2006 UTC vs.
Revision 1.58 by root, Mon Apr 10 11:41:17 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;
45our $STATUS_LINE; 45our $STATUS_LINE;
46
47our $TOPLEVEL;
48
49our $tw; # Test widget #d#
50 46
51my $last_refresh; 47my $last_refresh;
52my %ANIMATE; 48my %ANIMATE;
53my $refresh_handler; 49my $refresh_handler;
50
51our ($tw, $te); # Test widget #d#
54 52
55sub init_screen { 53sub init_screen {
56 $SDL_APP = new SDL::App 54 $SDL_APP = new SDL::App
57 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 55 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
58 -title => "Crossfire+ Client", 56 -title => "Crossfire+ Client",
65 -alpha_size => 0, 63 -alpha_size => 0,
66 -double_buffer => 1, 64 -double_buffer => 1,
67 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
68 -resizeable => 0; 66 -resizeable => 0;
69 67
68 $SDL_EV = new SDL::Event;
69 $SDL_EV->set_unicode (1);
70
70 $last_refresh = SDL::GetTicks; 71 $last_refresh = SDL::GetTicks;
71 72
72 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 73 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
73 74
74 $GL_EXT{GL_ARB_texture_non_power_of_two} 75 $GL_EXT{GL_ARB_texture_non_power_of_two}
91 ############################################################################# 92 #############################################################################
92 93
93 $STATUS_LINE = new Crossfire::Client::Widget::Label 94 $STATUS_LINE = new Crossfire::Client::Widget::Label
94 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, 95 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
95 ""; 96 "";
96 $TOPLEVEL->add ($STATUS_LINE); 97 $Crossfire::Client::Widget::TOPLEVEL->add ($STATUS_LINE);
97 98
98 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 99 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
99 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, 100 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
100 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 101 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
101 $TOPLEVEL->add ($ALT_ENTER_MESSAGE); 102 $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
102 103
103 # Test code #d# 104 # Test code #d#
104 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
105 $tw = new Crossfire::Client::Widget::Animator; 111 $tw = new Crossfire::Client::Widget::Animator;
106 my $lbl1 = new Crossfire::Client::Widget::Label 112 my $lbl1 = new Crossfire::Client::Widget::Label
107 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!";
108 my $lbl2 = new Crossfire::Client::Widget::Label 114 my $lbl2 = new Crossfire::Client::Widget::Label
109 0, 0, 10, $FONTSIZE, "LBL2"; 115 0, 0, 10, $FONTSIZE, "LBL2";
119 $tw->add ($vb); 125 $tw->add ($vb);
120 $tw->w (400); 126 $tw->w (400);
121 $tw->h (300); 127 $tw->h (300);
122 $tw->move ($WIDTH - 200, 0); 128 $tw->move ($WIDTH - 200, 0);
123 $tw->moveto (0, 0); 129 $tw->moveto (0, 0);
124 $TOPLEVEL->add ($tw); 130 $Crossfire::Client::Widget::TOPLEVEL->add ($tw);
125 131
126# $f->move ($WIDTH - 200, 0); 132# $f->move ($WIDTH - 200, 0);
127# $TOPLEVEL->add ($f); 133# $Crossfire::Client::Widget::TOPLEVEL->add ($f);
128 } 134 }
129} 135}
130 136
131sub start_game { 137sub start_game {
132 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 138 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
164 undef $SDL_APP; 170 undef $SDL_APP;
165 undef $CONN; 171 undef $CONN;
166 SDL::Quit; 172 SDL::Quit;
167} 173}
168 174
169
170sub force_refresh { 175sub force_refresh {
171 glViewport 0, 0, $WIDTH, $HEIGHT; 176 glViewport 0, 0, $WIDTH, $HEIGHT;
172 177
173 glMatrixMode GL_PROJECTION; 178 glMatrixMode GL_PROJECTION;
174 glLoadIdentity; 179 glLoadIdentity;
175 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; 180 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000;
176 glMatrixMode GL_MODELVIEW; 181 glMatrixMode GL_MODELVIEW;
177 182
178 glClear GL_COLOR_BUFFER_BIT; 183 glClear GL_COLOR_BUFFER_BIT;
179 184
180 $TOPLEVEL->draw; 185 $Crossfire::Client::Widget::TOPLEVEL->draw;
181 186
182 SDL::GLSwapBuffers; 187 SDL::GLSwapBuffers;
183} 188}
184 189
185sub refresh { 190sub refresh {
186 $refresh_handler ||= add Glib::Idle sub { 191 $refresh_handler ||= add Glib::Idle sub {
187 return unless $SDL_APP; 192 if ($SDL_APP) {
188
189 my $next_refresh = SDL::GetTicks; 193 my $next_refresh = SDL::GetTicks;
190 my $interval = ($next_refresh - $last_refresh) * 0.001; 194 my $interval = ($next_refresh - $last_refresh) * 0.001;
191 $last_refresh = $next_refresh; 195 $last_refresh = $next_refresh;
192 196
193 force_refresh; 197 force_refresh;
194 $_->animate ($interval) for grep $_, values %ANIMATE; 198 $_->animate ($interval) for grep $_, values %ANIMATE;
195 199
196 if (%ANIMATE) { 200 if (%ANIMATE) {
201 1
202 } else {
203 undef $refresh_handler;
204 0
197 1 205 }
198 } else { 206 } else {
199 undef $refresh_handler; 207 undef $refresh_handler;
200 0 208 0
201 } 209 }
202 }; 210 };
235 }, 243 },
236 SDL_KEYUP() => sub { 244 SDL_KEYUP() => sub {
237 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); 245 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
238 }, 246 },
239 SDL_MOUSEMOTION() => sub { 247 SDL_MOUSEMOTION() => sub {
240 warn "sdl motion\n";#d# 248 Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV);
241 }, 249 },
242 SDL_MOUSEBUTTONDOWN() => sub { 250 SDL_MOUSEBUTTONDOWN() => sub {
243 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); 251 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
244 }, 252 },
245 SDL_MOUSEBUTTONUP() => sub { 253 SDL_MOUSEBUTTONUP() => sub {
246 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); 254 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV);
247 }, 255 },
248 SDL_ACTIVEEVENT() => sub { 256 SDL_ACTIVEEVENT() => sub {
249 warn "active\n";#d# 257 printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
250 }, 258 },
251); 259);
252 260
253@conn::ISA = Crossfire::Protocol::; 261@conn::ISA = Crossfire::Protocol::;
254 262
391 399
392############################################################################# 400#############################################################################
393 401
394SDL::Init SDL_INIT_EVERYTHING; 402SDL::Init SDL_INIT_EVERYTHING;
395 403
396$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
397
398my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 404my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
399 405
400$TOPLEVEL->add ($mapwidget); 406$Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget);
401$mapwidget->focus_in; 407$mapwidget->focus_in;
402 408
403Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 409Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
404 410
405$CFG ||= { 411$CFG ||= {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines