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.29 by elmex, Fri Apr 7 23:05:21 2006 UTC vs.
Revision 1.39 by root, Sun Apr 9 00:09:50 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 $tw; # Test widget #d#
47
39sub init_screen { 48sub init_screen {
40 $SDL_APP = new SDL::App 49 $SDL_APP = new SDL::App
41 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 50 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
42 -title => "Crossfire+ Client", 51 -title => "Crossfire+ Client",
43 -width => $CFG->{width}, 52 -width => $WIDTH,
44 -height => $CFG->{height}, 53 -height => $HEIGHT,
45 -opengl => 1, 54 -opengl => 1,
46 -red_size => 8, 55 -red_size => 8,
47 -green_size => 8, 56 -green_size => 8,
48 -blue_size => 8, 57 -blue_size => 8,
49 -double_buffer => 1, 58 -double_buffer => 1,
50 -fullscreen => $CFG->{fullscreen}, 59 -fullscreen => $FULLSCREEN,
51 -resizeable => 0; 60 -resizeable => 0;
52 61
53 $UIFONT = SDL::TTFOpenFont Crossfire::Client::find_rcfile "uifont.ttf", $CFG->{height} / 40 62 %GL_EXT = map +($_ => 1), split /\s+/, Crossfire::Client::gl_extensions;
54 or die "TTFOpenFont: $!"; 63
64 $GL_EXT{GL_ARB_texture_non_power_of_two}
65 or warn "WARNING: non-power-of-two opengl extension required";
66
67 $FONTSIZE = int $HEIGHT / 40;
68
69 $ALT_ENTER_MESSAGE = new Crossfire::Client::Widget::Label 0, $FONTSIZE, $HEIGHT - $FONTSIZE, $FONTSIZE, "Alt-Enter toggles fullscreen mode";
70 $ALT_ENTER_MESSAGE->move (0, $HEIGHT - ($ALT_ENTER_MESSAGE->size_request)[1]);
71 $ALT_ENTER_MESSAGE->activate;
72
73 # Test code #d#
74 {
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, $FONTSIZE, "Foo in the garden!");
78 $tw->add ($frm);
79
80 $tw->move (0, $HEIGHT - 120);
81 $tw->activate;
82 }
55 83
56 glClearColor 0, 0, 0, 0; 84 glClearColor 0, 0, 0, 0;
57 85
58 glEnable GL_TEXTURE_2D; 86 glEnable GL_TEXTURE_2D;
87 glEnable GL_COLOR_MATERIAL;
59 glShadeModel GL_FLAT; 88 glShadeModel GL_FLAT;
60 glDisable GL_DEPTH_TEST; 89 glDisable GL_DEPTH_TEST;
61 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 90 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
62 91
63 glMatrixMode GL_PROJECTION;
64 glLoadIdentity;
65 glOrtho 0, $CFG->{width}, $CFG->{height}, 0, -100 , 100;
66
67 glMatrixMode GL_MODELVIEW;
68
69 $_->() for @GL_INIT; 92 $_->() for @GL_INIT;
70} 93}
71 94
72my $label;#d#
73
74sub start_game { 95sub start_game {
75 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 96 $SDL_TIMER = add Glib::Timeout 1000/100, sub {
76 while ($SDL_EV->poll) {
77 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->(); 97 ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->()
78 } 98 while $SDL_EV->poll;
79 99
80 1 100 1
81 }; 101 };
82 102
103 $WIDTH = $CFG->{width};
104 $HEIGHT = $CFG->{height};
105 $FULLSCREEN = 0;
106
83 init_screen; 107 init_screen;
84
85 my $v = new Crossfire::Client::Widget::Table;
86 $v->add (0, 0, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "T");
87 $v->add (0, 1, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "TT");
88 $v->add (0, 2, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "TTT");
89 $v->add (1, 1, $label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]");
90 $v->size_request;
91 my $f = new Crossfire::Client::Widget::Frame;
92 $f->add ($v);
93 $f->activate;
94
95# $v->add ($label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]");
96# $v->add ($label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]!!");
97# $v->activate;
98# $f->add ($v);#$label = new Crossfire::Client::Widget::Label 500, 10, 1, $UIFONT, "Testü[]");
99# $label->activate;
100 108
101 $CONN = new conn 109 $CONN = new conn
102 host => $CFG->{host}, 110 host => $CFG->{host},
103 port => $CFG->{port}, 111 port => $CFG->{port},
104 user => $CFG->{user}, 112 user => $CFG->{user},
105 pass => $CFG->{password}; 113 pass => $CFG->{password},
114 mapw => 50,
115 maph => 37,
116 ;
106} 117}
107 118
108sub stop_game { 119sub stop_game {
109 remove Glib::Source $SDL_TIMER; 120 remove Glib::Source $SDL_TIMER;
110 121
111 undef $SDL_APP; 122 undef $SDL_APP;
112 SDL::Quit; 123 SDL::Quit;
113} 124}
114 125
126
127sub force_refresh {
128 glViewport 0, 0, $WIDTH, $HEIGHT;
129
130 glMatrixMode GL_PROJECTION;
131 glLoadIdentity;
132 glOrtho 0, $WIDTH, $HEIGHT, 0, -100 , 100;
133 glMatrixMode GL_MODELVIEW;
134
135 glClear GL_COLOR_BUFFER_BIT;
136
137 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS;
138
139 SDL::GLSwapBuffers;
140}
141
142my $refresh_handler;
143
115sub refresh { 144sub refresh {
116 glClear GL_COLOR_BUFFER_BIT; 145 $refresh_handler ||= add Glib::Idle sub {
117 146 force_refresh;
118 $_->draw for @Crossfire::Client::Widget::ACTIVE_WIDGETS; 147 undef $refresh_handler;
119 148 0
120 SDL::GLSwapBuffers; 149 };
121} 150}
122 151
123%SDL_CB = ( 152%SDL_CB = (
124 SDL_QUIT() => sub { 153 SDL_QUIT() => sub {
125 main_quit Gtk2; 154 main_quit Gtk2;
130 refresh; 159 refresh;
131 }, 160 },
132 SDL_KEYDOWN() => sub { 161 SDL_KEYDOWN() => sub {
133 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) {
134 # alt-enter 163 # alt-enter
135 $CFG->{fullscreen} = !$CFG->{fullscreen}; 164 $FULLSCREEN = !$FULLSCREEN;
136 init_screen; 165 init_screen;
137 } else { 166 } else {
138 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV); 167 Crossfire::Client::Widget::feed_sdl_key_down_event ($SDL_EV);
139 } 168 }
140 }, 169 },
185 my ($self, $face) = @_; 214 my ($self, $face) = @_;
186 215
187 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image}; 216 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
188 217
189 $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#
190} 225}
191 226
192sub gtk_add_cfg_field { 227sub gtk_add_cfg_field {
193 my ($tbl, $cfg, $klbl, $key, $value) = @_; 228 my ($tbl, $cfg, $klbl, $key, $value) = @_;
194 my $i = $cfg->{_i}++; 229 my $i = $cfg->{_i}++;
282 317
283 318
284############################################################################# 319#############################################################################
285 320
286SDL::Init SDL_INIT_EVERYTHING; 321SDL::Init SDL_INIT_EVERYTHING;
287SDL::TTFInit;
288 322
289my $mapwidget = Crossfire::Client::Widget::MapWidget->new; 323my $mapwidget = Crossfire::Client::Widget::MapWidget->new;
290 324
291$mapwidget->activate; 325$mapwidget->activate;
292$mapwidget->focus_in; 326$mapwidget->focus_in;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines