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.50 by root, Sun Apr 9 21:05:50 2006 UTC vs.
Revision 1.61 by root, Mon Apr 10 11:57: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;
45 45our $STATUS_LINE;
46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49 46
50my $last_refresh; 47my $last_refresh;
51my %ANIMATE; 48my %ANIMATE;
52my $refresh_handler; 49my $refresh_handler;
50
51our ($tw, $te); # Test widget #d#
53 52
54sub init_screen { 53sub init_screen {
55 $SDL_APP = new SDL::App 54 $SDL_APP = new SDL::App
56 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 55 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
57 -title => "Crossfire+ Client", 56 -title => "Crossfire+ Client",
58 -width => $WIDTH, 57 -width => $WIDTH,
59 -height => $HEIGHT, 58 -height => $HEIGHT,
60 -opengl => 1, 59 -opengl => 1,
61 -red_size => 8, 60 -red_size => 5,
62 -green_size => 8, 61 -green_size => 5,
63 -blue_size => 8, 62 -blue_size => 5,
63 -alpha_size => 0,
64 -double_buffer => 1, 64 -double_buffer => 1,
65 -fullscreen => $FULLSCREEN, 65 -fullscreen => $FULLSCREEN,
66 -resizeable => 0; 66 -resizeable => 0;
67 67
68 $SDL_EV = new SDL::Event;
69 $SDL_EV->set_unicode (1);
70
68 $last_refresh = SDL::GetTicks; 71 $last_refresh = SDL::GetTicks;
69 72
70 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 73 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
71 74
72 $GL_EXT{GL_ARB_texture_non_power_of_two} 75 $GL_EXT{GL_ARB_texture_non_power_of_two}
73 or warn "WARNING: non-power-of-two opengl extension required"; 76 or warn "WARNING: non-power-of-two opengl extension required";
74 77
75 $FONTSIZE = int $HEIGHT / 50; 78 $FONTSIZE = int $HEIGHT / 50;
76 79
80 #############################################################################
81
82 glClearColor 0.7, 0.7, 0.7, 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
77 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 99 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
78 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, 100 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
79 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 101 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
80 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]); 102 $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
81 $TOPLEVEL->add ($ALT_ENTER_MESSAGE);
82 103
83 # Test code #d# 104 # Test code #d#
84 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
85 $tw = new Crossfire::Client::Widget::Animator; 111 $tw = new Crossfire::Client::Widget::Animator;
86 my $lbl1 = new Crossfire::Client::Widget::Label 112 my $lbl1 = new Crossfire::Client::Widget::Label
87 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!";
88 my $lbl2 = new Crossfire::Client::Widget::Label 114 my $lbl2 = new Crossfire::Client::Widget::Label
89 0, 0, 10, $FONTSIZE, "LBL2"; 115 0, 0, 10, $FONTSIZE, "LBL2";
99 $tw->add ($vb); 125 $tw->add ($vb);
100 $tw->w (400); 126 $tw->w (400);
101 $tw->h (300); 127 $tw->h (300);
102 $tw->move ($WIDTH - 200, 0); 128 $tw->move ($WIDTH - 200, 0);
103 $tw->moveto (0, 0); 129 $tw->moveto (0, 0);
104 $TOPLEVEL->add ($tw); 130 $Crossfire::Client::Widget::TOPLEVEL->add ($tw);
105 131
106# $f->move ($WIDTH - 200, 0); 132# $f->move ($WIDTH - 200, 0);
107# $TOPLEVEL->add ($f); 133# $Crossfire::Client::Widget::TOPLEVEL->add ($f);
108 } 134 }
109
110 glClearColor 0, 0, 0, 0;
111
112 glEnable GL_TEXTURE_2D;
113 glEnable GL_COLOR_MATERIAL;
114 glShadeModel GL_FLAT;
115 glDisable GL_DEPTH_TEST;
116 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
117
118 $_->() for @GL_INIT;
119} 135}
120 136
121sub start_game { 137sub start_game {
122 $SDL_TIMER = add Glib::Timeout 1000/50, sub { 138 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
123 ($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 })->()
130 $HEIGHT = $CFG->{height}; 146 $HEIGHT = $CFG->{height};
131 $FULLSCREEN = 0; 147 $FULLSCREEN = 0;
132 148
133 init_screen; 149 init_screen;
134 150
135 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; 151 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
136 152
137 $CONN = new conn 153 $CONN = new conn
138 host => $CFG->{host}, 154 host => $CFG->{host},
139 port => $CFG->{port}, 155 port => $CFG->{port},
140 user => $CFG->{user}, 156 user => $CFG->{user},
146 Crossfire::Client::lowdelay fileno $CONN->{fh}; 162 Crossfire::Client::lowdelay fileno $CONN->{fh};
147} 163}
148 164
149sub stop_game { 165sub stop_game {
150 remove Glib::Source $SDL_TIMER; 166 remove Glib::Source $SDL_TIMER;
151 remove Glib::Source $refresh_handler; 167 remove Glib::Source $refresh_handler if $refresh_handler;
152 undef $refresh_handler; 168 undef $refresh_handler;
153 169
154 undef $SDL_APP; 170 undef $SDL_APP;
155 undef $CONN; 171 undef $CONN;
156 SDL::Quit; 172 SDL::Quit;
157} 173}
158 174
159
160sub force_refresh { 175sub force_refresh {
161 glViewport 0, 0, $WIDTH, $HEIGHT; 176 glViewport 0, 0, $WIDTH, $HEIGHT;
162 177
163 glMatrixMode GL_PROJECTION; 178 glMatrixMode GL_PROJECTION;
164 glLoadIdentity; 179 glLoadIdentity;
165 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; 180 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
166 glMatrixMode GL_MODELVIEW; 181 glMatrixMode GL_MODELVIEW;
167 182
168 glClear GL_COLOR_BUFFER_BIT; 183 glClear GL_COLOR_BUFFER_BIT;
169 184
170 $TOPLEVEL->draw; 185 $Crossfire::Client::Widget::TOPLEVEL->draw;
171 186
172 SDL::GLSwapBuffers; 187 SDL::GLSwapBuffers;
173} 188}
174 189
175sub refresh { 190sub refresh {
176 $refresh_handler ||= add Glib::Idle sub { 191 $refresh_handler ||= add Glib::Idle sub {
177 return unless $SDL_APP; 192 if ($SDL_APP) {
178
179 my $next_refresh = SDL::GetTicks; 193 my $next_refresh = SDL::GetTicks;
180 my $interval = ($next_refresh - $last_refresh) * 0.001; 194 my $interval = ($next_refresh - $last_refresh) * 0.001;
181 $last_refresh = $next_refresh; 195 $last_refresh = $next_refresh;
182 196
183 force_refresh; 197 force_refresh;
184 $_->animate ($interval) for grep $_, values %ANIMATE; 198 $_->animate ($interval) for grep $_, values %ANIMATE;
185 199
186 if (%ANIMATE) { 200 if (%ANIMATE) {
201 1
202 } else {
203 undef $refresh_handler;
204 0
187 1 205 }
188 } else { 206 } else {
189 undef $refresh_handler; 207 undef $refresh_handler;
190 0 208 0
191 } 209 }
192 }; 210 };
225 }, 243 },
226 SDL_KEYUP() => sub { 244 SDL_KEYUP() => sub {
227 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); 245 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
228 }, 246 },
229 SDL_MOUSEMOTION() => sub { 247 SDL_MOUSEMOTION() => sub {
230 warn "sdl motion\n";#d# 248 Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV);
231 }, 249 },
232 SDL_MOUSEBUTTONDOWN() => sub { 250 SDL_MOUSEBUTTONDOWN() => sub {
233 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); 251 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
234 }, 252 },
235 SDL_MOUSEBUTTONUP() => sub { 253 SDL_MOUSEBUTTONUP() => sub {
236 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); 254 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV);
237 }, 255 },
238 SDL_ACTIVEEVENT() => sub { 256 SDL_ACTIVEEVENT() => sub {
239 warn "active\n";#d# 257 printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
240 }, 258 },
241); 259);
242 260
243@conn::ISA = Crossfire::Protocol::; 261@conn::ISA = Crossfire::Protocol::;
244 262
381 399
382############################################################################# 400#############################################################################
383 401
384SDL::Init SDL_INIT_EVERYTHING; 402SDL::Init SDL_INIT_EVERYTHING;
385 403
386$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
387
388my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 404my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
389 405
390$TOPLEVEL->add ($mapwidget); 406$Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget);
391$mapwidget->focus_in; 407$mapwidget->focus_in;
392 408
393Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 409Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
394 410
395$CFG ||= { 411$CFG ||= {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines