ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.14
Committed: Fri Apr 7 16:36:44 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.13: +3 -1 lines
Log Message:
added some more options

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3 root 1.2 use strict;
4    
5 root 1.13 use Glib;
6     use Gtk2 -init;
7    
8     use SDL;
9     use SDL::App;
10     use SDL::Event;
11     use SDL::Surface;
12     use SDL::OpenGL;
13     use SDL::OpenGL::Constants;
14    
15 elmex 1.11 use Crossfire;
16 root 1.2 use Crossfire::Client;
17     use Crossfire::Protocol;
18    
19 elmex 1.10 use Client::Util;
20    
21 root 1.13 our $VERSION = '0.1';
22 root 1.2
23 elmex 1.10 our $CFG;
24 root 1.13 our $CONN;
25 root 1.2
26 root 1.13 our $SDL_TIMER;
27     our $SDL_APP;
28     our $SDL_EV = new SDL::Event;
29     our %SDL_CB;
30 root 1.2
31 root 1.13 sub init_screen {
32 root 1.2 # nuke all gl context data
33    
34 root 1.13 $SDL_APP = new SDL::App
35 root 1.5 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
36     -title => "Crossfire+ Client",
37 root 1.13 -width => $CFG->{width},
38     -height => $CFG->{height},
39 root 1.5 -opengl => 1,
40     -red_size => 8,
41     -green_size => 8,
42     -blue_size => 8,
43 root 1.2 -double_buffer => 1,
44 root 1.13 -fullscreen => $CFG->{fullscreen},
45 root 1.5 -resizeable => 0;
46 root 1.2
47     glEnable GL_TEXTURE_2D;
48 root 1.9 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
49 root 1.2 glShadeModel GL_FLAT;
50     glDisable GL_DEPTH_TEST;
51 root 1.9 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
52 root 1.8 glEnable GL_BLEND;
53 root 1.2
54 root 1.9 glMatrixMode GL_PROJECTION;
55 root 1.4 glLoadIdentity;
56 root 1.13 glOrtho 0, $CFG->{width} / 32, $CFG->{height} / 32, 0, -1 , 1;
57 root 1.4
58 root 1.2 # re-bind all textures
59     }
60    
61 root 1.13 sub start_game {
62     $SDL_TIMER = add Glib::Timeout 1000/20, sub {
63     while ($SDL_EV->poll) {
64     ($SDL_CB{$SDL_EV->type} || sub { warn "unhandled event ", $SDL_EV->type })->();
65     }
66    
67     1
68     };
69    
70     init_screen;
71    
72     $CONN = new conn
73     host => $CFG->{host},
74     port => $CFG->{port};
75     }
76    
77     sub stop_game {
78     remove Glib::Source $SDL_TIMER;
79    
80     undef $SDL_APP;
81     SDL::Quit;
82     }
83    
84 root 1.2 sub refresh {
85 root 1.8 glClearColor 0, 0, 0, 0;
86 root 1.5 glClear GL_COLOR_BUFFER_BIT;
87 root 1.2
88 root 1.13 my $map = $CONN->{map};
89 root 1.1
90 root 1.13 for my $x (0 .. $CONN->{mapw} - 1) {
91     for my $y (0 .. $CONN->{maph} - 1) {
92 root 1.1
93 root 1.2 my $cell = $map->[$x][$y]
94     or next;
95    
96 root 1.9 my $darkness = $cell->[3] * (1 / 255);
97     glColor $darkness, $darkness, $darkness;
98 root 1.8
99 root 1.2 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
100 root 1.13 my $tex = $CONN->{face}[$num]{texture} || 0;
101 root 1.2
102     glBindTexture GL_TEXTURE_2D, $tex;
103    
104     glBegin GL_QUADS;
105     glTexCoord 0, 0; glVertex $x, $y;
106 root 1.8 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 root 1.2 glEnd;
110     }
111     }
112     }
113 root 1.1
114 root 1.2 SDL::GLSwapBuffers;
115 root 1.1 }
116    
117 root 1.13 %SDL_CB = (
118     SDL_QUIT() => sub {
119     warn "sdl quit\n";#d#
120     exit;
121     },
122     SDL_VIDEORESIZE() => sub {
123     },
124     SDL_VIDEOEXPOSE() => sub {
125     refresh;
126     },
127     SDL_KEYDOWN() => sub {
128     },
129     SDL_KEYUP() => sub {
130     },
131     SDL_MOUSEMOTION() => sub {
132     warn "sdl motion\n";#d#
133     },
134     SDL_MOUSEBUTTONDOWN() => sub {
135     },
136     SDL_MOUSEBUTTONUP() => sub {
137     },
138     SDL_ACTIVEEVENT() => sub {
139     warn "active\n";#d#
140     },
141     );
142 root 1.1
143 root 1.2 @conn::ISA = Crossfire::Protocol::;
144 root 1.1
145 root 1.2 sub conn::map_update {
146 root 1.1 my ($self, $dirty) = @_;
147    
148 root 1.2 refresh;
149 root 1.1 }
150    
151 root 1.2 sub conn::map_scroll {
152 root 1.1 my ($self, $dx, $dy) = @_;
153    
154 root 1.2 refresh;
155 root 1.1 }
156    
157 root 1.2 sub conn::map_clear {
158 root 1.1 my ($self) = @_;
159    
160 root 1.2 refresh;
161 root 1.1 }
162    
163 root 1.2 sub conn::face_update {
164 root 1.1 my ($self, $num, $face) = @_;
165    
166 root 1.9 my $pb = new Gtk2::Gdk::PixbufLoader;
167     $pb->write ($face->{image});
168     $pb->close;
169 root 1.1
170 root 1.9 $pb = $pb->get_pixbuf;
171     $pb = $pb->add_alpha (0, 0, 0, 0);
172 root 1.1
173 root 1.9 glGetError();
174 root 1.2 my ($tex) = @{glGenTextures 1};
175 root 1.1
176 root 1.2 $face->{texture} = $tex;
177    
178     glBindTexture GL_TEXTURE_2D, $tex;
179     my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr;
180    
181 root 1.5 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
182 elmex 1.7 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
183 root 1.6 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
184     glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
185 root 1.2
186     glTexImage2D GL_TEXTURE_2D, 0,
187 root 1.9 GL_RGBA8,
188     $pb->get_width, $pb->get_height,
189 root 1.2 0,
190     GL_RGBA,
191     GL_UNSIGNED_BYTE,
192 root 1.9 $pb->get_pixels;
193 root 1.2 my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr;
194 root 1.1 }
195    
196     #############################################################################
197    
198 elmex 1.11 Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
199 elmex 1.10
200 root 1.13 $CFG ||= {
201     width => 640,
202     height => 480,
203     fullscreen => 0,
204     host => "crossfire.schmorp.de",
205     port => 13327,
206     };
207 elmex 1.12
208 elmex 1.14 Client::Util::run_config_dialog
209     login => sub { print "Login $_[0] with $_[1]\n" },
210     logout => sub { print "Logout" };
211 root 1.1
212 root 1.13 main Gtk2;
213 root 1.1