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.23 by elmex, Fri Apr 7 20:15:01 2006 UTC vs.
Revision 1.37 by root, Sat Apr 8 22:25:37 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
2use strict; 3use strict;
4use utf8;
3 5
4use Glib; 6use Glib;
5use Gtk2 -init; 7use Gtk2 -init;
6 8
7use SDL; 9use SDL;
13 15
14use Crossfire; 16use Crossfire;
15use Crossfire::Client; 17use Crossfire::Client;
16use Crossfire::Protocol; 18use Crossfire::Protocol;
17 19
18use Crossfire::Client::Util;
19use Crossfire::Client::Widget; 20use Crossfire::Client::Widget;
20 21
21our $FACECACHE; 22our $FACECACHE;
22 23
23our $VERSION = '0.1'; 24our $VERSION = '0.1';
25
26our %GL_EXT;
24 27
25our $CFG; 28our $CFG;
26our $CONN; 29our $CONN;
30
31our $WIDTH;
32our $HEIGHT;
33our $FULLSCREEN;
34
35our $UIFONT;
27 36
28our $SDL_TIMER; 37our $SDL_TIMER;
29our $SDL_APP; 38our $SDL_APP;
30our $SDL_EV = new SDL::Event; 39our $SDL_EV = new SDL::Event;
31our %SDL_CB; 40our %SDL_CB;
32 41
33our @GL_INIT; # hooks called on every gl init 42our @GL_INIT; # hooks called on every gl init
34 43
44our $ALT_ENTER_MESSAGE;
45
46our $tw; # Test widget #d#
47
35sub init_screen { 48sub init_screen {
36 $SDL_APP = new SDL::App 49 $SDL_APP = new SDL::App
37 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 50 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
38 -title => "Crossfire+ Client", 51 -title => "Crossfire+ Client",
39 -width => $CFG->{width}, 52 -width => $WIDTH,
40 -height => $CFG->{height}, 53 -height => $HEIGHT,
41 -opengl => 1, 54 -opengl => 1,
42 -red_size => 8, 55 -red_size => 8,
43 -green_size => 8, 56 -green_size => 8,
44 -blue_size => 8, 57 -blue_size => 8,
45 -double_buffer => 1, 58 -double_buffer => 1,
46 -fullscreen => $CFG->{fullscreen}, 59 -fullscreen => $FULLSCREEN,
47 -resizeable => 0; 60 -resizeable => 0;
48 61
62 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
63
64 $GL_EXT{GL_ARB_texture_non_power_of_two}
65 or warn "WARNING: non-power-of-two opengl extension required";
66
67 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $HEIGHT / 40
68 or die "TTFOpenFont: $!";
69
70 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $HEIGHT - $HEIGHT / 40, 10, $UIFONT, "Alt-Enter toggles fullscreen mode";
71 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
72 $ALT_ENTER_MESSAGE->activate;
73
74 # Test code #d#
75 my $frm = new Crossfire::Client::Widget::Frame;
76 $tw = new Crossfire::Client::Widget::Window;
77 $frm->add (new Crossfire::Client::Widget::Label 0, 0, 10, $UIFONT, "Foo in the garden!");
78 $tw->add ($frm);
79
80 $tw->move (0, $HEIGHT - 120);
81 $tw->activate;
82 # Test code end #d#
83
49 glClearColor 0, 0, 0, 0; 84 glClearColor 0, 0, 0, 0;
50 85
51 glEnable GL_TEXTURE_2D; 86 glEnable GL_TEXTURE_2D;
52 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 87 glEnable GL_COLOR_MATERIAL;
53 glShadeModel GL_FLAT; 88 glShadeModel GL_FLAT;
54 glDisable GL_DEPTH_TEST; 89 glDisable GL_DEPTH_TEST;
55 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 90 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
56 glEnable GL_BLEND; 91
92 $_->() for @GL_INIT;
93}
94
95sub start_game {
96 $SDL_TIMER = add Glib::Timeout 1000/100, sub {
97 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
98 while $SDL_EV->poll;
99
100 1
101 };
102
103 $WIDTH = $CFG->{width};
104 $HEIGHT = $CFG->{height};
105 $FULLSCREEN = 0;
106
107 init_screen;
108
109 $CONN = new conn
110 host => $CFG->{host},
111 port => $CFG->{port},
112 user => $CFG->{user},
113 pass => $CFG->{password},
114 mapw => 50,
115 maph => 37,
116 ;
117}
118
119sub stop_game {
120 remove Glib::Source $SDL_TIMER;
121
122 undef $SDL_APP;
123 SDL::Quit;
124}
125
126
127sub force_refresh {
128 glViewport 0, 0, $WIDTH, $HEIGHT;
57 129
58 glMatrixMode GL_PROJECTION; 130 glMatrixMode GL_PROJECTION;
59 glLoadIdentity; 131 glLoadIdentity;
60 glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -100 , 100; 132 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
61
62 glMatrixMode GL_MODELVIEW; 133 glMatrixMode GL_MODELVIEW;
63 134
64 $_->() for @GL_INIT; 135 glClear GL_COLOR_BUFFER_BIT;
65}
66 136
67sub start_game { 137 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS;
68 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 138
69 while ($SDL_EV->poll) { 139 SDL::GLSwapBuffers;
70 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); 140}
141
142my $refresh_handler;
143
144sub refresh {
145 $refresh_handler ||= add Glib::Idle sub {
146 force_refresh;
147 undef $refresh_handler;
71 } 148 0
72
73 1
74 }; 149 };
75
76 init_screen;
77
78 $CONN = new conn
79 host => $CFG->{host},
80 port => $CFG->{port};
81}
82
83sub stop_game {
84 remove Glib::Source $SDL_TIMER;
85
86 undef $SDL_APP;
87 SDL::Quit;
88}
89
90sub refresh {
91 glClear GL_COLOR_BUFFER_BIT;
92
93 $_->draw for values %Crossfire::Client::Widget::ACTIVE_WIDGETS;
94
95 SDL::GLSwapBuffers;
96} 150}
97 151
98%SDL_CB = ( 152%SDL_CB = (
99 SDL_QUIT() => sub { 153 SDL_QUIT() => sub {
100 main_quit Gtk2; 154 main_quit Gtk2;
105 refresh; 159 refresh;
106 }, 160 },
107 SDL_KEYDOWN() => sub { 161 SDL_KEYDOWN() => sub {
108 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) { 162 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
109 # alt-enter 163 # alt-enter
110 $CFG->{fullscreen} = !$CFG->{fullscreen}; 164 $FULLSCREEN = !$FULLSCREEN;
111 init_screen; 165 init_screen;
112 } else { 166 } else {
113 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); 167 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
114 } 168 }
115 }, 169 },
160 my ($self, $face) = @_; 214 my ($self, $face) = @_;
161 215
162 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 216 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
163 217
164 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image}; 218 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
219}
220
221sub conn::query {
222 my ($self, $flags, $prompt) = @_;
223
224 warn "<<<<QUERY:$flags:$prompt>>>\n";#d#
165} 225}
166 226
167sub gtk_add_cfg_field { 227sub gtk_add_cfg_field {
168 my ($tbl, $cfg, $klbl, $key, $value) = @_; 228 my ($tbl, $cfg, $klbl, $key, $value) = @_;
169 my $i = $cfg->{_i}++; 229 my $i = $cfg->{_i}++;
256} 316}
257 317
258 318
259############################################################################# 319#############################################################################
260 320
261SDL::Init(SDL_INIT_EVERYTHING()); 321SDL::Init SDL_INIT_EVERYTHING;
322SDL::TTFInit;
262 323
263my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 324my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
264
265find_rcfile "uifont.ttf";
266 325
267$mapwidget->activate; 326$mapwidget->activate;
268$mapwidget->focus_in; 327$mapwidget->focus_in;
269 328
270Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc"; 329Crossfire::Client::read_cfg "$Crossfire::VARDIR/pclientrc";
271
272$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
273 330
274$CFG ||= { 331$CFG ||= {
275 width => 640, 332 width => 640,
276 height => 480, 333 height => 480,
277 fullscreen => 0, 334 fullscreen => 0,
278 host => "crossfire.schmorp.de", 335 host => "crossfire.schmorp.de",
279 port => 13327, 336 port => 13327,
280}; 337};
281 338
339$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
340
282run_config_dialog 341run_config_dialog
283 login => sub { start_game }, 342 login => sub { start_game },
284 logout => sub { stop_game }; 343 logout => sub { stop_game };
285 344
286main Gtk2; 345main Gtk2;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines