ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.10
Committed: Fri Apr 7 16:04:03 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.9: +7 -1 lines
Log Message:
added config stuff

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2    
3 root 1.2 use strict;
4    
5     use Crossfire::Client;
6     use Crossfire::Protocol;
7    
8 elmex 1.10 use Client::Util;
9    
10 root 1.2 package Crossfire::Client; # uh, yeah
11    
12     use strict;
13    
14 elmex 1.10 our $CFG;
15     our $VERSION = '0.1';
16    
17 root 1.1 use SDL;
18     use SDL::App;
19     use SDL::Event;
20     use SDL::Surface;
21 root 1.2 use SDL::OpenGL;
22     use SDL::OpenGL::Constants;
23 root 1.1
24     my $conn;
25 root 1.2 my $app;
26    
27     my $WIDTH = 640;
28     my $HEIGHT = 480;
29    
30     sub glinit {
31     # nuke all gl context data
32    
33     $app = new SDL::App
34 root 1.5 -flags => SDL_ANYFORMAT | SDL_HWSURFACE,
35     -title => "Crossfire+ Client",
36     -width => $WIDTH,
37     -height => $HEIGHT,
38     -opengl => 1,
39     -red_size => 8,
40     -green_size => 8,
41     -blue_size => 8,
42 root 1.2 -double_buffer => 1,
43 root 1.5 -resizeable => 0;
44 root 1.2
45     glEnable GL_TEXTURE_2D;
46 root 1.9 glTexEnv GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE;
47 root 1.2 glShadeModel GL_FLAT;
48     glDisable GL_DEPTH_TEST;
49 root 1.9 glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA;
50 root 1.8 glEnable GL_BLEND;
51 root 1.2
52 root 1.9 glMatrixMode GL_PROJECTION;
53 root 1.4 glLoadIdentity;
54     glOrtho 0, $WIDTH / 32, $HEIGHT / 32, 0, -1 , 1;
55    
56 root 1.2 # re-bind all textures
57     }
58    
59     sub refresh {
60 root 1.8 glClearColor 0, 0, 0, 0;
61 root 1.5 glClear GL_COLOR_BUFFER_BIT;
62 root 1.2
63     my $map = $conn->{map};
64 root 1.1
65 root 1.2 for my $x (0 .. $conn->{mapw} - 1) {
66     for my $y (0 .. $conn->{maph} - 1) {
67 root 1.1
68 root 1.2 my $cell = $map->[$x][$y]
69     or next;
70    
71 root 1.9 my $darkness = $cell->[3] * (1 / 255);
72     my $darkness = 0.8 + 0.2*rand;
73     glColor $darkness, $darkness, $darkness;
74 root 1.8
75 root 1.2 for my $num (grep $_, $cell->[0], $cell->[1], $cell->[2]) {
76 root 1.3 my $tex = $conn->{face}[$num]{texture} || 0;
77 root 1.2
78     glBindTexture GL_TEXTURE_2D, $tex;
79    
80     glBegin GL_QUADS;
81     glTexCoord 0, 0; glVertex $x, $y;
82 root 1.8 glTexCoord 0, 1; glVertex $x, $y + 1;
83     glTexCoord 1, 1; glVertex $x + 1, $y + 1;
84     glTexCoord 1, 0; glVertex $x + 1, $y;
85 root 1.2 glEnd;
86     }
87     }
88     }
89 root 1.1
90 root 1.2 SDL::GLSwapBuffers;
91 root 1.1 }
92    
93     my $ev = new SDL::Event;
94     my %ev_cb;
95    
96     sub event(&$) {
97     $ev_cb{$_[0]->()} = $_[1];
98     }
99    
100     sub does(&) { shift }
101    
102     event {SDL_QUIT} does {
103     exit;
104     };
105    
106     event {SDL_VIDEORESIZE} does {
107     print "resize\n";
108     };
109    
110 root 1.4 event {SDL_VIDEOEXPOSE} does {
111     refresh;
112     };
113    
114 root 1.1 event {SDL_KEYDOWN} does {
115     print "keypress\n";
116     };
117    
118     event {SDL_KEYUP} does {
119     print "keyup\n";#d#
120     };
121    
122     event {SDL_MOUSEMOTION} does {
123     print "motion\n";
124     };
125    
126     event {SDL_MOUSEBUTTONDOWN} does {
127     print "button\n";
128     };
129    
130     event {SDL_MOUSEBUTTONUP} does {
131     print "buttup\n";
132     };
133    
134     event {SDL_ACTIVEEVENT} does {
135     print "active\n";
136     };
137    
138 root 1.2 package Crossfire::Client;
139 root 1.1
140 root 1.2 @conn::ISA = Crossfire::Protocol::;
141 root 1.1
142 root 1.2 sub conn::map_update {
143 root 1.1 my ($self, $dirty) = @_;
144    
145 root 1.2 refresh;
146 root 1.1 }
147    
148 root 1.2 sub conn::map_scroll {
149 root 1.1 my ($self, $dx, $dy) = @_;
150    
151 root 1.2 refresh;
152 root 1.1 }
153    
154 root 1.2 sub conn::map_clear {
155 root 1.1 my ($self) = @_;
156    
157 root 1.2 refresh;
158 root 1.1 }
159    
160 root 1.2 sub conn::face_update {
161 root 1.1 my ($self, $num, $face) = @_;
162    
163     warn "up face $self,$num,$face\n";#d#
164 root 1.9 use Gtk2;
165 root 1.1
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     use Event;
199    
200 elmex 1.10 Client::Util::read_cfg "$Crossfire::VARDIR/pclient";
201    
202 root 1.2 glinit;
203    
204 root 1.1 $conn = new conn
205     host => "cf.schmorp.de",
206     port => 13327;
207    
208     Event->timer (after => 0, interval => 1/20, hard => 1, cb => sub {
209     while ($ev->poll) {
210     ($ev_cb{$ev->type} || sub { warn "unhandled event ", $ev->type })->();
211     }
212     });
213    
214     Event::loop;
215