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.13 by root, Fri Apr 7 16:30:23 2006 UTC vs.
Revision 1.19 by root, Fri Apr 7 19:33:42 2006 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2
3use strict; 2use strict;
4 3
5use Glib; 4use Glib;
6use Gtk2 -init; 5use Gtk2 -init;
7 6
15use Crossfire; 14use Crossfire;
16use Crossfire::Client; 15use Crossfire::Client;
17use Crossfire::Protocol; 16use Crossfire::Protocol;
18 17
19use Client::Util; 18use Client::Util;
19use Client::Widget;
20
21our $FACECACHE;
20 22
21our $VERSION = '0.1'; 23our $VERSION = '0.1';
22 24
23our $CFG; 25our $CFG;
24our $CONN; 26our $CONN;
26our $SDL_TIMER; 28our $SDL_TIMER;
27our $SDL_APP; 29our $SDL_APP;
28our $SDL_EV = new SDL::Event; 30our $SDL_EV = new SDL::Event;
29our %SDL_CB; 31our %SDL_CB;
30 32
33our @GL_INIT; # hooks called on every gl init
34
31sub init_screen { 35sub init_screen {
32 # nuke all gl context data
33
34 $SDL_APP = new SDL::App 36 $SDL_APP = new SDL::App
35 -flags => SDL_ANYFORMAT | SDL_HWSURFACE, 37 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
36 -title => "Crossfire+ Client", 38 -title => "Crossfire+ Client",
37 -width => $CFG->{width}, 39 -width => $CFG->{width},
38 -height => $CFG->{height}, 40 -height => $CFG->{height},
42 -blue_size => 8, 44 -blue_size => 8,
43 -double_buffer => 1, 45 -double_buffer => 1,
44 -fullscreen => $CFG->{fullscreen}, 46 -fullscreen => $CFG->{fullscreen},
45 -resizeable => 0; 47 -resizeable => 0;
46 48
49 glClearColor 0, 0, 0, 0;
50
47 glEnable GL_TEXTURE_2D; 51 glEnable GL_TEXTURE_2D;
48 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE; 52 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
49 glShadeModel GL_FLAT; 53 glShadeModel GL_FLAT;
50 glDisable GL_DEPTH_TEST; 54 glDisable GL_DEPTH_TEST;
51 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA; 55 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
52 glEnable GL_BLEND; 56 glEnable GL_BLEND;
53 57
54 glMatrixMode GL_PROJECTION; 58 glMatrixMode GL_PROJECTION;
55 glLoadIdentity; 59 glLoadIdentity;
56 glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1; 60 glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -100 , 100;
57 61
58 # re-bind all textures 62 glMatrixMode GL_MODELVIEW;
63
64 $_->() for @GL_INIT;
59} 65}
60 66
61sub start_game { 67sub start_game {
62 $SDL_TIMER = add Glib::Timeout 1000/20, sub { 68 $SDL_TIMER = add Glib::Timeout 1000/20, sub {
63 while ($SDL_EV->poll) { 69 while ($SDL_EV->poll) {
80 undef $SDL_APP; 86 undef $SDL_APP;
81 SDL::Quit; 87 SDL::Quit;
82} 88}
83 89
84sub refresh { 90sub refresh {
85 glClearColor 0, 0, 0, 0;
86 glClear GL_COLOR_BUFFER_BIT; 91 glClear GL_COLOR_BUFFER_BIT;
87 92
88 my $map = $CONN->{map}; 93 for (values %Client::Widget::ACTIVE_WIDGETS) {
89 94 $_->draw
90 for my $x (0 .. $CONN->{mapw} - 1) {
91 for my $y (0 .. $CONN->{maph} - 1) {
92
93 my $cell = $map->[$x][$y]
94 or next;
95
96 my $darkness = $cell->[3] * (1 / 255);
97 glColor $darkness, $darkness, $darkness;
98
99 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
100 my $tex = $CONN->{face}[$num]{texture} || 0;
101
102 glBindTexture GL_TEXTURE_2D, $tex;
103
104 glBegin GL_QUADS;
105 glTexCoord 0, 0; glVertex $x, $y;
106 glTexCoord 0, 1; glVertex $x, $y + 1;
107 glTexCoord 1, 1; glVertex $x + 1, $y + 1;
108 glTexCoord 1, 0; glVertex $x + 1, $y;
109 glEnd;
110 }
111 }
112 } 95 }
113 96
114 SDL::GLSwapBuffers; 97 SDL::GLSwapBuffers;
115} 98}
116 99
117%SDL_CB = ( 100%SDL_CB = (
118 SDL_QUIT() => sub { 101 SDL_QUIT() => sub {
119 warn "sdl quit\n";#d# 102 warn "sdl quit\n";#d#
120 exit; 103 main_quit Gtk2;
121 }, 104 },
122 SDL_VIDEORESIZE() => sub { 105 SDL_VIDEORESIZE() => sub {
123 }, 106 },
124 SDL_VIDEOEXPOSE() => sub { 107 SDL_VIDEOEXPOSE() => sub {
125 refresh; 108 refresh;
126 }, 109 },
127 SDL_KEYDOWN() => sub { 110 SDL_KEYDOWN() => sub {
111 if ($SDL_EV->key_mod & KMOD_ALT && $SDL_EV->key_sym == SDLK_RETURN) {
112 # alt-enter
113 $CFG->{fullscreen} = !$CFG->{fullscreen};
114 init_screen;
115 } else {
116 Client::Widget::feed_sdl_key_down_event ($SDL_EV);
117 }
128 }, 118 },
129 SDL_KEYUP() => sub { 119 SDL_KEYUP() => sub {
120 Client::Widget::feed_sdl_key_up_event ($SDL_EV);
130 }, 121 },
131 SDL_MOUSEMOTION() => sub { 122 SDL_MOUSEMOTION() => sub {
132 warn "sdl motion\n";#d# 123 warn "sdl motion\n";#d#
133 }, 124 },
134 SDL_MOUSEBUTTONDOWN() => sub { 125 SDL_MOUSEBUTTONDOWN() => sub {
126 Client::Widget::feed_sdl_button_down_event ($SDL_EV);
135 }, 127 },
136 SDL_MOUSEBUTTONUP() => sub { 128 SDL_MOUSEBUTTONUP() => sub {
129 Client::Widget::feed_sdl_button_up_event ($SDL_EV);
137 }, 130 },
138 SDL_ACTIVEEVENT() => sub { 131 SDL_ACTIVEEVENT() => sub {
139 warn "active\n";#d# 132 warn "active\n";#d#
140 }, 133 },
141); 134);
158 my ($self) = @_; 151 my ($self) = @_;
159 152
160 refresh; 153 refresh;
161} 154}
162 155
156sub conn::face_find {
157 my ($self, $face) = @_;
158
159 $FACECACHE->{"$face->{chksum},$face->{name}"}
160}
161
163sub conn::face_update { 162sub conn::face_update {
164 my ($self, $num, $face) = @_; 163 my ($self, $face) = @_;
165 164
166 my $pb = new Gtk2::Gdk::PixbufLoader; 165 $FACECACHE->{"$face->{chksum},$face->{name}"} = $face->{image};
167 $pb->write ($face->{image});
168 $pb->close;
169 166
170 $pb = $pb->get_pixbuf; 167 $face->{texture} = new_from_image Crossfire::Client::Texture delete $face->{image};
171 $pb = $pb->add_alpha (0, 0, 0, 0);
172
173 glGetError();
174 my ($tex) = @{glGenTextures 1};
175
176 $face->{texture} = $tex;
177
178 glBindTexture GL_TEXTURE_2D, $tex;
179 my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr;
180
181 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
182 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
183 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
184 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
185
186 glTexImage2D GL_TEXTURE_2D, 0,
187 GL_RGBA8,
188 $pb->get_width, $pb->get_height,
189 0,
190 GL_RGBA,
191 GL_UNSIGNED_BYTE,
192 $pb->get_pixels;
193 my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr;
194} 168}
195 169
196############################################################################# 170#############################################################################
197 171
172my $mapwidget = Client::MapWidget->new;
173
174$mapwidget->activate;
175$mapwidget->focus_in;
176
198Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc"; 177Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
178
179$FACECACHE = eval { Crossfire::load_ref "$Crossfire::VARDIR/pclient.faces" } || {};
199 180
200$CFG ||= { 181$CFG ||= {
201 width => 640, 182 width => 640,
202 height => 480, 183 height => 480,
203 fullscreen => 0, 184 fullscreen => 0,
204 host => "crossfire.schmorp.de", 185 host => "crossfire.schmorp.de",
205 port => 13327, 186 port => 13327,
206}; 187};
207 188
208Client::Util::run_config_dialog; 189Client::Util::run_config_dialog
190 login => sub { start_game },
191 logout => sub { stop_game };
209 192
210main Gtk2; 193main Gtk2;
211 194
195Crossfire::save_ref $FACECACHE, "$Crossfire::VARDIR/pclient.faces";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines