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.25 by root, Fri Apr 7 20:55:32 2006 UTC vs.
Revision 1.41 by elmex, Sun Apr 9 01:21:11 2006 UTC

15 15
16use Crossfire; 16use Crossfire;
17use Crossfire::Client; 17use Crossfire::Client;
18use Crossfire::Protocol; 18use Crossfire::Protocol;
19 19
20use Crossfire::Client::Util;
21use Crossfire::Client::Widget; 20use Crossfire::Client::Widget;
22 21
23our $FACECACHE; 22our $FACECACHE;
24 23
25our $VERSION = '0.1'; 24our $VERSION = '0.1';
25
26our %GL_EXT;
26 27
27our $CFG; 28our $CFG;
28our $CONN; 29our $CONN;
29 30
31our $WIDTH;
32our $HEIGHT;
33our $FULLSCREEN;
34
30our $UIFONT; 35our $FONTSIZE;
31 36
32our $SDL_TIMER; 37our $SDL_TIMER;
33our $SDL_APP; 38our $SDL_APP;
34our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
35our %SDL_CB; 40our %SDL_CB;
36 41
37our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
38 43
44our $ALT_ENTER_MESSAGE;
45
46our $TOPLEVEL;
47
48our $tw; # Test widget #d#
49
39sub init_screen { 50sub init_screen {
40 $SDL_APP = new SDL::App 51 $SDL_APP = new SDL::App
41 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 52 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
42 -title => "Crossfire+ Client", 53 -title => "Crossfire+ Client",
43 -width => $CFG->{width}, 54 -width => $WIDTH,
44 -height => $CFG->{height}, 55 -height => $HEIGHT,
45 -opengl => 1, 56 -opengl => 1,
46 -red_size => 8, 57 -red_size => 8,
47 -green_size => 8, 58 -green_size => 8,
48 -blue_size => 8, 59 -blue_size => 8,
49 -double_buffer => 1, 60 -double_buffer => 1,
50 -fullscreen => $CFG->{fullscreen}, 61 -fullscreen => $FULLSCREEN,
51 -resizeable => 0; 62 -resizeable => 0;
52 63
64 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
65
66 $GL_EXT{GL_ARB_texture_non_power_of_two}
67 or warn "WARNING: non-power-of-two opengl extension required";
68
69 $FONTSIZE = int $HEIGHT / 50;
70
71 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label
72 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE,
73 "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);
76
77 # Test code #d#
78 {
79 my $frm = new Crossfire::Client::Widget::Frame;
80 $tw = new Crossfire::Client::Widget::Window;
81 $frm->add (my $te = new Crossfire::Client::Widget::TextEntry 0, 0, 10, $FONTSIZE, "Foo in the garden!");
82 $tw->add ($frm);
83
84 $tw->move (0, $HEIGHT - 120);
85 $TOPLEVEL->add ($tw);
86# $te->focus_in;
87 }
88
53 glClearColor 0, 0, 0, 0; 89 glClearColor 0, 0, 0, 0;
54 90
55 glEnable GL_TEXTURE_2D; 91 glEnable GL_TEXTURE_2D;
92 glEnable GL_COLOR_MATERIAL;
56 glShadeModel GL_FLAT; 93 glShadeModel GL_FLAT;
57 glDisable GL_DEPTH_TEST; 94 glDisable GL_DEPTH_TEST;
58 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 95 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
59 96
97 $_->() for @GL_INIT;
98}
99
100sub start_game {
101 $SDL_TIMER = add Glib::Timeout 1000/100, sub {
102 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
103 while $SDL_EV->poll;
104
105 1
106 };
107
108 $WIDTH = $CFG->{width};
109 $HEIGHT = $CFG->{height};
110 $FULLSCREEN = 0;
111
112 init_screen;
113
114 $CONN = new conn
115 host => $CFG->{host},
116 port => $CFG->{port},
117 user => $CFG->{user},
118 pass => $CFG->{password},
119 mapw => 50,
120 maph => 37,
121 ;
122}
123
124sub stop_game {
125 remove Glib::Source $SDL_TIMER;
126
127 undef $SDL_APP;
128 SDL::Quit;
129}
130
131
132sub force_refresh {
133 glViewport 0, 0, $WIDTH, $HEIGHT;
134
60 glMatrixMode GL_PROJECTION; 135 glMatrixMode GL_PROJECTION;
61 glLoadIdentity; 136 glLoadIdentity;
62 glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100; 137 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
63
64 glMatrixMode GL_MODELVIEW; 138 glMatrixMode GL_MODELVIEW;
65 139
66 $_->() for @GL_INIT; 140 glClear GL_COLOR_BUFFER_BIT;
67}
68 141
69my $label;#d# 142 $TOPLEVEL->draw;
70 143
71sub start_game { 144 SDL::GLSwapBuffers;
72 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 145}
73 while ($SDL_EV->poll) { 146
74 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); 147my $refresh_handler;
148
149sub refresh {
150 $refresh_handler ||= add Glib::Idle sub {
151 force_refresh;
152 undef $refresh_handler;
75 } 153 0
76
77 1
78 }; 154 };
79
80 init_screen;
81
82 $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]";
83 $label->activate;
84
85 $CONN = new conn
86 host => $CFG->{host},
87 port => $CFG->{port};
88}
89
90sub stop_game {
91 remove Glib::Source $SDL_TIMER;
92
93 undef $SDL_APP;
94 SDL::Quit;
95}
96
97sub refresh {
98 glClear GL_COLOR_BUFFER_BIT;
99
100 $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS;
101
102 SDL::GLSwapBuffers;
103} 155}
104 156
105%SDL_CB = ( 157%SDL_CB = (
106 SDL_QUIT() => sub { 158 SDL_QUIT() => sub {
107 main_quit Gtk2; 159 main_quit Gtk2;
112 refresh; 164 refresh;
113 }, 165 },
114 SDL_KEYDOWN() => sub { 166 SDL_KEYDOWN() => sub {
115 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 167 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
116 # alt-enter 168 # alt-enter
117 $CFG->{fullscreen} = !$CFG->{fullscreen}; 169 $FULLSCREEN = !$FULLSCREEN;
118 init_screen; 170 init_screen;
119 } else { 171 } else {
120 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); 172 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
121 } 173 }
122 }, 174 },
167 my ($self, $face) = @_; 219 my ($self, $face) = @_;
168 220
169 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 221 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
170 222
171 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; 223 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
224}
225
226sub conn::query {
227 my ($self, $flags, $prompt) = @_;
228
229 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
172} 230}
173 231
174sub gtk_add_cfg_field { 232sub gtk_add_cfg_field {
175 my ($tbl, $cfg, $klbl, $key, $value) = @_; 233 my ($tbl, $cfg, $klbl, $key, $value) = @_;
176 my $i = $cfg->{_i}++; 234 my $i = $cfg->{_i}++;
265 323
266############################################################################# 324#############################################################################
267 325
268SDL::Init SDL_INIT_EVERYTHING; 326SDL::Init SDL_INIT_EVERYTHING;
269 327
328$TOPLEVEL = Crossfire::Client::Widget::Toplevel->new;
329
270my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 330my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
271 331
272$mapwidget->activate; 332$TOPLEVEL->add ($mapwidget);
273$mapwidget->focus_in; 333$mapwidget->focus_in;
274 334
275Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 335Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
276 336
277$CFG ||= { 337$CFG ||= {
280 fullscreen => 0, 340 fullscreen => 0,
281 host => "crossfire.schmorp.de", 341 host => "crossfire.schmorp.de",
282 port => 13327, 342 port => 13327,
283}; 343};
284 344
345Crossfire::Client::add_font Crossfire::Client::find_rcfile "uifont.ttf";
346Crossfire::Client::set_font "[Bitstream Vera Sans Mono]";
347
285$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {}; 348$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
286
287SDL::TTFInit;
288
289$UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", 24
290 or die "TTFOpenFont: $!";
291 349
292run_config_dialog 350run_config_dialog
293 login => sub { start_game }, 351 login => sub { start_game },
294 logout => sub { stop_game }; 352 logout => sub { stop_game };
295 353

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines