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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines