ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pclient
Revision: 1.16
Committed: Fri Apr 7 17:37:11 2006 UTC (18 years, 1 month ago) by elmex
Branch: MAIN
Changes since 1.15: +13 -31 lines
Log Message:
added mapwidget

File Contents

# User Rev Content
1 root 1.1 #!/opt/bin/perl
2 root 1.2 use strict;
3    
4 root 1.13 use Glib;
5     use Gtk2 -init;
6    
7     use SDL;
8     use SDL::App;
9     use SDL::Event;
10     use SDL::Surface;
11     use SDL::OpenGL;
12     use SDL::OpenGL::Constants;
13    
14 elmex 1.11 use Crossfire;
15 root 1.2 use Crossfire::Client;
16     use Crossfire::Protocol;
17    
18 elmex 1.10 use Client::Util;
19 elmex 1.15 use Client::Widget;
20 elmex 1.10
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 elmex 1.16 for (values %Client::Widget::ACTIVE_WIDGETS) {
89     $_->draw
90 root 1.2 }
91 root 1.1
92 root 1.2 SDL::GLSwapBuffers;
93 root 1.1 }
94    
95 root 1.13 %SDL_CB = (
96     SDL_QUIT() => sub {
97     warn "sdl quit\n";#d#
98     exit;
99     },
100     SDL_VIDEORESIZE() => sub {
101     },
102     SDL_VIDEOEXPOSE() => sub {
103     refresh;
104     },
105     SDL_KEYDOWN() => sub {
106 elmex 1.16 Client::Widget::feed_sdl_key_down_event ($SDL_EV);
107 root 1.13 },
108     SDL_KEYUP() => sub {
109 elmex 1.16 Client::Widget::feed_sdl_key_up_event ($SDL_EV);
110 root 1.13 },
111     SDL_MOUSEMOTION() => sub {
112     warn "sdl motion\n";#d#
113     },
114     SDL_MOUSEBUTTONDOWN() => sub {
115 elmex 1.16 Client::Widget::feed_sdl_button_down_event ($SDL_EV);
116 root 1.13 },
117     SDL_MOUSEBUTTONUP() => sub {
118 elmex 1.16 Client::Widget::feed_sdl_button_up_event ($SDL_EV);
119 root 1.13 },
120     SDL_ACTIVEEVENT() => sub {
121     warn "active\n";#d#
122     },
123     );
124 root 1.1
125 root 1.2 @conn::ISA = Crossfire::Protocol::;
126 root 1.1
127 root 1.2 sub conn::map_update {
128 root 1.1 my ($self, $dirty) = @_;
129    
130 root 1.2 refresh;
131 root 1.1 }
132    
133 root 1.2 sub conn::map_scroll {
134 root 1.1 my ($self, $dx, $dy) = @_;
135    
136 root 1.2 refresh;
137 root 1.1 }
138    
139 root 1.2 sub conn::map_clear {
140 root 1.1 my ($self) = @_;
141    
142 root 1.2 refresh;
143 root 1.1 }
144    
145 root 1.2 sub conn::face_update {
146 root 1.1 my ($self, $num, $face) = @_;
147    
148 root 1.9 my $pb = new Gtk2::Gdk::PixbufLoader;
149     $pb->write ($face->{image});
150     $pb->close;
151 root 1.1
152 root 1.9 $pb = $pb->get_pixbuf;
153     $pb = $pb->add_alpha (0, 0, 0, 0);
154 root 1.1
155 root 1.9 glGetError();
156 root 1.2 my ($tex) = @{glGenTextures 1};
157 root 1.1
158 root 1.2 $face->{texture} = $tex;
159    
160     glBindTexture GL_TEXTURE_2D, $tex;
161     my $glerr=glGetError(); die "a: ".gluErrorString($glerr)."\n" if $glerr;
162    
163 root 1.5 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR;
164 elmex 1.7 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR;#_MIPMAP_LINEAR;
165 root 1.6 glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP;
166     glTexParameter GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP;
167 root 1.2
168     glTexImage2D GL_TEXTURE_2D, 0,
169 root 1.9 GL_RGBA8,
170     $pb->get_width, $pb->get_height,
171 root 1.2 0,
172     GL_RGBA,
173     GL_UNSIGNED_BYTE,
174 root 1.9 $pb->get_pixels;
175 root 1.2 my $glerr=glGetError(); die "Problem setting up 2d Texture (dimensions not a power of 2?)):".gluErrorString($glerr)."\n" if $glerr;
176 root 1.1 }
177    
178     #############################################################################
179    
180 elmex 1.16 my $mapwidget = Client::MapWidget->new;
181    
182     $mapwidget->activate;
183     $mapwidget->focus_in;
184    
185 elmex 1.11 Client::Util::read_cfg "$Crossfire::VARDIR/pclientrc";
186 elmex 1.10
187 root 1.13 $CFG ||= {
188     width => 640,
189     height => 480,
190     fullscreen => 0,
191     host => "crossfire.schmorp.de",
192     port => 13327,
193     };
194 elmex 1.12
195 elmex 1.14 Client::Util::run_config_dialog
196 elmex 1.16 login => sub { start_game },
197     logout => sub { stop_game };
198 root 1.1
199 root 1.13 main Gtk2;