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.55 by root, Sun Apr 9 22:27:52 2006 UTC vs.
Revision 1.62 by root, Mon Apr 10 19:34:04 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';
25
26our %GL_EXT;
27 25
28our $CFG; 26our $CFG;
29our $CONN; 27our $CONN;
30 28
31our $WIDTH; 29our $WIDTH;
32our $HEIGHT; 30our $HEIGHT;
33our $FULLSCREEN; 31our $FULLSCREEN;
34 32
35our $FONTSIZE; 33our $FONTSIZE;
36our $FOCUS;
37our $HOVER;
38 34
39our $SDL_TIMER; 35our $SDL_TIMER;
40our $SDL_APP; 36our $SDL_APP;
41our $SDL_EV = new SDL::Event; 37our $SDL_EV;
42our %SDL_CB; 38our %SDL_CB;
43
44our @GL_INIT; # hooks called on every gl init
45 39
46our $ALT_ENTER_MESSAGE; 40our $ALT_ENTER_MESSAGE;
47our $STATUS_LINE; 41our $STATUS_LINE;
48
49our $TOPLEVEL;
50
51our $tw; # Test widget #d#
52 42
53my $last_refresh; 43my $last_refresh;
54my %ANIMATE; 44my %ANIMATE;
55my $refresh_handler; 45my $refresh_handler;
46
47our ($tw, $te); # Test widget #d#
56 48
57sub init_screen { 49sub init_screen {
58 $SDL_APP = new SDL::App 50 $SDL_APP = new SDL::App
59 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 51 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
60 -title => "Crossfire+ Client", 52 -title => "Crossfire+ Client",
67 -alpha_size => 0, 59 -alpha_size => 0,
68 -double_buffer => 1, 60 -double_buffer => 1,
69 -fullscreen => $FULLSCREEN, 61 -fullscreen => $FULLSCREEN,
70 -resizeable => 0; 62 -resizeable => 0;
71 63
64 $SDL_EV = new SDL::Event;
65 $SDL_EV->set_unicode (1);
66
67 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
68 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
69 while $SDL_EV->poll;
70
71 1
72 };
73
72 $last_refresh = SDL::GetTicks; 74 $last_refresh = SDL::GetTicks;
73 75
74 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions; 76 Crossfire::Client::gl_init;
75
76 $GL_EXT{GL_ARB_texture_non_power_of_two}
77 or warn "WARNING: non-power-of-two opengl extension required";
78 77
79 $FONTSIZE = int $HEIGHT / 50; 78 $FONTSIZE = int $HEIGHT / 50;
80 79
81 ############################################################################# 80 #############################################################################
82 81
83 glClearColor 0, 0, 0, 0; 82 glClearColor 0.45, 0.45, 0.45, 1;
84 83
85 glEnable GL_TEXTURE_2D; 84 glEnable GL_TEXTURE_2D;
86 glEnable GL_COLOR_MATERIAL; 85 glEnable GL_COLOR_MATERIAL;
87 glShadeModel GL_FLAT; 86 glShadeModel GL_FLAT;
88 glDisable GL_DEPTH_TEST; 87 glDisable GL_DEPTH_TEST;
89 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 88 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
90 89
91 $_->() for @GL_INIT;
92
93 ############################################################################# 90 #############################################################################
94 91
95 $STATUS_LINE = new Crossfire::Client::Widget::Label 92 $STATUS_LINE = new Crossfire::Client::Widget::Label
96 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE, 93 0, $HEIGHT * 59 / 60 - $FONTSIZE, 1, $FONTSIZE,
97 ""; 94 "";
98 $TOPLEVEL->add ($STATUS_LINE); 95 $Crossfire::Client::Widget::TOPLEVEL->add ($STATUS_LINE);
99 96
100 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 97 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
101 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60, 98 0, $HEIGHT * 59 / 60, 1, $HEIGHT / 60,
102 "Use <b>Alt-Enter</b> to toggle fullscreen mode"; 99 "Use <b>Alt-Enter</b> to toggle fullscreen mode";
103 $TOPLEVEL->add ($ALT_ENTER_MESSAGE); 100 $Crossfire::Client::Widget::TOPLEVEL->add ($ALT_ENTER_MESSAGE);
104 101
105 # Test code #d# 102 # Test code #d#
106 unless ($tw) { # haha... 103 unless ($tw) { # haha...
104 $te = new Crossfire::Client::Widget::FancyFrame;
105 $te->add (new Crossfire::Client::Widget::Entry);
106 $te->move (300, 0, 2);
107 $Crossfire::Client::Widget::TOPLEVEL->add ($te);
108
107 $tw = new Crossfire::Client::Widget::Animator; 109 $tw = new Crossfire::Client::Widget::Animator;
108 my $lbl1 = new Crossfire::Client::Widget::Label 110 my $lbl1 = new Crossfire::Client::Widget::Label
109 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!"; 111 0, 0, 10, $FONTSIZE, "<i>This</i> is a\n<u>TEST</u>!\nOf a themed\nFrame!";
110 my $lbl2 = new Crossfire::Client::Widget::Label 112 my $lbl2 = new Crossfire::Client::Widget::Label
111 0, 0, 10, $FONTSIZE, "LBL2"; 113 0, 0, 10, $FONTSIZE, "LBL2";
121 $tw->add ($vb); 123 $tw->add ($vb);
122 $tw->w (400); 124 $tw->w (400);
123 $tw->h (300); 125 $tw->h (300);
124 $tw->move ($WIDTH - 200, 0); 126 $tw->move ($WIDTH - 200, 0);
125 $tw->moveto (0, 0); 127 $tw->moveto (0, 0);
126 $TOPLEVEL->add ($tw); 128 $Crossfire::Client::Widget::TOPLEVEL->add ($tw);
127 129
128# $f->move ($WIDTH - 200, 0); 130# $f->move ($WIDTH - 200, 0);
129# $TOPLEVEL->add ($f); 131# $Crossfire::Client::Widget::TOPLEVEL->add ($f);
130 } 132 }
131} 133}
132 134
135sub destroy_screen {
136 remove Glib::Source $SDL_TIMER;
137 undef $SDL_APP;
138 undef $SDL_EV;
139 SDL::Quit;
140}
141
133sub start_game { 142sub start_game {
134 $SDL_TIMER = add Glib::Timeout 1000/50, sub {
135 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
136 while $SDL_EV->poll;
137
138 1
139 };
140
141 $WIDTH = $CFG->{width}; 143 $WIDTH = $CFG->{width};
142 $HEIGHT = $CFG->{height}; 144 $HEIGHT = $CFG->{height};
143 $FULLSCREEN = 0; 145 $FULLSCREEN = 0;
144 146
145 init_screen; 147 init_screen;
146 148
147 my $mapsize = List::Util::min 64, List::Util::max 11, int $HEIGHT * $CFG->{mapsize} * 0.01 / 32; 149 my $mapsize = List::Util::min 64, List::Util::max 11, int $WIDTH * $CFG->{mapsize} * 0.01 / 32;
148 150
149 $CONN = new conn 151 $CONN = new conn
150 host => $CFG->{host}, 152 host => $CFG->{host},
151 port => $CFG->{port}, 153 port => $CFG->{port},
152 user => $CFG->{user}, 154 user => $CFG->{user},
157 159
158 Crossfire::Client::lowdelay fileno $CONN->{fh}; 160 Crossfire::Client::lowdelay fileno $CONN->{fh};
159} 161}
160 162
161sub stop_game { 163sub stop_game {
162 remove Glib::Source $SDL_TIMER;
163 remove Glib::Source $refresh_handler if $refresh_handler; 164 remove Glib::Source $refresh_handler if $refresh_handler;
164 undef $refresh_handler; 165 undef $refresh_handler;
165 166
166 undef $SDL_APP;
167 undef $CONN; 167 undef $CONN;
168 SDL::Quit; 168 destroy_screen;
169} 169}
170
171 170
172sub force_refresh { 171sub force_refresh {
173 glViewport 0, 0, $WIDTH, $HEIGHT; 172 glViewport 0, 0, $WIDTH, $HEIGHT;
174 173
175 glMatrixMode GL_PROJECTION; 174 glMatrixMode GL_PROJECTION;
176 glLoadIdentity; 175 glLoadIdentity;
177 glOrtho 0, $WIDTH, $HEIGHT, 0, -6000 , 6000; 176 glOrtho 0, $WIDTH, $HEIGHT, 0, -10000 , 10000;
178 glMatrixMode GL_MODELVIEW; 177 glMatrixMode GL_MODELVIEW;
179 178
180 glClear GL_COLOR_BUFFER_BIT; 179 glClear GL_COLOR_BUFFER_BIT;
181 180
182 $TOPLEVEL->draw; 181 $Crossfire::Client::Widget::TOPLEVEL->draw;
183 182
184 SDL::GLSwapBuffers; 183 SDL::GLSwapBuffers;
185} 184}
186 185
187sub refresh { 186sub refresh {
188 $refresh_handler ||= add Glib::Idle sub { 187 $refresh_handler ||= add Glib::Idle sub {
189 return unless $SDL_APP; 188 if ($SDL_APP) {
190
191 my $next_refresh = SDL::GetTicks; 189 my $next_refresh = SDL::GetTicks;
192 my $interval = ($next_refresh - $last_refresh) * 0.001; 190 my $interval = ($next_refresh - $last_refresh) * 0.001;
193 $last_refresh = $next_refresh; 191 $last_refresh = $next_refresh;
194 192
195 force_refresh; 193 force_refresh;
196 $_->animate ($interval) for grep $_, values %ANIMATE; 194 $_->animate ($interval) for grep $_, values %ANIMATE;
197 195
198 if (%ANIMATE) { 196 if (%ANIMATE) {
197 1
198 } else {
199 undef $refresh_handler;
200 0
199 1 201 }
200 } else { 202 } else {
201 undef $refresh_handler; 203 undef $refresh_handler;
202 0 204 0
203 } 205 }
204 }; 206 };
237 }, 239 },
238 SDL_KEYUP() => sub { 240 SDL_KEYUP() => sub {
239 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV); 241 Crossfire::Client::Widget::feed_sdl_key_up_event ($SDL_EV);
240 }, 242 },
241 SDL_MOUSEMOTION() => sub { 243 SDL_MOUSEMOTION() => sub {
242 my ($x, $y) = ($SDL_EV->motion_x, $SDL_EV->motion_y); 244 Crossfire::Client::Widget::feed_sdl_motion_event ($SDL_EV);
243 $HOVER = $TOPLEVEL->find_widget ($x, $y);
244 $self->refresh;
245
246 warn "mouse $x, $y = $HOVER\n";
247 }, 245 },
248 SDL_MOUSEBUTTONDOWN() => sub { 246 SDL_MOUSEBUTTONDOWN() => sub {
249 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV); 247 Crossfire::Client::Widget::feed_sdl_button_down_event ($SDL_EV);
250 }, 248 },
251 SDL_MOUSEBUTTONUP() => sub { 249 SDL_MOUSEBUTTONUP() => sub {
252 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV); 250 Crossfire::Client::Widget::feed_sdl_button_up_event ($SDL_EV);
253 }, 251 },
254 SDL_ACTIVEEVENT() => sub { 252 SDL_ACTIVEEVENT() => sub {
255 warn "active\n";#d# 253 printf "active %x %x\n", $SDL_EV->active_gain, $SDL_EV->active_state;#d#
256 }, 254 },
257); 255);
258 256
259@conn::ISA = Crossfire::Protocol::; 257@conn::ISA = Crossfire::Protocol::;
260 258
397 395
398############################################################################# 396#############################################################################
399 397
400SDL::Init SDL_INIT_EVERYTHING; 398SDL::Init SDL_INIT_EVERYTHING;
401 399
402$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
403
404my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 400my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
405 401
406$TOPLEVEL->add ($mapwidget); 402$Crossfire::Client::Widget::TOPLEVEL->add ($mapwidget);
407$mapwidget->focus_in; 403$mapwidget->focus_in;
408 404
409Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 405Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
410 406
411$CFG ||= { 407$CFG ||= {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines